diff --git a/app/policies/activity_policy.rb b/app/policies/activity_policy.rb index ea813b34a5..fd8e23f50d 100644 --- a/app/policies/activity_policy.rb +++ b/app/policies/activity_policy.rb @@ -58,6 +58,7 @@ def media? def submit? return false if record.removed? return false if user.blank? + return false if record.not_valid? return true if user.admin? return true if record.ok? diff --git a/test/controllers/submissions_controller_test.rb b/test/controllers/submissions_controller_test.rb index a362ac2e5b..e7a5e44905 100644 --- a/test/controllers/submissions_controller_test.rb +++ b/test/controllers/submissions_controller_test.rb @@ -486,4 +486,24 @@ def expected_score_string(*args) assert_response :ok end + + test 'should not be able to submit to invalid exercise' do + attrs = generate_attr_hash + exercise = Exercise.find(attrs[:exercise_id]) + exercise.update!(status: :not_valid) + + sign_in create(:staff) + create_request(attr_hash: attrs) + + assert_response :unprocessable_entity + end + + test 'should not be able to submit to valid exercise' do + attrs = generate_attr_hash + + sign_in create(:staff) + create_request(attr_hash: attrs) + + assert_response :success + end end diff --git a/test/system/activities_test.rb b/test/system/activities_test.rb index 54733b2f18..b16a99fd28 100644 --- a/test/system/activities_test.rb +++ b/test/system/activities_test.rb @@ -68,4 +68,11 @@ class ActivitiesTest < ApplicationSystemTestCase assert_text '`\\n\n\\0`' end + + test 'should not be able to submit to invalid exercise' do + @instance.update!(status: :not_valid) + visit exercise_path(id: @instance.id) + + assert_no_selector '#editor-process-btn' + end end