Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f1fdaf
commit d77b0e1
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |