Commit c6427402b414c67d82b6db0dff2e7e3eb31d9854

Authored by Leandro Nunes dos Santos
1 parent a748e15f

refactoring more_comments and more_replies method

app/controllers/public/profile_controller.rb
@@ -211,8 +211,7 @@ class ProfileController < PublicController @@ -211,8 +211,7 @@ class ProfileController < PublicController
211 end 211 end
212 212
213 def more_comments 213 def more_comments
214 - activity_id = params[:activity].to_i  
215 - activity = ActionTracker::Record.find(:first, :conditions => {:id => activity_id, :user_id => @profile.id}) 214 + activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity], :user_id => @profile})
216 comments_count = activity.comments.count 215 comments_count = activity.comments.count
217 comment_page = (params[:comment_page] || 1).to_i 216 comment_page = (params[:comment_page] || 1).to_i
218 comments_per_page = 5 217 comments_per_page = 5
@@ -232,8 +231,7 @@ class ProfileController < PublicController @@ -232,8 +231,7 @@ class ProfileController < PublicController
232 end 231 end
233 232
234 def more_replies 233 def more_replies
235 - activity_id = params[:activity].to_i  
236 - activity = Scrap.find(:first, :conditions => {:id => activity_id, :receiver_id => @profile.id, :scrap_id => nil}) 234 + activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil})
237 comments_count = activity.replies.count 235 comments_count = activity.replies.count
238 comment_page = (params[:comment_page] || 1).to_i 236 comment_page = (params[:comment_page] || 1).to_i
239 comments_per_page = 5 237 comments_per_page = 5
test/functional/profile_controller_test.rb
@@ -734,7 +734,7 @@ class ProfileControllerTest < ActionController::TestCase @@ -734,7 +734,7 @@ class ProfileControllerTest < ActionController::TestCase
734 end 734 end
735 735
736 should 'see the activities_items paginated' do 736 should 'see the activities_items paginated' do
737 - p1= Person.first 737 + p1 = create_user('some').person
738 ActionTracker::Record.destroy_all 738 ActionTracker::Record.destroy_all
739 40.times{Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))} 739 40.times{Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))}
740 login_as(p1.identifier) 740 login_as(p1.identifier)
test/unit/comment_test.rb
@@ -285,22 +285,6 @@ class CommentTest < ActiveSupport::TestCase @@ -285,22 +285,6 @@ class CommentTest < ActiveSupport::TestCase
285 assert_equal [c1,c3], c.reload.children 285 assert_equal [c1,c3], c.reload.children
286 end 286 end
287 287
288 - should "return activities comments as a thread" do  
289 - person = fast_create(Person)  
290 - a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body')  
291 - c0 = Comment.create!(:source => a, :body => 'My comment', :author => person)  
292 - c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)  
293 - c2 = Comment.create!(:reply_of_id => c1.id, :source => a, :body => 'bla', :author => person)  
294 - c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)  
295 - c4 = Comment.create!(:source => a, :body => 'My comment', :author => person)  
296 - result = a.activity.comments_as_thread  
297 - assert_equal c0, result[0]  
298 - assert_equal [c1, c3], result[0].replies  
299 - assert_equal [c2], result[0].replies[0].replies  
300 - assert_equal c4, result[1]  
301 - assert result[1].replies.empty?  
302 - end  
303 -  
304 should 'provide author url for authenticated user' do 288 should 'provide author url for authenticated user' do
305 author = Person.new 289 author = Person.new
306 author.expects(:url).returns('http://blabla.net/author') 290 author.expects(:url).returns('http://blabla.net/author')