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ée? 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 Given /^qui a déjà reçu un appel le ([0-9-]+)$/ do |date|
122 Timecop.travel(Time.parse(date)) do
123 NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
127 When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
128 @file = member_filename_for_id(new_id)
129 File.write @file, render_member_file(EXTRA_MEMBER)
132 When /^j'ajoute une fiche vide$/ do
133 @file = member_filename_for_id(new_id)
137 When /^j'ajoute une fiche sans YAML$/ do
138 @file = member_filename_for_id(new_id)
139 File.write @file, <<-EOF.gsub(/^ /, '')
140 Ceci est une fiche sans YAML.
144 When /^j'ajoute une fiche avec du mauvais YAML$/ do
145 @file = member_filename_for_id(new_id)
146 File.write @file, <<-EOF.gsub(/^ /, '')
148 [This is missing a closing bracket
153 When /^j'ajoute une fiche sans email$/ do
154 @file = member_filename_for_id(new_id)
155 File.write @file, <<-EOF.gsub(/^ /, '')
161 joined_on: 2013-02-20
162 membership_fee_paid_on: 2013-02-20
167 When /^j'ajoute une fiche sans nom$/ do
168 @file = member_filename_for_id(new_id)
169 File.write @file, <<-EOF.gsub(/^ /, '')
171 email: joe@example.org
175 joined_on: 2013-02-20
176 membership_fee_paid_on: 2013-02-20
181 When /^j'ajoute une fiche avec comme date d'adhésion "([^"]*)"$/ do |date|
182 @file = member_filename_for_id(new_id)
183 File.write @file, <<-EOF.gsub(/^ /, '')
186 email: joe@example.org
191 membership_fee_paid_on: 2013-04-04
196 When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
197 @file = member_filename_for_id(new_id)
198 File.write @file, <<-EOF.gsub(/^ /, '')
201 email: joe@example.org
205 joined_on: 2013-04-04
206 membership_fee_paid_on: #{date}
211 When /^je supprime le nom sur une fiche existante$/ do
212 @file = member_filename_for_id(1)
213 run_command_and_stop "sed -e '/^name:/d' -i #{@file}"
216 When /^j'ajoute un fichier hors de la base des adhérents$/ do
217 @file = expand_path('test')
218 File.write @file, 'Test content.'