Sha256: cac745ae3ec45c96af6b483923c0170911254ed45d75f62ccf3ffeca18923c1c
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
require 'test_helper' require 'minitest/mock' class FilteredContext extend Surrounded::Context protect_triggers initialize :user, :other_user trigger :if_ready do 'ready' end guard :if_ready do user.name != 'Amy' end trigger :check_disallow_behavior do # used for disallow check end disallow :check_disallow_behavior do user.special end role :user do def special 'special user method' end end end describe Surrounded::Context, 'access control' do let(:user){ User.new("Jim") } let(:other_user){ User.new("Guille") } let(:context){ FilteredContext.new(user, other_user) } it 'includes triggers when allowed' do context.stub(:disallow_if_ready?, false) do assert context.triggers.include?(:if_ready) end end it 'excludes triggers when not allowed' do refute context.triggers.include?(:if_ready) end it 'raises error specific to the context class when trigger method not allowed' do error = assert_raises(::FilteredContext::AccessError){ context.if_ready } assert_match(/access to FilteredContext#if_ready is not allowed/i, error.message) end it 'supports rescuing from Surrounded defined error when trigger method not allowed' do begin context.if_ready rescue ::Surrounded::Context::AccessError => error assert "rescued!" end assert_match(/access to FilteredContext#if_ready is not allowed/i, error.message) end it 'applies roles in disallow blocks' do assert_equal 'special user method', context.disallow_check_disallow_behavior? end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
surrounded-0.8.4 | test/context_access_test.rb |
surrounded-0.8.3 | test/context_access_test.rb |