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

wants to merge 1 commit into


None yet

2 participants


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

class Group < ActiveRecord::Base
  validates_presence_of :name

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

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 @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