Commit 5aa38f73e6599774c6f5d9ba9515f30442a4cc8a
1 parent
2140347f
Exists in
master
and in
29 other branches
Fixing tests
Showing
6 changed files
with
49 additions
and
133 deletions
Show diff stats
app/models/community.rb
@@ -80,7 +80,7 @@ class Community < Organization | @@ -80,7 +80,7 @@ class Community < Organization | ||
80 | end | 80 | end |
81 | 81 | ||
82 | def activities | 82 | def activities |
83 | - Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} ORDER BY updated_at DESC") | 83 | + Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY action_tracker.updated_at DESC") |
84 | end | 84 | end |
85 | 85 | ||
86 | end | 86 | end |
lib/notify_activity_to_profiles_job.rb
1 | class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | 1 | class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) |
2 | NOTIFY_ONLY_COMMUNITY = [ | 2 | NOTIFY_ONLY_COMMUNITY = [ |
3 | 'add_member_in_community', | 3 | 'add_member_in_community', |
4 | - 'remove_member_in_community', | ||
5 | ] | 4 | ] |
6 | 5 | ||
7 | NOT_NOTIFY_COMMUNITY = [ | 6 | NOT_NOTIFY_COMMUNITY = [ |
8 | 'join_community', | 7 | 'join_community', |
9 | - 'leave_community', | ||
10 | ] | 8 | ] |
11 | def perform | 9 | def perform |
12 | return unless ActionTracker::Record.exists?(tracked_action_id) | 10 | return unless ActionTracker::Record.exists?(tracked_action_id) |
test/unit/community_test.rb
@@ -274,22 +274,19 @@ class CommunityTest < ActiveSupport::TestCase | @@ -274,22 +274,19 @@ class CommunityTest < ActiveSupport::TestCase | ||
274 | end | 274 | end |
275 | end | 275 | end |
276 | 276 | ||
277 | - should "be created an tracked action to the community when an community's article is commented" do | 277 | + should "update the action of article creation when an community's article is commented" do |
278 | ActionTrackerNotification.delete_all | 278 | ActionTrackerNotification.delete_all |
279 | p1 = Person.first | 279 | p1 = Person.first |
280 | community = fast_create(Community) | 280 | community = fast_create(Community) |
281 | p2 = fast_create(Person) | 281 | p2 = fast_create(Person) |
282 | p3 = fast_create(Person) | 282 | p3 = fast_create(Person) |
283 | community.add_member(p3) | 283 | community.add_member(p3) |
284 | - article = fast_create(Article, :profile_id => community.id) | ||
285 | - ActionTracker::Record.destroy_all | ||
286 | - assert_difference(ActionTrackerNotification, :count, 3) do | ||
287 | - Comment.create!(:article_id => article.id, :title => 'some', :body => 'some', :author_id => p2.id) | ||
288 | - process_delayed_job_queue | ||
289 | - end | ||
290 | - ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | ||
291 | - assert [community,p1,p3].include?(profile) | ||
292 | - end | 284 | + article = create(TextileArticle, :profile_id => community.id) |
285 | + time = article.activity.updated_at | ||
286 | + Time.stubs(:now).returns(time + 1.day) | ||
287 | + Comment.create!(:source_id => article.id, :title => 'some', :body => 'some', :author_id => p2.id) | ||
288 | + process_delayed_job_queue | ||
289 | + assert_equal time, article.activity.updated_at | ||
293 | end | 290 | end |
294 | 291 | ||
295 | should "see get all received scraps" do | 292 | should "see get all received scraps" do |
@@ -348,34 +345,28 @@ class CommunityTest < ActiveSupport::TestCase | @@ -348,34 +345,28 @@ class CommunityTest < ActiveSupport::TestCase | ||
348 | 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')) |
349 | activity = ActionTracker::Record.last | 346 | activity = ActionTracker::Record.last |
350 | 347 | ||
351 | - assert_equal 'An article about free software', activity.get_name.last | ||
352 | - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 348 | + assert_equal [scrap], community.activities.map { |a| a.klass.constantize.find(a.id) } |
353 | end | 349 | end |
354 | 350 | ||
355 | - should 'return tracked_actions as activities' do | 351 | + should 'return tracked_actions of community as activities' do |
356 | person = fast_create(Person) | 352 | person = fast_create(Person) |
357 | - another_person = fast_create(Person) | 353 | + community = fast_create(Community) |
358 | 354 | ||
359 | - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) | ||
360 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once | 355 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once |
361 | - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') | ||
362 | - activity = ActionTracker::Record.last | 356 | + article = create(TinyMceArticle, :profile => community, :name => 'An article about free software') |
363 | 357 | ||
364 | - assert_equal 'An article about free software', activity.get_name.last | ||
365 | - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 358 | + assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) } |
366 | end | 359 | end |
367 | 360 | ||
368 | - should 'return articles published on communities as activities' do | 361 | + should 'not return tracked_actions of other community as activities' do |
369 | person = fast_create(Person) | 362 | person = fast_create(Person) |
370 | - another_person = fast_create(Person) | 363 | + community = fast_create(Community) |
364 | + community2 = fast_create(Community) | ||
371 | 365 | ||
372 | - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) | ||
373 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once | 366 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once |
374 | - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') | ||
375 | - activity = ActionTracker::Record.last | 367 | + article = create(TinyMceArticle, :profile => community2, :name => 'Another article about free software') |
376 | 368 | ||
377 | - assert_equal 'An article about free software', activity.get_name.last | ||
378 | - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 369 | + assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity |
379 | end | 370 | end |
380 | 371 | ||
381 | end | 372 | end |
test/unit/person_test.rb
@@ -1013,65 +1013,14 @@ class PersonTest < ActiveSupport::TestCase | @@ -1013,65 +1013,14 @@ class PersonTest < ActiveSupport::TestCase | ||
1013 | assert has_add_member_notification | 1013 | assert has_add_member_notification |
1014 | end | 1014 | end |
1015 | 1015 | ||
1016 | - should 'track only one action when a person leaves a community' do | 1016 | + should 'not track when a person leaves a community' do |
1017 | p = create_user('test_user').person | 1017 | p = create_user('test_user').person |
1018 | c = fast_create(Community, :name => "Foo") | 1018 | c = fast_create(Community, :name => "Foo") |
1019 | c.add_member(p) | 1019 | c.add_member(p) |
1020 | c.add_moderator(p) | 1020 | c.add_moderator(p) |
1021 | ActionTracker::Record.delete_all | 1021 | ActionTracker::Record.delete_all |
1022 | c.remove_member(p) | 1022 | c.remove_member(p) |
1023 | - assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'leave_community'}).get_resource_name | ||
1024 | - end | ||
1025 | - | ||
1026 | - should 'the tracker target be Community when a person leaves a community' do | ||
1027 | - ActionTracker::Record.delete_all | ||
1028 | - p = create_user('test_user').person | ||
1029 | - c = fast_create(Community, :name => "Foo") | ||
1030 | - c.add_member(p) | ||
1031 | - c.add_moderator(p) | ||
1032 | - ActionTracker::Record.delete_all | ||
1033 | - c.remove_member(p) | ||
1034 | - assert_kind_of Community, ActionTracker::Record.last(:conditions => {:verb => 'leave_community'}).target | ||
1035 | - end | ||
1036 | - | ||
1037 | - should 'the community be notified specifically when a person leaves a community' do | ||
1038 | - ActionTracker::Record.delete_all | ||
1039 | - p = create_user('test_user').person | ||
1040 | - c = fast_create(Community, :name => "Foo") | ||
1041 | - c.add_member(p) | ||
1042 | - c.add_moderator(p) | ||
1043 | - ActionTracker::Record.delete_all | ||
1044 | - c.remove_member(p) | ||
1045 | - assert_not_nil ActionTracker::Record.last(:conditions => {:verb => 'remove_member_in_community'}) | ||
1046 | - end | ||
1047 | - | ||
1048 | - should 'the community specific notification created when a member leaves community could not be propagated to members' do | ||
1049 | - ActionTracker::Record.delete_all | ||
1050 | - p1 = Person.first | ||
1051 | - p2 = create_user('test_user').person | ||
1052 | - p3 = create_user('test_user').person | ||
1053 | - c = fast_create(Community, :name => "Foo") | ||
1054 | - process_delayed_job_queue | ||
1055 | - Delayed::Job.delete_all | ||
1056 | - c.add_member(p1) | ||
1057 | - c.add_member(p3) | ||
1058 | - c.add_moderator(p1) | ||
1059 | - c.add_moderator(p3) | ||
1060 | - ActionTracker::Record.delete_all | ||
1061 | - c.remove_member(p1) | ||
1062 | - process_delayed_job_queue | ||
1063 | - c.remove_member(p3) | ||
1064 | - process_delayed_job_queue | ||
1065 | - assert_equal 4, ActionTracker::Record.count | ||
1066 | - assert_equal 5, ActionTrackerNotification.count | ||
1067 | - has_remove_member_notification = false | ||
1068 | - ActionTrackerNotification.all.map do |notification| | ||
1069 | - if notification.action_tracker.verb == 'remove_member_in_community' | ||
1070 | - has_remove_member_notification = true | ||
1071 | - assert_equal c, notification.profile | ||
1072 | - end | ||
1073 | - end | ||
1074 | - assert has_remove_member_notification | 1023 | + assert_equal [], ActionTracker::Record.all |
1075 | end | 1024 | end |
1076 | 1025 | ||
1077 | should 'get all friends online' do | 1026 | should 'get all friends online' do |
@@ -1250,11 +1199,9 @@ class PersonTest < ActiveSupport::TestCase | @@ -1250,11 +1199,9 @@ class PersonTest < ActiveSupport::TestCase | ||
1250 | 1199 | ||
1251 | scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) | 1200 | scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap')) |
1252 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once | 1201 | UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once |
1253 | - TinyMceArticle.create!(:profile => person, :name => 'An article about free software') | ||
1254 | - activity = ActionTracker::Record.last | 1202 | + article = TinyMceArticle.create!(:profile => person, :name => 'An article about free software') |
1255 | 1203 | ||
1256 | - assert_equal 'An article about free software', activity.get_name.last | ||
1257 | - assert_equal [scrap,activity], person.activities.map { |a| a.klass.constantize.find(a.id) } | 1204 | + assert_equal [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) } |
1258 | end | 1205 | end |
1259 | 1206 | ||
1260 | should 'not return tracked_actions and scraps from others as activities' do | 1207 | should 'not return tracked_actions and scraps from others as activities' do |
test/unit/tiny_mce_article_test.rb
@@ -134,80 +134,64 @@ class TinyMceArticleTest < ActiveSupport::TestCase | @@ -134,80 +134,64 @@ class TinyMceArticleTest < ActiveSupport::TestCase | ||
134 | assert_equal 1, ActionTracker::Record.count | 134 | assert_equal 1, ActionTracker::Record.count |
135 | end | 135 | end |
136 | 136 | ||
137 | - should 'notify with different trackers activity create with different targets' do | 137 | + should 'not group trackers activity of article\'s creation' do |
138 | ActionTracker::Record.delete_all | 138 | ActionTracker::Record.delete_all |
139 | profile = fast_create(Profile) | 139 | profile = fast_create(Profile) |
140 | TinyMceArticle.create! :name => 'bar', :profile_id => profile.id, :published => true | 140 | TinyMceArticle.create! :name => 'bar', :profile_id => profile.id, :published => true |
141 | TinyMceArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true | 141 | TinyMceArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true |
142 | - assert_equal 1, ActionTracker::Record.count | ||
143 | - TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | ||
144 | assert_equal 2, ActionTracker::Record.count | 142 | assert_equal 2, ActionTracker::Record.count |
143 | + TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | ||
144 | + assert_equal 3, ActionTracker::Record.count | ||
145 | end | 145 | end |
146 | 146 | ||
147 | - should 'notify activity on update' do | 147 | + should 'update activity on update of an article' do |
148 | ActionTracker::Record.delete_all | 148 | ActionTracker::Record.delete_all |
149 | - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | ||
150 | - assert_equal 1, ActionTracker::Record.count | ||
151 | - a.name = 'foo' | ||
152 | - a.save! | ||
153 | - assert_equal 2, ActionTracker::Record.count | 149 | + profile = fast_create(Profile) |
150 | + article = create(TextileArticle, :profile_id => profile.id) | ||
151 | + time = article.activity.updated_at | ||
152 | + Time.stubs(:now).returns(time + 1.day) | ||
153 | + assert_no_difference ActionTracker::Record, :count do | ||
154 | + article.name = 'foo' | ||
155 | + article.save! | ||
156 | + end | ||
157 | + assert_equal time + 1.day, article.activity.updated_at | ||
154 | end | 158 | end |
155 | 159 | ||
156 | - should 'notify with different trackers activity update with different targets' do | 160 | + should 'not create trackers activity when updating articles' do |
157 | ActionTracker::Record.delete_all | 161 | ActionTracker::Record.delete_all |
158 | a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 162 | a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true |
159 | a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 163 | a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true |
160 | - assert_equal 2, ActionTracker::Record.count | ||
161 | - a1.name = 'foo' | ||
162 | - a1.save! | ||
163 | - assert_equal 3, ActionTracker::Record.count | ||
164 | - a2.name = 'another foo' | ||
165 | - a2.save! | ||
166 | - assert_equal 4, ActionTracker::Record.count | 164 | + assert_no_difference ActionTracker::Record, :count do |
165 | + a1.name = 'foo';a1.save! | ||
166 | + a2.name = 'another foo';a2.save! | ||
167 | + end | ||
167 | end | 168 | end |
168 | 169 | ||
169 | - should 'notify activity on destroy' do | ||
170 | - ActionTracker::Record.delete_all | ||
171 | - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | ||
172 | - assert_equal 1, ActionTracker::Record.count | ||
173 | - a.destroy | ||
174 | - assert_equal 2, ActionTracker::Record.count | ||
175 | - end | ||
176 | - | ||
177 | - should 'notify different activities when destroy articles with diferrents targets' do | 170 | + should 'not notify when an article is destroyed' do |
178 | ActionTracker::Record.delete_all | 171 | ActionTracker::Record.delete_all |
179 | a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 172 | a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true |
180 | a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | 173 | a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true |
181 | - assert_equal 2, ActionTracker::Record.count | ||
182 | - a1.destroy | ||
183 | - assert_equal 3, ActionTracker::Record.count | ||
184 | - a2.destroy | ||
185 | - assert_equal 4, ActionTracker::Record.count | 174 | + assert_no_difference ActionTracker::Record, :count do |
175 | + a1.destroy | ||
176 | + a2.destroy | ||
177 | +end | ||
186 | end | 178 | end |
187 | 179 | ||
188 | - should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do | 180 | + should "the tracker action target be defined as the article on articles'creation in communities" do |
189 | ActionTracker::Record.delete_all | 181 | ActionTracker::Record.delete_all |
190 | community = fast_create(Community) | 182 | community = fast_create(Community) |
191 | p1 = Person.first | 183 | p1 = Person.first |
192 | community.add_member(p1) | 184 | community.add_member(p1) |
193 | assert p1.is_member_of?(community) | 185 | assert p1.is_member_of?(community) |
194 | article = TinyMceArticle.create! :name => 'test', :profile_id => community.id | 186 | article = TinyMceArticle.create! :name => 'test', :profile_id => community.id |
195 | - assert_equal true, article.published? | ||
196 | - assert_equal true, article.notifiable? | ||
197 | - assert_equal false, article.image? | ||
198 | - assert_equal Community, article.profile.class | ||
199 | - assert_equal Community, ActionTracker::Record.last.target.class | 187 | + assert_equal article, ActionTracker::Record.last.target |
200 | end | 188 | end |
201 | 189 | ||
202 | - should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do | 190 | + should "the tracker action target be defined as the article on articles'creation in profile" do |
203 | ActionTracker::Record.delete_all | 191 | ActionTracker::Record.delete_all |
204 | person = Person.first | 192 | person = Person.first |
205 | article = TinyMceArticle.create! :name => 'test', :profile_id => person.id | 193 | article = TinyMceArticle.create! :name => 'test', :profile_id => person.id |
206 | - assert_equal true, article.published? | ||
207 | - assert_equal true, article.notifiable? | ||
208 | - assert_equal false, article.image? | ||
209 | - assert_equal Person, article.profile.class | ||
210 | - assert_equal person, ActionTracker::Record.last.target | 194 | + assert_equal article, ActionTracker::Record.last.target |
211 | end | 195 | end |
212 | 196 | ||
213 | should 'not notify activity if the article is not advertise' do | 197 | should 'not notify activity if the article is not advertise' do |
vendor/plugins/access_control/lib/role_assignment.rb
@@ -9,10 +9,6 @@ class RoleAssignment < ActiveRecord::Base | @@ -9,10 +9,6 @@ class RoleAssignment < ActiveRecord::Base | ||
9 | 9 | ||
10 | track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource | 10 | track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource |
11 | 11 | ||
12 | - track_actions :leave_community, :before_destroy, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource | ||
13 | - | ||
14 | - track_actions :remove_member_in_community, :before_destroy, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_target => :resource, :custom_user => :accessor | ||
15 | - | ||
16 | def has_permission?(perm, res) | 12 | def has_permission?(perm, res) |
17 | return false unless role.has_permission?(perm.to_s) && (resource || is_global) | 13 | return false unless role.has_permission?(perm.to_s) && (resource || is_global) |
18 | return true if is_global | 14 | return true if is_global |