3 # Système de gestion des adhésions de Nos oignons
4 # Copyright © 2013-2014 Nos oignons <contact@nos-oignons.net>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 create_directory NosOignons::MEMBERS_DB_DIR
21 @member_db_path = expand_path(NosOignons::MEMBERS_DB_DIR)
22 ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] = expand_path('.')
25 def new_member_data(name, joined_on, paid_on)
27 'address' => "At #{name}",
28 'email' => "#{name.downcase}@example.org",
29 'joined_on' => joined_on,
30 'membership_fee_paid_on' => paid_on
34 def add_member(member_data)
35 @last_member = member_data
36 init_db unless @member_db_path
37 file = member_filename_for_id(new_id)
38 File.write file, render_member_file(@last_member)
41 def create_new_member(*args)
42 add_member(new_member_data(*args))
45 Given /une base de membres vide$/ do
49 Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa cotisation cette année)$/ do |name, uptodate|
51 joined_on = (Time.now - 3600*24*30*15).strftime('%Y-%m-%d')
53 when ', à jour de cotisation'
55 paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
59 create_new_member(name, joined_on, paid_on)
62 Given /^une base avec (\w+) qui a adhéré le ([0-9-]+) et payé sa dernière cotisation le ([0-9-]+)$/ do |name, joined_on, paid_on|
63 create_new_member(name, joined_on, paid_on)
66 Given /^une base avec (\w+), membre (\w+), ayant cotisé le ([0-9-]+)$/ do |name, member_id, paid_on|
67 create_new_member(name, paid_on, paid_on)
68 expect(File.read(member_filename_for_id(member_id))).to include(name)
71 Given /^une base avec (\w+), membre (\w+), n'ayant jamais cotisé$/ do |name, member_id|
72 joined_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
73 create_new_member(name, joined_on, nil)
74 expect(File.read(member_filename_for_id(member_id))).to include(name)
77 Given /^une base avec uniquement (\w+), membre (\w+)$/ do |name, member_id|
78 paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
79 create_new_member(name, paid_on, paid_on)
80 member_path = File.join(member_filename_for_id(member_id))
81 expect(File.read(member_path)).to include(name)
82 expect(Dir.glob("#{@member_db_path}/[0-9]*").size).to eq(1)
85 Given /^(?:une base )?avec (\w+) (ayant une adresse postale et |qui n'a pas d'adresse postale et )?qui doit renouveler sa cotisation d'ici (\d+) jours$/ do |name, address_status, days_before_anniversary|
87 paid_on = Time.new(now.year - 1, now.month, now.day).to_date + days_before_anniversary.to_i
89 member_data = new_member_data(name, joined_on, paid_on)
92 member_data['address'] = "At #{name}'s"
94 member_data.delete('address')
96 add_member(member_data)
99 Given /^une nouvelle adhésion de (\w+)$/ do |name|
100 joined_on = Time.now.strftime('%Y-%m-%d')
101 create_new_member(name, joined_on, joined_on)
104 Given /^une nouvelle adhésion de (\w+) qui a payé sa cotisation il y a (\d+) jours$/ do |name, days|
105 joined_on = (Time.now.to_date - days.to_i).strftime('%Y-%m-%d')
106 create_new_member(name, joined_on, joined_on)
109 Given /^elle avait déjà reçu des appels l'année précédente$/ do
110 Timecop.travel(Time.now.to_date - 375) do
111 NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
115 Given /^qui a déjà reçu un appel (\d+) jours plus tôt$/ do |days_ago|
116 Timecop.travel(Time.now.to_date - days_ago.to_i) do
117 NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
121 When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
122 @file = member_filename_for_id(new_id)
123 File.write @file, render_member_file(EXTRA_MEMBER)
126 When /^j'ajoute une fiche vide$/ do
127 @file = member_filename_for_id(new_id)
131 When /^j'ajoute une fiche sans YAML$/ do
132 @file = member_filename_for_id(new_id)
133 File.write @file, <<-EOF.gsub(/^ /, '')
134 Ceci est une fiche sans YAML.
138 When /^j'ajoute une fiche avec du mauvais YAML$/ do
139 @file = member_filename_for_id(new_id)
140 File.write @file, <<-EOF.gsub(/^ /, '')
142 [This is missing a closing bracket
147 When /^j'ajoute une fiche sans email$/ do
148 @file = member_filename_for_id(new_id)
149 File.write @file, <<-EOF.gsub(/^ /, '')
155 joined_on: 2013-02-20
156 membership_fee_paid_on: 2013-02-20
161 When /^j'ajoute une fiche sans nom$/ do
162 @file = member_filename_for_id(new_id)
163 File.write @file, <<-EOF.gsub(/^ /, '')
165 email: joe@example.org
169 joined_on: 2013-02-20
170 membership_fee_paid_on: 2013-02-20
175 When /^j'ajoute une fiche avec comme date d'adhésion "([^"]*)"$/ do |date|
176 @file = member_filename_for_id(new_id)
177 File.write @file, <<-EOF.gsub(/^ /, '')
180 email: joe@example.org
185 membership_fee_paid_on: 2013-04-04
190 When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
191 @file = member_filename_for_id(new_id)
192 File.write @file, <<-EOF.gsub(/^ /, '')
195 email: joe@example.org
199 joined_on: 2013-04-04
200 membership_fee_paid_on: #{date}
205 When /^je supprime le nom sur une fiche existante$/ do
206 @file = member_filename_for_id(1)
207 run_simple "sed -e '/^name:/d' -i #{@file}"
210 When /^j'ajoute un fichier hors de la base des adhérents$/ do
211 @file = expand_path('test')
212 File.write @file, 'Test content.'