Closed passalini closed 10 years ago
I would implement like this:
context 'new object' do
it { should have_valid(:address).when(nil, '') }
end
context 'existing object' do
subject { User.create }
it { should_not have_valid(:address).when(nil, '') }
end
ValidAttribute would have no way of knowing what state your model should be in when persisted. So it always just works off of the subject. It is up to you to define the state of the subject to run validation tests off of.
@bcardarella thanks!!! =D
Just make sure you create a valid object in the 2nd context so that the validations are fired on the persisted state (update state)
If I have
validates_presence_of :address, on: :update
how can I test it? I thoughtit { should_not have_valid(:address).on(:update).when('', nil) }
, but this did not work and looking (very fast) the repo, looks like you do not have this feature or am I wrong?