Commit 6a65d7a4ba34c78dea4852e60302f22518f5e028
1 parent
57763b61
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
fix tests and controler
Showing
5 changed files
with
110 additions
and
108 deletions
Show diff stats
plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb
| ... | ... | @@ -3,7 +3,7 @@ class CommentParagraphPluginPublicController < PublicController |
| 3 | 3 | |
| 4 | 4 | def comment_paragraph |
| 5 | 5 | @comment = Comment.find(params[:id]) |
| 6 | - render :json => { :paragraph_id => comment.paragraph_id } | |
| 6 | + render :json => { :paragraph_id => @comment.paragraph_id } | |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | end | ... | ... |
plugins/comment_paragraph/test/functional/comment_group_plugin_profile_controller_test.rb
| ... | ... | @@ -1,72 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | -require File.dirname(__FILE__) + '/../../controllers/profile/comment_paragraph_plugin_profile_controller' | |
| 3 | - | |
| 4 | -# Re-raise errors caught by the controller. | |
| 5 | -class CommentParagraphPluginProfileController; def rescue_action(e) raise e end; end | |
| 6 | - | |
| 7 | -class CommentParagraphPluginProfileControllerTest < ActionController::TestCase | |
| 8 | - | |
| 9 | - def setup | |
| 10 | - @controller = CommentParagraphPluginProfileController.new | |
| 11 | - @request = ActionController::TestRequest.new | |
| 12 | - @response = ActionController::TestResponse.new | |
| 13 | - | |
| 14 | - @profile = create_user('testuser').person | |
| 15 | - @article = profile.articles.build(:name => 'test') | |
| 16 | - @article.save! | |
| 17 | - end | |
| 18 | - attr_reader :article | |
| 19 | - attr_reader :profile | |
| 20 | - | |
| 21 | - should 'be able to show paragraph comments' do | |
| 22 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 23 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 24 | - assert_template 'comment_paragraph_plugin_profile/view_comments' | |
| 25 | - assert_match /comments_list_paragraph_0/, @response.body | |
| 26 | - assert_match /\"comment-count-0\", \"1\"/, @response.body | |
| 27 | - end | |
| 28 | - | |
| 29 | - should 'do not show global comments' do | |
| 30 | - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_id => nil) | |
| 31 | - fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 32 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 33 | - assert_template 'comment_paragraph_plugin_profile/view_comments' | |
| 34 | - assert_match /comments_list_paragraph_0/, @response.body | |
| 35 | - assert_match /\"comment-count-0\", \"1\"/, @response.body | |
| 36 | - end | |
| 37 | - | |
| 38 | - should 'show first page comments only' do | |
| 39 | - comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :paragraph_id => 0) | |
| 40 | - 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) | |
| 41 | - 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) | |
| 42 | - 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) | |
| 43 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 44 | - assert_match /firstpage 1/, @response.body | |
| 45 | - assert_match /firstpage 2/, @response.body | |
| 46 | - assert_match /firstpage 3/, @response.body | |
| 47 | - assert_no_match /secondpage/, @response.body | |
| 48 | - end | |
| 49 | - | |
| 50 | - should 'show link to display more comments' do | |
| 51 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 52 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 53 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 54 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :paragraph_id => 0) | |
| 55 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 56 | - assert_match /paragraph_comment_page=2/, @response.body | |
| 57 | - end | |
| 58 | - | |
| 59 | - should 'do not show link to display more comments if do not have more pages' do | |
| 60 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 61 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 62 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 63 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 64 | - assert_no_match /paragraph_comment_page/, @response.body | |
| 65 | - end | |
| 66 | - | |
| 67 | - should 'do not show link to display more comments if do not have any comments' do | |
| 68 | - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 69 | - assert_no_match /paragraph_comment_page/, @response.body | |
| 70 | - end | |
| 71 | - | |
| 72 | -end |
plugins/comment_paragraph/test/functional/comment_group_plugin_public_controller_test.rb
| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | -require File.dirname(__FILE__) + '/../../controllers/public/comment_paragraph_plugin_public_controller' | |
| 3 | - | |
| 4 | -# Re-raise errors caught by the controller. | |
| 5 | -class CommentParagraphPluginPublicController; def rescue_action(e) raise e end; end | |
| 6 | - | |
| 7 | -class CommentParagraphPluginPublicControllerTest < ActionController::TestCase | |
| 8 | - | |
| 9 | - def setup | |
| 10 | - @controller = CommentParagraphPluginPublicController.new | |
| 11 | - @request = ActionController::TestRequest.new | |
| 12 | - @response = ActionController::TestResponse.new | |
| 13 | - | |
| 14 | - @profile = create_user('testuser').person | |
| 15 | - @article = profile.articles.build(:name => 'test') | |
| 16 | - @article.save! | |
| 17 | - end | |
| 18 | - attr_reader :article | |
| 19 | - attr_reader :profile | |
| 20 | - | |
| 21 | -=begin fix me on monday | |
| 22 | - should 'be able to return paragraph_id for a comment' do | |
| 23 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 24 | - xhr :get, :comment_paragraph, :id => comment.id | |
| 25 | - assert_match /\{\"paragraph_id\":0\}/, @response.body | |
| 26 | - end | |
| 27 | - | |
| 28 | - should 'return paragraph_id=null for a global comment' do | |
| 29 | - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) | |
| 30 | - xhr :get, :comment_paragraph, :id => comment.id | |
| 31 | - assert_match /\{\"paragraph_id\":null\}/, @response.body | |
| 32 | - end | |
| 33 | -=end | |
| 34 | - | |
| 35 | -end |
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,72 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | +require File.dirname(__FILE__) + '/../../controllers/profile/comment_paragraph_plugin_profile_controller' | |
| 3 | + | |
| 4 | +# Re-raise errors caught by the controller. | |
| 5 | +class CommentParagraphPluginProfileController; def rescue_action(e) raise e end; end | |
| 6 | + | |
| 7 | +class CommentParagraphPluginProfileControllerTest < ActionController::TestCase | |
| 8 | + | |
| 9 | + def setup | |
| 10 | + @controller = CommentParagraphPluginProfileController.new | |
| 11 | + @request = ActionController::TestRequest.new | |
| 12 | + @response = ActionController::TestResponse.new | |
| 13 | + | |
| 14 | + @profile = create_user('testuser').person | |
| 15 | + @article = profile.articles.build(:name => 'test') | |
| 16 | + @article.save! | |
| 17 | + end | |
| 18 | + attr_reader :article | |
| 19 | + attr_reader :profile | |
| 20 | + | |
| 21 | + should 'be able to show paragraph comments' do | |
| 22 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 23 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 24 | + assert_template 'comment_paragraph_plugin_profile/view_comments' | |
| 25 | + assert_match /comments_list_paragraph_0/, @response.body | |
| 26 | + assert_match /\"comment-count-0\", \"1\"/, @response.body | |
| 27 | + end | |
| 28 | + | |
| 29 | + should 'do not show global comments' do | |
| 30 | + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :paragraph_id => nil) | |
| 31 | + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 32 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 33 | + assert_template 'comment_paragraph_plugin_profile/view_comments' | |
| 34 | + assert_match /comments_list_paragraph_0/, @response.body | |
| 35 | + assert_match /\"comment-count-0\", \"1\"/, @response.body | |
| 36 | + end | |
| 37 | + | |
| 38 | + should 'show first page comments only' do | |
| 39 | + comment1 = fast_create(Comment, :created_at => Time.now - 1.days, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :paragraph_id => 0) | |
| 40 | + 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) | |
| 41 | + 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) | |
| 42 | + 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) | |
| 43 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 44 | + assert_match /firstpage 1/, @response.body | |
| 45 | + assert_match /firstpage 2/, @response.body | |
| 46 | + assert_match /firstpage 3/, @response.body | |
| 47 | + assert_no_match /secondpage/, @response.body | |
| 48 | + end | |
| 49 | + | |
| 50 | + should 'show link to display more comments' do | |
| 51 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 52 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 53 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 54 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :paragraph_id => 0) | |
| 55 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 56 | + assert_match /paragraph_comment_page=2/, @response.body | |
| 57 | + end | |
| 58 | + | |
| 59 | + should 'do not show link to display more comments if do not have more pages' do | |
| 60 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 61 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 62 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 63 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 64 | + assert_no_match /paragraph_comment_page/, @response.body | |
| 65 | + end | |
| 66 | + | |
| 67 | + should 'do not show link to display more comments if do not have any comments' do | |
| 68 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :paragraph_id => 0 | |
| 69 | + assert_no_match /paragraph_comment_page/, @response.body | |
| 70 | + end | |
| 71 | + | |
| 72 | +end | ... | ... |
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_public_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | +require File.dirname(__FILE__) + '/../../controllers/public/comment_paragraph_plugin_public_controller' | |
| 3 | + | |
| 4 | + | |
| 5 | +# Re-raise errors caught by the controller. | |
| 6 | +class CommentParagraphPluginPublicController; def rescue_action(e) raise e end; end | |
| 7 | + | |
| 8 | +class CommentParagraphPluginPublicControllerTest < ActionController::TestCase | |
| 9 | + | |
| 10 | + def setup | |
| 11 | + @controller = CommentParagraphPluginPublicController.new | |
| 12 | + @request = ActionController::TestRequest.new | |
| 13 | + @response = ActionController::TestResponse.new | |
| 14 | + | |
| 15 | + @profile = create_user('testuser').person | |
| 16 | + @article = profile.articles.build(:name => 'test') | |
| 17 | + @article.save! | |
| 18 | + end | |
| 19 | + attr_reader :article | |
| 20 | + attr_reader :profile | |
| 21 | + | |
| 22 | + | |
| 23 | + should 'be able to return paragraph_id for a comment' do | |
| 24 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_id => 0) | |
| 25 | + cid = comment.id | |
| 26 | + xhr :get, :comment_paragraph, :id => cid | |
| 27 | + assert_match /\{\"paragraph_id\":0\}/, @response.body | |
| 28 | + end | |
| 29 | + | |
| 30 | + should 'return paragraph_id=null for a global comment' do | |
| 31 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) | |
| 32 | + xhr :get, :comment_paragraph, :id => comment.id | |
| 33 | + assert_match /\{\"paragraph_id\":null\}/, @response.body | |
| 34 | + end | |
| 35 | + | |
| 36 | + | |
| 37 | +end | ... | ... |