-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forced creating of an invalid record #578
Comments
@shaggyone you can use custom methods to persist objects: factory :different_orm_model do
to_create {|instance| instance.save(validate: false) }
end |
But this way you always will save that factory objects skipping validations. It would be nice to have a way to define multiple creation methods, or simply be able to provide some argument to Thanks! |
Does this work?
|
Yeah, surely it works... but I usually like to have one factory per model, and just provide ways to have fined control over it through traits. But surely this is just my workflow and your proposal should be 100% acceptable. Thanks. |
Using this technique inside traits seems to work. trait :pay do
# Turn off validation so we can create order with pay status directly
to_create {|instance| instance.save(validate: false) }
status "pay"
end |
what about forcing to save record, column_validation not in model. is it still possible? |
@aldrienht You can't ignore or disable constraints in Postgres. If you really want to test with a |
trait :skip_validate do
to_create {|instance| instance.save(validate: false) }
end |
Hello, is there any standart way to create an invalid record using factory girl.
First thing, of course is to use:
let(:var) { FactoryGirl.build :factory_name, ... }
before { var.save(validate: false) }
But maybe there is some pretty looking syntax for using FactoryGirl.create ?
The text was updated successfully, but these errors were encountered: