Commit f0d6e0a36e6af3595d02ac861c6f12648f5cb7f5
1 parent
3a1370f6
Exists in
master
and in
29 other branches
Tests for sending emails on spaminator
Showing
5 changed files
with
62 additions
and
5 deletions
Show diff stats
plugins/spaminator/lib/spaminator_plugin/mailer.rb
| 1 | class SpaminatorPlugin::Mailer < Noosfero::Plugin::MailerBase | 1 | class SpaminatorPlugin::Mailer < Noosfero::Plugin::MailerBase |
| 2 | 2 | ||
| 3 | def inactive_person_notification(person) | 3 | def inactive_person_notification(person) |
| 4 | - hostname = person.hostname || person.environment.default_hostname | ||
| 5 | recipients person.email | 4 | recipients person.email |
| 6 | - from 'no-reply@' + hostname | 5 | + from "#{person.environment.name} <#{person.environment.contact_email}>" |
| 7 | subject _("[%s] You must reactivate your account.") % person.environment.name | 6 | subject _("[%s] You must reactivate your account.") % person.environment.name |
| 8 | content_type 'text/html' | 7 | content_type 'text/html' |
| 9 | body :person => person, | 8 | body :person => person, |
| 10 | :environment => person.environment, | 9 | :environment => person.environment, |
| 11 | - :url => url_for(:host => hostname, :controller => 'account', :action => 'forgot_password') | 10 | + :url => url_for(:host => person.default_hostname, :controller => 'account', :action => 'forgot_password') |
| 12 | end | 11 | end |
| 13 | 12 | ||
| 14 | end | 13 | end |
plugins/spaminator/lib/spaminator_plugin/spaminator.rb
| @@ -136,8 +136,9 @@ class SpaminatorPlugin::Spaminator | @@ -136,8 +136,9 @@ class SpaminatorPlugin::Spaminator | ||
| 136 | end | 136 | end |
| 137 | 137 | ||
| 138 | def disable_person(person) | 138 | def disable_person(person) |
| 139 | - person.disable | ||
| 140 | - SpaminatorPlugin::Mailer.delay.deliver_inactive_person_notification(person) | 139 | + if person.disable |
| 140 | + SpaminatorPlugin::Mailer.delay.deliver_inactive_person_notification(person) | ||
| 141 | + end | ||
| 141 | end | 142 | end |
| 142 | 143 | ||
| 143 | def mark_as_spammer(person) | 144 | def mark_as_spammer(person) |
plugins/spaminator/test/unit/spaminator_plugin/mailer_test.rb
0 → 100644
| @@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
| 1 | +require 'test_helper' | ||
| 2 | + | ||
| 3 | +class SpaminatorPlugin::MailerTest < ActiveSupport::TestCase | ||
| 4 | + CHARSET = "utf-8" | ||
| 5 | + | ||
| 6 | + def setup | ||
| 7 | + Noosfero::Plugin::MailerBase.delivery_method = :test | ||
| 8 | + Noosfero::Plugin::MailerBase.perform_deliveries = true | ||
| 9 | + Noosfero::Plugin::MailerBase.deliveries = [] | ||
| 10 | + @environment = Environment.default | ||
| 11 | + @settings = Noosfero::Plugin::Settings.new(@environment, SpaminatorPlugin) | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + attr_accessor :environment, :settings | ||
| 15 | + | ||
| 16 | + should 'be able to send a inactive person notification message' do | ||
| 17 | + environment.contact_email = 'no-reply@noosfero.org' | ||
| 18 | + environment.save | ||
| 19 | + | ||
| 20 | + person = create_user('spammer').person | ||
| 21 | + mail = SpaminatorPlugin::Mailer.deliver_inactive_person_notification(person) | ||
| 22 | + | ||
| 23 | + assert_equal ['spammer@noosfero.org'], mail.to | ||
| 24 | + assert_equal ['no-reply@noosfero.org'], mail.from | ||
| 25 | + assert_match(/You must reactivate your account/, mail.subject) | ||
| 26 | + end | ||
| 27 | +end |
plugins/spaminator/test/unit/spaminator_plugin/spaminator_test.rb
| @@ -128,6 +128,21 @@ class SpaminatorPlugin::SpaminatorTest < ActiveSupport::TestCase | @@ -128,6 +128,21 @@ class SpaminatorPlugin::SpaminatorTest < ActiveSupport::TestCase | ||
| 128 | assert !person.visible | 128 | assert !person.visible |
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | + should 'send email notification after disabling person' do | ||
| 132 | + person = create_user('spammer').person | ||
| 133 | + assert_difference(ActionMailer::Base.deliveries, :size, 1) do | ||
| 134 | + spaminator.send(:disable_person, person) | ||
| 135 | + end | ||
| 136 | + end | ||
| 137 | + | ||
| 138 | + should 'not send email notification if person was not disabled' do | ||
| 139 | + person = create_user('spammer').person | ||
| 140 | + person.expects(:disable).returns(false) | ||
| 141 | + assert_no_difference(ActionMailer::Base.deliveries, :size) do | ||
| 142 | + spaminator.send(:disable_person, person) | ||
| 143 | + end | ||
| 144 | + end | ||
| 145 | + | ||
| 131 | private | 146 | private |
| 132 | 147 | ||
| 133 | def report | 148 | def report |
test/unit/person_test.rb
| @@ -1316,4 +1316,19 @@ class PersonTest < ActiveSupport::TestCase | @@ -1316,4 +1316,19 @@ class PersonTest < ActiveSupport::TestCase | ||
| 1316 | assert_includes non_abusers, person | 1316 | assert_includes non_abusers, person |
| 1317 | end | 1317 | end |
| 1318 | 1318 | ||
| 1319 | + should 'not return canceled complaints as abusers' do | ||
| 1320 | + abuser = create_user('abuser1').person | ||
| 1321 | + AbuseComplaint.create!(:reported => abuser).finish | ||
| 1322 | + not_abuser = create_user('abuser2').person | ||
| 1323 | + AbuseComplaint.create!(:reported => not_abuser).cancel | ||
| 1324 | + | ||
| 1325 | + abusers = Person.abusers | ||
| 1326 | + assert_includes abusers, abuser | ||
| 1327 | + assert_not_includes abusers, not_abuser | ||
| 1328 | + | ||
| 1329 | + non_abusers = Person.non_abusers | ||
| 1330 | + assert_not_includes non_abusers, abuser | ||
| 1331 | + assert_includes non_abusers, not_abuser | ||
| 1332 | + end | ||
| 1333 | + | ||
| 1319 | end | 1334 | end |