Sha256: 25e1ed2cb6179d2d872fc44809df4052b2fc106827371017cc0c5ab49f28ca41

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'test_helper'

class ActionControlTest < ActiveSupport::TestCase
	setup do
		@authorizable = Class.new do
			include ActionControl
		end
	end

	test 'should raise `AuthorizationNotPerformedError` if #authorized? is not defined' do
		assert_raise ActionControl::AuthorizationNotPerformedError do
			@authorizable.new.authorize!
		end
	end

	test 'should raise `NotAuthorizedError` if #authorized? returns not true' do
		@authorizable.class_eval do
			def authorized?; false; end
		end

		assert_raise ActionControl::NotAuthorizedError do
			@authorizable.new.authorize!
		end
	end

	test 'should raise no exception if #authorized? returns true' do
		@authorizable.class_eval do
			def authorized?; true; end
		end

		assert_nothing_raised do
			@authorizable.new.authorize!
		end
	end


	test 'should raise `AuthenticationNotPerformedError` if #authenticated? is not defined' do
		assert_raise ActionControl::AuthenticationNotPerformedError do
			@authorizable.new.authenticate!
		end
	end

	test 'should raise `NotAuthenticatedError` if #authenticated? returns not true' do
		@authorizable.class_eval do
			def authenticated?; false; end
		end

		assert_raise ActionControl::NotAuthenticatedError do
			@authorizable.new.authenticate!
		end
	end

	test 'should raise no exception if #authenticated? returns true' do
		@authorizable.class_eval do
			def authenticated?; true; end
		end

		assert_nothing_raised do
			@authorizable.new.authenticate!
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_control-0.2 test/action_control_test.rb