Commit 76c36e2fabe4cb93c80bdff7ea86b37898fe7f4b

Authored by Daniela Feitosa
1 parent 00390384

Fixing tests

lib/notify_activity_to_profiles_job.rb
... ... @@ -19,10 +19,17 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id)
19 19  
20 20 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})")
21 21  
22   - if target.is_a?(Community) || (target.is_a?(Article) && target.profile.is_a?(Community))
  22 + if target.is_a?(Community)
23 23 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}")
24 24  
25 25 ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb)
26 26 end
  27 +
  28 + if target.is_a?(Article) && target.profile.is_a?(Community)
  29 + 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}")
  30 +
  31 + ActionTrackerNotification.create(:profile_id => target.profile.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb)
  32 + end
  33 +
27 34 end
28 35 end
... ...
test/unit/approve_article_test.rb
... ... @@ -268,20 +268,6 @@ class ApproveArticleTest < ActiveSupport::TestCase
268 268 assert_equal 3, ActionTracker::Record.count
269 269 end
270 270  
271   - should 'update activity on update of an article' do
272   - ActionTracker::Record.delete_all
273   - a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile)
274   - a.finish
275   - published = community.articles.find_by_name(a.name)
276   - time = published.activity.updated_at
277   - Time.stubs(:now).returns(time + 1.day)
278   - assert_no_difference ActionTracker::Record, :count do
279   - published.name = 'foo'
280   - published.save!
281   - end
282   - assert_equal time + 1.day, published.activity.updated_at
283   - end
284   -
285 271 should 'not create trackers activity when updating articles' do
286 272 ActionTracker::Record.delete_all
287 273 article1 = fast_create(TextileArticle)
... ...
test/unit/article_test.rb
... ... @@ -946,16 +946,14 @@ assert_equal 'bla', profile.articles.map(&:comments_count)
946 946 p3 = fast_create(Person)
947 947 community.add_member(p1)
948 948 community.add_member(p2)
949   - Article.destroy_all
950   - ActionTracker::Record.destroy_all
951 949 UserStampSweeper.any_instance.expects(:current_user).returns(p1).at_least_once
  950 +
952 951 article = create(TinyMceArticle, :profile_id => community.id)
  952 + activity = article.activity
953 953  
954 954 process_delayed_job_queue
955   - assert_equal 3, ActionTrackerNotification.all
956   - ActionTrackerNotification.all.map{|a|a.profile}.map do |profile|
957   - assert [p1,p2,community].include?(profile)
958   - end
  955 + assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).count
  956 + assert_equivalent [p1,p2,community], ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).map(&:profile)
959 957 end
960 958  
961 959 should 'not track action when a published article is removed' do
... ... @@ -965,17 +963,6 @@ assert_equal 'bla', profile.articles.map(&:comments_count)
965 963 end
966 964 end
967 965  
968   - should 'update action when article is updated' do
969   - article = create(TinyMceArticle, :profile => profile)
970   - action = ActionTracker::Record.last
971   - time = action.updated_at
972   -
973   - Time.stubs(:now).returns(time + 1.day)
974   - article.name = 'New name'
975   - article.save
976   - assert_not_equal time, ActionTracker::Record.last.updated_at
977   - end
978   -
979 966 should 'notifiable is false by default' do
980 967 a = fast_create(Article)
981 968 assert !a.notifiable?
... ... @@ -1047,41 +1034,27 @@ assert_equal 'bla', profile.articles.map(&:comments_count)
1047 1034 assert_equal false, a.is_trackable?
1048 1035 end
1049 1036  
1050   - should 'create the notification to the member when one member has the notification and the other no' do
  1037 + should 'create the notification to organization and all organization members' do
1051 1038 community = fast_create(Community)
1052   - p1 = Person.first || fast_create(Person)
1053   - community.add_member(p1)
1054   - assert p1.is_member_of?(community)
1055   - Article.destroy_all
1056   - ActionTracker::Record.destroy_all
  1039 + member_1 = Person.first
  1040 + community.add_member(member_1)
  1041 +
1057 1042 article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => community.id
1058   - assert article.published?
1059   - assert_kind_of Community, article.profile
1060   - assert_equal 1, ActionTracker::Record.count
1061   - ta = ActionTracker::Record.first
1062   - assert_equal 'Tracked Article 1', ta.get_name.last
1063   - assert_equal article.url, ta.get_url.last
1064   - assert p1, ta.user
1065   - assert community, ta.target
1066   - process_delayed_job_queue
1067   - assert_equal 2, ActionTrackerNotification.count
  1043 + first_activity = article.activity
  1044 + assert_equal [first_activity], ActionTracker::Record.find_all_by_verb('create_article')
1068 1045  
1069   - p2 = fast_create(Person)
1070   - community.add_member(p2)
1071 1046 process_delayed_job_queue
1072   - assert_equal 5, ActionTrackerNotification.count
1073   -
1074   - article = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id
1075   - assert article.published?
1076   - assert_kind_of Community, article.profile
1077   - assert_equal 3, ActionTracker::Record.count
1078   - ta = ActionTracker::Record.first
1079   - assert_equal 'Tracked Article 2', ta.get_name.last
1080   - assert_equal article.url, ta.get_url.last
1081   - assert_equal p1, ta.user
1082   - assert_equal community, ta.target
  1047 + assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(first_activity.id).count
  1048 +
  1049 + member_2 = fast_create(Person)
  1050 + community.add_member(member_2)
  1051 +
  1052 + article2 = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id
  1053 + second_activity = article2.activity
  1054 + assert_equivalent [first_activity, second_activity], ActionTracker::Record.find_all_by_verb('create_article')
  1055 +
1083 1056 process_delayed_job_queue
1084   - assert_equal 6, ActionTrackerNotification.count
  1057 + assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(second_activity.id).count
1085 1058 end
1086 1059  
1087 1060 should 'create notifications to friends when creating an article' do
... ... @@ -1098,12 +1071,10 @@ assert_equal 'bla', profile.articles.map(&:comments_count)
1098 1071 end
1099 1072  
1100 1073 should 'create the notification to the friend when one friend has the notification and the other no' do
1101   - Article.destroy_all
1102   - ActionTracker::Record.destroy_all
1103   - ActionTrackerNotification.destroy_all
1104   -
1105 1074 f1 = fast_create(Person)
1106 1075 profile.add_friend(f1)
  1076 +
  1077 + UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once
1107 1078 article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => profile.id
1108 1079 assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count
1109 1080 process_delayed_job_queue
... ...
test/unit/profile_test.rb
... ... @@ -1763,6 +1763,7 @@ class ProfileTest < ActiveSupport::TestCase
1763 1763 assert_raise NoMethodError do
1764 1764 Profile::Roles.invalid_role(env.id)
1765 1765 end
  1766 + end
1766 1767  
1767 1768 should 'return empty array as activities' do
1768 1769 profile = Profile.new
... ... @@ -1771,7 +1772,6 @@ class ProfileTest < ActiveSupport::TestCase
1771 1772  
1772 1773 private
1773 1774  
1774   -
1775 1775 def assert_invalid_identifier(id)
1776 1776 profile = Profile.new(:identifier => id)
1777 1777 assert !profile.valid?
... ...