From 33b629d330eada04300aeed502379a031f35940c Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 12 May 2015 16:54:37 -0300 Subject: [PATCH] unit tests: display_login_popup? and stylesheet? --- plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb b/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb index 92b4e1d..7f5dcd7 100644 --- a/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb +++ b/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb @@ -5,9 +5,10 @@ class RequireAuthToCommentPluginTest < ActiveSupport::TestCase def setup @plugin = RequireAuthToCommentPlugin.new @comment = Comment.new + @environment = fast_create(Environment) end - attr_reader :plugin, :comment + attr_reader :plugin, :comment, :environment should 'reject comments for unauthenticated users' do plugin.context = logged_in(false) @@ -29,6 +30,35 @@ class RequireAuthToCommentPluginTest < ActiveSupport::TestCase assert !comment.rejected? end + should 'the default require type setting be hide_button' do + assert_equal 'hide_button', plugin.class.require_type_default_setting + end + + should 'display_login_popup? be false by default' do + context = mock(); + context.expects(:environment).returns(environment) + plugin.expects(:context).returns(context) + assert !plugin.display_login_popup? + end + + should 'display_login_popup? be true if require_type is defined as display_login_popup' do + context = mock(); + context.expects(:environment).returns(environment) + environment[:settings] = {:require_auth_to_comment_plugin => {:require_type => "display_login_popup"}} + plugin.expects(:context).returns(context) + assert plugin.display_login_popup? + end + + should 'not display stylesheet if login popup is active' do + plugin.expects(:display_login_popup?).returns(true) + assert !plugin.stylesheet? + end + + should 'display stylesheet if login popup is inactive' do + plugin.expects(:display_login_popup?).returns(false) + assert plugin.stylesheet? + end + protected def logged_in(boolean) -- libgit2 0.21.2