class Clearance::Testing::Matchers::DenyAccessMatcher
@api private
Attributes
Public Class Methods
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 41 def initialize(context, opts) @context = context @flash = opts[:flash] @url = opts[:redirect] @failure_message = '' @failure_message_when_negated = '' end
Public Instance Methods
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 50 def description 'deny access' end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 59 def failure_message_for_should failure_message end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 63 def failure_message_for_should_not failure_message_when_negated end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 54 def matches?(controller) @controller = controller sets_the_flash? && redirects_to_url? end
Private Instance Methods
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 77 def clearance_session @controller.request.env[:clearance] end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 69 def denied_access_url if clearance_session.signed_in? Clearance.configuration.redirect_url else @controller.sign_in_url end end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 81 def flash_alert_value @controller.flash[:alert] end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 85 def redirects_to_url? @url ||= denied_access_url begin @context.send(:assert_redirected_to, @url) @failure_message_when_negated << "Didn't expect to redirect to #{@url}." true rescue ::Minitest::Assertion, ::Test::Unit::AssertionFailedError @failure_message << "Expected to redirect to #{@url} but did not." false end end
Source
# File lib/clearance/testing/deny_access_matcher.rb, line 99 def sets_the_flash? if @flash.blank? true elsif flash_alert_value == @flash @failure_message_when_negated << "Didn't expect to set the flash to #{@flash}" true else @failure_message << "Expected the flash to be set to #{@flash} "\ "but was #{flash_alert_value}" false end end