ENV['NOS_OIGNONS_BOARD_WIKI_PATH'] = expand_path('.')
end
-def create_new_member(name, joined_on, paid_on)
- @last_member = { 'name' => name,
- 'address' => "At #{name}",
- 'email' => "#{name.downcase}@example.org",
- 'joined_on' => joined_on,
- 'membership_fee_paid_on' => paid_on
- }
+def new_member_data(name, joined_on, paid_on)
+ { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'joined_on' => joined_on,
+ 'membership_fee_paid_on' => paid_on
+ }
+end
+
+def add_member(member_data)
+ @last_member = member_data
init_db unless @member_db_path
file = member_filename_for_id(new_id)
File.write file, render_member_file(@last_member)
end
+def create_new_member(*args)
+ add_member(new_member_data(*args))
+end
+
Given /une base de membres vide$/ do
init_db
end
create_new_member(name, joined_on, paid_on)
end
-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|
+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|
create_new_member(name, joined_on, paid_on)
end
expect(Dir.glob("#{@member_db_path}/[0-9]*").size).to eq(1)
end
-
-Given /^(?:une base )?avec (\w+) qui doit renouveler sa cotisation d'ici (\d+) jours$/ do |name, days_before_anniversary|
+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|
now = Time.now
paid_on = Time.new(now.year - 1, now.month, now.day).to_date + days_before_anniversary.to_i
joined_on = paid_on
- create_new_member(name, joined_on, paid_on)
+ member_data = new_member_data(name, joined_on, paid_on)
+ case address_status
+ when /ayant/
+ member_data['address'] = "At #{name}'s"
+ when /qui n'a pas/
+ member_data.delete('address')
+ end
+ add_member(member_data)
end
Given /^une nouvelle adhésion de (\w+)$/ do |name|
create_new_member(name, joined_on, joined_on)
end
-
Given /^elle avait déjà reçu des appels l'année précédente$/ do
Timecop.travel(Time.now.to_date - 375) do
NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
end
end
+Given /^qui a déjà reçu un appel le ([0-9-]+)$/ do |date|
+ Timecop.travel(Time.parse(date)) do
+ NosOignons::ReminderDb.instance.record(OpenStruct.new(@last_member))
+ end
+end
+
When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
@file = member_filename_for_id(new_id)
File.write @file, render_member_file(EXTRA_MEMBER)