From: Lunar Date: Sat, 1 Jun 2013 10:13:56 +0000 (+0200) Subject: Continue implementing list-emails X-Git-Url: https://nos-oignons.net/gitweb/gestion-adh.git/commitdiff_plain/c2e8982b068dc4f47015679ea383a424c4defef1?ds=sidebyside Continue implementing list-emails --- diff --git a/bin/list-emails b/bin/list-emails index 5d3fb74..569571e 100755 --- a/bin/list-emails +++ b/bin/list-emails @@ -4,3 +4,10 @@ require 'rubygems' require 'bundler' Bundler.setup + +require 'nos_oignons/subscriptions' + +subscriptions = read_subscriptions +subscriptions.each_pair do |subscription_id, data| + puts data['email'] +end diff --git a/features/step_definitions/commands.rb b/features/step_definitions/commands.rb index ae6d798..ce9c5da 100644 --- a/features/step_definitions/commands.rb +++ b/features/step_definitions/commands.rb @@ -13,3 +13,8 @@ end Then /^la sortie doit-être vide$/ do expect(all_output).to be_empty end + +Then /^la sortie doit être:$/ do |expected| + # add an extra line feed for nice scenario + assert_exact_output(expected + "\n", all_stdout) +end diff --git a/features/step_definitions/subscriptions.rb b/features/step_definitions/subscriptions.rb index aa3365d..62306e9 100644 --- a/features/step_definitions/subscriptions.rb +++ b/features/step_definitions/subscriptions.rb @@ -2,6 +2,19 @@ Given /une base de membres vide$/ do create_dir 'Membres' end +Given /^une base avec (\w+), à jour de cotisation$/ do |name| + data = { 'name' => name, + 'address' => "At #{name}", + 'email' => "#{name.downcase}@example.org", + 'membership_fee_paid_on' => + # one month ago + (Time.now - 3600*24*30).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) diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb index 47290c7..2c54036 100644 --- a/features/support/fixtures.rb +++ b/features/support/fixtures.rb @@ -70,6 +70,7 @@ def render_subscription_file(locals) end def new_id - new_id = Dir.glob("#{current_dir}/Membres/*.mdwn"). - collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max + 1 + max_id = Dir.glob("#{current_dir}/Membres/*.mdwn"). + collect { |f| File.basename(f).gsub(/\.mdwn$/, '').to_i }.max || 0 + max_id + 1 end diff --git a/lib/nos_oignons/subscriptions.rb b/lib/nos_oignons/subscriptions.rb index 2c8585e..a433c8c 100644 --- a/lib/nos_oignons/subscriptions.rb +++ b/lib/nos_oignons/subscriptions.rb @@ -26,3 +26,12 @@ def is_valid_subscription_file?(ref, file) is_valid_subscription?(f.read) end end + +def read_subscriptions + subscriptions = {} + Dir.glob("#{SUBSCRIPTIONS_ROOT}/*.mdwn") do |file| + subscription_id = File.basename(file).gsub(/\.mdwn$/, '') + subscriptions[subscription_id] = YAML.load_file(file) + end + subscriptions +end