]> nos-oignons.net Git - gestion-adh.git/commitdiff
Only send reminders when the time has really come
authorLunar <lunar@anargeek.net>
Thu, 2 Jan 2014 09:13:20 +0000 (10:13 +0100)
committerLunar <lunar@anargeek.net>
Thu, 2 Jan 2014 09:13:20 +0000 (10:13 +0100)
features/send-membership-reminders.feature
features/step_definitions/emails.rb
lib/nos_oignons.rb

index 88609e5b10cdff0ccbfe87b6f81588984095886b..09bdce721860a0d7821587817f4c9a6b4b5aea8a 100644 (file)
@@ -65,4 +65,4 @@ Fonctionnalité: prévenir les membres qu'il faut renouveller leur cotisation
     Et avec Fred qui doit renouveller sa cotisation d'ici 10 jours
     Et avec Moly qui doit renouveller sa cotisation d'ici 30 jours
     Lorsque j'exécute send-membership-reminders
-    Alors 4 emails doivent avoir été envoyés
+    Alors des emails doivent avoir été envoyés à Jane, Fatima, Fred et Moly
index 2bbecd33a1583d23dccac6b9b0b3bb57a805a5cf..e2e562e2bf46c7afa2a17238cd4057aa12ce944d 100644 (file)
@@ -28,6 +28,14 @@ Then /^(\d+) emails? (?:doit|doivent) avoir été envoyés?$/ do |count|
   Mail::TestMailer.deliveries.should have(count).email
 end
 
+Then /^des emails doivent avoir été envoyés à Jane, Fatima, Fred et Moly$/ do
+  recipients = Mail::TestMailer.deliveries.collect(&:to)
+  recipients.should include(['jane@example.org'])
+  recipients.should include(['fatima@example.org'])
+  recipients.should include(['fred@example.org'])
+  recipients.should include(['moly@example.org'])
+end
+
 Then /^un email doit avoir été envoyé au comité de déontologie$/ do
   expect(Mail::TestMailer.deliveries).to have(1).email
   expect(Mail::TestMailer.deliveries.first.to).to include('deontologie@nos-oignons.net')
index 66116bf7a5f7ba41892d23c3fb37677a4bc219b3..758c6752767497a01aa8fa3a3a918a1e362a6abf 100644 (file)
@@ -58,7 +58,9 @@ module NosOignons
                                member.joined_on.day).to_date
         next if member.membership_fee_paid_on >= anniversary
         next if member.reminded_on && member.reminded_on >= today
-        NosOignons::Reminder.all.sort_by(&:days).reverse.each do |reminder|
+        reminders = NosOignons::Reminder.all.sort_by(&:days).reverse
+        next if anniversary > today + reminders.first.days
+        reminders.each do |reminder|
           next if anniversary < today + reminder.days
 
           member.remind(reminder)