Skip to content

Commit

Permalink
Added basic tests for enforcers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Feb 27, 2010
1 parent 7f1fdaf commit d77b0e1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test_enforcers.rb
@@ -0,0 +1,32 @@
require 'helper'

class EnforcersTest < Test::Unit::TestCase
context "Including Canable::Enforcers in a class" do
setup do
klass = Class.new do
include Canable::Enforcers
attr_accessor :current_user, :article

def show
enforce_view_permission(article)
end
end

@article = mock('article')
@user = mock('user')
@controller = klass.new
@controller.article = @article
@controller.current_user = @user
end

should "not raise error if can" do
@user.expects(:can_view?).with(@article).returns(true)
assert_nothing_raised { @controller.show }
end

should "raise error if cannot" do
@user.expects(:can_view?).with(@article).returns(false)
assert_raises(Canable::Transgression) { @controller.show }
end
end
end

0 comments on commit d77b0e1

Please sign in to comment.