Fix a bug where matchers fail on models with an autosaved belongs_to associations #271

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@triskweline
Contributor

When a model has an autosaved belongs_to associations, matchers fail when validating records of that model.

E.g. you have a User that belongs_to a Group and accepts nested attributes for that group:

class User < ActiveRecord::Base
  accepts_nested_attributes_for :group
end

class Group < ActiveRecord::Base
  validates_presence_of :name
end

When using one of the matchers on User records with a nameless group, user.errors has an entry for group.name (sic). The matcher tries to come up with a helpful error message that includes the value for group.name but of course fails because the user does not respond_to?('group.name').

The attached pull request checks if a record responds to an error key before obtaining the attribute value for that key.

A new patch release would be greatly appreciated!

Thanks.

@drapergeek
Member

Thanks @henning-koch! Merged.

@drapergeek drapergeek closed this Apr 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment