I'm having an awful time trying to understand what my validation method is having trouble with.
I installed shoulda and when I tried to use it it errors out with a strange undefined method NoMethodError: undefined method '[]' for false:FalseClass
which is very odd.
I narrowed it down to this piece of offending code:
validates_each :name do |record, attr, value|
name_hash = self.parse_name(value)
record.errors.add attr, 'must have a first and last name' if
( name_hash[:first_name].nil? || name_hash[:last_name].nil? )
end
You can see the full error, offending model (simplified), the test case, and environment info at gist-596202
Any insight would be greatly appreciated.
Your parse_name
method starts with this line:
return false unless name.is_a?(String)
This would indicate that the value is not a string (probably nil) when you're trying to validate it. The shoulda matcher for validate_presence_of
will test it with a nil value, which is why you're getting the failure.