Is there an equivalent to
it { should validate...
it { should validate_uniqueness_of(
etc for
validates_associated
Something like,
it { should validate_associate(:associated_model_object)
except, you know, functional.
Thanks!
I think something like this would work:
it "should validate associate_model_object" do
m = Model.new(valid_params)
m.associated_models.build(invalid_params)
m.save.should eq(false)
end
Replace the middle line with this if you're coming from the other direction:
m.build_associated_model(invalid_params)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With