Commit 70f901d4685b58463325017dadf98ebd41931a98
1 parent
5aa38f73
Exists in
master
and in
22 other branches
Fixing tests
Showing
11 changed files
with
108 additions
and
191 deletions
Show diff stats
app/models/scrap.rb
| @@ -11,7 +11,7 @@ class Scrap < ActiveRecord::Base | @@ -11,7 +11,7 @@ class Scrap < ActiveRecord::Base | ||
| 11 | 11 | ||
| 12 | named_scope :not_replies, :conditions => {:scrap_id => nil} | 12 | named_scope :not_replies, :conditions => {:scrap_id => nil} |
| 13 | 13 | ||
| 14 | - track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender} | 14 | + track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender}, :custom_target => :action_tracker_target |
| 15 | track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} | 15 | track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} |
| 16 | 16 | ||
| 17 | after_create do |scrap| | 17 | after_create do |scrap| |
lib/notify_activity_to_profiles_job.rb
| @@ -19,7 +19,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | @@ -19,7 +19,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | ||
| 19 | 19 | ||
| 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})") | 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) | 22 | + if target.is_a?(Community) || (target.is_a?(Article) && target.profile.is_a?(Community)) |
| 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}") | 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 | ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) | 25 | ActionTrackerNotification.create(:profile_id => target.id, :action_tracker_id => tracked_action.id) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) |
test/unit/action_tracker_notification_test.rb
| @@ -77,11 +77,27 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase | @@ -77,11 +77,27 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase | ||
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | should "have comments through action_tracker" do | 79 | should "have comments through action_tracker" do |
| 80 | - action = fast_create(ActionTracker::Record) | ||
| 81 | - notification = fast_create(ActionTrackerNotification, :action_tracker_id => action.id, :profile_id => 1) | 80 | + person = fast_create(Person) |
| 81 | + community = fast_create(Community) | ||
| 82 | + community.add_member(person) | ||
| 83 | + activity = ActionTracker::Record.last | ||
| 84 | + process_delayed_job_queue | ||
| 85 | + notification = ActionTrackerNotification.last | ||
| 86 | + | ||
| 87 | + comment = create(Comment, :source => activity, :author => person) | ||
| 88 | + | ||
| 89 | + assert_equal activity.comments, notification.comments | ||
| 90 | + end | ||
| 91 | + | ||
| 92 | + should "have comments through article action_tracker" do | ||
| 93 | + person = fast_create(Person) | ||
| 94 | + article = create(TextileArticle, :profile_id => person.id) | ||
| 95 | + process_delayed_job_queue | ||
| 96 | + notification = ActionTrackerNotification.last | ||
| 97 | + | ||
| 98 | + comment = create(Comment, :source => article, :author => person) | ||
| 82 | 99 | ||
| 83 | - comment = fast_create(Comment, :source_id => action.id) | ||
| 84 | - assert_equal action.comments, notification.comments | 100 | + assert_equal article.activity.comments, notification.comments |
| 85 | end | 101 | end |
| 86 | 102 | ||
| 87 | end | 103 | end |
test/unit/approve_article_test.rb
| @@ -250,7 +250,7 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -250,7 +250,7 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
| 250 | assert_equal 1, ActionTracker::Record.count | 250 | assert_equal 1, ActionTracker::Record.count |
| 251 | end | 251 | end |
| 252 | 252 | ||
| 253 | - should 'notify with different trackers activity create with different targets' do | 253 | + should 'not group trackers activity of article\'s creation' do |
| 254 | ActionTracker::Record.delete_all | 254 | ActionTracker::Record.delete_all |
| 255 | 255 | ||
| 256 | article = fast_create(TextileArticle) | 256 | article = fast_create(TextileArticle) |
| @@ -260,28 +260,29 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -260,28 +260,29 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
| 260 | article = fast_create(TextileArticle) | 260 | article = fast_create(TextileArticle) |
| 261 | a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => community, :requestor => profile) | 261 | a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => community, :requestor => profile) |
| 262 | a.finish | 262 | a.finish |
| 263 | - assert_equal 1, ActionTracker::Record.count | ||
| 264 | 263 | ||
| 265 | article = fast_create(TextileArticle) | 264 | article = fast_create(TextileArticle) |
| 266 | other_community = fast_create(Community) | 265 | other_community = fast_create(Community) |
| 267 | a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => other_community, :requestor => profile) | 266 | a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => other_community, :requestor => profile) |
| 268 | a.finish | 267 | a.finish |
| 269 | - assert_equal 2, ActionTracker::Record.count | 268 | + assert_equal 3, ActionTracker::Record.count |
| 270 | end | 269 | end |
| 271 | 270 | ||
| 272 | - should 'notify activity on update' do | 271 | + should 'update activity on update of an article' do |
| 273 | ActionTracker::Record.delete_all | 272 | ActionTracker::Record.delete_all |
| 274 | a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile) | 273 | a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile) |
| 275 | a.finish | 274 | a.finish |
| 276 | - assert_equal 1, ActionTracker::Record.count | ||
| 277 | - | ||
| 278 | - published = article.class.last | ||
| 279 | - published.name = 'foo' | ||
| 280 | - published.save! | ||
| 281 | - assert_equal 2, ActionTracker::Record.count | 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 | ||
| 282 | end | 283 | end |
| 283 | 284 | ||
| 284 | - should 'notify with different trackers activity update with different targets' do | 285 | + should 'not create trackers activity when updating articles' do |
| 285 | ActionTracker::Record.delete_all | 286 | ActionTracker::Record.delete_all |
| 286 | article1 = fast_create(TextileArticle) | 287 | article1 = fast_create(TextileArticle) |
| 287 | a = ApproveArticle.create!(:name => 'bar', :article => article1, :target => community, :requestor => profile) | 288 | a = ApproveArticle.create!(:name => 'bar', :article => article1, :target => community, :requestor => profile) |
| @@ -293,16 +294,16 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -293,16 +294,16 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
| 293 | a.finish | 294 | a.finish |
| 294 | assert_equal 2, ActionTracker::Record.count | 295 | assert_equal 2, ActionTracker::Record.count |
| 295 | 296 | ||
| 296 | - published = article1.class.last | ||
| 297 | - published.name = 'foo';published.save! | ||
| 298 | - assert_equal 3, ActionTracker::Record.count | ||
| 299 | - | ||
| 300 | - published = article2.class.last | ||
| 301 | - published.name = 'another foo';published.save! | ||
| 302 | - assert_equal 4, ActionTracker::Record.count | 297 | + assert_no_difference ActionTracker::Record, :count do |
| 298 | + published = article1.class.last | ||
| 299 | + published.name = 'foo';published.save! | ||
| 300 | + | ||
| 301 | + published = article2.class.last | ||
| 302 | + published.name = 'another foo';published.save! | ||
| 303 | + end | ||
| 303 | end | 304 | end |
| 304 | 305 | ||
| 305 | - should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do | 306 | + should "the tracker action target be defined as the article on articles'creation in communities" do |
| 306 | ActionTracker::Record.delete_all | 307 | ActionTracker::Record.delete_all |
| 307 | person = fast_create(Person) | 308 | person = fast_create(Person) |
| 308 | community.add_member(person) | 309 | community.add_member(person) |
| @@ -310,17 +311,21 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -310,17 +311,21 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
| 310 | a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) | 311 | a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) |
| 311 | a.finish | 312 | a.finish |
| 312 | 313 | ||
| 313 | - assert_equal Community, ActionTracker::Record.last.target.class | 314 | + approved_article = community.articles.find_by_name(article.name) |
| 315 | + | ||
| 316 | + assert_equal approved_article, ActionTracker::Record.last.target | ||
| 314 | end | 317 | end |
| 315 | 318 | ||
| 316 | - should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do | 319 | + should "the tracker action target be defined as the article on articles'creation in profile" do |
| 317 | ActionTracker::Record.delete_all | 320 | ActionTracker::Record.delete_all |
| 318 | person = fast_create(Person) | 321 | person = fast_create(Person) |
| 319 | 322 | ||
| 320 | a = ApproveArticle.create!(:article => article, :target => person, :requestor => profile) | 323 | a = ApproveArticle.create!(:article => article, :target => person, :requestor => profile) |
| 321 | a.finish | 324 | a.finish |
| 322 | 325 | ||
| 323 | - assert_equal Person, ActionTracker::Record.last.target.class | 326 | + approved_article = person.articles.find_by_name(article.name) |
| 327 | + | ||
| 328 | + assert_equal approved_article, ActionTracker::Record.last.target | ||
| 324 | end | 329 | end |
| 325 | 330 | ||
| 326 | should "have the same is_trackable method as original article" do | 331 | should "have the same is_trackable method as original article" do |
test/unit/article_test.rb
| @@ -934,66 +934,31 @@ class ArticleTest < ActiveSupport::TestCase | @@ -934,66 +934,31 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 934 | end | 934 | end |
| 935 | 935 | ||
| 936 | should 'track action when a published article is created outside a community' do | 936 | should 'track action when a published article is created outside a community' do |
| 937 | - article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => profile.id | ||
| 938 | - assert article.published? | ||
| 939 | - assert_kind_of Person, article.profile | ||
| 940 | - ta = ActionTracker::Record.last | ||
| 941 | - assert_equal 'Tracked Article', ta.get_name.last | ||
| 942 | - assert_equal article.url, ta.get_url.last | ||
| 943 | - assert_kind_of Person, ta.user | ||
| 944 | - ta.created_at = Time.now.ago(26.hours); ta.save! | ||
| 945 | - article = TinyMceArticle.create! :name => 'Another Tracked Article', :profile_id => profile.id | ||
| 946 | - ta = ActionTracker::Record.last | ||
| 947 | - assert_equal ['Another Tracked Article'], ta.get_name | ||
| 948 | - assert_equal [article.url], ta.get_url | 937 | + article = create(TinyMceArticle, :profile_id => profile.id) |
| 938 | + ta = article.activity | ||
| 939 | + assert_equal article.name, ta.get_name | ||
| 940 | + assert_equal article.url, ta.get_url | ||
| 949 | end | 941 | end |
| 950 | 942 | ||
| 951 | should 'track action when a published article is created in a community' do | 943 | should 'track action when a published article is created in a community' do |
| 952 | community = fast_create(Community) | 944 | community = fast_create(Community) |
| 953 | - p1 = ActionTracker::Record.current_user_from_model | 945 | + p1 = fast_create(Person) |
| 954 | p2 = fast_create(Person) | 946 | p2 = fast_create(Person) |
| 955 | p3 = fast_create(Person) | 947 | p3 = fast_create(Person) |
| 956 | community.add_member(p1) | 948 | community.add_member(p1) |
| 957 | community.add_member(p2) | 949 | community.add_member(p2) |
| 958 | - assert p1.is_member_of?(community) | ||
| 959 | - assert p2.is_member_of?(community) | ||
| 960 | - assert !p3.is_member_of?(community) | ||
| 961 | Article.destroy_all | 950 | Article.destroy_all |
| 962 | ActionTracker::Record.destroy_all | 951 | ActionTracker::Record.destroy_all |
| 963 | - article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => community.id | ||
| 964 | - assert article.published? | ||
| 965 | - assert_kind_of Community, article.profile | ||
| 966 | - ta = ActionTracker::Record.last | ||
| 967 | - assert_equal 'Tracked Article', ta.get_name.last | ||
| 968 | - assert_equal article.url, ta.get_url.last | ||
| 969 | - assert_kind_of Person, ta.user | 952 | + UserStampSweeper.any_instance.expects(:current_user).returns(p1).at_least_once |
| 953 | + article = create(TinyMceArticle, :profile_id => community.id) | ||
| 954 | + | ||
| 970 | process_delayed_job_queue | 955 | process_delayed_job_queue |
| 971 | - assert_equal 3, ActionTrackerNotification.count | 956 | + assert_equal 3, ActionTrackerNotification.all |
| 972 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | 957 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| |
| 973 | assert [p1,p2,community].include?(profile) | 958 | assert [p1,p2,community].include?(profile) |
| 974 | end | 959 | end |
| 975 | end | 960 | end |
| 976 | 961 | ||
| 977 | - should 'track action when a published article is updated' do | ||
| 978 | - a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id | ||
| 979 | - a.update_attributes! :name => 'b' | ||
| 980 | - ta = ActionTracker::Record.last | ||
| 981 | - assert_equal ['b'], ta.get_name | ||
| 982 | - assert_equal [a.reload.url], ta.get_url | ||
| 983 | - a.update_attributes! :name => 'c' | ||
| 984 | - ta = ActionTracker::Record.last | ||
| 985 | - assert_equal ['b','c'], ta.get_name | ||
| 986 | - assert_equal [a.url,a.reload.url], ta.get_url | ||
| 987 | - a.update_attributes! :body => 'test' | ||
| 988 | - ta = ActionTracker::Record.last | ||
| 989 | - assert_equal ['b','c','c'], ta.get_name | ||
| 990 | - assert_equal [a.url,a.reload.url,a.reload.url], ta.get_url | ||
| 991 | - a.update_attributes! :hits => 50 | ||
| 992 | - ta = ActionTracker::Record.last | ||
| 993 | - assert_equal ['b','c','c'], ta.get_name | ||
| 994 | - assert_equal [a.url,a.reload.url,a.reload.url], ta.get_url | ||
| 995 | - end | ||
| 996 | - | ||
| 997 | should 'track action when a published article is removed' do | 962 | should 'track action when a published article is removed' do |
| 998 | a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id | 963 | a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id |
| 999 | a.destroy | 964 | a.destroy |
| @@ -1022,13 +987,13 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1022,13 +987,13 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1022 | 987 | ||
| 1023 | should 'update action when comment is created' do | 988 | should 'update action when comment is created' do |
| 1024 | article = create(TinyMceArticle, :profile => profile) | 989 | article = create(TinyMceArticle, :profile => profile) |
| 1025 | - action = ActionTracker::Record.last | 990 | + action = article.activity |
| 1026 | time = action.updated_at | 991 | time = action.updated_at |
| 1027 | 992 | ||
| 1028 | Time.stubs(:now).returns(time + 1.day) | 993 | Time.stubs(:now).returns(time + 1.day) |
| 1029 | 994 | ||
| 1030 | - article.comments << Comment.create(:name => 'Guest', :email => 'guest@example.com', :title => 'test comment', :body => 'hello!') | ||
| 1031 | - assert_not_equal time, ActionTracker::Record.last.updated_at | 995 | + comment = create(Comment, :source => article, :author => profile) |
| 996 | + assert_equal time + 1.day, article.activity.updated_at | ||
| 1032 | end | 997 | end |
| 1033 | 998 | ||
| 1034 | should 'notifiable is false by default' do | 999 | should 'notifiable is false by default' do |
| @@ -1162,36 +1127,17 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1162,36 +1127,17 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1162 | assert_equal 6, ActionTrackerNotification.count | 1127 | assert_equal 6, ActionTrackerNotification.count |
| 1163 | end | 1128 | end |
| 1164 | 1129 | ||
| 1165 | - should 'not create more than one notification track action to friends when update more than one artile' do | ||
| 1166 | - p1 = Person.first || fast_create(Person) | 1130 | + should 'create notifications to friends when creating an article' do |
| 1167 | friend = fast_create(Person) | 1131 | friend = fast_create(Person) |
| 1168 | - p1.add_friend(friend) | 1132 | + profile.add_friend(friend) |
| 1169 | Article.destroy_all | 1133 | Article.destroy_all |
| 1170 | ActionTracker::Record.destroy_all | 1134 | ActionTracker::Record.destroy_all |
| 1171 | ActionTrackerNotification.destroy_all | 1135 | ActionTrackerNotification.destroy_all |
| 1172 | - article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => p1.id | ||
| 1173 | - assert article.published? | ||
| 1174 | - assert_kind_of Person, article.profile | ||
| 1175 | - assert_equal 1, ActionTracker::Record.count | ||
| 1176 | - ta = ActionTracker::Record.last | ||
| 1177 | - assert_equal 'Tracked Article 1', ta.get_name.last | ||
| 1178 | - assert_equal article.url, ta.get_url.last | ||
| 1179 | - assert p1, ta.user | ||
| 1180 | - assert p1, ta.target | ||
| 1181 | - process_delayed_job_queue | ||
| 1182 | - assert_equal 2, ActionTrackerNotification.count | 1136 | + UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once |
| 1137 | + article = create(TinyMceArticle, :profile_id => profile.id) | ||
| 1183 | 1138 | ||
| 1184 | - article = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => p1.id | ||
| 1185 | - assert article.published? | ||
| 1186 | - assert_kind_of Person, article.profile | ||
| 1187 | - assert_equal 1, ActionTracker::Record.count | ||
| 1188 | - ta = ActionTracker::Record.last | ||
| 1189 | - assert_equal 'Tracked Article 2', ta.get_name.last | ||
| 1190 | - assert_equal article.url, ta.get_url.last | ||
| 1191 | - assert_equal p1, ta.user | ||
| 1192 | - assert_equal p1, ta.target | ||
| 1193 | process_delayed_job_queue | 1139 | process_delayed_job_queue |
| 1194 | - assert_equal 2, ActionTrackerNotification.count | 1140 | + assert_equal friend, ActionTrackerNotification.last.profile |
| 1195 | end | 1141 | end |
| 1196 | 1142 | ||
| 1197 | should 'create the notification to the friend when one friend has the notification and the other no' do | 1143 | should 'create the notification to the friend when one friend has the notification and the other no' do |
| @@ -1582,7 +1528,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1582,7 +1528,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1582 | should 'survive to a invalid src attribute while looking for images in body' do | 1528 | should 'survive to a invalid src attribute while looking for images in body' do |
| 1583 | article = Article.new(:body => "An article with invalid src in img tag <img src='path with spaces.png' />", :profile => @profile) | 1529 | article = Article.new(:body => "An article with invalid src in img tag <img src='path with spaces.png' />", :profile => @profile) |
| 1584 | assert_nothing_raised URI::InvalidURIError do | 1530 | assert_nothing_raised URI::InvalidURIError do |
| 1585 | - assert_equal ['http://localhost/path%20with%20spaces.png'], article.body_images_paths | 1531 | + assert_equal ["http://#{profile.environment.default_hostname}/path%20with%20spaces.png"], article.body_images_paths |
| 1586 | end | 1532 | end |
| 1587 | end | 1533 | end |
| 1588 | 1534 |
test/unit/comment_test.rb
| @@ -74,11 +74,13 @@ class CommentTest < ActiveSupport::TestCase | @@ -74,11 +74,13 @@ class CommentTest < ActiveSupport::TestCase | ||
| 74 | assert_equal cc + 1, Article.find(art.id).comments_count | 74 | assert_equal cc + 1, Article.find(art.id).comments_count |
| 75 | end | 75 | end |
| 76 | 76 | ||
| 77 | - should 'update counter cache in activity' do | ||
| 78 | - action = fast_create(ActionTracker::Record) | ||
| 79 | - cc = action.comments_count | ||
| 80 | - comment = fast_create(Comment, :source_id => action.id) | 77 | + should 'update counter cache in article activity' do |
| 78 | + owner = create_user('testuser').person | ||
| 79 | + article = create(TextileArticle, :profile_id => owner.id) | ||
| 81 | 80 | ||
| 81 | + action = article.activity | ||
| 82 | + cc = action.comments_count | ||
| 83 | + comment = create(Comment, :source => action, :author_id => owner.id) | ||
| 82 | assert_equal cc + 1, ActionTracker::Record.find(action.id).comments_count | 84 | assert_equal cc + 1, ActionTracker::Record.find(action.id).comments_count |
| 83 | end | 85 | end |
| 84 | 86 |
test/unit/community_test.rb
| @@ -345,7 +345,7 @@ class CommunityTest < ActiveSupport::TestCase | @@ -345,7 +345,7 @@ class CommunityTest < ActiveSupport::TestCase | ||
| 345 | scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => community, :content => 'A scrap')) | 345 | scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => community, :content => 'A scrap')) |
| 346 | activity = ActionTracker::Record.last | 346 | activity = ActionTracker::Record.last |
| 347 | 347 | ||
| 348 | - assert_equal [scrap], community.activities.map { |a| a.klass.constantize.find(a.id) } | 348 | + assert_equal [activity,scrap], community.activities.map { |a| a.klass.constantize.find(a.id) } |
| 349 | end | 349 | end |
| 350 | 350 | ||
| 351 | should 'return tracked_actions of community as activities' do | 351 | should 'return tracked_actions of community as activities' do |
test/unit/notify_activity_to_profiles_job_test.rb
| @@ -24,28 +24,6 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | @@ -24,28 +24,6 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | ||
| 24 | end | 24 | end |
| 25 | end | 25 | end |
| 26 | 26 | ||
| 27 | - should 'notify just the community in tracker with remove_member_in_community verb' do | ||
| 28 | - person = fast_create(Person) | ||
| 29 | - community = fast_create(Community) | ||
| 30 | - action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :target_id => community.id, :verb => 'remove_member_in_community') | ||
| 31 | - assert NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb) | ||
| 32 | - p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person) | ||
| 33 | - fast_create(Friendship, :person_id => person.id, :friend_id => p1.id) | ||
| 34 | - fast_create(Friendship, :person_id => person.id, :friend_id => p2.id) | ||
| 35 | - fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => community.id) | ||
| 36 | - fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => community.id) | ||
| 37 | - ActionTrackerNotification.delete_all | ||
| 38 | - job = NotifyActivityToProfilesJob.new(action_tracker.id) | ||
| 39 | - job.perform | ||
| 40 | - process_delayed_job_queue | ||
| 41 | - | ||
| 42 | - assert_equal 1, ActionTrackerNotification.count | ||
| 43 | - [community].each do |profile| | ||
| 44 | - notification = ActionTrackerNotification.find_by_profile_id profile.id | ||
| 45 | - assert_equal action_tracker, notification.action_tracker | ||
| 46 | - end | ||
| 47 | - end | ||
| 48 | - | ||
| 49 | should 'notify just the users and his friends tracking user actions' do | 27 | should 'notify just the users and his friends tracking user actions' do |
| 50 | person = fast_create(Person) | 28 | person = fast_create(Person) |
| 51 | community = fast_create(Community) | 29 | community = fast_create(Community) |
| @@ -132,36 +110,14 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | @@ -132,36 +110,14 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | ||
| 132 | end | 110 | end |
| 133 | end | 111 | end |
| 134 | 112 | ||
| 135 | - should 'not notify the community tracking leave_community verb' do | ||
| 136 | - person = fast_create(Person) | ||
| 137 | - community = fast_create(Community) | ||
| 138 | - action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :target_id => community.id, :verb => 'leave_community') | ||
| 139 | - assert !NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb) | ||
| 140 | - p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person) | ||
| 141 | - fast_create(Friendship, :person_id => person.id, :friend_id => p1.id) | ||
| 142 | - fast_create(Friendship, :person_id => person.id, :friend_id => p2.id) | ||
| 143 | - fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => community.id) | ||
| 144 | - fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => community.id) | ||
| 145 | - ActionTrackerNotification.delete_all | ||
| 146 | - job = NotifyActivityToProfilesJob.new(action_tracker.id) | ||
| 147 | - job.perform | ||
| 148 | - process_delayed_job_queue | ||
| 149 | - | ||
| 150 | - assert_equal 5, ActionTrackerNotification.count | ||
| 151 | - [person, p1, p2, m1, m2].each do |profile| | ||
| 152 | - notification = ActionTrackerNotification.find_by_profile_id profile.id | ||
| 153 | - assert_equal action_tracker, notification.action_tracker | ||
| 154 | - end | ||
| 155 | - end | ||
| 156 | - | ||
| 157 | should "the NOTIFY_ONLY_COMMUNITY constant has all the verbs tested" do | 113 | should "the NOTIFY_ONLY_COMMUNITY constant has all the verbs tested" do |
| 158 | - notify_community_verbs = ['add_member_in_community', 'remove_member_in_community'] | 114 | + notify_community_verbs = ['add_member_in_community'] |
| 159 | assert_equal [], notify_community_verbs - NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY | 115 | assert_equal [], notify_community_verbs - NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY |
| 160 | assert_equal [], NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY - notify_community_verbs | 116 | assert_equal [], NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY - notify_community_verbs |
| 161 | end | 117 | end |
| 162 | 118 | ||
| 163 | should "the NOT_NOTIFY_COMMUNITY constant has all the verbs tested" do | 119 | should "the NOT_NOTIFY_COMMUNITY constant has all the verbs tested" do |
| 164 | - not_notify_community_verbs = ['join_community', 'leave_community'] | 120 | + not_notify_community_verbs = ['join_community'] |
| 165 | assert_equal [], not_notify_community_verbs - NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY | 121 | assert_equal [], not_notify_community_verbs - NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY |
| 166 | assert_equal [], NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY - not_notify_community_verbs | 122 | assert_equal [], NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY - not_notify_community_verbs |
| 167 | end | 123 | end |
test/unit/textile_article_test.rb
| @@ -38,80 +38,72 @@ class TextileArticleTest < ActiveSupport::TestCase | @@ -38,80 +38,72 @@ class TextileArticleTest < ActiveSupport::TestCase | ||
| 38 | assert_equal 1, ActionTracker::Record.count | 38 | assert_equal 1, ActionTracker::Record.count |
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | - should 'notify with different trackers activity create with different targets' do | 41 | + should 'not group trackers activity of article\'s creation' do |
| 42 | ActionTracker::Record.delete_all | 42 | ActionTracker::Record.delete_all |
| 43 | profile = fast_create(Profile) | 43 | profile = fast_create(Profile) |
| 44 | TextileArticle.create! :name => 'bar', :profile_id => profile.id, :published => true | 44 | TextileArticle.create! :name => 'bar', :profile_id => profile.id, :published => true |
| 45 | TextileArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true | 45 | TextileArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true |
| 46 | - assert_equal 1, ActionTracker::Record.count | ||
| 47 | TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 46 | TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true |
| 48 | - assert_equal 2, ActionTracker::Record.count | 47 | + assert_equal 3, ActionTracker::Record.count |
| 49 | end | 48 | end |
| 50 | 49 | ||
| 51 | - should 'notify activity on update' do | 50 | + should 'update activity on update of an article' do |
| 52 | ActionTracker::Record.delete_all | 51 | ActionTracker::Record.delete_all |
| 53 | - a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | ||
| 54 | - assert_equal 1, ActionTracker::Record.count | ||
| 55 | - a.name = 'foo' | ||
| 56 | - a.save! | ||
| 57 | - assert_equal 2, ActionTracker::Record.count | 52 | + profile = fast_create(Profile) |
| 53 | + article = create(TextileArticle, :profile_id => profile.id) | ||
| 54 | + time = article.activity.updated_at | ||
| 55 | + Time.stubs(:now).returns(time + 1.day) | ||
| 56 | + assert_no_difference ActionTracker::Record, :count do | ||
| 57 | + article.name = 'foo' | ||
| 58 | + article.save! | ||
| 59 | + end | ||
| 60 | + assert_equal time + 1.day, article.activity.updated_at | ||
| 58 | end | 61 | end |
| 59 | 62 | ||
| 60 | - should 'notify with different trackers activity update with different targets' do | 63 | + should 'not create trackers activity when updating articles' do |
| 61 | ActionTracker::Record.delete_all | 64 | ActionTracker::Record.delete_all |
| 62 | a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 65 | a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true |
| 63 | a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 66 | a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true |
| 64 | - assert_equal 2, ActionTracker::Record.count | ||
| 65 | - a1.name = 'foo' | ||
| 66 | - a1.save! | ||
| 67 | - assert_equal 3, ActionTracker::Record.count | ||
| 68 | - a2.name = 'another foo' | ||
| 69 | - a2.save! | ||
| 70 | - assert_equal 4, ActionTracker::Record.count | 67 | + assert_no_difference ActionTracker::Record, :count do |
| 68 | + a1.name = 'foo';a1.save! | ||
| 69 | + a2.name = 'another foo';a2.save! | ||
| 70 | + end | ||
| 71 | end | 71 | end |
| 72 | 72 | ||
| 73 | - should 'notify activity on destroy' do | 73 | + should 'not notify activity on destroy' do |
| 74 | ActionTracker::Record.delete_all | 74 | ActionTracker::Record.delete_all |
| 75 | a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 75 | a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true |
| 76 | - assert_equal 1, ActionTracker::Record.count | ||
| 77 | - a.destroy | ||
| 78 | - assert_equal 2, ActionTracker::Record.count | 76 | + assert_no_difference ActionTracker::Record, :count do |
| 77 | + a.destroy | ||
| 78 | + end | ||
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | - should 'notify different activities when destroy articles with diferrents targets' do | 81 | + should 'not notify when an article is destroyed' do |
| 82 | ActionTracker::Record.delete_all | 82 | ActionTracker::Record.delete_all |
| 83 | a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 83 | a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true |
| 84 | a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 84 | a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true |
| 85 | assert_equal 2, ActionTracker::Record.count | 85 | assert_equal 2, ActionTracker::Record.count |
| 86 | - a1.destroy | ||
| 87 | - assert_equal 3, ActionTracker::Record.count | ||
| 88 | - a2.destroy | ||
| 89 | - assert_equal 4, ActionTracker::Record.count | 86 | + assert_no_difference ActionTracker::Record, :count do |
| 87 | + a1.destroy | ||
| 88 | + a2.destroy | ||
| 89 | + end | ||
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | - should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do | 92 | + should "the tracker action target be defined as the article on articles'creation in communities" do |
| 93 | ActionTracker::Record.delete_all | 93 | ActionTracker::Record.delete_all |
| 94 | community = fast_create(Community) | 94 | community = fast_create(Community) |
| 95 | p1 = Person.first | 95 | p1 = Person.first |
| 96 | community.add_member(p1) | 96 | community.add_member(p1) |
| 97 | assert p1.is_member_of?(community) | 97 | assert p1.is_member_of?(community) |
| 98 | article = TextileArticle.create! :name => 'test', :profile_id => community.id | 98 | article = TextileArticle.create! :name => 'test', :profile_id => community.id |
| 99 | - assert_equal true, article.published? | ||
| 100 | - assert_equal true, article.notifiable? | ||
| 101 | - assert_equal false, article.image? | ||
| 102 | - assert_equal Community, article.profile.class | ||
| 103 | - assert_equal Community, ActionTracker::Record.last.target.class | 99 | + assert_equal article, ActionTracker::Record.last.target |
| 104 | end | 100 | end |
| 105 | 101 | ||
| 106 | - should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do | 102 | + should "the tracker action target be defined as the article on articles'creation in profile" do |
| 107 | ActionTracker::Record.delete_all | 103 | ActionTracker::Record.delete_all |
| 108 | person = Person.first | 104 | person = Person.first |
| 109 | article = TextileArticle.create! :name => 'test', :profile_id => person.id | 105 | article = TextileArticle.create! :name => 'test', :profile_id => person.id |
| 110 | - assert_equal true, article.published? | ||
| 111 | - assert_equal true, article.notifiable? | ||
| 112 | - assert_equal false, article.image? | ||
| 113 | - assert_equal Person, article.profile.class | ||
| 114 | - assert_equal person, ActionTracker::Record.last.target | 106 | + assert_equal article, ActionTracker::Record.last.target |
| 115 | end | 107 | end |
| 116 | 108 | ||
| 117 | should 'not notify activity if the article is not advertise' do | 109 | should 'not notify activity if the article is not advertise' do |
test/unit/tiny_mce_article_test.rb
| @@ -147,7 +147,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -147,7 +147,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
| 147 | should 'update activity on update of an article' do | 147 | should 'update activity on update of an article' do |
| 148 | ActionTracker::Record.delete_all | 148 | ActionTracker::Record.delete_all |
| 149 | profile = fast_create(Profile) | 149 | profile = fast_create(Profile) |
| 150 | - article = create(TextileArticle, :profile_id => profile.id) | 150 | + article = create(TinyMceArticle, :profile_id => profile.id) |
| 151 | time = article.activity.updated_at | 151 | time = article.activity.updated_at |
| 152 | Time.stubs(:now).returns(time + 1.day) | 152 | Time.stubs(:now).returns(time + 1.day) |
| 153 | assert_no_difference ActionTracker::Record, :count do | 153 | assert_no_difference ActionTracker::Record, :count do |
vendor/plugins/action_tracker_has_comments/init.rb
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | ActionTracker::Record.module_eval do | 3 | ActionTracker::Record.module_eval do |
| 4 | 4 | ||
| 5 | - has_many :comments, :class_name => 'Comment', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC' | 5 | + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC' |
| 6 | 6 | ||
| 7 | def conditions_for_comments | 7 | def conditions_for_comments |
| 8 | type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) | 8 | type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) |