diff --git a/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb b/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb index 8d8dbc3..aed8078 100644 --- a/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb +++ b/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb @@ -43,7 +43,9 @@ class RequireAuthToCommentPlugin < Noosfero::Plugin protected - delegate :logged_in?, :to => :context + def logged_in? + context.send(:logged_in?) + end def allowed_by_profile context.profile && context.profile.allow_unauthenticated_comments diff --git a/plugins/require_auth_to_comment/test/functional/comment_controller_test.rb b/plugins/require_auth_to_comment/test/functional/comment_controller_test.rb new file mode 100644 index 0000000..2eec4e6 --- /dev/null +++ b/plugins/require_auth_to_comment/test/functional/comment_controller_test.rb @@ -0,0 +1,28 @@ +require_relative '../test_helper' + +class CommentControllerTest < ActionController::TestCase + + def setup + @environment = Environment.default + @environment.enable_plugin(RequireAuthToCommentPlugin) + @community = fast_create(Community) + @person = create_user.person + @article = fast_create(TextArticle, :profile_id => @community.id, :body => "some article") + end + + attr_reader :community, :article, :person + + should 'not make comments if not logged in' do + assert_no_difference 'Comment.count' do + xhr :post, :create, :profile => community.identifier, :id => article.id, :comment => {:body => "Some comment..."}, :confirm => 'true' + end + + end + + should 'make comments if logged in' do + login_as person.user.login + assert_difference 'Comment.count', 1 do + xhr :post, :create, :profile => community.identifier, :id => article.id, :comment => {:body => "Some comment..."}, :confirm => 'true' + end + end +end diff --git a/plugins/require_auth_to_comment/test/test_helper.rb b/plugins/require_auth_to_comment/test/test_helper.rb new file mode 100644 index 0000000..70322cf --- /dev/null +++ b/plugins/require_auth_to_comment/test/test_helper.rb @@ -0,0 +1 @@ +require_relative '../../../test/test_helper' -- libgit2 0.21.2