diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index c011ca8..05e8a2b 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -9,13 +9,11 @@ class ProfileController < PublicController def index @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) - @network_activities = [] @wall_items = [] - if !@profile.is_a?(Person) - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) - elsif logged_in? && current_person.follows?(@profile) - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) - @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) if @profile.is_a?(Person) + @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) : [] + if logged_in? && current_person.follows?(@profile) + @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) if @network_activities.empty? + @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) end @tags = profile.article_tags unless profile.display_info_to?(user) diff --git a/app/models/person.rb b/app/models/person.rb index 9d47bd1..aa2afd7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -17,7 +17,6 @@ class Person < Profile has_many :mailings - has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id named_scope :more_popular, @@ -35,11 +34,6 @@ class Person < Profile self.user.destroy if self.user end - def scraps(scrap=nil) - scrap = scrap.is_a?(Scrap) ? scrap.id : scrap - scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) - end - def can_control_scrap?(scrap) begin !self.scraps(scrap).nil? diff --git a/app/models/profile.rb b/app/models/profile.rb index 72c74bb..4a48ced 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -91,12 +91,18 @@ class Profile < ActiveRecord::Base has_many :action_tracker_notifications, :foreign_key => 'profile_id' has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' + has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" # FIXME ugly workaround def self.human_attribute_name(attrib) _(self.superclass.human_attribute_name(attrib)) end + def scraps(scrap=nil) + scrap = scrap.is_a?(Scrap) ? scrap.id : scrap + scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) + end + class_inheritable_accessor :extra_index_methods self.extra_index_methods = [] diff --git a/app/models/scrap.rb b/app/models/scrap.rb index b384710..065de4d 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -2,7 +2,7 @@ class Scrap < ActiveRecord::Base validates_presence_of :content validates_presence_of :sender_id, :receiver_id - belongs_to :receiver, :class_name => 'Person', :foreign_key => 'receiver_id' + belongs_to :receiver, :class_name => 'Profile', :foreign_key => 'receiver_id' belongs_to :sender, :class_name => 'Person', :foreign_key => 'sender_id' has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' @@ -11,12 +11,12 @@ class Scrap < ActiveRecord::Base named_scope :not_replies, :conditions => {:scrap_id => nil} - track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender} + 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 track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? - Scrap::Notifier.deliver_mail(scrap) unless scrap.sender == scrap.receiver + Scrap::Notifier.deliver_mail(scrap) if !scrap.receiver.is_a?(Community) && !(scrap.sender == scrap.receiver) end before_validation :strip_all_html_tags @@ -26,6 +26,10 @@ class Scrap < ActiveRecord::Base self.content = sanitizer.sanitize(self.content, :tags => []) end + def action_tracker_target + self.receiver.is_a?(Community) ? self.receiver : self + end + class Notifier < ActionMailer::Base def mail(scrap) sender, receiver = scrap.sender, scrap.receiver diff --git a/app/views/profile/_common.rhtml b/app/views/profile/_common.rhtml index 37b0f04..8b394b5 100644 --- a/app/views/profile/_common.rhtml +++ b/app/views/profile/_common.rhtml @@ -1,53 +1,63 @@ - <% unless @action %> - <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> - - - <%= _('Content') %> - - - <% profile.blogs.each do |blog| %> - - <%= blog.name + ':' %> - - <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %> - - - <% end %> - <% profile.image_galleries.each do |gallery| %> - - <%= gallery.name + ':' %> - - <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %> - - - <% end %> + +<% unless @action %> + <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> + + + <%= _('Content') %> + + + + <% profile.blogs.each do |blog| %> - <%= _('Events:') %> + <%= blog.name + ':' %> - <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %> + <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %> + <% end %> + <% profile.image_galleries.each do |gallery| %> + <%= gallery.name + ':' %> - <%= _('Tags:') %> - - - <%= tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10%> + <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %> + <% end %> + + + <%= _('Events:') %> + + <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %> + + + + + <%= _('Tags:') %> + + + <%= tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10%> + + - <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> + <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> + + <%= _('Interests') %> + + <% profile.interests.each do |item| %> - <%= _('Interests') %> + + <%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %> - <% profile.interests.each do |item| %> - - - <%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %> - - <% end %> <% end %> <% end %> <% end %> +<% end %> diff --git a/app/views/profile/_organization.rhtml b/app/views/profile/_organization.rhtml index 0780922..ca96d0d 100644 --- a/app/views/profile/_organization.rhtml +++ b/app/views/profile/_organization.rhtml @@ -4,10 +4,16 @@
+ <% if logged_in? && current_person.follows?(@profile) %> + <%= render :partial => 'profile_wall' %> + <% end %> <%= render :partial => 'profile_network' %>
diff --git a/app/views/profile/_person.rhtml b/app/views/profile/_person.rhtml index c012d97..ddc8084 100644 --- a/app/views/profile/_person.rhtml +++ b/app/views/profile/_person.rhtml @@ -22,15 +22,6 @@ <%= render :partial => 'profile_activity' %> <% end %> - -
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index e15cca6..0235f72 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -769,8 +769,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'the network activity be paginated' do p1= Person.first - at = fast_create(ActionTracker::Record) - 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => at.id, :profile_id => p1.id)} + 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => fast_create(ActionTracker::Record), :profile_id => p1.id)} @controller.stubs(:logged_in?).returns(true) user = mock() @@ -838,8 +837,7 @@ class ProfileControllerTest < Test::Unit::TestCase should 'the network activity be paginated on communities' do community = fast_create(Community) - at = fast_create(ActionTracker::Record, :user_id => profile.id) - 40.times{ fast_create(ActionTrackerNotification, :profile_id => community.id, :action_tracker_id => at.id) } + 40.times{ fast_create(ActionTrackerNotification, :profile_id => community.id, :action_tracker_id => fast_create(ActionTracker::Record, :user_id => profile.id)) } get :index, :profile => community.identifier assert_equal 30, assigns(:network_activities).count end @@ -872,7 +870,7 @@ class ProfileControllerTest < Test::Unit::TestCase assert_equal [], assigns(:wall_items) end - should 'the wall_itens be the received scraps' do + should 'the wall_itens be the received scraps in people profile' do p1 = ActionTracker::Record.current_user_from_model p2 = fast_create(Person) p3 = fast_create(Person) @@ -890,7 +888,26 @@ class ProfileControllerTest < Test::Unit::TestCase assert_equal [s2,s3], assigns(:wall_items) end - should 'the wall_itens be paginated' do + should 'the wall_itens be the received scraps in community profile' do + c = fast_create(Community) + p1 = fast_create(Person) + p2 = fast_create(Person) + p3 = fast_create(Person) + s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) + s2 = fast_create(Scrap, :sender_id => p2.id, :receiver_id => c.id) + s3 = fast_create(Scrap, :sender_id => p3.id, :receiver_id => c.id) + + @controller.stubs(:logged_in?).returns(true) + user = mock() + user.stubs(:person).returns(p1) + user.stubs(:login).returns('some') + @controller.stubs(:current_user).returns(user) + Person.any_instance.stubs(:follows?).returns(true) + get :index, :profile => c.identifier + assert_equal [s2,s3], assigns(:wall_items) + end + + should 'the wall_itens be paginated in people profiles' do p1 = Person.first 40.times{fast_create(Scrap, :sender_id => p1.id)} @@ -905,6 +922,22 @@ class ProfileControllerTest < Test::Unit::TestCase assert_equal 30, assigns(:wall_items).count end + should 'the wall_itens be paginated in community profiles' do + p1 = Person.first + c = fast_create(Community) + 40.times{fast_create(Scrap, :receiver_id => c.id)} + + @controller.stubs(:logged_in?).returns(true) + user = mock() + user.stubs(:person).returns(p1) + user.stubs(:login).returns('some') + @controller.stubs(:current_user).returns(user) + Person.any_instance.stubs(:follows?).returns(true) + assert_equal 40, c.scraps_received.not_replies.count + get :index, :profile => c.identifier + assert_equal 30, assigns(:wall_items).count + end + should "the owner of activity could remove it" do login_as(profile.identifier) at = fast_create(ActionTracker::Record, :user_id => profile.id) @@ -993,7 +1026,7 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'li', :attributes => {:id => "profile-activity-item-#{atn.id}"} end - should "view more scraps paginate the scraps" do + should "view more scraps paginate the scraps in people profiles" do login_as(profile.identifier) 40.times{fast_create(Scrap, :receiver_id => profile.id)} get :view_more_scraps, :profile => profile.identifier, :page => 2 @@ -1002,11 +1035,27 @@ class ProfileControllerTest < Test::Unit::TestCase assert_equal 10, assigns(:scraps).count end - should "be logged in to access the view_more_scraps action" do + should "view more scraps paginate the scraps in community profiles" do + login_as(profile.identifier) + c = fast_create(Community) + 40.times{fast_create(Scrap, :receiver_id => c.id)} + get :view_more_scraps, :profile => c.identifier, :page => 2 + assert_response :success + assert_template '_profile_scraps' + assert_equal 10, assigns(:scraps).count + end + + should "be logged in to access the view_more_scraps action in people profiles" do get :view_more_scraps, :profile => profile.identifier assert_redirected_to :controller => 'account', :action => 'login' end + should "be logged in to access the view_more_scraps action in community profiles" do + c = fast_create(Community) + get :view_more_scraps, :profile => c.identifier + assert_redirected_to :controller => 'account', :action => 'login' + end + should "view more activities paginated" do login_as(profile.identifier) 40.times{ fast_create(ActionTracker::Record, :user_id => profile.id)} @@ -1024,8 +1073,7 @@ class ProfileControllerTest < Test::Unit::TestCase should "view more network activities paginated" do login_as(profile.identifier) - at = fast_create(ActionTracker::Record, :user_id => profile.id) - 40.times{fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id) } + 40.times{fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => fast_create(ActionTracker::Record, :user_id => profile.id)) } assert_equal 40, profile.tracked_notifications.count get :view_more_network_activities, :profile => profile.identifier, :page => 2 assert_response :success diff --git a/test/unit/action_tracker_notification_test.rb b/test/unit/action_tracker_notification_test.rb index c0128ef..7d75de4 100644 --- a/test/unit/action_tracker_notification_test.rb +++ b/test/unit/action_tracker_notification_test.rb @@ -41,9 +41,9 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase should "destroy the notifications if the activity is destroyed" do action_tracker = fast_create(ActionTracker::Record) count = ActionTrackerNotification.count - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 1) + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 2) + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 3) action_tracker.destroy assert_equal count, ActionTrackerNotification.count end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 2d79655..a7181ed 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -274,4 +274,48 @@ class CommunityTest < Test::Unit::TestCase end end + should "see get all received scraps" do + c = fast_create(Community) + assert_equal [], c.scraps_received + fast_create(Scrap, :receiver_id => c.id) + fast_create(Scrap, :receiver_id => c.id) + assert_equal 2, c.scraps_received.count + c2 = fast_create(Community) + fast_create(Scrap, :receiver_id => c2.id) + assert_equal 2, c.scraps_received.count + fast_create(Scrap, :receiver_id => c.id) + assert_equal 3, c.scraps_received.count + end + + should "see get all received scraps that are not replies" do + c = fast_create(Community) + s1 = fast_create(Scrap, :receiver_id => c.id) + s2 = fast_create(Scrap, :receiver_id => c.id) + s3 = fast_create(Scrap, :receiver_id => c.id, :scrap_id => s1.id) + assert_equal 3, c.scraps_received.count + assert_equal [s1,s2], c.scraps_received.not_replies + c2 = fast_create(Community) + s4 = fast_create(Scrap, :receiver_id => c2.id) + s5 = fast_create(Scrap, :receiver_id => c2.id, :scrap_id => s4.id) + assert_equal 2, c2.scraps_received.count + assert_equal [s4], c2.scraps_received.not_replies + end + + should "the community browse for a scrap with a Scrap object" do + c = fast_create(Community) + s1 = fast_create(Scrap, :receiver_id => c.id) + s2 = fast_create(Scrap, :receiver_id => c.id) + s3 = fast_create(Scrap, :receiver_id => c.id) + assert_equal s2, c.scraps(s2) + end + + should "the person browse for a scrap with an integer and string id" do + c = fast_create(Community) + s1 = fast_create(Scrap, :receiver_id => c.id) + s2 = fast_create(Scrap, :receiver_id => c.id) + s3 = fast_create(Scrap, :receiver_id => c.id) + assert_equal s2, c.scraps(s2.id) + assert_equal s2, c.scraps(s2.id.to_s) + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 0420d2e..34eb459 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -777,7 +777,7 @@ class PersonTest < Test::Unit::TestCase assert_equal s2, person.scraps(s2) end - should "the person browse for a scrap with an inter and string id" do + should "the person browse for a scrap with an integer and string id" do person = fast_create(Person) s1 = fast_create(Scrap, :sender_id => person.id) s2 = fast_create(Scrap, :sender_id => person.id) @@ -918,11 +918,10 @@ class PersonTest < Test::Unit::TestCase a2 = fast_create(ActionTracker::Record, :user_id => person.id ) a3 = fast_create(ActionTracker::Record) assert_equal 3, ActionTracker::Record.count - fast_create(ActionTrackerNotification, :action_tracker_id => a1.id) - fast_create(ActionTrackerNotification, :action_tracker_id => a1.id) + fast_create(ActionTrackerNotification, :action_tracker_id => a1.id, :profile_id => person.id) fast_create(ActionTrackerNotification, :action_tracker_id => a3.id) - fast_create(ActionTrackerNotification, :action_tracker_id => a2.id) - assert_equal 4, ActionTrackerNotification.count + fast_create(ActionTrackerNotification, :action_tracker_id => a2.id, :profile_id => person.id) + assert_equal 3, ActionTrackerNotification.count person.destroy assert_equal 1, ActionTracker::Record.count assert_equal 1, ActionTrackerNotification.count diff --git a/test/unit/scrap_test.rb b/test/unit/scrap_test.rb index 4fca7ed..f4253b0 100644 --- a/test/unit/scrap_test.rb +++ b/test/unit/scrap_test.rb @@ -51,6 +51,14 @@ class ScrapTest < ActiveSupport::TestCase end end + should "be associated to Community as receiver" do + community = fast_create(Community) + s = Scrap.new + assert_nothing_raised do + s.receiver = community + end + end + should "collect all scraps sent and received of a person" do person = fast_create(Person) s1 = fast_create(Scrap, :sender_id => person.id) @@ -61,6 +69,17 @@ class ScrapTest < ActiveSupport::TestCase assert_equal [s1,s2,s3], Scrap.all_scraps(person) end + should "collect all scraps sent and received of a community" do + community = fast_create(Community) + person = fast_create(Person) + s1 = fast_create(Scrap, :sender_id => person.id) + assert_equal [], Scrap.all_scraps(community) + s2 = fast_create(Scrap, :receiver_id => community.id, :sender_id => person.id) + assert_equal [s2], Scrap.all_scraps(community) + s3 = fast_create(Scrap, :receiver_id => community.id) + assert_equal [s2,s3], Scrap.all_scraps(community) + end + should "create the leave_scrap action tracker verb on scrap creation of one user to another" do p1 = ActionTracker::Record.current_user_from_model p2 = fast_create(Person) @@ -78,6 +97,24 @@ class ScrapTest < ActiveSupport::TestCase assert_equal p1, ta.user end + should "create the leave_scrap action tracker verb on scrap creation of one user to community" do + p = Person.first + c = fast_create(Community) + s = Scrap.new + s.sender= p + s.receiver= c + s.content = 'some content' + s.save! + ta = ActionTracker::Record.last + assert_equal s.content, ta.params['content'] + assert_equal s.sender.name, ta.params['sender_name'] + assert_equal s.receiver.name, ta.params['receiver_name'] + assert_equal s.receiver.url, ta.params['receiver_url'] + assert_equal 'leave_scrap', ta.verb + assert_equal p, ta.user + assert_equal c, ta.target + end + should "notify leave_scrap action tracker verb to friends and itself" do p1 = ActionTracker::Record.current_user_from_model p2 = fast_create(Person) @@ -96,6 +133,24 @@ class ScrapTest < ActiveSupport::TestCase end end + should "notify leave_scrap action tracker verb to members of the communities and the community itself" do + p = Person.first + c = fast_create(Community) + c.add_member(p) + ActionTrackerNotification.destroy_all + Delayed::Job.destroy_all + s = Scrap.new + s.sender= p + s.receiver= c + s.content = 'some content' + s.save! + process_delayed_job_queue + assert_equal 2, ActionTrackerNotification.count + ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| + assert [p,c].include?(profile) + end + end + should "create the leave_scrap_to_self action tracker verb on scrap creation of one user to itself" do p1 = Person.first s = Scrap.new @@ -194,4 +249,13 @@ class ScrapTest < ActiveSupport::TestCase assert s.valid? end + should 'the action_tracker_target be the community when the scraps has the community as receiver' do + scrap = Scrap.new + assert_equal scrap, scrap.action_tracker_target + + community = fast_create(Community) + scrap.receiver = community + assert_equal community, scrap.action_tracker_target + end + end -- libgit2 0.21.2