[rspec-users] specs for attributes with default values on the SQL layer
svoop at delirium.ch
Thu Apr 16 13:43:50 EDT 2009
I'm not sure what would be best practise to treat this case.
t.boolean :fetched, :null => false, :default => false
validates_inclusion_of :fetched, :in => [true, false]
article = Article.new(valid_attributes.except(:fetched))
Like this the spec will always fail because although fetched is excepted from
the hash returned by valid_attributes, it still gets set to false due to the
default value. Therefore no error and therefore the spec booms.
A solution would be to use this instead:
article = Article.new(valid_attributes.with(:fetched => nil))
But that would block refactoring if many attributes are tested for errors.
More information about the rspec-users