Factory-girl create that bypasses my model validation
This isn't very specific to FactoryGirl, but you can always bypass validations when saving models via save(validate: false)
:
describe ".current" do
let!(:current_group) { FactoryGirl.create(:group) }
let!(:old_group) do
g = FactoryGirl.build(:group, expiry: Time.now - 3.days)
g.save(validate: false)
g
end
specify { Group.current.should == [current_group] }
end
I prefer this solution from https://github.com/thoughtbot/factory_girl/issues/578.
Inside the factory:
trait :without_validations do
to_create { |instance| instance.save(validate: false) }
end