From 8c2f76568ee8e06d4de4aa885a9a83b3dec04601 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 2 Aug 2012 16:40:48 -0300 Subject: [PATCH] Grouping activities of images upload --- app/models/uploaded_file.rb | 7 +------ app/views/profile/_upload_image.rhtml | 6 ------ test/unit/action_tracker_notification_test.rb | 9 ++++----- test/unit/uploaded_file_test.rb | 22 ++++++++++++++++------ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index b4f6b58..cb722a4 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -8,7 +8,7 @@ class UploadedFile < Article _('File') end - track_actions :upload_image, :after_create, :keep_params => ["view_url", "thumbnail_path", "parent.url", "parent.name"], :if => Proc.new { |a| a.published? && a.image? && !a.parent.nil? && a.parent.gallery? }, :custom_target => :action_tracker_target + track_actions :upload_image, :after_create, :keep_params => ["view_url", "thumbnail_path", "parent.url", "parent.name"], :if => Proc.new { |a| a.published? && a.image? && !a.parent.nil? && a.parent.gallery? }, :custom_target => :parent include ShortFilename @@ -144,9 +144,4 @@ class UploadedFile < Article def uploaded_file? true end - - def action_tracker_target - self - end - end diff --git a/app/views/profile/_upload_image.rhtml b/app/views/profile/_upload_image.rhtml index 017118b..9e49394 100644 --- a/app/views/profile/_upload_image.rhtml +++ b/app/views/profile/_upload_image.rhtml @@ -6,15 +6,9 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

<%= time_ago_as_sentence(activity.created_at) %>

- <%= link_to(s_('profile|Comment'), '#', { :class => 'focus-on-comment'}) unless activity.get_view_url.size == 1 %> <%= link_to_remote(content_tag(:span, _('Remove')), :confirm => _('Are you sure?'), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %>
- -<% if activity.get_view_url.size == 1 %> - <%= render :partial => 'profile_comments', :locals => { :activity => activity, :tab_action => tab_action } %> -<% end %> -
diff --git a/test/unit/action_tracker_notification_test.rb b/test/unit/action_tracker_notification_test.rb index fa1a0bf..8ff6c6e 100644 --- a/test/unit/action_tracker_notification_test.rb +++ b/test/unit/action_tracker_notification_test.rb @@ -78,14 +78,13 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase should "have comments through action_tracker" do person = fast_create(Person) - community = fast_create(Community) - community.add_member(person) - activity = ActionTracker::Record.last + friend = fast_create(Person) + person.add_friend(friend) process_delayed_job_queue - notification = ActionTrackerNotification.last + activity = ActionTracker::Record.find_last_by_verb 'new_friendship' + notification = ActionTrackerNotification.find_by_action_tracker_id activity.id comment = create(Comment, :source => activity, :author => person) - assert_equal activity.comments, notification.comments end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index 9698ef3..2a2f83a 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -22,7 +22,7 @@ class UploadedFileTest < ActiveSupport::TestCase f = UploadedFile.new f.expects(:content_type).returns('application/pdf') assert_equal 'application/pdf', f.mime_type - end + end should 'provide proper description' do assert_kind_of String, UploadedFile.description @@ -330,11 +330,21 @@ class UploadedFileTest < ActiveSupport::TestCase assert_equal 'hello_world.php.txt', file.filename end - should 'use itself as target for action tracker' do - p = fast_create(Gallery, :profile_id => @profile.id) - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) - ta = f.activity - assert_equal f, ta.target + should 'use gallery as target for action tracker' do + gallery = fast_create(Gallery, :profile_id => profile.id) + image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) + activity = ActionTracker::Record.find_last_by_verb 'upload_image' + assert_equal gallery, activity.target + end + + should 'group trackers activity of image\'s upload' do + gallery = fast_create(Gallery, :profile_id => profile.id) + + image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) + assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count + + image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) + assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count end end -- libgit2 0.21.2