Answer the question
In order to leave comments, you need to log in
How to fix error when saving ActiveRecord to spec?
Good afternoon.
Today a specific error appeared: there is a spec test with several examples. Initially, for all contexts in the before :all block, I create common data for the test using FactoryGirl.create() .
In each test case, in one of these objects, 2 fields with the parameters I need are changed and saved using save!
However, everything works fine only for the first test case, on subsequent calls to save! an error:
Mysql2::Error: Duplicate entry '154' for key 'PRIMARY': INSERT INTO `table_name`
Answer the question
In order to leave comments, you need to log in
The problem turned out to be much more strange - the following construct is written in spec_helper.rb :
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question