merging with master

This commit is contained in:
Ryan Bates 2011-03-25 14:32:29 -07:00
commit bcac159b3e
5 changed files with 38 additions and 5 deletions

View File

@ -1,3 +1,10 @@
1.6.3 (March 25, 2011)
* Make sure ActiveRecord::Relation is defined before checking conditions against it so Rails 2 is supported again - see issue #312
* Return subject passed to authorize! - see issue #314
1.6.2 (March 18, 2011)
* Fixed instance loading when :singleton option is used - see issue #310

View File

@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "cancan"
s.version = "1.6.2"
s.version = "1.6.3"
s.author = "Ryan Bates"
s.email = "ryan@railscasts.com"
s.homepage = "http://github.com/ryanb/cancan"

View File

@ -223,6 +223,7 @@ module CanCan
elsif sufficient_attribute_check?(action, subject, attribute) && sufficient_condition_check?(action, subject)
fully_authorized!(action, subject)
end
subject
end
def unauthorized_message(action, subject)

View File

@ -99,7 +99,7 @@ module CanCan
def override_scope
conditions = @rules.map(&:conditions).compact
if conditions.any? { |c| c.kind_of?(ActiveRecord::Relation) }
if defined?(ActiveRecord::Relation) && conditions.any? { |c| c.kind_of?(ActiveRecord::Relation) }
if conditions.size == 1
conditions.first
else

View File

@ -359,7 +359,30 @@ describe CanCan::Ability do
end
end
it "raises access denied exception with default message if not specified" do
it "should not raise access denied exception if ability is authorized to perform an action and return subject" do
@ability.can :read, :foo
lambda {
@ability.authorize!(:read, :foo).should == :foo
}.should_not raise_error
end
it "should know when block is used in conditions" do
@ability.can :read, :foo
@ability.should_not have_block(:read, :foo)
@ability.can :read, :foo do |foo|
false
end
@ability.should have_block(:read, :foo)
end
it "should know when raw sql is used in conditions" do
@ability.can :read, :foo
@ability.should_not have_raw_sql(:read, :foo)
@ability.can :read, :foo, 'false'
@ability.should have_raw_sql(:read, :foo)
end
it "should raise access denied exception with default message if not specified" do
begin
@ability.authorize! :read, :books
rescue CanCan::AccessDenied => e
@ -370,9 +393,11 @@ describe CanCan::Ability do
end
end
it "does not raise access denied exception if ability is authorized to perform an action" do
it "does not raise access denied exception if ability is authorized to perform an action and return subject" do
@ability.can :read, :books
lambda { @ability.authorize!(:read, :books) }.should_not raise_error
lambda {
@ability.authorize!(:read, :books).should == :books
}.should_not raise_error
end