diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index f7b55dc..0a91eb6 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,5 +1,9 @@ 1.4.0 (not yet released) +* Adding Gemfile; to get specs running just +bundle+ and +rake+ - see issue #163 + +* Stop at 'cannot' definition when there are no conditions - see issue #161 + * The :through option will now call a method with that name if instance variable doesn't exist - see issue #146 * Adding :shallow option to load_resource to bring back old behavior of fetching a child without a parent diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 36d3482..0d9e9d9 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -224,7 +224,7 @@ module CanCan def has_block?(action, subject) relevant_can_definitions(action, subject).any?(&:only_block?) end - + def has_raw_sql?(action, subject) relevant_can_definitions(action, subject).any?(&:only_raw_sql?) end @@ -271,7 +271,7 @@ module CanCan can_definition.relevant? action, subject end end - + def relevant_can_definitions_for_match(action, subject) relevant_can_definitions(action, subject).each do |can_definition| if can_definition.only_raw_sql? diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index 071bc03..1adba11 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -56,7 +56,7 @@ module CanCan def only_block? conditions_empty? && !@block.nil? end - + def only_raw_sql? @block.nil? && !conditions_empty? && !@conditions.kind_of?(Hash) end diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 4888dc5..70f00fd 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -324,7 +324,7 @@ describe CanCan::Ability do 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) diff --git a/spec/cancan/active_record_additions_spec.rb b/spec/cancan/active_record_additions_spec.rb index f3b663d..4ce7c66 100644 --- a/spec/cancan/active_record_additions_spec.rb +++ b/spec/cancan/active_record_additions_spec.rb @@ -56,14 +56,14 @@ describe CanCan::ActiveRecordAdditions do stub(@model_class).scoped{|*args| args.inspect} @model_class.accessible_by(@ability).should == :found_records end - + it "should not allow to fetch records when ability with just block present" do @ability.can :read, @model_class do false end lambda { @model_class.accessible_by(@ability) }.should raise_error(CanCan::Error) end - + it "should not allow to check ability on object when nonhash sql ability definition without block present" do @ability.can :read, @model_class, ['bar = ?', 1] lambda {