Commit b931c6033b3b91ff08181b1982989fa7213dc520

Authored by Daniela Feitosa
1 parent 415d3eec

Fixed bug when sending email to community members

(ActionItem2618)
app/models/organization_mailing.rb
@@ -5,7 +5,7 @@ class OrganizationMailing < Mailing @@ -5,7 +5,7 @@ class OrganizationMailing < Mailing
5 end 5 end
6 6
7 def recipients(offset=0, limit=100) 7 def recipients(offset=0, limit=100)
8 - 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 }) 8 + 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 })
9 end 9 end
10 10
11 def each_recipient 11 def each_recipient
test/unit/organization_mailing_test.rb
@@ -66,6 +66,12 @@ class OrganizationMailingTest < ActiveSupport::TestCase @@ -66,6 +66,12 @@ class OrganizationMailingTest < ActiveSupport::TestCase
66 assert_equal 2, ActionMailer::Base.deliveries.count 66 assert_equal 2, ActionMailer::Base.deliveries.count
67 end 67 end
68 68
  69 + should 'deliver mailing when there are many mailings created' do
  70 + 50.times { OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) }
  71 + process_delayed_job_queue
  72 + assert_equal 50*community.members_count, ActionMailer::Base.deliveries.count
  73 + end
  74 +
69 should 'create mailing sent to each recipient after delivering mailing' do 75 should 'create mailing sent to each recipient after delivering mailing' do
70 mailing = OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person) 76 mailing = OrganizationMailing.create(:source => community, :subject => 'Hello', :body => 'We have some news', :person => person)
71 assert_difference MailingSent, :count, 2 do 77 assert_difference MailingSent, :count, 2 do