Commit 28545c9fa400136c462012d8902a779b05a5d94d
Committed by
Antonio Terceiro
1 parent
47295de6
Exists in
master
and in
28 other branches
Adding scraps to communities.
(ActionItem1303)
Showing
12 changed files
with
243 additions
and
79 deletions
Show diff stats
app/controllers/public/profile_controller.rb
@@ -9,13 +9,11 @@ class ProfileController < PublicController | @@ -9,13 +9,11 @@ class ProfileController < PublicController | ||
9 | 9 | ||
10 | def index | 10 | def index |
11 | @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) | 11 | @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) |
12 | - @network_activities = [] | ||
13 | @wall_items = [] | 12 | @wall_items = [] |
14 | - if !@profile.is_a?(Person) | ||
15 | - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) | ||
16 | - elsif logged_in? && current_person.follows?(@profile) | ||
17 | - @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) | ||
18 | - @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) if @profile.is_a?(Person) | 13 | + @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) : [] |
14 | + if logged_in? && current_person.follows?(@profile) | ||
15 | + @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) if @network_activities.empty? | ||
16 | + @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) | ||
19 | end | 17 | end |
20 | @tags = profile.article_tags | 18 | @tags = profile.article_tags |
21 | unless profile.display_info_to?(user) | 19 | unless profile.display_info_to?(user) |
app/models/person.rb
@@ -17,7 +17,6 @@ class Person < Profile | @@ -17,7 +17,6 @@ class Person < Profile | ||
17 | 17 | ||
18 | has_many :mailings | 18 | has_many :mailings |
19 | 19 | ||
20 | - has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" | ||
21 | has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id | 20 | has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id |
22 | 21 | ||
23 | named_scope :more_popular, | 22 | named_scope :more_popular, |
@@ -35,11 +34,6 @@ class Person < Profile | @@ -35,11 +34,6 @@ class Person < Profile | ||
35 | self.user.destroy if self.user | 34 | self.user.destroy if self.user |
36 | end | 35 | end |
37 | 36 | ||
38 | - def scraps(scrap=nil) | ||
39 | - scrap = scrap.is_a?(Scrap) ? scrap.id : scrap | ||
40 | - scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) | ||
41 | - end | ||
42 | - | ||
43 | def can_control_scrap?(scrap) | 37 | def can_control_scrap?(scrap) |
44 | begin | 38 | begin |
45 | !self.scraps(scrap).nil? | 39 | !self.scraps(scrap).nil? |
app/models/profile.rb
@@ -91,12 +91,18 @@ class Profile < ActiveRecord::Base | @@ -91,12 +91,18 @@ class Profile < ActiveRecord::Base | ||
91 | 91 | ||
92 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' | 92 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' |
93 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' | 93 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' |
94 | + has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC" | ||
94 | 95 | ||
95 | # FIXME ugly workaround | 96 | # FIXME ugly workaround |
96 | def self.human_attribute_name(attrib) | 97 | def self.human_attribute_name(attrib) |
97 | _(self.superclass.human_attribute_name(attrib)) | 98 | _(self.superclass.human_attribute_name(attrib)) |
98 | end | 99 | end |
99 | 100 | ||
101 | + def scraps(scrap=nil) | ||
102 | + scrap = scrap.is_a?(Scrap) ? scrap.id : scrap | ||
103 | + scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) | ||
104 | + end | ||
105 | + | ||
100 | class_inheritable_accessor :extra_index_methods | 106 | class_inheritable_accessor :extra_index_methods |
101 | self.extra_index_methods = [] | 107 | self.extra_index_methods = [] |
102 | 108 |
app/models/scrap.rb
@@ -2,7 +2,7 @@ class Scrap < ActiveRecord::Base | @@ -2,7 +2,7 @@ class Scrap < ActiveRecord::Base | ||
2 | validates_presence_of :content | 2 | validates_presence_of :content |
3 | validates_presence_of :sender_id, :receiver_id | 3 | validates_presence_of :sender_id, :receiver_id |
4 | 4 | ||
5 | - belongs_to :receiver, :class_name => 'Person', :foreign_key => 'receiver_id' | 5 | + belongs_to :receiver, :class_name => 'Profile', :foreign_key => 'receiver_id' |
6 | belongs_to :sender, :class_name => 'Person', :foreign_key => 'sender_id' | 6 | belongs_to :sender, :class_name => 'Person', :foreign_key => 'sender_id' |
7 | has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy | 7 | has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy |
8 | belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' | 8 | belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' |
@@ -11,12 +11,12 @@ class Scrap < ActiveRecord::Base | @@ -11,12 +11,12 @@ 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| |
18 | scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? | 18 | scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? |
19 | - Scrap::Notifier.deliver_mail(scrap) unless scrap.sender == scrap.receiver | 19 | + Scrap::Notifier.deliver_mail(scrap) if !scrap.receiver.is_a?(Community) && !(scrap.sender == scrap.receiver) |
20 | end | 20 | end |
21 | 21 | ||
22 | before_validation :strip_all_html_tags | 22 | before_validation :strip_all_html_tags |
@@ -26,6 +26,10 @@ class Scrap < ActiveRecord::Base | @@ -26,6 +26,10 @@ class Scrap < ActiveRecord::Base | ||
26 | self.content = sanitizer.sanitize(self.content, :tags => []) | 26 | self.content = sanitizer.sanitize(self.content, :tags => []) |
27 | end | 27 | end |
28 | 28 | ||
29 | + def action_tracker_target | ||
30 | + self.receiver.is_a?(Community) ? self.receiver : self | ||
31 | + end | ||
32 | + | ||
29 | class Notifier < ActionMailer::Base | 33 | class Notifier < ActionMailer::Base |
30 | def mail(scrap) | 34 | def mail(scrap) |
31 | sender, receiver = scrap.sender, scrap.receiver | 35 | sender, receiver = scrap.sender, scrap.receiver |
app/views/profile/_common.rhtml
1 | - <% unless @action %> | ||
2 | - <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> | ||
3 | - <tr> | ||
4 | - <th colspan='2'> | ||
5 | - <%= _('Content') %> | ||
6 | - </th> | ||
7 | - </tr> | ||
8 | 1 | ||
9 | - <% profile.blogs.each do |blog| %> | ||
10 | - <tr> | ||
11 | - <td><%= blog.name + ':' %></td> | ||
12 | - <td> | ||
13 | - <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %> | ||
14 | - </td> | ||
15 | - </tr> | ||
16 | - <% end %> | ||
17 | - <% profile.image_galleries.each do |gallery| %> | ||
18 | - <tr> | ||
19 | - <td><%= gallery.name + ':' %></td> | ||
20 | - <td> | ||
21 | - <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %> | ||
22 | - </td> | ||
23 | - </tr> | ||
24 | - <% end %> | 2 | +<script type="text/javascript"> |
3 | + jQuery( function() { | ||
4 | + var parent_selector = '.profile-wall-description, .profile-activity-description, .profile-network-description'; | ||
5 | + var child_selector = '.icon-delete, .icon-reply, .icon-scrap'; | ||
6 | + jQuery(parent_selector).live('mouseover', function () { jQuery(this).find(child_selector).css('visibility', 'visible'); }); | ||
7 | + jQuery(parent_selector).live('mouseout', function () { jQuery(this).find(child_selector).css('visibility', 'hidden'); }); | ||
8 | + }); | ||
9 | +</script> | ||
25 | 10 | ||
11 | +<% unless @action %> | ||
12 | + <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> | ||
13 | + <tr> | ||
14 | + <th colspan='2'> | ||
15 | + <%= _('Content') %> | ||
16 | + </th> | ||
17 | + </tr> | ||
18 | + | ||
19 | + <% profile.blogs.each do |blog| %> | ||
26 | <tr> | 20 | <tr> |
27 | - <td><%= _('Events:') %></td> | 21 | + <td><%= blog.name + ':' %></td> |
28 | <td> | 22 | <td> |
29 | - <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %> | 23 | + <%= link_to(n_('One post', '%{num} posts', blog.posts.published.count) % { :num => blog.posts.published.count }, blog.url) %> |
30 | </td> | 24 | </td> |
31 | </tr> | 25 | </tr> |
26 | + <% end %> | ||
27 | + <% profile.image_galleries.each do |gallery| %> | ||
32 | <tr> | 28 | <tr> |
29 | + <td><%= gallery.name + ':' %></td> | ||
33 | <td> | 30 | <td> |
34 | - <%= _('Tags:') %> | ||
35 | - </td> | ||
36 | - <td> | ||
37 | - <%= tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10%> | 31 | + <%= link_to(n_('One picture', '%{num} pictures', gallery.images.published.count) % { :num => gallery.images.published.count }, gallery.url) %> |
38 | </td> | 32 | </td> |
39 | </tr> | 33 | </tr> |
34 | + <% end %> | ||
35 | + | ||
36 | + <tr> | ||
37 | + <td><%= _('Events:') %></td> | ||
38 | + <td> | ||
39 | + <%= link_to profile.events.published.count, :controller => 'events', :action => 'events' %> | ||
40 | + </td> | ||
41 | + </tr> | ||
42 | + <tr> | ||
43 | + <td> | ||
44 | + <%= _('Tags:') %> | ||
45 | + </td> | ||
46 | + <td> | ||
47 | + <%= tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10%> | ||
48 | + </td> | ||
49 | + </tr> | ||
40 | 50 | ||
41 | - <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> | 51 | + <% if !environment.enabled?('disable_categories') && !profile.interests.empty? %> |
52 | + <tr> | ||
53 | + <th colspan='2'><%= _('Interests') %></th> | ||
54 | + </tr> | ||
55 | + <% profile.interests.each do |item| %> | ||
42 | <tr> | 56 | <tr> |
43 | - <th colspan='2'><%= _('Interests') %></th> | 57 | + <td></td> |
58 | + <td><%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %></td> | ||
44 | </tr> | 59 | </tr> |
45 | - <% profile.interests.each do |item| %> | ||
46 | - <tr> | ||
47 | - <td></td> | ||
48 | - <td><%= link_to item.name, :controller => 'search', :action => 'category_index', :category_path => item.explode_path %></td> | ||
49 | - </tr> | ||
50 | - <% end %> | ||
51 | <% end %> | 60 | <% end %> |
52 | <% end %> | 61 | <% end %> |
53 | <% end %> | 62 | <% end %> |
63 | +<% end %> |
app/views/profile/_organization.rhtml
@@ -4,10 +4,16 @@ | @@ -4,10 +4,16 @@ | ||
4 | <div class='ui-tabs'> | 4 | <div class='ui-tabs'> |
5 | 5 | ||
6 | <ul> | 6 | <ul> |
7 | + <% if logged_in? && current_person.follows?(@profile) %> | ||
8 | + <li class='tab'><a href='#profile-wall'><%= _('Wall') %></a></li> | ||
9 | + <% end %> | ||
7 | <li class='tab'><a href='#profile-network'><%= _('What\'s new') %></a></li> | 10 | <li class='tab'><a href='#profile-network'><%= _('What\'s new') %></a></li> |
8 | <li class='tab'><a href='#community-profile'><%= _('Profile') %></a></li> | 11 | <li class='tab'><a href='#community-profile'><%= _('Profile') %></a></li> |
9 | </ul> | 12 | </ul> |
10 | 13 | ||
14 | + <% if logged_in? && current_person.follows?(@profile) %> | ||
15 | + <%= render :partial => 'profile_wall' %> | ||
16 | + <% end %> | ||
11 | <%= render :partial => 'profile_network' %> | 17 | <%= render :partial => 'profile_network' %> |
12 | 18 | ||
13 | <div id='community-profile'> | 19 | <div id='community-profile'> |
app/views/profile/_person.rhtml
@@ -22,15 +22,6 @@ | @@ -22,15 +22,6 @@ | ||
22 | <%= render :partial => 'profile_activity' %> | 22 | <%= render :partial => 'profile_activity' %> |
23 | <% end %> | 23 | <% end %> |
24 | 24 | ||
25 | - <script type="text/javascript"> | ||
26 | - jQuery( function() { | ||
27 | - var parent_selector = '.profile-wall-description, .profile-activity-description, .profile-network-description'; | ||
28 | - var child_selector = '.icon-delete, .icon-reply, .icon-scrap'; | ||
29 | - jQuery(parent_selector).live('mouseover', function () { jQuery(this).find(child_selector).css('visibility', 'visible'); }); | ||
30 | - jQuery(parent_selector).live('mouseout', function () { jQuery(this).find(child_selector).css('visibility', 'hidden'); }); | ||
31 | - }); | ||
32 | - </script> | ||
33 | - | ||
34 | <div id='person-profile'> | 25 | <div id='person-profile'> |
35 | <table> | 26 | <table> |
36 | <tr> | 27 | <tr> |
test/functional/profile_controller_test.rb
@@ -769,8 +769,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -769,8 +769,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
769 | 769 | ||
770 | should 'the network activity be paginated' do | 770 | should 'the network activity be paginated' do |
771 | p1= Person.first | 771 | p1= Person.first |
772 | - at = fast_create(ActionTracker::Record) | ||
773 | - 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => at.id, :profile_id => p1.id)} | 772 | + 40.times{fast_create(ActionTrackerNotification, :action_tracker_id => fast_create(ActionTracker::Record), :profile_id => p1.id)} |
774 | 773 | ||
775 | @controller.stubs(:logged_in?).returns(true) | 774 | @controller.stubs(:logged_in?).returns(true) |
776 | user = mock() | 775 | user = mock() |
@@ -838,8 +837,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -838,8 +837,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
838 | 837 | ||
839 | should 'the network activity be paginated on communities' do | 838 | should 'the network activity be paginated on communities' do |
840 | community = fast_create(Community) | 839 | community = fast_create(Community) |
841 | - at = fast_create(ActionTracker::Record, :user_id => profile.id) | ||
842 | - 40.times{ fast_create(ActionTrackerNotification, :profile_id => community.id, :action_tracker_id => at.id) } | 840 | + 40.times{ fast_create(ActionTrackerNotification, :profile_id => community.id, :action_tracker_id => fast_create(ActionTracker::Record, :user_id => profile.id)) } |
843 | get :index, :profile => community.identifier | 841 | get :index, :profile => community.identifier |
844 | assert_equal 30, assigns(:network_activities).count | 842 | assert_equal 30, assigns(:network_activities).count |
845 | end | 843 | end |
@@ -872,7 +870,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -872,7 +870,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
872 | assert_equal [], assigns(:wall_items) | 870 | assert_equal [], assigns(:wall_items) |
873 | end | 871 | end |
874 | 872 | ||
875 | - should 'the wall_itens be the received scraps' do | 873 | + should 'the wall_itens be the received scraps in people profile' do |
876 | p1 = ActionTracker::Record.current_user_from_model | 874 | p1 = ActionTracker::Record.current_user_from_model |
877 | p2 = fast_create(Person) | 875 | p2 = fast_create(Person) |
878 | p3 = fast_create(Person) | 876 | p3 = fast_create(Person) |
@@ -890,7 +888,26 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -890,7 +888,26 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
890 | assert_equal [s2,s3], assigns(:wall_items) | 888 | assert_equal [s2,s3], assigns(:wall_items) |
891 | end | 889 | end |
892 | 890 | ||
893 | - should 'the wall_itens be paginated' do | 891 | + should 'the wall_itens be the received scraps in community profile' do |
892 | + c = fast_create(Community) | ||
893 | + p1 = fast_create(Person) | ||
894 | + p2 = fast_create(Person) | ||
895 | + p3 = fast_create(Person) | ||
896 | + s1 = fast_create(Scrap, :sender_id => p1.id, :receiver_id => p2.id) | ||
897 | + s2 = fast_create(Scrap, :sender_id => p2.id, :receiver_id => c.id) | ||
898 | + s3 = fast_create(Scrap, :sender_id => p3.id, :receiver_id => c.id) | ||
899 | + | ||
900 | + @controller.stubs(:logged_in?).returns(true) | ||
901 | + user = mock() | ||
902 | + user.stubs(:person).returns(p1) | ||
903 | + user.stubs(:login).returns('some') | ||
904 | + @controller.stubs(:current_user).returns(user) | ||
905 | + Person.any_instance.stubs(:follows?).returns(true) | ||
906 | + get :index, :profile => c.identifier | ||
907 | + assert_equal [s2,s3], assigns(:wall_items) | ||
908 | + end | ||
909 | + | ||
910 | + should 'the wall_itens be paginated in people profiles' do | ||
894 | p1 = Person.first | 911 | p1 = Person.first |
895 | 40.times{fast_create(Scrap, :sender_id => p1.id)} | 912 | 40.times{fast_create(Scrap, :sender_id => p1.id)} |
896 | 913 | ||
@@ -905,6 +922,22 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -905,6 +922,22 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
905 | assert_equal 30, assigns(:wall_items).count | 922 | assert_equal 30, assigns(:wall_items).count |
906 | end | 923 | end |
907 | 924 | ||
925 | + should 'the wall_itens be paginated in community profiles' do | ||
926 | + p1 = Person.first | ||
927 | + c = fast_create(Community) | ||
928 | + 40.times{fast_create(Scrap, :receiver_id => c.id)} | ||
929 | + | ||
930 | + @controller.stubs(:logged_in?).returns(true) | ||
931 | + user = mock() | ||
932 | + user.stubs(:person).returns(p1) | ||
933 | + user.stubs(:login).returns('some') | ||
934 | + @controller.stubs(:current_user).returns(user) | ||
935 | + Person.any_instance.stubs(:follows?).returns(true) | ||
936 | + assert_equal 40, c.scraps_received.not_replies.count | ||
937 | + get :index, :profile => c.identifier | ||
938 | + assert_equal 30, assigns(:wall_items).count | ||
939 | + end | ||
940 | + | ||
908 | should "the owner of activity could remove it" do | 941 | should "the owner of activity could remove it" do |
909 | login_as(profile.identifier) | 942 | login_as(profile.identifier) |
910 | at = fast_create(ActionTracker::Record, :user_id => profile.id) | 943 | at = fast_create(ActionTracker::Record, :user_id => profile.id) |
@@ -993,7 +1026,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -993,7 +1026,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
993 | assert_no_tag :tag => 'li', :attributes => {:id => "profile-activity-item-#{atn.id}"} | 1026 | assert_no_tag :tag => 'li', :attributes => {:id => "profile-activity-item-#{atn.id}"} |
994 | end | 1027 | end |
995 | 1028 | ||
996 | - should "view more scraps paginate the scraps" do | 1029 | + should "view more scraps paginate the scraps in people profiles" do |
997 | login_as(profile.identifier) | 1030 | login_as(profile.identifier) |
998 | 40.times{fast_create(Scrap, :receiver_id => profile.id)} | 1031 | 40.times{fast_create(Scrap, :receiver_id => profile.id)} |
999 | get :view_more_scraps, :profile => profile.identifier, :page => 2 | 1032 | get :view_more_scraps, :profile => profile.identifier, :page => 2 |
@@ -1002,11 +1035,27 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -1002,11 +1035,27 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
1002 | assert_equal 10, assigns(:scraps).count | 1035 | assert_equal 10, assigns(:scraps).count |
1003 | end | 1036 | end |
1004 | 1037 | ||
1005 | - should "be logged in to access the view_more_scraps action" do | 1038 | + should "view more scraps paginate the scraps in community profiles" do |
1039 | + login_as(profile.identifier) | ||
1040 | + c = fast_create(Community) | ||
1041 | + 40.times{fast_create(Scrap, :receiver_id => c.id)} | ||
1042 | + get :view_more_scraps, :profile => c.identifier, :page => 2 | ||
1043 | + assert_response :success | ||
1044 | + assert_template '_profile_scraps' | ||
1045 | + assert_equal 10, assigns(:scraps).count | ||
1046 | + end | ||
1047 | + | ||
1048 | + should "be logged in to access the view_more_scraps action in people profiles" do | ||
1006 | get :view_more_scraps, :profile => profile.identifier | 1049 | get :view_more_scraps, :profile => profile.identifier |
1007 | assert_redirected_to :controller => 'account', :action => 'login' | 1050 | assert_redirected_to :controller => 'account', :action => 'login' |
1008 | end | 1051 | end |
1009 | 1052 | ||
1053 | + should "be logged in to access the view_more_scraps action in community profiles" do | ||
1054 | + c = fast_create(Community) | ||
1055 | + get :view_more_scraps, :profile => c.identifier | ||
1056 | + assert_redirected_to :controller => 'account', :action => 'login' | ||
1057 | + end | ||
1058 | + | ||
1010 | should "view more activities paginated" do | 1059 | should "view more activities paginated" do |
1011 | login_as(profile.identifier) | 1060 | login_as(profile.identifier) |
1012 | 40.times{ fast_create(ActionTracker::Record, :user_id => profile.id)} | 1061 | 40.times{ fast_create(ActionTracker::Record, :user_id => profile.id)} |
@@ -1024,8 +1073,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -1024,8 +1073,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
1024 | 1073 | ||
1025 | should "view more network activities paginated" do | 1074 | should "view more network activities paginated" do |
1026 | login_as(profile.identifier) | 1075 | login_as(profile.identifier) |
1027 | - at = fast_create(ActionTracker::Record, :user_id => profile.id) | ||
1028 | - 40.times{fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id) } | 1076 | + 40.times{fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => fast_create(ActionTracker::Record, :user_id => profile.id)) } |
1029 | assert_equal 40, profile.tracked_notifications.count | 1077 | assert_equal 40, profile.tracked_notifications.count |
1030 | get :view_more_network_activities, :profile => profile.identifier, :page => 2 | 1078 | get :view_more_network_activities, :profile => profile.identifier, :page => 2 |
1031 | assert_response :success | 1079 | assert_response :success |
test/unit/action_tracker_notification_test.rb
@@ -41,9 +41,9 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase | @@ -41,9 +41,9 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase | ||
41 | should "destroy the notifications if the activity is destroyed" do | 41 | should "destroy the notifications if the activity is destroyed" do |
42 | action_tracker = fast_create(ActionTracker::Record) | 42 | action_tracker = fast_create(ActionTracker::Record) |
43 | count = ActionTrackerNotification.count | 43 | count = ActionTrackerNotification.count |
44 | - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) | ||
45 | - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) | ||
46 | - fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id) | 44 | + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 1) |
45 | + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 2) | ||
46 | + fast_create(ActionTrackerNotification, :action_tracker_id => action_tracker.id, :profile_id => 3) | ||
47 | action_tracker.destroy | 47 | action_tracker.destroy |
48 | assert_equal count, ActionTrackerNotification.count | 48 | assert_equal count, ActionTrackerNotification.count |
49 | end | 49 | end |
test/unit/community_test.rb
@@ -274,4 +274,48 @@ class CommunityTest < Test::Unit::TestCase | @@ -274,4 +274,48 @@ class CommunityTest < Test::Unit::TestCase | ||
274 | end | 274 | end |
275 | end | 275 | end |
276 | 276 | ||
277 | + should "see get all received scraps" do | ||
278 | + c = fast_create(Community) | ||
279 | + assert_equal [], c.scraps_received | ||
280 | + fast_create(Scrap, :receiver_id => c.id) | ||
281 | + fast_create(Scrap, :receiver_id => c.id) | ||
282 | + assert_equal 2, c.scraps_received.count | ||
283 | + c2 = fast_create(Community) | ||
284 | + fast_create(Scrap, :receiver_id => c2.id) | ||
285 | + assert_equal 2, c.scraps_received.count | ||
286 | + fast_create(Scrap, :receiver_id => c.id) | ||
287 | + assert_equal 3, c.scraps_received.count | ||
288 | + end | ||
289 | + | ||
290 | + should "see get all received scraps that are not replies" do | ||
291 | + c = fast_create(Community) | ||
292 | + s1 = fast_create(Scrap, :receiver_id => c.id) | ||
293 | + s2 = fast_create(Scrap, :receiver_id => c.id) | ||
294 | + s3 = fast_create(Scrap, :receiver_id => c.id, :scrap_id => s1.id) | ||
295 | + assert_equal 3, c.scraps_received.count | ||
296 | + assert_equal [s1,s2], c.scraps_received.not_replies | ||
297 | + c2 = fast_create(Community) | ||
298 | + s4 = fast_create(Scrap, :receiver_id => c2.id) | ||
299 | + s5 = fast_create(Scrap, :receiver_id => c2.id, :scrap_id => s4.id) | ||
300 | + assert_equal 2, c2.scraps_received.count | ||
301 | + assert_equal [s4], c2.scraps_received.not_replies | ||
302 | + end | ||
303 | + | ||
304 | + should "the community browse for a scrap with a Scrap object" do | ||
305 | + c = fast_create(Community) | ||
306 | + s1 = fast_create(Scrap, :receiver_id => c.id) | ||
307 | + s2 = fast_create(Scrap, :receiver_id => c.id) | ||
308 | + s3 = fast_create(Scrap, :receiver_id => c.id) | ||
309 | + assert_equal s2, c.scraps(s2) | ||
310 | + end | ||
311 | + | ||
312 | + should "the person browse for a scrap with an integer and string id" do | ||
313 | + c = fast_create(Community) | ||
314 | + s1 = fast_create(Scrap, :receiver_id => c.id) | ||
315 | + s2 = fast_create(Scrap, :receiver_id => c.id) | ||
316 | + s3 = fast_create(Scrap, :receiver_id => c.id) | ||
317 | + assert_equal s2, c.scraps(s2.id) | ||
318 | + assert_equal s2, c.scraps(s2.id.to_s) | ||
319 | + end | ||
320 | + | ||
277 | end | 321 | end |
test/unit/person_test.rb
@@ -777,7 +777,7 @@ class PersonTest < Test::Unit::TestCase | @@ -777,7 +777,7 @@ class PersonTest < Test::Unit::TestCase | ||
777 | assert_equal s2, person.scraps(s2) | 777 | assert_equal s2, person.scraps(s2) |
778 | end | 778 | end |
779 | 779 | ||
780 | - should "the person browse for a scrap with an inter and string id" do | 780 | + should "the person browse for a scrap with an integer and string id" do |
781 | person = fast_create(Person) | 781 | person = fast_create(Person) |
782 | s1 = fast_create(Scrap, :sender_id => person.id) | 782 | s1 = fast_create(Scrap, :sender_id => person.id) |
783 | s2 = fast_create(Scrap, :sender_id => person.id) | 783 | s2 = fast_create(Scrap, :sender_id => person.id) |
@@ -918,11 +918,10 @@ class PersonTest < Test::Unit::TestCase | @@ -918,11 +918,10 @@ class PersonTest < Test::Unit::TestCase | ||
918 | a2 = fast_create(ActionTracker::Record, :user_id => person.id ) | 918 | a2 = fast_create(ActionTracker::Record, :user_id => person.id ) |
919 | a3 = fast_create(ActionTracker::Record) | 919 | a3 = fast_create(ActionTracker::Record) |
920 | assert_equal 3, ActionTracker::Record.count | 920 | assert_equal 3, ActionTracker::Record.count |
921 | - fast_create(ActionTrackerNotification, :action_tracker_id => a1.id) | ||
922 | - fast_create(ActionTrackerNotification, :action_tracker_id => a1.id) | 921 | + fast_create(ActionTrackerNotification, :action_tracker_id => a1.id, :profile_id => person.id) |
923 | fast_create(ActionTrackerNotification, :action_tracker_id => a3.id) | 922 | fast_create(ActionTrackerNotification, :action_tracker_id => a3.id) |
924 | - fast_create(ActionTrackerNotification, :action_tracker_id => a2.id) | ||
925 | - assert_equal 4, ActionTrackerNotification.count | 923 | + fast_create(ActionTrackerNotification, :action_tracker_id => a2.id, :profile_id => person.id) |
924 | + assert_equal 3, ActionTrackerNotification.count | ||
926 | person.destroy | 925 | person.destroy |
927 | assert_equal 1, ActionTracker::Record.count | 926 | assert_equal 1, ActionTracker::Record.count |
928 | assert_equal 1, ActionTrackerNotification.count | 927 | assert_equal 1, ActionTrackerNotification.count |
test/unit/scrap_test.rb
@@ -51,6 +51,14 @@ class ScrapTest < ActiveSupport::TestCase | @@ -51,6 +51,14 @@ class ScrapTest < ActiveSupport::TestCase | ||
51 | end | 51 | end |
52 | end | 52 | end |
53 | 53 | ||
54 | + should "be associated to Community as receiver" do | ||
55 | + community = fast_create(Community) | ||
56 | + s = Scrap.new | ||
57 | + assert_nothing_raised do | ||
58 | + s.receiver = community | ||
59 | + end | ||
60 | + end | ||
61 | + | ||
54 | should "collect all scraps sent and received of a person" do | 62 | should "collect all scraps sent and received of a person" do |
55 | person = fast_create(Person) | 63 | person = fast_create(Person) |
56 | s1 = fast_create(Scrap, :sender_id => person.id) | 64 | s1 = fast_create(Scrap, :sender_id => person.id) |
@@ -61,6 +69,17 @@ class ScrapTest < ActiveSupport::TestCase | @@ -61,6 +69,17 @@ class ScrapTest < ActiveSupport::TestCase | ||
61 | assert_equal [s1,s2,s3], Scrap.all_scraps(person) | 69 | assert_equal [s1,s2,s3], Scrap.all_scraps(person) |
62 | end | 70 | end |
63 | 71 | ||
72 | + should "collect all scraps sent and received of a community" do | ||
73 | + community = fast_create(Community) | ||
74 | + person = fast_create(Person) | ||
75 | + s1 = fast_create(Scrap, :sender_id => person.id) | ||
76 | + assert_equal [], Scrap.all_scraps(community) | ||
77 | + s2 = fast_create(Scrap, :receiver_id => community.id, :sender_id => person.id) | ||
78 | + assert_equal [s2], Scrap.all_scraps(community) | ||
79 | + s3 = fast_create(Scrap, :receiver_id => community.id) | ||
80 | + assert_equal [s2,s3], Scrap.all_scraps(community) | ||
81 | + end | ||
82 | + | ||
64 | should "create the leave_scrap action tracker verb on scrap creation of one user to another" do | 83 | should "create the leave_scrap action tracker verb on scrap creation of one user to another" do |
65 | p1 = ActionTracker::Record.current_user_from_model | 84 | p1 = ActionTracker::Record.current_user_from_model |
66 | p2 = fast_create(Person) | 85 | p2 = fast_create(Person) |
@@ -78,6 +97,24 @@ class ScrapTest < ActiveSupport::TestCase | @@ -78,6 +97,24 @@ class ScrapTest < ActiveSupport::TestCase | ||
78 | assert_equal p1, ta.user | 97 | assert_equal p1, ta.user |
79 | end | 98 | end |
80 | 99 | ||
100 | + should "create the leave_scrap action tracker verb on scrap creation of one user to community" do | ||
101 | + p = Person.first | ||
102 | + c = fast_create(Community) | ||
103 | + s = Scrap.new | ||
104 | + s.sender= p | ||
105 | + s.receiver= c | ||
106 | + s.content = 'some content' | ||
107 | + s.save! | ||
108 | + ta = ActionTracker::Record.last | ||
109 | + assert_equal s.content, ta.params['content'] | ||
110 | + assert_equal s.sender.name, ta.params['sender_name'] | ||
111 | + assert_equal s.receiver.name, ta.params['receiver_name'] | ||
112 | + assert_equal s.receiver.url, ta.params['receiver_url'] | ||
113 | + assert_equal 'leave_scrap', ta.verb | ||
114 | + assert_equal p, ta.user | ||
115 | + assert_equal c, ta.target | ||
116 | + end | ||
117 | + | ||
81 | should "notify leave_scrap action tracker verb to friends and itself" do | 118 | should "notify leave_scrap action tracker verb to friends and itself" do |
82 | p1 = ActionTracker::Record.current_user_from_model | 119 | p1 = ActionTracker::Record.current_user_from_model |
83 | p2 = fast_create(Person) | 120 | p2 = fast_create(Person) |
@@ -96,6 +133,24 @@ class ScrapTest < ActiveSupport::TestCase | @@ -96,6 +133,24 @@ class ScrapTest < ActiveSupport::TestCase | ||
96 | end | 133 | end |
97 | end | 134 | end |
98 | 135 | ||
136 | + should "notify leave_scrap action tracker verb to members of the communities and the community itself" do | ||
137 | + p = Person.first | ||
138 | + c = fast_create(Community) | ||
139 | + c.add_member(p) | ||
140 | + ActionTrackerNotification.destroy_all | ||
141 | + Delayed::Job.destroy_all | ||
142 | + s = Scrap.new | ||
143 | + s.sender= p | ||
144 | + s.receiver= c | ||
145 | + s.content = 'some content' | ||
146 | + s.save! | ||
147 | + process_delayed_job_queue | ||
148 | + assert_equal 2, ActionTrackerNotification.count | ||
149 | + ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| | ||
150 | + assert [p,c].include?(profile) | ||
151 | + end | ||
152 | + end | ||
153 | + | ||
99 | should "create the leave_scrap_to_self action tracker verb on scrap creation of one user to itself" do | 154 | should "create the leave_scrap_to_self action tracker verb on scrap creation of one user to itself" do |
100 | p1 = Person.first | 155 | p1 = Person.first |
101 | s = Scrap.new | 156 | s = Scrap.new |
@@ -194,4 +249,13 @@ class ScrapTest < ActiveSupport::TestCase | @@ -194,4 +249,13 @@ class ScrapTest < ActiveSupport::TestCase | ||
194 | assert s.valid? | 249 | assert s.valid? |
195 | end | 250 | end |
196 | 251 | ||
252 | + should 'the action_tracker_target be the community when the scraps has the community as receiver' do | ||
253 | + scrap = Scrap.new | ||
254 | + assert_equal scrap, scrap.action_tracker_target | ||
255 | + | ||
256 | + community = fast_create(Community) | ||
257 | + scrap.receiver = community | ||
258 | + assert_equal community, scrap.action_tracker_target | ||
259 | + end | ||
260 | + | ||
197 | end | 261 | end |