+#-*- coding: utf-8 -*-
+
+Given /une base de membres vide$/ do
+ create_dir 'Membres'
+end
+
+Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa cotisation cette année)$/ do |name, uptodate|
+ case uptodate
+ when ', à jour de cotisation'
+ # ± 1 month ago
+ paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
+ else
+ # ± 15 months ago
+ paid_on = (Time.now - 3600*24*30*15).strftime('%Y-%m-%d')
+ end
+ data = { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'membership_fee_paid_on' => paid_on
+ }
+ create_dir 'Membres'
+ file = subscription_filename_for_id(new_id)
+ write_file file, render_subscription_file(data)
+end
+
+Given /^une nouvelle adhésion de (\w+)$/ do |name|
+ data = { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'membership_fee_paid_on' => Time.now.strftime('%Y-%m-%d')
+ }
+ create_dir 'Membres'
+ file = subscription_filename_for_id(new_id)
+ write_file file, render_subscription_file(data)
+end
+
When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
@file = subscription_filename_for_id(new_id)
write_file @file, render_subscription_file(EXTRA_SUBSCRIPTION)
@file = subscription_filename_for_id(new_id)
write_file @file, ''
end
+
+When /^j'ajoute une fiche sans YAML$/ do
+ @file = subscription_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ Ceci est une fiche sans YAML.
+ EOF
+end
+
+When /^j'ajoute une fiche avec du mauvais YAML$/ do
+ @file = subscription_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ [This is missing a closing bracket
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche sans email$/ do
+ @file = subscription_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ name: J. Example
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: 2013-02-20
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche sans nom$/ do
+ @file = subscription_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ email: joe@example.org
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: 2013-02-20
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
+ @file = subscription_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ name: J. Example
+ email: joe@example.org
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: #{date}
+ ---
+ EOF
+end
+
+When /^je supprime le nom sur une fiche existante$/ do
+ @file = subscription_filename_for_id(1)
+ run_simple "sed -e '/^name:/d' -i #{@file}"
+end
+
+When /^j'ajoute un fichier hors de la base des adhérents$/ do
+ @file = 'test'
+ write_file @file, 'Test content.'
+end