Dr. Chocolate
Dr. Chocolate

Reputation: 2165

FactoryGirl, Does it save to the database?

When I create a Model with factory girl and call the save function does that save that data to the database?

trait :myTrait do
  after :create do |user|
    user.partners << Partner.MyPartner
    user.save
  end
end

Upvotes: 1

Views: 1957

Answers (1)

Raj
Raj

Reputation: 22956

Depends on your transaction level setting of your test suite.

rails_helper.rb:

RSpec.configure do |config|

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
end

If config.use_transactional_fixtures is true, the records are not saved to the database but the test will have access to the created data.

Upvotes: 4

Related Questions