diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 001a402..3e63569 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -178,8 +178,8 @@ class ProfileController < PublicController @scrap.receiver= receiver @tab_action = params[:tab_action] @message = @scrap.save ? _("Message successfully sent.") : _("You can't leave an empty message.") - @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) if params[:not_load_scraps].nil? - render :partial => 'profile_activities_list' + activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) if params[:not_load_scraps].nil? + render :partial => 'profile_activities_list', :locals => {:activities => activities} end def leave_comment_on_activity @@ -191,8 +191,8 @@ class ProfileController < PublicController @comment.source_type, @comment.source_id = (@activity.target_type == 'Article' ? ['Article', @activity.target_id] : [@activity.class.to_s, @activity.id]) @tab_action = params[:tab_action] @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") - @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) if params[:not_load_scraps].nil? - render :partial => 'profile_activities_list' + activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) if params[:not_load_scraps].nil? + render :partial => 'profile_activities_list', :locals => {:activities => activities} end def view_more_scraps @@ -202,7 +202,7 @@ class ProfileController < PublicController def view_more_activities @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) - render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} + render :partial => 'profile_activities_list', :locals => {:activities => @activities} end def view_more_network_activities diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 16d132e..c3f84fe 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -181,4 +181,8 @@ class Enterprise < Organization true end + def activities + 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") + end + end diff --git a/app/models/scrap.rb b/app/models/scrap.rb index d84dcd6..4fc3ac5 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -13,6 +13,8 @@ class Scrap < ActiveRecord::Base 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) if scrap.send_notification? diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index f90fbd3..a032766 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -140,4 +140,9 @@ class UploadedFile < Article def uploaded_file? true end + + def action_tracker_target + self + end + end diff --git a/app/views/profile/_comment.rhtml b/app/views/profile/_comment.rhtml index a4de820..b9d886f 100644 --- a/app/views/profile/_comment.rhtml +++ b/app/views/profile/_comment.rhtml @@ -1,26 +1,27 @@ +<%# Comment %>
<% comment.replies.each do |reply| %> <%= render :partial => 'comment', :locals => { :comment => reply } %> diff --git a/app/views/profile/_create_article.rhtml b/app/views/profile/_create_article.rhtml index a2623c4..702c612 100644 --- a/app/views/profile/_create_article.rhtml +++ b/app/views/profile/_create_article.rhtml @@ -4,7 +4,7 @@
- <%= activity.params['name'] %>
+ <%= link_to(activity.params['name'], activity.params['url']) %>
<%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %>
diff --git a/app/views/profile/_leave_comment_on_activity.rhtml b/app/views/profile/_leave_comment_on_activity.rhtml
index 4d9ac6e..ab8c8e0 100644
--- a/app/views/profile/_leave_comment_on_activity.rhtml
+++ b/app/views/profile/_leave_comment_on_activity.rhtml
@@ -1,4 +1 @@
-<%= @message %>
-<% unless @activities.nil? %>
- <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %>
-<% end %>
+NÃO É PRA APARECER
diff --git a/app/views/profile/_leave_scrap.rhtml b/app/views/profile/_leave_scrap.rhtml
index 4d9ac6e..c363075 100644
--- a/app/views/profile/_leave_scrap.rhtml
+++ b/app/views/profile/_leave_scrap.rhtml
@@ -1,4 +1 @@
-<%= @message %>
-<% unless @activities.nil? %>
- <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %>
-<% end %>
+NÂO DEVE APARECER
diff --git a/app/views/profile/_leave_scrap_to_self.rhtml b/app/views/profile/_leave_scrap_to_self.rhtml
index 4d9ac6e..ab8c8e0 100644
--- a/app/views/profile/_leave_scrap_to_self.rhtml
+++ b/app/views/profile/_leave_scrap_to_self.rhtml
@@ -1,4 +1 @@
-<%= @message %>
-<% unless @activities.nil? %>
- <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %>
-<% end %>
+NÃO É PRA APARECER
diff --git a/app/views/profile/_profile.rhtml b/app/views/profile/_profile.rhtml
index df3e96b..d63e1c3 100644
--- a/app/views/profile/_profile.rhtml
+++ b/app/views/profile/_profile.rhtml
@@ -1,28 +1,2 @@
-
-
+NÃO DEVE APARECER
- <% plugins_tabs = @plugins.dispatch(:profile_tabs).
- map { |tab| {:title => tab[:title], :id => tab[:id], :content => instance_eval(&tab[:content]), :start => tab[:title]} }%>
-
- <% tabs = plugins_tabs.select { |tab| tab[:start] } %>
-
- <% if @profile.organization? %>
- <% tabs << {:title => _('Profile'), :id => 'organization-profile', :content => (render :partial => 'organization_profile')} %>
- <% if logged_in? && current_person.follows?(@profile) %>
- <% tabs << {:title => _('Wall'), :id => 'profile-wall', :content => (render :partial => 'profile_wall')} %>
- <% end %>
- <% tabs << {:title => _('What\'s new'), :id => 'profile-network', :content => (render :partial => 'profile_network')} %>
- <% elsif @profile.person? %>
- <% tabs << {:title => _('Profile'), :id => 'person-profile', :content => (render :partial => 'person_profile')} %>
- <% if logged_in? && current_person.follows?(@profile) %>
- <% tabs << {:title => _('Wall'), :id => 'profile-wall', :content => (render :partial => 'profile_wall')} %>
- <% tabs << {:title => _('Network'), :id => 'profile-network', :content => (render :partial => 'profile_network')} %>
- <% end %>
- <% end %>
-
- <% tabs += plugins_tabs.select { |tab| !tab[:start] } %>
-
- <%= render_tabs(tabs) %>
-
-
-
diff --git a/app/views/profile/_profile_activities_list.rhtml b/app/views/profile/_profile_activities_list.rhtml
index 4d9ac6e..19ae645 100644
--- a/app/views/profile/_profile_activities_list.rhtml
+++ b/app/views/profile/_profile_activities_list.rhtml
@@ -1,4 +1,10 @@
-<%= @message %>
-<% unless @activities.nil? %>
- <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %>
+<% unless activities.nil? %>
+ <% activities.each do |a| %>
+ <% activity = a.klass.constantize.find(a.id) %>
+ <% if activity.kind_of?(ActionTracker::Record) %>
+ <%= render :partial => 'profile_activity', :locals => {:activity => activity} if activity.visible? %>
+ <% else %>
+ <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %>
+ <% end %>
+ <% end %>
<% end %>
diff --git a/app/views/profile/_profile_activities_scraps.rhtml b/app/views/profile/_profile_activities_scraps.rhtml
index e9fb670..538839a 100644
--- a/app/views/profile/_profile_activities_scraps.rhtml
+++ b/app/views/profile/_profile_activities_scraps.rhtml
@@ -1,8 +1,2 @@
-<% activities.each do |a| %>
- <% activity = a.klass.constantize.find(a.id) %>
- <% if activity.kind_of?(ActionTracker::Record) %>
- <%= render :partial => 'profile_activity', :locals => {:activity => activity} if activity.visible? %>
- <% else %>
- <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %>
- <% end %>
-<% end %>
+NÂO DEVE APARECER!!
+
diff --git a/app/views/profile/_profile_wall.rhtml b/app/views/profile/_profile_wall.rhtml
index 3736552..be8c267 100644
--- a/app/views/profile/_profile_wall.rhtml
+++ b/app/views/profile/_profile_wall.rhtml
@@ -8,7 +8,7 @@
- <%= render :partial => 'profile' %>
+
+
+ <% plugins_tabs = @plugins.dispatch(:profile_tabs).
+ map { |tab| {:title => tab[:title], :id => tab[:id], :content => instance_eval(&tab[:content]), :start => tab[:title]} }%>
+
+ <% tabs = plugins_tabs.select { |tab| tab[:start] } %>
+
+ <% if @profile.organization? %>
+ <% tabs << {:title => _('Profile'), :id => 'organization-profile', :content => (render :partial => 'organization_profile')} %>
+ <% if logged_in? && current_person.follows?(@profile) %>
+ <% tabs << {:title => _('Wall'), :id => 'profile-wall', :content => (render :partial => 'profile_wall')} %>
+ <% end %>
+ <% tabs << {:title => _('What\'s new'), :id => 'profile-network', :content => (render :partial => 'profile_network')} %>
+ <% elsif @profile.person? %>
+ <% tabs << {:title => _('Profile'), :id => 'person-profile', :content => (render :partial => 'person_profile')} %>
+ <% if logged_in? && current_person.follows?(@profile) %>
+ <% tabs << {:title => _('Wall'), :id => 'profile-wall', :content => (render :partial => 'profile_wall')} %>
+ <% tabs << {:title => _('Network'), :id => 'profile-network', :content => (render :partial => 'profile_network')} %>
+ <% end %>
+ <% end %>
+
+ <% tabs += plugins_tabs.select { |tab| !tab[:start] } %>
+
+ <%= render_tabs(tabs) %>
+
+
<% end %>
diff --git a/config/initializers/action_tracker.rb b/config/initializers/action_tracker.rb
index 7cfb0f1..7ee8bd9 100644
--- a/config/initializers/action_tracker.rb
+++ b/config/initializers/action_tracker.rb
@@ -23,7 +23,7 @@ ActionTrackerConfig.verbs = {
},
:upload_image => {
- :description => lambda { n_('uploaded 1 image: %{details}
<%= link_to activity.user.name, activity.user.url %>
<%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(activity.params['lead']).gsub(/(\xA0|\xC2|\s)+/, ' ').gsub(/^\s+/, '') %> <%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %>
- <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %> + <%= render :partial => 'profile_activities_list', :locals => {:activities => @activities} %>
<% if @activities.current_page < @activities.total_pages %> diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml index d32f12d..05f3100 100644 --- a/app/views/profile/index.rhtml +++ b/app/views/profile/index.rhtml @@ -17,6 +17,31 @@ <% if @profile.public? || (logged_in? && current_person.follows?(@profile)) %>%{thumbnails}
', 'uploaded %{num} images: %{details}
%{thumbnails}
', get_view_url.size) % { :num => get_view_url.size, :thumbnails => '{{ta.collect_group_with_index(:thumbnail_path){ |t,i| content_tag(:span, image_tag(t) + link_to(nil, ta.get_view_url[i]))}.last(3).join}}', :details => '{{unique_with_count(ta.collect_group_with_index(:parent_name){ |n,i| link_to(n, ta.get_parent_url[i])}, "%s").join(", ")}}' % _("in the gallery") } }, + :description => lambda { n_('uploaded 1 image
%{thumbnails}
', 'uploaded %{num} images
%{thumbnails}
', get_view_url.size) % { :num => get_view_url.size, :thumbnails => '{{ta.collect_group_with_index(:thumbnail_path){ |t,i| content_tag(:span, image_tag(t) + link_to(nil, ta.get_view_url[i]))}.last(3).join}}' } }, :type => :groupable }, diff --git a/features/profile_activities.feature b/features/profile_activities.feature deleted file mode 100644 index 38ea67d..0000000 --- a/features/profile_activities.feature +++ /dev/null @@ -1,88 +0,0 @@ -Feature: list activities of a profile - As a visitor - I want to see the activities of a profile - - Background: - Given the following users - | login | name | - | joaosilva | Joao Silva | - And the following articles - | owner | name | body | - | joaosilva | article to comment | first paragraph | - And the following comments - | article | author | title | body | - | article to comment | joaosilva | hi | how are you? | - - Scenario: see the activity of a profile - Given I am logged in as "joaosilva" - When I go to Joao Silva's homepage -#Não tá rodando o delayed job :( -Then I should see "dkjfhv" - Then I should see "first paragraph" within ".profile-activity-item" - And I should see "how are you?" within ".profile-wall-activities-comments" - - @selenium - Scenario: post a comment while not authenticated - Given I am on /booking/article-to-comment - And I fill in "Name" with "Joey Ramone" - And I fill in "e-mail" with "joey@ramones.com" - And I fill in "Title" with "Hey ho, let's go!" - And I fill in "Enter your comment" with "Hey ho, let's go!" - When I press "Post comment" - Then I should see "Hey ho, let's go" - - @selenium - Scenario: post comment while authenticated - Given I am logged in as "booking" - And I am on /booking/article-to-comment - And I fill in "Title" with "Hey ho, let's go!" - And I fill in "Enter your comment" with "Hey ho, let's go!" - When I press "Post comment" - Then I should see "Hey ho, let's go" - - @selenium - Scenario: redirect to right place after comment a picture - Given the following files - | owner | file | mime | - | booking | rails.png | image/png | - Given I am logged in as "booking" - And I am on /booking/rails.png?view=true - And I fill in "Title" with "Hey ho, let's go!" - And I fill in "Enter your comment" with "Hey ho, let's go!" - When I press "Post comment" - Then I should be exactly on /booking/rails.png?view=true - - @selenium - Scenario: show error messages when make a blank comment - Given I am logged in as "booking" - And I am on /booking/article-to-comment - When I press "Post comment" - Then I should see "Title can't be blank" - And I should see "Body can't be blank" - - @selenium - Scenario: disable post comment button - Given I am on /booking/article-to-comment - And I fill in "Name" with "Joey Ramone" - And I fill in "e-mail" with "joey@ramones.com" - And I fill in "Title" with "Hey ho, let's go!" - And I fill in "Enter your comment" with "Hey ho, let's go!" - When I press "Post comment" - Then the "value.Post comment" button should not be enabled - And I should see "Hey ho, let's go" - - @selenium - Scenario: render comment form and go to bottom - Given I am on /booking/article-with-comment - When I follow "Post a comment" within ".post-comment-button" - Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened" - And I should be exactly on /booking/article-with-comment - And I should be moved to anchor "comment_form" - - @selenium - Scenario: keep comments field filled while trying to do a comment - Given I am on /booking/article-with-comment - And I fill in "Name" with "Joey Ramone" - When I press "Post comment" - Then the "Name" field should contain "Joey Ramone" - And I should see "errors prohibited" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f398ed2..0e8a4fc 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1434,7 +1434,8 @@ a.comment-picture { border-radius: 5px; } -.comment-replies .article-comment-inner { +.comment-replies .article-comment-inner, +.scrap-replies { border: 1px solid #fff; padding: 0; -moz-border-radius: 4px; @@ -5895,6 +5896,9 @@ h1#agenda-title { position: relative; } +#profile-activity li, #profile-network li, #profile-wall li { +} + .profile-activity-lead img { width: 124px; float: left; @@ -5954,12 +5958,12 @@ h1#agenda-title { } #profile-wall li.profile-activity-item.upload_image span, -#profile-wall li.profile-activity-item.upload_image span img, +#Xprofile-wall li.profile-activity-item.upload_image span img, #profile-wall li.profile-activity-item.upload_image span a, #profile-network li.profile-activity-item.upload_image span, -#profile-network li.profile-activity-item.upload_image span img, +#Xprofile-network li.profile-activity-item.upload_image span img, #profile-network li.profile-activity-item.upload_image span a { - width: 124px; + width: 120px; height: 100px; display: block; overflow: hidden; @@ -5967,13 +5971,16 @@ h1#agenda-title { } #profile-wall li.profile-activity-item.upload_image .activity-gallery-images-count-1 span, -#profile-wall li.profile-activity-item.upload_image .activity-gallery-images-count-1 span img, #profile-wall li.profile-activity-item.upload_image .activity-gallery-images-count-1 span a, #profile-network li.profile-activity-item.upload_image .activity-gallery-images-count-1 span, -#profile-network li.profile-activity-item.upload_image .activity-gallery-images-count-1 span img, #profile-network li.profile-activity-item.upload_image .activity-gallery-images-count-1 span a { width: 383px; - height: 177px; + height: auto; +} + +#profile-wall li.profile-activity-item.upload_image span img, +#profile-network li.profile-activity-item.upload_image span img { + display: block; } #profile-wall li.profile-activity-item.upload_image span, @@ -5992,6 +5999,7 @@ h1#agenda-title { #profile-wall li.profile-activity-item.upload_image .activity-gallery-images-count-1 span a, #profile-network li.profile-activity-item.upload_image .activity-gallery-images-count-1 span a { background-image: url(/images/gallery-image-activity-border-big.png); + position: relative; } #profile-wall li.profile-activity-item.upload_image .article-comment span, @@ -6555,6 +6563,10 @@ h1#agenda-title { padding: 0 5px; } +.scrap-replies .profile-wall-reply-form { + margin-left: 0px; +} + .profile-wall-scrap-replies { float: right; margin-right: 2px; @@ -6584,11 +6596,6 @@ h1#agenda-title { word-wrap: break-word; } -#profile-wall .profile-wall-scrap-replies textarea, -#profile-network textarea, #profile-wall textarea { - width: 98%; -} - #profile-wall textarea { width: 375px; } @@ -6597,6 +6604,12 @@ h1#agenda-title { width: 388px; } +#profile-wall .profile-wall-scrap-replies textarea, +#profile-network textarea, #profile-wall textarea, +#profile-wall li .profile-wall-reply-form textarea { + width: 98%; +} + #profile-wall #leave_scrap textarea { width: 442px; } diff --git a/test/factories.rb b/test/factories.rb index fb24dcf..b85c2b7 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -370,7 +370,7 @@ module Noosfero::Factory ############################################### def defaults_for_scrap(params = {}) - { :content => 'soment content ', :sender_id => 1, :receiver_id => 1, :created_at => DateTime.now }.merge(params) + { :content => 'some content ', :sender_id => 1, :receiver_id => 1, :created_at => DateTime.now }.merge(params) end ############################################### diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 0bed02d..c1d52f8 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -714,22 +714,15 @@ class ProfileControllerTest < ActionController::TestCase assert_no_tag :tag => 'p', :content => 'A scrap' end - should 'see only actions of the current profile when he is not followed by the viewer' do - p1= Person.first + should 'not display activities of the current profile when he is not followed by the viewer' do + p1= fast_create(Person) p2= fast_create(Person) - p3= fast_create(Person) -# UserStampSweeper.any_instance.stubs(:current_user).returns(p1) - ActionTracker::Record.destroy_all - scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) - -# UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) -# a2 = ActionTracker::Record.last + UserStampSweeper.any_instance.stubs(:current_user).returns(p1) + scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p2)) -# UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - scrap3 = Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) -# a3 = ActionTracker::Record.last + UserStampSweeper.any_instance.stubs(:current_user).returns(p2) + scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p1)) UserStampSweeper.any_instance.stubs(:current_user).returns(p1) TinyMceArticle.create!(:profile => p1, :name => 'An article about free software') @@ -737,8 +730,7 @@ class ProfileControllerTest < ActionController::TestCase login_as(profile.identifier) get :index, :profile => p1.identifier - assert_not_nil assigns(:activities) - assert_equal [a1], assigns(:activities) + assert_nil assigns(:activities) end should 'see the activities_items paginated' do @@ -750,31 +742,27 @@ class ProfileControllerTest < ActionController::TestCase assert_equal 30, assigns(:activities).count end - should 'not see the friends actions and scraps in the current profile activity' do - p1= Person.first + should 'not see the friends activities in the current profile' do p2= fast_create(Person) - assert !p1.is_a_friend?(p2) + assert !profile.is_a_friend?(p2) p3= fast_create(Person) - p1.add_friend(p3) - assert p1.is_a_friend?(p3) + p3.add_friend(profile) + assert p3.is_a_friend?(profile) ActionTracker::Record.destroy_all - scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) - scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) - scrap3 = Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) + scrap1 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) + scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => profile)) UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - TinyMceArticle.create!(:profile => p3, :name => 'An article about free software') - a1 = ActionTracker::Record.last + article1 = TinyMceArticle.create!(:profile => p3, :name => 'An article about free software') - UserStampSweeper.any_instance.stubs(:current_user).returns(p1) - TinyMceArticle.create!(:profile => p1, :name => 'Another article about free software') - a2 = ActionTracker::Record.last + UserStampSweeper.any_instance.stubs(:current_user).returns(p2) + article2 = TinyMceArticle.create!(:profile => p2, :name => 'Another article about free software') login_as(profile.identifier) - get :index, :profile => p1.identifier + get :index, :profile => p3.identifier assert_not_nil assigns(:activities) - assert_equal [a2], assigns(:activities) + assert_equivalent [scrap1, article1.activity], assigns(:activities).map { |a| a.klass.constantize.find(a.id) } end should 'see all the activities in the current profile network' do @@ -942,13 +930,29 @@ class ProfileControllerTest < ActionController::TestCase assert_template 'index' end - should 'have wall_itens defined' do - p1= ActionTracker::Record.current_user_from_model + should 'not have activities defined if not logged in' do + p1= fast_create(Person) get :index, :profile => p1.identifier - assert_equal [], assigns(:wall_items) + assert_nil assigns(:actvities) end - should 'the wall_itens be the received scraps in people profile' do + should 'not have activities defined if logged in but is not following profile' do + login_as(profile.identifier) + p1= fast_create(Person) + get :index, :profile => p1.identifier + assert_nil assigns(:activities) + end + + should 'have activities defined if logged in and is following profile' do + login_as(profile.identifier) + p1= fast_create(Person) + p1.add_friend(profile) + ActionTracker::Record.destroy_all + get :index, :profile => p1.identifier + assert_equal [], assigns(:activities) + end + + should 'the activities be the received scraps in people profile' do p1 = ActionTracker::Record.current_user_from_model p2 = fast_create(Person) p3 = fast_create(Person) @@ -963,10 +967,10 @@ class ProfileControllerTest < ActionController::TestCase @controller.stubs(:current_user).returns(user) Person.any_instance.stubs(:follows?).returns(true) get :index, :profile => p1.identifier - assert_equal [s2,s3], assigns(:wall_items) + assert_equal [s2,s3], assigns(:activities) end - should 'the wall_itens be the received scraps in community profile' do + should 'the activities be the received scraps in community profile' do c = fast_create(Community) p1 = fast_create(Person) p2 = fast_create(Person) @@ -982,10 +986,10 @@ class ProfileControllerTest < ActionController::TestCase @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) + assert_equal [s2,s3], assigns(:activities) end - should 'the wall_itens be paginated in people profiles' do + should 'the activities be paginated in people profiles' do p1 = Person.first 40.times{fast_create(Scrap, :sender_id => p1.id, :created_at => Time.now)} @@ -997,10 +1001,10 @@ class ProfileControllerTest < ActionController::TestCase Person.any_instance.stubs(:follows?).returns(true) assert_equal 40, p1.scraps_received.not_replies.count get :index, :profile => p1.identifier - assert_equal 30, assigns(:wall_items).count + assert_equal 30, assigns(:activities).count end - should 'the wall_itens be paginated in community profiles' do + should 'the activities be paginated in community profiles' do p1 = Person.first c = fast_create(Community) 40.times{fast_create(Scrap, :receiver_id => c.id)} @@ -1013,7 +1017,7 @@ class ProfileControllerTest < ActionController::TestCase 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 + assert_equal 30, assigns(:activities).count end should "the owner of activity could remove it" do @@ -1083,17 +1087,17 @@ class ProfileControllerTest < ActionController::TestCase end end - should "not show the scrap button on network activity if the user don't follow the user" do + should "not show the network activity if the viewer don't follow the profile" do login_as(profile.identifier) person = fast_create(Person) at = fast_create(ActionTracker::Record, :user_id => person.id) atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id) - get :index, :profile => profile.identifier - assert_no_tag :tag => 'p', :attributes => {:class => 'profile-network-send-message'} + get :index, :profile => person.identifier + assert_no_tag :tag => 'div', :attributes => {:id => 'profile-network'} person.add_friend(profile) - get :index, :profile => profile.identifier - assert_tag :tag => 'p', :attributes => {:class => 'profile-network-send-message'} + get :index, :profile => person.identifier + assert_tag :tag => 'div', :attributes => {:id => 'profile-network'} end should "not show the scrap button on network activity if the user is himself" do @@ -1104,16 +1108,16 @@ class ProfileControllerTest < ActionController::TestCase assert_no_tag :tag => 'p', :attributes => {:class => 'profile-network-send-message'} end - should "not show the scrap button on wall activity if the user don't follow the user" do + should "not show the scrap area on wall if the user don't follow the user" do login_as(profile.identifier) person = fast_create(Person) scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id) - get :index, :profile => profile.identifier - assert_no_tag :tag => 'p', :attributes => {:class => 'profile-wall-send-message'} + get :index, :profile => person.identifier + assert_no_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } person.add_friend(profile) - get :index, :profile => profile.identifier - assert_tag :tag => 'p', :attributes => {:class => 'profile-wall-send-message'} + get :index, :profile => person.identifier + assert_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } end should "not show the scrap button on wall activity if the user is himself" do @@ -1169,7 +1173,7 @@ class ProfileControllerTest < ActionController::TestCase assert_equal 40, profile.tracked_actions.count get :view_more_activities, :profile => profile.identifier, :page => 2 assert_response :success - assert_template '_profile_activities_scraps' + assert_template '_profile_activities_list' assert_equal 10, assigns(:activities).count end @@ -1270,8 +1274,8 @@ class ProfileControllerTest < ActionController::TestCase login_as(profile.identifier) get :index, :profile => profile.identifier - assert_tag :tag => 'div', :attributes => { :id => 'profile-wall' }, :descendant => { :tag => 'p', :content => 'A scrap' } - assert_tag :tag => 'div', :attributes => { :id => 'profile-wall' }, :descendant => { :tag => 'a', :content => 'An article about free software' } + assert_tag :tag => 'p', :content => 'A scrap', :attributes => { :class => 'profile-activity-text'} + assert_tag :tag => 'div', :attributes => { :class => 'profile-activity-lead' }, :descendant => { :tag => 'a', :content => 'An article about free software' } end should 'have scraps and activities on activities' do @@ -1307,7 +1311,7 @@ class ProfileControllerTest < ActionController::TestCase assert_equal 0, count post :leave_comment_on_activity, :profile => profile.identifier, :comment => {:body => 'something'}, :source_id => activity.id - assert_equal count + 1, activity.comments.count + assert_equal count + 1, ActionTracker::Record.find(activity.id).comments_count assert_response :success assert_equal "Comment successfully added.", assigns(:message) end @@ -1318,10 +1322,9 @@ class ProfileControllerTest < ActionController::TestCase TinyMceArticle.create!(:profile => another_person, :name => 'An article about free software') activity = ActionTracker::Record.last count = activity.comments.count -puts activity.inspect assert_equal 0, count post :leave_comment_on_activity, :profile => another_person.identifier, :comment => {:body => 'something'}, :source_id => activity.id - assert_equal count + 1, activity.comments.count + assert_equal count + 1, ActionTracker::Record.find(activity.id).comments_count assert_response :success assert_equal "Comment successfully added.", assigns(:message) end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index b205c67..5c54ead 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -323,11 +323,13 @@ class ArticleTest < ActiveSupport::TestCase (1..4).each do |n| create(TextileArticle, :name => "art #{n}", :profile_id => profile.id) end - 2.times { profile.articles.first.comments.build(:title => 'test', :body => 'asdsad', :author => profile).save! } - 4.times { profile.articles.last.comments.build(:title => 'test', :body => 'asdsad', :author => profile).save! } -assert_equal 'bla', profile.articles.map(&:comments_count) + first_article = profile.articles.first + 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => first_article).save! } + + last_article = profile.articles.last + 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => last_article).save! } # should respect the order (more commented comes first) - assert_equal [profile.articles.first], profile.articles.most_commented(2) + assert_equal [last_article, first_article], profile.articles.most_commented(2) end should 'identify itself as a non-folder' do @@ -361,16 +363,16 @@ assert_equal 'bla', profile.articles.map(&:comments_count) should 'index comments title together with article' do owner = create_user('testuser').person - art = owner.articles.build(:name => 'ytest'); art.save! - c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! + art = fast_create(TinyMceArticle, :profile_id => owner.id, :name => 'ytest') + c1 = Comment.create(:title => 'a nice comment', :body => 'anything', :author => owner, :source => art ); c1.save! assert_includes Article.find_by_contents('nice'), art end should 'index comments body together with article' do owner = create_user('testuser').person - art = owner.articles.build(:name => 'ytest'); art.save! - c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! + art = fast_create(TinyMceArticle, :profile_id => owner.id, :name => 'ytest') + c1 = Comment.create(:title => 'test comment', :body => 'anything', :author => owner, :source => art); c1.save! assert_includes Article.find_by_contents('anything'), art end diff --git a/test/unit/category_finder_test.rb b/test/unit/category_finder_test.rb index cd296f4..33eeb7a 100644 --- a/test/unit/category_finder_test.rb +++ b/test/unit/category_finder_test.rb @@ -188,17 +188,20 @@ class CategoryFinderTest < ActiveSupport::TestCase end should 'return most commented articles' do + person = create_user('testuser').person Article.delete_all - person = create_user('testuser').person - articles = (1..4).map {|n| a = person.articles.build(:name => "art #{n}", :category_ids => [@category.id]); a.save!; a } + (1..4).map {|n| create(TextileArticle, :profile_id => person.id, :name => "art #{n}", :category_ids => [@category.id]) } + + first_article = person.articles.first + 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => person, :source => first_article) } - 2.times { articles[0].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! } - 4.times { articles[1].comments.build(:title => 'test', :body => 'asdsad', :author => person).save! } + last_article = person.articles.last + 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => person, :source => last_article) } result = @finder.most_commented_articles(2) # should respect the order (more commented comes first) - assert_equal [articles[1], articles[0]], result + assert_equal [last_article, first_article], result assert_respond_to result, :total_entries end diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index 8292454..6923b40 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -260,13 +260,14 @@ class CategoryTest < ActiveSupport::TestCase a2 = person.articles.build(:name => 'art2', :category_ids => [c.id]); a2.save! a3 = person.articles.build(:name => 'art3', :category_ids => [c.id]); a3.save! - a1.comments.build(:title => 'test', :body => 'asdsa', :author => person).save! - 5.times { a2.comments.build(:title => 'test', :body => 'asdsa', :author => person).save! } + Comment.create(:title => 'test', :body => 'asdsa', :author => person, :source => a1) + 5.times { Comment.create(:title => 'test', :body => 'asdsa', :author => person, :source => a2) } - 10.times { a3.comments.build(:title => 'test', :body => 'kajsdsa', :author => person).save! } + 10.times { Comment.create(:title => 'test', :body => 'kajsdsa', :author => person, :source => a3) } assert_equal [a3, a2], c.most_commented_articles(2) end + should 'have comments' do c = @env.categories.build(:name => 'my category'); c.save! person = create_user('testuser').person diff --git a/test/unit/comment_notifier_test.rb b/test/unit/comment_notifier_test.rb index dacc054..7f5f909 100644 --- a/test/unit/comment_notifier_test.rb +++ b/test/unit/comment_notifier_test.rb @@ -12,26 +12,26 @@ class CommentNotifierTest < ActiveSupport::TestCase @article = fast_create(Article, :name => 'Article test', :profile_id => @profile.id, :notify_comments => true) end - should 'deliver mail after make aarticle commment' do + should 'deliver mail after make an article comment' do assert_difference ActionMailer::Base.deliveries, :size do - @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') + Comment.create(:author => @profile, :title => 'test comment', :body => 'you suck!', :source => @article ) end end should 'deliver mail to owner of article' do - @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') + Comment.create(:author => @profile, :title => 'test comment', :body => 'you suck!', :source => @article ) sent = ActionMailer::Base.deliveries.first assert_equal [@profile.email], sent.to end should 'display author name in delivered mail' do - @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') + Comment.create(:author => @profile, :title => 'test comment', :body => 'you suck!', :source => @article) sent = ActionMailer::Base.deliveries.first assert_match /user_comment_test/, sent.body end should 'display unauthenticated author name and email in delivered mail' do - @article.comments << Comment.new(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!') + Comment.create(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!', :source => @article ) sent = ActionMailer::Base.deliveries.first assert_match /flatline/, sent.body assert_match /flatline@invalid.com/, sent.body @@ -45,13 +45,13 @@ class CommentNotifierTest < ActiveSupport::TestCase end should 'include comment title in the e-mail' do - @article.comments << Comment.new(:author => @profile, :title => 'comment title', :body => 'comment title') + Comment.create(:author => @profile, :title => 'comment title', :body => 'comment body', :source => @article) sent = ActionMailer::Base.deliveries.first assert_match /comment title/, sent.body end should 'include comment text in the e-mail' do - @article.comments << Comment.new(:author => @profile, :title => 'comment title', :body => 'comment body') + Comment.create(:author => @profile, :title => 'comment title', :body => 'comment body', :source => @article) sent = ActionMailer::Base.deliveries.first assert_match /comment body/, sent.body end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index f70dad3..055057f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -339,8 +339,6 @@ class CommentTest < ActiveSupport::TestCase assert c.rejected? end - should 'update activity when add a comment' - should 'update article activity when add a comment' do profile = create_user('testuser').person article = create(TinyMceArticle, :profile => profile) diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 6aa38d6..32cb415 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -451,5 +451,36 @@ class EnterpriseTest < ActiveSupport::TestCase assert_respond_to e, :production_costs end - should 'return tracked_actions and scraps as activities' + should 'return scraps as activities' do + person = fast_create(Person) + enterprise = fast_create(Enterprise) + + + activity = ActionTracker::Record.last + scrap = Scrap.create!(defaults_for_scrap(:sender => person, :receiver => enterprise, :content => 'A scrap')) + + assert_equal [scrap], enterprise.activities.map { |a| a.klass.constantize.find(a.id) } + end + + should 'return tracked_actions of community as activities' do + person = fast_create(Person) + enterprise = fast_create(Enterprise) + + UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once + article = create(TinyMceArticle, :profile => enterprise, :name => 'An article about free software') + + assert_equal [article.activity], enterprise.activities.map { |a| a.klass.constantize.find(a.id) } + end + + should 'not return tracked_actions of other community as activities' do + person = fast_create(Person) + enterprise = fast_create(Enterprise) + enterprise2 = fast_create(Enterprise) + + UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once + article = create(TinyMceArticle, :profile => enterprise2, :name => 'Another article about free software') + + assert_not_includes enterprise.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity + end + end diff --git a/test/unit/forum_helper_test.rb b/test/unit/forum_helper_test.rb index c0376a7..2f57d65 100644 --- a/test/unit/forum_helper_test.rb +++ b/test/unit/forum_helper_test.rb @@ -63,7 +63,7 @@ class ForumHelperTest < ActiveSupport::TestCase some_post.comments << Comment.new(:name => 'John', :email => 'lenon@example.com', :title => 'test', :body => 'test') c = Comment.last out = last_topic_update(some_post) - assert_match "#{c.created_at.to_s} ago by John", out + assert_match "#{c.created_at.to_s} by John", out assert_match 'John', out end diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb index 92b43ad..9f53137 100644 --- a/test/unit/textile_article_test.rb +++ b/test/unit/textile_article_test.rb @@ -47,7 +47,7 @@ class TextileArticleTest < ActiveSupport::TestCase assert_equal 3, ActionTracker::Record.count end - should 'update activity on update of an article' do + should 'not update activity on update of an article' do ActionTracker::Record.delete_all profile = fast_create(Profile) article = create(TextileArticle, :profile_id => profile.id) @@ -57,7 +57,7 @@ class TextileArticleTest < ActiveSupport::TestCase article.name = 'foo' article.save! end - assert_equal time + 1.day, article.activity.updated_at + assert_equal time, article.activity.updated_at end should 'not create trackers activity when updating articles' do diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 2ea21bb..c65b89c 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -144,7 +144,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase assert_equal 3, ActionTracker::Record.count end - should 'update activity on update of an article' do + should 'not update activity on update of an article' do ActionTracker::Record.delete_all profile = fast_create(Profile) article = create(TinyMceArticle, :profile_id => profile.id) @@ -154,7 +154,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase article.name = 'foo' article.save! end - assert_equal time + 1.day, article.activity.updated_at + assert_equal time, article.activity.updated_at end should 'not create trackers activity when updating articles' do diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index a08eae1..9698ef3 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -231,10 +231,10 @@ class UploadedFileTest < ActiveSupport::TestCase should 'return a thumbnail for images' do f = UploadedFile.new f.expects(:image?).returns(true) - f.expects(:full_filename).with(:thumb).returns(File.join(RAILS_ROOT, 'public', 'images', '0000', '0005', 'x.png')) + f.expects(:full_filename).with(:display).returns(File.join(RAILS_ROOT, 'public', 'images', '0000', '0005', 'x.png')) assert_equal '/images/0000/0005/x.png', f.thumbnail_path f = UploadedFile.new - f.stubs(:full_filename).with(:thumb).returns(File.join(RAILS_ROOT, 'public', 'images', '0000', '0005', 'x.png')) + f.stubs(:full_filename).with(:display).returns(File.join(RAILS_ROOT, 'public', 'images', '0000', '0005', 'x.png')) f.expects(:image?).returns(false) assert_nil f.thumbnail_path end @@ -330,11 +330,11 @@ class UploadedFileTest < ActiveSupport::TestCase assert_equal 'hello_world.php.txt', file.filename end - should 'use the gallery as the parent for action tracker' do + 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 = ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) - assert_equal f.parent, ta.target + ta = f.activity + assert_equal f, ta.target end end -- libgit2 0.21.2