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 create_new_member(name, joined_on, paid_on)
26 @last_member = { 'name' => name,
27 'address' => "At #{name}",
28 'email' => "#{name.downcase}@example.org",
29 'joined_on' => joined_on,
30 'membership_fee_paid_on' => paid_on
32 init_db unless @member_db_path
33 file = member_filename_for_id(new_id)
34 File.write file, render_member_file(@last_member)
37 Given /une base de membres vide$/ do
41 Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa cotisation cette année)$/ do |name, uptodate|
43 joined_on = (Time.now - 3600*24*30*15).strftime('%Y-%m-%d')
45 when ', à jour de cotisation'
47 paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
51 create_new_member(name, joined_on, paid_on)
54 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|
55 create_new_member(name, joined_on, paid_on)
58 Given /^une base avec (\w+), membre (\w+), ayant cotisé le ([0-9-]+)$/ do |name, member_id, paid_on|
59 create_new_member(name, paid_on, paid_on)
60 expect(File.read(member_filename_for_id(member_id))).to include(name)
63 Given /^une base avec (\w+), membre (\w+), n'ayant jamais cotisé$/ do |name, member_id|
64 joined_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
65 create_new_member(name, joined_on, nil)
66 expect(File.read(member_filename_for_id(member_id))).to include(name)
69 Given /^une base avec uniquement (\w+), membre (\w+)$/ do |name, member_id|
70 paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
71 create_new_member(name, paid_on, paid_on)
72 member_path = File.join(member_filename_for_id(member_id))
73 expect(File.read(member_path)).to include(name)
74 expect(Dir.glob("#{@member_db_path}/[0-9]*").size).to eq(1)
78 Given /^(?:une base )?avec (\w+) qui doit renouveler sa cotisation d'ici (\d+) jours$/ do |name, days_before_anniversary|
80 paid_on = Time.new(now.year - 1, now.month, now.day).to_date + days_before_anniversary.to_i
82 create_new_member(name, joined_on, paid_on)
85 Given /^une nouvelle adhésion de (\w+)$/ do |name|
86 joined_on = Time.now.strftime('%Y-%m-%d')
87 create_new_member(name, joined_on, joined_on)
90 Given /^une nouvelle adhésion de (\w+) qui a payé sa cotisation il y a (\d+) jours$/ do |name, days|
91 joined_on = (Time.now.to_date - days.to_i).strftime('%Y-%m-%d')
92 create_new_member(name, joined_on, joined_on)
96 Given /^elle avait déjà reçu des appels l'année précédente$/ do
97 Timecop.travel(Time.now.to_date - 375) do
98 NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
102 Given /^qui a déjà reçu un appel (\d+) jours plus tôt$/ do |days_ago|
103 Timecop.travel(Time.now.to_date - days_ago.to_i) do
104 NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
108 When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
109 @file = member_filename_for_id(new_id)
110 File.write @file, render_member_file(EXTRA_MEMBER)
113 When /^j'ajoute une fiche vide$/ do
114 @file = member_filename_for_id(new_id)
118 When /^j'ajoute une fiche sans YAML$/ do
119 @file = member_filename_for_id(new_id)
120 File.write @file, <<-EOF.gsub(/^ /, '')
121 Ceci est une fiche sans YAML.
125 When /^j'ajoute une fiche avec du mauvais YAML$/ do
126 @file = member_filename_for_id(new_id)
127 File.write @file, <<-EOF.gsub(/^ /, '')
129 [This is missing a closing bracket
134 When /^j'ajoute une fiche sans email$/ do
135 @file = member_filename_for_id(new_id)
136 File.write @file, <<-EOF.gsub(/^ /, '')
142 joined_on: 2013-02-20
143 membership_fee_paid_on: 2013-02-20
148 When /^j'ajoute une fiche sans nom$/ do
149 @file = member_filename_for_id(new_id)
150 File.write @file, <<-EOF.gsub(/^ /, '')
152 email: joe@example.org
156 joined_on: 2013-02-20
157 membership_fee_paid_on: 2013-02-20
162 When /^j'ajoute une fiche avec comme date d'adhésion "([^"]*)"$/ do |date|
163 @file = member_filename_for_id(new_id)
164 File.write @file, <<-EOF.gsub(/^ /, '')
167 email: joe@example.org
172 membership_fee_paid_on: 2013-04-04
177 When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
178 @file = member_filename_for_id(new_id)
179 File.write @file, <<-EOF.gsub(/^ /, '')
182 email: joe@example.org
186 joined_on: 2013-04-04
187 membership_fee_paid_on: #{date}
192 When /^je supprime le nom sur une fiche existante$/ do
193 @file = member_filename_for_id(1)
194 run_simple "sed -e '/^name:/d' -i #{@file}"
197 When /^j'ajoute un fichier hors de la base des adhérents$/ do
198 @file = expand_path('test')
199 File.write @file, 'Test content.'