Upgrade DatabaseCleaner strategy
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CodeOcean::FilesController do
|
||||
@ -48,6 +50,8 @@ describe CodeOcean::FilesController do
|
||||
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:exercise)
|
||||
it 'redirects to exercise path' do
|
||||
expect(controller).to redirect_to(exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExercisesController do
|
||||
@ -230,8 +232,8 @@ describe ExercisesController do
|
||||
describe 'POST #submit' do
|
||||
let(:output) { {} }
|
||||
let(:perform_request) { post :submit, format: :json, params: { id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} } }
|
||||
let!(:external_user) { FactoryBot.create(:external_user) }
|
||||
let!(:lti_parameter) { FactoryBot.create(:lti_parameter, external_user: external_user, exercise: exercise) }
|
||||
let(:user) { FactoryBot.create(:external_user) }
|
||||
let!(:lti_parameter) { FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise) }
|
||||
|
||||
before(:each) do
|
||||
allow_any_instance_of(Submission).to receive(:normalized_score).and_return(1)
|
||||
|
@ -1,10 +1,48 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'capybara/rspec'
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
config.use_transactional_fixtures = false
|
||||
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
if config.use_transactional_fixtures?
|
||||
raise(<<-MSG)
|
||||
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
|
||||
(or set it to false) to prevent uncommitted transactions being used in
|
||||
JavaScript-dependent specs.
|
||||
|
||||
During testing, the app-under-test that the browser driver connects to
|
||||
uses a different database connection to the database connection used by
|
||||
the spec. The app's database connection would not be able to access
|
||||
uncommitted transaction data setup over the spec's database connection.
|
||||
MSG
|
||||
end
|
||||
|
||||
DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
|
||||
config.around(:each) do |example|
|
||||
DatabaseCleaner.cleaning { example.run }
|
||||
config.before do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
|
||||
config.before(:each, type: :feature) do
|
||||
# :rack_test driver's Rack app under test shares database connection
|
||||
# with the specs, so continue to use transaction strategy for speed.
|
||||
unless Capybara.current_driver == :rack_test
|
||||
# Driver is probably for an external browser with an app
|
||||
# under test that does *not* share a database connection with the
|
||||
# specs, so use truncation strategy.
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
end
|
||||
end
|
||||
|
||||
config.before do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
config.append_after do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user