Closed sachin21 closed 7 years ago
@amatsuda @deeeki How about this?
You should try the following.
rails_helper.rb
using rails g rspec:install
rails_helper.rb
, not in spec/support
If it doesn't work, please create and show your own repository to reproduce the same error.
Thank you for suggesting to how to reproduce. I'll try and report that at tonight.
@deeeki @amatsuda I'm really sorry. I created supporting files for factory_girl, shoulda_matchers and database_rewinder then It works for me. I will be closing this issue. I think this problem is not a bug of database_rewinder. I sincerely apologize again. But I will report how to solve this problem later.
I found the cause. My project has ActiveRecord::Base's monkey patch. If removed this file, it works.
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
def self.clear_all_connections!
@@shared_connection = nil
super
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
# 競合回避のため、Mysql2::Client#queryをMutex#synchronizeでラップする
# see: https://gist.github.com/josevalim/470808#gistcomment-1415458
module MutexLockedQuerying
@@semaphore = Mutex.new
def query(*)
@@semaphore.synchronize { super }
end
end
Mysql2::Client.prepend(MutexLockedQuerying)
An error occurred when factory_girl's
create
method is executed. It looks like factory_girl's problem but when I am using database_cleaner, RSpec execution all is well so I think database_rewinder's problem.Environment information
What
A configuration file for database_rewinder
I tried these configuration codes
Case 1: Replaced DatabaseCleaner with DatabaseRewinder
Case 2: Syntax accourding to database_cleaner
However, those will occur the following error.
Error message