You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have one ActiveRecord model (RawDatum) set up to read/write to/from the secondary database.
Here's a summarized version of my RSpec spec:
require"rails_helper"describeSomeJob,type: :jobdoshared_examples"perform"do |api_server_id,expected_records_count|
describe"#perform"doit"inserts records into RawDatum"do# This will fail on the 2nd `it_behaves_like` belowexpect(RawDatum.count).toeq(0)described_class.perform_now(api_server_id)expect(RawDatum.count).toeq(expected_records_count)endendenddescribe"API One"doit_behaves_like"perform",1,822enddescribe"API Two"doit_behaves_like"perform",2,439endend
@coderberry Interesting problem. I'm not 100% sure what could be the problem.
Here are some options:
I don't think you need all of this:
config.before(:each) do
DatabaseCleaner[:active_record, db: :primary].start
DatabaseCleaner[:active_record, db: :cache].start
end
config.after(:each) do
DatabaseCleaner[:active_record, db: :primary].clean
DatabaseCleaner[:active_record, db: :cache].clean
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
Could you test with one (cleaning) or the other (start+clean)?
If you get the same results, I'd probably keep the start+clean and get rid of the cleaning call.
It might be an issue due to multiple database connections?
Another idea is that you could test this PR: #108 -- it might be related to your problem.
This might be a rare use case, but I have an app that uses two databases. Here's a snippet from my
database.yml
file:I have one ActiveRecord model (
RawDatum
) set up to read/write to/from the secondary database.Here's a summarized version of my RSpec spec:
Here is my
spec/support/database_cleaner.rb
file:The text was updated successfully, but these errors were encountered: