Has anyone ran into problem like that?
I have a controller, which triggers mailer delivery:
def create
create! do |success, failure|
success.js do
CandidateMailer.donation_notification(current_candidate).deliver
end
end
end
And I got that mailer:
def donation_notification(candidate)
puts Candidate.count # note: during test - count of candidates is 0
@candidate = candidate
email_with_name = "#{@candidate.profile.name} <#{@candidate.email}>"
mail(to: email_with_name, subject: 'New Donation Received!')
end
I don't understand why database cleaner removes all data before test is actually finished.
It's a JS test (with Webkit) if that matters at all.
Here's my config:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = [:truncation, { pre_count: true }]
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
If I understand correctly from the code, both clean and clean_with actually delegate to strategy.clean
, which means they both actively clean.
When you call
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
It cleans your database before the tests begin.
In a test situation, this might be OK, if you seed your test data at the beginning of the suite (or before each test).