Commit 1400ff7105bb71c2f125b5e718bb1848dca79309
Committed by
Antonio Terceiro
1 parent
87b6e60c
Exists in
master
and in
29 other branches
Allowed scrap replies on a community
(ActionItem1765)
Showing
6 changed files
with
37 additions
and
2 deletions
Show diff stats
app/models/community.rb
app/models/person.rb
app/models/scrap.rb
... | ... | @@ -16,7 +16,7 @@ class Scrap < ActiveRecord::Base |
16 | 16 | |
17 | 17 | after_create do |scrap| |
18 | 18 | scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? |
19 | - Scrap::Notifier.deliver_mail(scrap) if !scrap.receiver.is_a?(Community) && !(scrap.sender == scrap.receiver) | |
19 | + Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? | |
20 | 20 | end |
21 | 21 | |
22 | 22 | before_validation :strip_all_html_tags |
... | ... | @@ -30,8 +30,16 @@ class Scrap < ActiveRecord::Base |
30 | 30 | self.receiver.is_a?(Community) ? self.receiver : self |
31 | 31 | end |
32 | 32 | |
33 | + def is_root? | |
34 | + !root.nil? | |
35 | + end | |
36 | + | |
33 | 37 | def scrap_wall_url |
34 | - self.root.nil? ? self.receiver.wall_url : self.root.receiver.wall_url | |
38 | + is_root? ? root.receiver.wall_url : receiver.wall_url | |
39 | + end | |
40 | + | |
41 | + def send_notification? | |
42 | + sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) | |
35 | 43 | end |
36 | 44 | |
37 | 45 | class Notifier < ActionMailer::Base | ... | ... |
test/unit/community_test.rb
... | ... | @@ -313,4 +313,9 @@ class CommunityTest < Test::Unit::TestCase |
313 | 313 | assert_equal s2, c.scraps(s2.id.to_s) |
314 | 314 | end |
315 | 315 | |
316 | + should 'receive scrap notification' do | |
317 | + community = fast_create(Community) | |
318 | + assert_equal false, community.receives_scrap_notification? | |
319 | + end | |
320 | + | |
316 | 321 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1111,4 +1111,9 @@ class PersonTest < Test::Unit::TestCase |
1111 | 1111 | assert_equal({ :host => "mycolivre.net", :profile => 'testprofile', :controller => 'profile', :action => 'index', :anchor => 'profile-wall' }, profile.wall_url) |
1112 | 1112 | end |
1113 | 1113 | |
1114 | + should 'receive scrap notification' do | |
1115 | + person = fast_create(Person) | |
1116 | + assert person.receives_scrap_notification? | |
1117 | + end | |
1118 | + | |
1114 | 1119 | end | ... | ... |
test/unit/scrap_notifier_test.rb
... | ... | @@ -55,6 +55,15 @@ class ScrapNotifierTest < Test::Unit::TestCase |
55 | 55 | end |
56 | 56 | end |
57 | 57 | |
58 | + should 'not deliver mail if is a reply on a community' do | |
59 | + community = fast_create(Community) | |
60 | + person = fast_create(Person) | |
61 | + scrap = fast_create(Scrap, :receiver_id => community.id, :sender_id => @sender.id) | |
62 | + assert_no_difference ActionMailer::Base.deliveries, :size do | |
63 | + Scrap.create!(:sender => person, :receiver => @sender, :scrap_id => scrap.id, :content => 'Hi myself!') | |
64 | + end | |
65 | + end | |
66 | + | |
58 | 67 | private |
59 | 68 | |
60 | 69 | def read_fixture(action) | ... | ... |