Skip to content

Commit

Permalink
consistency addition for ability check on Module
Browse files Browse the repository at this point in the history
  • Loading branch information
funny-falcon authored and ryanb committed Sep 20, 2010
1 parent cef55c9 commit ebef3cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cancan/can_definition.rb
Expand Up @@ -79,7 +79,8 @@ def attributes_from_conditions
private

def subject_class?(subject)
(subject.kind_of?(Hash) ? subject.values.first : subject).class == Class
klass = (subject.kind_of?(Hash) ? subject.values.first : subject).class
klass == Class || klass == Module
end

def matches_action?(action)
Expand Down
19 changes: 19 additions & 0 deletions spec/cancan/ability_spec.rb
Expand Up @@ -23,6 +23,14 @@
end
@ability.can?(:read, :some_symbol).should == true
end

it "should pass nil to a block when no instance is passed" do
@ability.can :read, Symbol do |sym|
sym.should be_nil
true
end
@ability.can?(:read, Symbol).should be_true
end

it "should pass to previous can definition, if block returns false or nil" do
@ability.can :read, Symbol
Expand Down Expand Up @@ -257,6 +265,17 @@ class A; include B; end
@ability.can?(:read, A).should be_true
@ability.can?(:read, A.new).should be_true
end

it "should pass nil to a block for ability on Module when no instance is passed" do
module B; end
class A; include B; end
@ability.can :read, B do |sym|
sym.should be_nil
true
end
@ability.can?(:read, B).should be_true
@ability.can?(:read, A).should be_true
end

it "passing a hash of subjects should check permissions through association" do
@ability.can :read, Range, :string => {:length => 3}
Expand Down

0 comments on commit ebef3cc

Please sign in to comment.