From b931c6033b3b91ff08181b1982989fa7213dc520 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 14 Mar 2013 15:11:31 -0300 Subject: [PATCH] Fixed bug when sending email to community members --- app/models/organization_mailing.rb | 2 +- test/unit/organization_mailing_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/organization_mailing.rb b/app/models/organization_mailing.rb index 9cf9d86..ddd9fb3 100644 --- a/app/models/organization_mailing.rb +++ b/app/models/organization_mailing.rb @@ -5,7 +5,7 @@ class OrganizationMailing < Mailing end def recipients(offset=0, limit=100) - source.members.all(:order => self.id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil }) + source.members.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil }) end def each_recipient diff --git a/test/unit/organization_mailing_test.rb b/test/unit/organization_mailing_test.rb index bb3dccc..33ad4b0 100644 --- a/test/unit/organization_mailing_test.rb +++ b/test/unit/organization_mailing_test.rb @@ -66,6 +66,12 @@ class OrganizationMailingTest < ActiveSupport::TestCase assert_equal 2, ActionMailer::Base.deliveries.count end + should 'deliver mailing when there are many mailings created' do + 50.times { OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) } + process_delayed_job_queue + assert_equal 50*community.members_count, ActionMailer::Base.deliveries.count + end + should 'create mailing sent to each recipient after delivering mailing' do mailing = OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) assert_difference MailingSent, :count, 2 do -- libgit2 0.21.2