From e5b76210e42ec0a028acfbc716bbbbe3fd9fe33e Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 25 Mar 2011 17:05:36 -0700 Subject: [PATCH] fixing marking fully_authorized on an object instance --- lib/cancan/ability.rb | 1 + spec/cancan/ability_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index b98d569..9e825ba 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -264,6 +264,7 @@ module CanCan end def fully_authorized!(action, subject) + subject = subject.class.to_s.underscore.pluralize.to_sym unless subject.kind_of?(Symbol) || subject.kind_of?(String) @fully_authorized ||= [] @fully_authorized << [action.to_sym, subject.to_sym] end diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index d3ba811..eedc49b 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -261,6 +261,8 @@ describe CanCan::Ability do @ability.should_not be_fully_authorized(:update, :ranges) @ability.authorize! "update", "ranges" @ability.should_not be_fully_authorized(:update, :ranges) + @ability.authorize! :update, 1..3 + @ability.should be_fully_authorized(:update, :ranges) end it "is not fully authorized when a block exists but no instance is used" do @@ -269,6 +271,8 @@ describe CanCan::Ability do end @ability.authorize! :update, :ranges @ability.should_not be_fully_authorized(:update, :ranges) + @ability.authorize! :update, 1..3 + @ability.should be_fully_authorized(:update, :ranges) end it "is not fully authorized when attributes are required but not checked in update/create actions" do