Fix flaky tests dependent on exercise.reload for files
This commit is contained in:
@ -63,20 +63,21 @@ describe CodeOcean::FilesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
let(:exercise) { create(:fibonacci) }
|
let!(:exercise) { create(:fibonacci) }
|
||||||
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.first.id} } }
|
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.reject(&:main_file?).first.id} } }
|
||||||
|
|
||||||
before { perform_request.call }
|
context 'with request performed' do
|
||||||
|
before { perform_request.call }
|
||||||
|
|
||||||
expect_assigns(file: CodeOcean::File)
|
expect_assigns(file: CodeOcean::File)
|
||||||
|
|
||||||
it 'destroys the file' do
|
it 'redirects to exercise path' do
|
||||||
create(:fibonacci)
|
expect(controller).to redirect_to(exercise)
|
||||||
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to exercise path' do
|
it 'destroys the file' do
|
||||||
expect(controller).to redirect_to(exercise)
|
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -144,7 +144,7 @@ describe Exercise do
|
|||||||
before { create(:test_file, context: exercise) }
|
before { create(:test_file, context: exercise) }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(exercise).to be_teacher_defined_assessment
|
expect(exercise.reload).to be_teacher_defined_assessment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ describe Exercise do
|
|||||||
before { create(:test_file, context: exercise, role: 'teacher_defined_linter') }
|
before { create(:test_file, context: exercise, role: 'teacher_defined_linter') }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(exercise).to be_teacher_defined_assessment
|
expect(exercise.reload).to be_teacher_defined_assessment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ describe Exercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(exercise).to be_teacher_defined_assessment
|
expect(exercise.reload).to be_teacher_defined_assessment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -188,7 +188,10 @@ describe ExercisePolicy do
|
|||||||
|
|
||||||
permissions :submit? do
|
permissions :submit? do
|
||||||
context 'when teacher-defined assessments are available' do
|
context 'when teacher-defined assessments are available' do
|
||||||
before { create(:test_file, context: exercise) }
|
before do
|
||||||
|
create(:test_file, context: exercise)
|
||||||
|
exercise.reload
|
||||||
|
end
|
||||||
|
|
||||||
it 'grants access to anyone' do
|
it 'grants access to anyone' do
|
||||||
%i[admin external_user teacher].each do |factory_name|
|
%i[admin external_user teacher].each do |factory_name|
|
||||||
|
Reference in New Issue
Block a user