Hide score button if exercise has no tests
We check for all teacher-defined assessments (linter and unit tests) to determine whether scoring should be possible
This commit is contained in:

committed by
Sebastian Serth

parent
ba5918b4ca
commit
e0c2c7b806
@ -6,7 +6,10 @@ describe ExercisesController do
|
||||
let(:exercise) { create(:dummy) }
|
||||
let(:user) { create(:admin) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
before do
|
||||
create(:test_file, context: exercise)
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
end
|
||||
|
||||
describe 'PUT #batch_update' do
|
||||
let(:attributes) { {public: 'true'} }
|
||||
|
@ -23,6 +23,7 @@ describe 'Editor', js: true do
|
||||
}]
|
||||
end
|
||||
let(:user) { create(:teacher) }
|
||||
let(:exercise_without_test) { create(:tdd) }
|
||||
|
||||
before do
|
||||
visit(sign_in_path)
|
||||
@ -93,12 +94,28 @@ describe 'Editor', js: true do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an exercise has one or more teacher-defined assessments' do
|
||||
it 'displays the score button' do
|
||||
visit(implement_exercise_path(exercise))
|
||||
expect(page).to have_content(exercise.title)
|
||||
expect(page).to have_content(I18n.t('exercises.editor.score'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an exercise has no teacher-defined assessment' do
|
||||
it 'disables the score button' do
|
||||
visit(implement_exercise_path(exercise_without_test))
|
||||
expect(page).to have_content(exercise_without_test.title)
|
||||
expect(page).not_to have_content(I18n.t('exercises.editor.score'))
|
||||
end
|
||||
end
|
||||
|
||||
it 'contains a button for submitting the exercise' do
|
||||
submission = build(:submission, user: user, exercise: exercise)
|
||||
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
||||
allow(Submission).to receive(:find).and_return(submission)
|
||||
click_button(I18n.t('exercises.editor.score'))
|
||||
expect(page).not_to have_css('#submit_outdated')
|
||||
expect(page).to have_css('#submit')
|
||||
expect(page).not_to have_content(I18n.t('exercises.editor.tooltips.exercise_deadline_passed'))
|
||||
expect(page).to have_content(I18n.t('exercises.editor.submit'))
|
||||
end
|
||||
end
|
||||
|
@ -124,4 +124,41 @@ describe Exercise do
|
||||
expect(exercise.duplicate).to be_a(described_class)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#teacher_defined_assessment?' do
|
||||
let(:exercise) { create(:dummy) }
|
||||
|
||||
context 'when no assessment is defined' do
|
||||
it 'returns false' do
|
||||
expect(exercise).not_to be_teacher_defined_assessment
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unit tests are defined' do
|
||||
before { create(:test_file, context: exercise) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(exercise).to be_teacher_defined_assessment
|
||||
end
|
||||
end
|
||||
|
||||
context 'when linter tests are defined' do
|
||||
before { create(:test_file, context: exercise, role: 'teacher_defined_linter') }
|
||||
|
||||
it 'returns true' do
|
||||
expect(exercise).to be_teacher_defined_assessment
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unit and linter tests are defined' do
|
||||
before do
|
||||
create(:test_file, context: exercise)
|
||||
create(:test_file, context: exercise, role: 'teacher_defined_linter')
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(exercise).to be_teacher_defined_assessment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ describe ExercisePolicy do
|
||||
end
|
||||
end
|
||||
|
||||
%i[implement? submit?].each do |action|
|
||||
%i[implement?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
@ -122,6 +122,28 @@ describe ExercisePolicy do
|
||||
end
|
||||
end
|
||||
|
||||
%i[submit?].each do |action|
|
||||
permissions(action) do
|
||||
context 'when teacher-defined assessments are available' do
|
||||
before { create(:test_file, context: exercise) }
|
||||
|
||||
it 'grants access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).to permit(build(factory_name), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when teacher-defined assessments are not available' do
|
||||
it 'does not grant access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(build(factory_name), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ExercisePolicy::Scope do
|
||||
describe '#resolve' do
|
||||
let(:admin) { create(:admin) }
|
||||
|
Reference in New Issue
Block a user