Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added basic tests for enforcers.

  • Loading branch information...
commit d77b0e1645eab4f2bc420b0f9dba15e122c12f55 1 parent 7f1fdaf
@jnunemaker authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/test_enforcers.rb
View
32 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
Please sign in to comment.
Something went wrong with that request. Please try again.