Skip to content

Commit

Permalink
Merge pull request ryanb#274 from joshsoftware/fix-enumerable-all-return
Browse files Browse the repository at this point in the history
Make the following fixes
  • Loading branch information
Senjai committed Nov 17, 2015
2 parents d3d1b5a + e681bee commit 3e3c366
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/cancan/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
30 changes: 30 additions & 0 deletions spec/cancan/model_adapters/active_record_4_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3e3c366

Please sign in to comment.