Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Placing conditions on optionally associated objects raises exceptions at rule match time #330

Merged
merged 1 commit into from
Apr 1, 2011
Merged

Placing conditions on optionally associated objects raises exceptions at rule match time #330

merged 1 commit into from
Apr 1, 2011

Conversation

thatothermitch
Copy link
Contributor

Consider the classes:

class Foo
   attr_accessor :my_bar
end

class Bar
   def baz; "quux"; end
end

The ability:

 can :manage, Foo, :bar => { :baz => "quux" }

And the check:

foo_without_bar = Foo.new
foo_without_bar.bar #  => nil
can? :manage, foo_without_bar # => Exception!

In 1.6.4 this results in the exception undefined method 'bar' for nil:NilClass. This patch modifies the Rule#matches_conditions_hash? to return false for this case.

Test included, and comments are welcome. Thanks!

…hrow exceptions if the associated object was not present at the rule match time.
@ryanb
Copy link
Owner

ryanb commented Apr 1, 2011

Looks great thanks. I'll get this pulled in soon.

@ryanb ryanb merged commit 6aaab9e into ryanb:master Apr 1, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants