diff --git a/controllers/public/comment_paragraph_plugin_public_controller.rb b/controllers/public/comment_paragraph_plugin_public_controller.rb index 9ee280e..a8bd78e 100644 --- a/controllers/public/comment_paragraph_plugin_public_controller.rb +++ b/controllers/public/comment_paragraph_plugin_public_controller.rb @@ -3,7 +3,7 @@ class CommentParagraphPluginPublicController < PublicController def comment_paragraph @comment = Comment.find(params[:id]) - render :json => { :paragraph_id => comment.paragraph_id } + render :json => { :paragraph_id => @comment.paragraph_id } end end diff --git a/test/functional/comment_group_plugin_profile_controller_test.rb b/test/functional/comment_group_plugin_profile_controller_test.rb deleted file mode 100644 index 012dc93..0000000 --- a/test/functional/comment_group_plugin_profile_controller_test.rb +++ /dev/null @@ -1,72 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -require File.dirname(__FILE__) + '/../../controllers/profile/comment_paragraph_plugin_profile_controller' - -# Re-raise errors caught by the controller. -class CommentParagraphPluginProfileController; def rescue_action(e) raise e end; end - -class CommentParagraphPluginProfileControllerTest < ActionController::TestCase - - def setup - @controller = CommentParagraphPluginProfileController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @profile = create_user('testuser').person - @article = profile.articles.build(:name => 'test') - @article.save! - end - attr_reader :article - attr_reader :profile - - should 'be able to show paragraph comments' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_template 'comment_paragraph_plugin_profile/view_comments' - assert_match /comments_list_paragraph_0/, @response.body - assert_match /\"comment-count-0\", \"1\"/, @response.body - end - - should 'do not show global comments' do - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_id => nil) - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_template 'comment_paragraph_plugin_profile/view_comments' - assert_match /comments_list_paragraph_0/, @response.body - assert_match /\"comment-count-0\", \"1\"/, @response.body - end - - should 'show first page comments only' do - comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :paragraph_id => 0) - comment2 = fast_create(Comment, :created_at => Time.now - 2.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :paragraph_id => 0) - comment3 = fast_create(Comment, :created_at => Time.now - 3.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :paragraph_id => 0) - comment4 = fast_create(Comment, :created_at => Time.now - 4.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_match /firstpage 1/, @response.body - assert_match /firstpage 2/, @response.body - assert_match /firstpage 3/, @response.body - assert_no_match /secondpage/, @response.body - end - - should 'show link to display more comments' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_match /paragraph_comment_page=2/, @response.body - end - - should 'do not show link to display more comments if do not have more pages' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_no_match /paragraph_comment_page/, @response.body - end - - should 'do not show link to display more comments if do not have any comments' do - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 - assert_no_match /paragraph_comment_page/, @response.body - end - -end diff --git a/test/functional/comment_group_plugin_public_controller_test.rb b/test/functional/comment_group_plugin_public_controller_test.rb deleted file mode 100644 index 3582832..0000000 --- a/test/functional/comment_group_plugin_public_controller_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -require File.dirname(__FILE__) + '/../../controllers/public/comment_paragraph_plugin_public_controller' - -# Re-raise errors caught by the controller. -class CommentParagraphPluginPublicController; def rescue_action(e) raise e end; end - -class CommentParagraphPluginPublicControllerTest < ActionController::TestCase - - def setup - @controller = CommentParagraphPluginPublicController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @profile = create_user('testuser').person - @article = profile.articles.build(:name => 'test') - @article.save! - end - attr_reader :article - attr_reader :profile - -=begin fix me on monday - should 'be able to return paragraph_id for a comment' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) - xhr :get, :comment_paragraph, :id => comment.id - assert_match /\{\"paragraph_id\":0\}/, @response.body - end - - should 'return paragraph_id=null for a global comment' do - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) - xhr :get, :comment_paragraph, :id => comment.id - assert_match /\{\"paragraph_id\":null\}/, @response.body - end -=end - -end diff --git a/test/functional/comment_paragraph_plugin_profile_controller_test.rb b/test/functional/comment_paragraph_plugin_profile_controller_test.rb new file mode 100644 index 0000000..012dc93 --- /dev/null +++ b/test/functional/comment_paragraph_plugin_profile_controller_test.rb @@ -0,0 +1,72 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/profile/comment_paragraph_plugin_profile_controller' + +# Re-raise errors caught by the controller. +class CommentParagraphPluginProfileController; def rescue_action(e) raise e end; end + +class CommentParagraphPluginProfileControllerTest < ActionController::TestCase + + def setup + @controller = CommentParagraphPluginProfileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = create_user('testuser').person + @article = profile.articles.build(:name => 'test') + @article.save! + end + attr_reader :article + attr_reader :profile + + should 'be able to show paragraph comments' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_template 'comment_paragraph_plugin_profile/view_comments' + assert_match /comments_list_paragraph_0/, @response.body + assert_match /\"comment-count-0\", \"1\"/, @response.body + end + + should 'do not show global comments' do + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_id => nil) + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_template 'comment_paragraph_plugin_profile/view_comments' + assert_match /comments_list_paragraph_0/, @response.body + assert_match /\"comment-count-0\", \"1\"/, @response.body + end + + should 'show first page comments only' do + comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :paragraph_id => 0) + comment2 = fast_create(Comment, :created_at => Time.now - 2.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :paragraph_id => 0) + comment3 = fast_create(Comment, :created_at => Time.now - 3.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :paragraph_id => 0) + comment4 = fast_create(Comment, :created_at => Time.now - 4.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :paragraph_id => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_match /firstpage 1/, @response.body + assert_match /firstpage 2/, @response.body + assert_match /firstpage 3/, @response.body + assert_no_match /secondpage/, @response.body + end + + should 'show link to display more comments' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :paragraph_id => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_match /paragraph_comment_page=2/, @response.body + end + + should 'do not show link to display more comments if do not have more pages' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_no_match /paragraph_comment_page/, @response.body + end + + should 'do not show link to display more comments if do not have any comments' do + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 + assert_no_match /paragraph_comment_page/, @response.body + end + +end diff --git a/test/functional/comment_paragraph_plugin_public_controller_test.rb b/test/functional/comment_paragraph_plugin_public_controller_test.rb new file mode 100644 index 0000000..43c12f5 --- /dev/null +++ b/test/functional/comment_paragraph_plugin_public_controller_test.rb @@ -0,0 +1,37 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/public/comment_paragraph_plugin_public_controller' + + +# Re-raise errors caught by the controller. +class CommentParagraphPluginPublicController; def rescue_action(e) raise e end; end + +class CommentParagraphPluginPublicControllerTest < ActionController::TestCase + + def setup + @controller = CommentParagraphPluginPublicController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = create_user('testuser').person + @article = profile.articles.build(:name => 'test') + @article.save! + end + attr_reader :article + attr_reader :profile + + + should 'be able to return paragraph_id for a comment' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) + cid = comment.id + xhr :get, :comment_paragraph, :id => cid + assert_match /\{\"paragraph_id\":0\}/, @response.body + end + + should 'return paragraph_id=null for a global comment' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) + xhr :get, :comment_paragraph, :id => comment.id + assert_match /\{\"paragraph_id\":null\}/, @response.body + end + + +end -- libgit2 0.21.2