Permalink
Browse files

Tests for ables.

  • Loading branch information...
1 parent 1616090 commit afe2b3dfd8d855e403f98aba379edcafbea3bc98 @jnunemaker committed Feb 27, 2010
Showing with 51 additions and 0 deletions.
  1. +51 −0 test/test_ables.rb
View
@@ -0,0 +1,51 @@
+require 'helper'
+
+class AblesTest < Test::Unit::TestCase
+ context "Class with Canable::Ables included" do
+ setup do
+ klass = Doc do
+ include Canable::Ables
+ end
+
+ @resource = klass.new
+ @user = mock('user')
+ end
+
+ should "default viewable_by? to true" do
+ assert @resource.viewable_by?(@user)
+ end
+
+ should "default creatable_by? to true" do
+ assert @resource.creatable_by?(@user)
+ end
+
+ should "default updatable_by? to true" do
+ assert @resource.updatable_by?(@user)
+ end
+
+ should "default destroyable_by? to true" do
+ assert @resource.destroyable_by?(@user)
+ end
+ end
+
+ context "Class that overrides an able method" do
+ setup do
+ klass = Doc do
+ include Canable::Ables
+
+ def viewable_by?(user)
+ user.name == 'John'
+ end
+ end
+
+ @resource = klass.new
+ @john = mock('user', :name => 'John')
+ @steve = mock('user', :name => 'Steve')
+ end
+
+ should "use the overriden method and not default to true" do
+ assert @resource.viewable_by?(@john)
+ assert ! @resource.viewable_by?(@steve)
+ end
+ end
+end

0 comments on commit afe2b3d

Please sign in to comment.