diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index 25e60630..7dc50d27 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -112,10 +112,10 @@ def matches_conditions_hash?(subject, conditions = @conditions) conditions.all? do |name, value| if adapter.override_condition_matching?(subject, name, value) - return adapter.matches_condition?(subject, name, value) + adapter.matches_condition?(subject, name, value) + else + condition_match?(subject.send(name), value) end - - condition_match?(subject.send(name), value) end end diff --git a/spec/README.rdoc b/spec/README.rdoc index fc409cb7..88638a93 100644 --- a/spec/README.rdoc +++ b/spec/README.rdoc @@ -16,7 +16,7 @@ You can then run all test sets: Or individual ones: - appraisal rails_3.0 rake + appraisal activerecord_3.2 rake A list of the tests is in the +Appraisal+ file. diff --git a/spec/cancan/model_adapters/active_record_4_adapter_spec.rb b/spec/cancan/model_adapters/active_record_4_adapter_spec.rb index d72d0650..b50b2a0f 100644 --- a/spec/cancan/model_adapters/active_record_4_adapter_spec.rb +++ b/spec/cancan/model_adapters/active_record_4_adapter_spec.rb @@ -75,6 +75,36 @@ class Shape < ActiveRecord::Base accessible = Shape.accessible_by(@ability, :update) expect(accessible).to contain_exactly(red, blue) end + + it "allows dual filter on enums" do + ActiveRecord::Schema.define do + create_table(:discs) do |t| + t.integer :color, default: 0, null: false + t.integer :shape, default: 3, null: false + end + end + + class Disc < ActiveRecord::Base + enum color: [:red, :green, :blue] + enum shape: { triangle: 3, rectangle: 4 } + end + + red_triangle = Disc.create!(color: Disc.colors[:red], shape: Disc.shapes[:triangle]) + green_triangle = Disc.create!(color: Disc.colors[:green], shape: Disc.shapes[:triangle]) + green_rectangle = Disc.create!(color: Disc.colors[:green], shape: Disc.shapes[:rectangle]) + blue_rectangle = Disc.create!(color: Disc.colors[:blue], shape: Disc.shapes[:rectangle]) + + # A condition with a dual filter. + @ability.can :read, Disc, color: Disc.colors[:green], shape: Disc.shapes[:rectangle] + + expect(@ability.cannot? :read, red_triangle).to be true + expect(@ability.cannot? :read, green_triangle).to be true + expect(@ability.can? :read, green_rectangle).to be true + expect(@ability.cannot? :read, blue_rectangle).to be true + + accessible = Disc.accessible_by(@ability) + expect(accessible).to contain_exactly(green_rectangle) + end end end