Sha256: d2b1e793ad68ae8b4575b91ffba9c47f4e8ccaf34841c1852c5b49d51c588030

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Suhyo
	module ControllerMatchers	
		class DenyAccess
			def matches?(response)
				@response = response
				@response.status.split(' ').first == '403' or (@response.redirect? and response.redirect_url == Suhyo.config.access_denied_url)
			end
			
			def failure_message
				if @response.redirect?
					"expected response to deny access (403 or 302 to #{Suhyo.config.access_denied_url}). Status was #{@response.status} with redirect to #{@response.redirect_url}."
				else
					"expected response to deny access (403 or 302 to #{Suhyo.config.access_denied_url}). Status was #{@response.status}."
				end
			end
			
			def negative_failure_message
				'expected response not to deny access'
			end
		end
		
		# Looks for either of two things:
		#
		# 1. HTTP status code 403 Forbidden
		# 2. Redirect to a certain access denied URL.
		#
		# The access denied URL is determined by +Suhyo.config.access_denied_url+,
		# which defaults to +http://test.host/login+.
		#
		# Usage:
		#
		#   get :some_restricted_action
		#   response.should deny_access
		def deny_access
			DenyAccess.new
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
suhyo-0.0.3 lib/suhyo/controller_matchers.rb
suhyo-0.0.2 lib/suhyo/controller_matchers.rb
suhyo-0.0.1 lib/suhyo/controller_matchers.rb