From 1400ff7105bb71c2f125b5e718bb1848dca79309 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 11 Nov 2010 16:26:32 -0300 Subject: [PATCH] Allowed scrap replies on a community --- app/models/community.rb | 4 ++++ app/models/person.rb | 4 ++++ app/models/scrap.rb | 12 ++++++++++-- test/unit/community_test.rb | 5 +++++ test/unit/person_test.rb | 5 +++++ test/unit/scrap_notifier_test.rb | 9 +++++++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/models/community.rb b/app/models/community.rb index f18e2b7..2832781 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -75,4 +75,8 @@ class Community < Organization end end + def receives_scrap_notification? + false + end + end diff --git a/app/models/person.rb b/app/models/person.rb index b6b1fe4..20bf897 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -44,6 +44,10 @@ class Person < Profile end end + def receives_scrap_notification? + true + end + def can_control_activity?(activity) self.tracked_notifications.exists?(activity) end diff --git a/app/models/scrap.rb b/app/models/scrap.rb index ea1acc2..50f497e 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -16,7 +16,7 @@ class Scrap < ActiveRecord::Base after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? - Scrap::Notifier.deliver_mail(scrap) if !scrap.receiver.is_a?(Community) && !(scrap.sender == scrap.receiver) + Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? end before_validation :strip_all_html_tags @@ -30,8 +30,16 @@ class Scrap < ActiveRecord::Base self.receiver.is_a?(Community) ? self.receiver : self end + def is_root? + !root.nil? + end + def scrap_wall_url - self.root.nil? ? self.receiver.wall_url : self.root.receiver.wall_url + is_root? ? root.receiver.wall_url : receiver.wall_url + end + + def send_notification? + sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?) end class Notifier < ActionMailer::Base diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index c9f0c61..437a7f0 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -313,4 +313,9 @@ class CommunityTest < Test::Unit::TestCase assert_equal s2, c.scraps(s2.id.to_s) end + should 'receive scrap notification' do + community = fast_create(Community) + assert_equal false, community.receives_scrap_notification? + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index a044c86..5c64349 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1111,4 +1111,9 @@ class PersonTest < Test::Unit::TestCase assert_equal({ :host => "mycolivre.net", :profile => 'testprofile', :controller => 'profile', :action => 'index', :anchor => 'profile-wall' }, profile.wall_url) end + should 'receive scrap notification' do + person = fast_create(Person) + assert person.receives_scrap_notification? + end + end diff --git a/test/unit/scrap_notifier_test.rb b/test/unit/scrap_notifier_test.rb index 4924066..c9925c3 100644 --- a/test/unit/scrap_notifier_test.rb +++ b/test/unit/scrap_notifier_test.rb @@ -55,6 +55,15 @@ class ScrapNotifierTest < Test::Unit::TestCase end end + should 'not deliver mail if is a reply on a community' do + community = fast_create(Community) + person = fast_create(Person) + scrap = fast_create(Scrap, :receiver_id => community.id, :sender_id => @sender.id) + assert_no_difference ActionMailer::Base.deliveries, :size do + Scrap.create!(:sender => person, :receiver => @sender, :scrap_id => scrap.id, :content => 'Hi myself!') + end + end + private def read_fixture(action) -- libgit2 0.21.2