diff --git a/lib/notify_activity_to_profiles_job.rb b/lib/notify_activity_to_profiles_job.rb index 39cdb05..16f96c1 100644 --- a/lib/notify_activity_to_profiles_job.rb +++ b/lib/notify_activity_to_profiles_job.rb @@ -19,10 +19,17 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select f.friend_id, #{tracked_action.id} from friendships as f where person_id=#{tracked_action.user.id} and f.friend_id not in (select atn.profile_id from action_tracker_notifications as atn where atn.action_tracker_id = #{tracked_action.id})") - if target.is_a?(Community) || (target.is_a?(Article) && target.profile.is_a?(Community)) + if target.is_a?(Community) ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}") ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) end + + if target.is_a?(Article) && target.profile.is_a?(Community) + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action.id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.profile.id}") + + ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) + end + end end diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index a57fb88..b2af40d 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -268,20 +268,6 @@ class ApproveArticleTest < ActiveSupport::TestCase assert_equal 3, ActionTracker::Record.count end - should 'update activity on update of an article' do - ActionTracker::Record.delete_all - a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile) - a.finish - published = community.articles.find_by_name(a.name) - time = published.activity.updated_at - Time.stubs(:now).returns(time + 1.day) - assert_no_difference ActionTracker::Record, :count do - published.name = 'foo' - published.save! - end - assert_equal time + 1.day, published.activity.updated_at - end - should 'not create trackers activity when updating articles' do ActionTracker::Record.delete_all article1 = fast_create(TextileArticle) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 252de5c..13a5a38 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -946,16 +946,14 @@ assert_equal 'bla', profile.articles.map(&:comments_count) p3 = fast_create(Person) community.add_member(p1) community.add_member(p2) - Article.destroy_all - ActionTracker::Record.destroy_all UserStampSweeper.any_instance.expects(:current_user).returns(p1).at_least_once + article = create(TinyMceArticle, :profile_id => community.id) + activity = article.activity process_delayed_job_queue - assert_equal 3, ActionTrackerNotification.all - ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| - assert [p1,p2,community].include?(profile) - end + assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).count + assert_equivalent [p1,p2,community], ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).map(&:profile) end should 'not track action when a published article is removed' do @@ -965,17 +963,6 @@ assert_equal 'bla', profile.articles.map(&:comments_count) end end - should 'update action when article is updated' do - article = create(TinyMceArticle, :profile => profile) - action = ActionTracker::Record.last - time = action.updated_at - - Time.stubs(:now).returns(time + 1.day) - article.name = 'New name' - article.save - assert_not_equal time, ActionTracker::Record.last.updated_at - end - should 'notifiable is false by default' do a = fast_create(Article) assert !a.notifiable? @@ -1047,41 +1034,27 @@ assert_equal 'bla', profile.articles.map(&:comments_count) assert_equal false, a.is_trackable? end - should 'create the notification to the member when one member has the notification and the other no' do + should 'create the notification to organization and all organization members' do community = fast_create(Community) - p1 = Person.first || fast_create(Person) - community.add_member(p1) - assert p1.is_member_of?(community) - Article.destroy_all - ActionTracker::Record.destroy_all + member_1 = Person.first + community.add_member(member_1) + article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => community.id - assert article.published? - assert_kind_of Community, article.profile - assert_equal 1, ActionTracker::Record.count - ta = ActionTracker::Record.first - assert_equal 'Tracked Article 1', ta.get_name.last - assert_equal article.url, ta.get_url.last - assert p1, ta.user - assert community, ta.target - process_delayed_job_queue - assert_equal 2, ActionTrackerNotification.count + first_activity = article.activity + assert_equal [first_activity], ActionTracker::Record.find_all_by_verb('create_article') - p2 = fast_create(Person) - community.add_member(p2) process_delayed_job_queue - assert_equal 5, ActionTrackerNotification.count - - article = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id - assert article.published? - assert_kind_of Community, article.profile - assert_equal 3, ActionTracker::Record.count - ta = ActionTracker::Record.first - assert_equal 'Tracked Article 2', ta.get_name.last - assert_equal article.url, ta.get_url.last - assert_equal p1, ta.user - assert_equal community, ta.target + assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(first_activity.id).count + + member_2 = fast_create(Person) + community.add_member(member_2) + + article2 = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id + second_activity = article2.activity + assert_equivalent [first_activity, second_activity], ActionTracker::Record.find_all_by_verb('create_article') + process_delayed_job_queue - assert_equal 6, ActionTrackerNotification.count + assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(second_activity.id).count end should 'create notifications to friends when creating an article' do @@ -1098,12 +1071,10 @@ assert_equal 'bla', profile.articles.map(&:comments_count) end should 'create the notification to the friend when one friend has the notification and the other no' do - Article.destroy_all - ActionTracker::Record.destroy_all - ActionTrackerNotification.destroy_all - f1 = fast_create(Person) profile.add_friend(f1) + + UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => profile.id assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count process_delayed_job_queue diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 3c33e7b..e98491f 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1763,6 +1763,7 @@ class ProfileTest < ActiveSupport::TestCase assert_raise NoMethodError do Profile::Roles.invalid_role(env.id) end + end should 'return empty array as activities' do profile = Profile.new @@ -1771,7 +1772,6 @@ class ProfileTest < ActiveSupport::TestCase private - def assert_invalid_identifier(id) profile = Profile.new(:identifier => id) assert !profile.valid? -- libgit2 0.21.2