@@ -930,17 +930,30 @@ def test_require_comment_for_feedback_submission_assess_in_portfolio
930930
931931 def test_resubmission_doesnt_change_submission_date
932932 Sidekiq ::Testing . inline! do
933- unit = FactoryBot . create ( :unit , task_count : 2 , student_count : 0 )
933+ unit = FactoryBot . create (
934+ :unit ,
935+ with_students : false ,
936+ student_count : 0 ,
937+ task_count : 0 ,
938+ tutorials : 0 ,
939+ stream_count : 0 ,
940+ staff_count : 0 ,
941+ campus_count : 0 ,
942+ outcome_count : 0
943+ )
934944 tutor = FactoryBot . create ( :user , :tutor )
935945
936946 unit_role = unit . employ_staff ( tutor , Role . tutor )
937947 tutorial_stream = FactoryBot . create ( :tutorial_stream , unit : unit )
938948 tutorial = FactoryBot . create ( :tutorial , unit : unit , tutorial_stream : tutorial_stream , campus : nil , unit_role : unit_role )
939-
940- td = unit . task_definitions . first
941-
942- td . update! ( due_date : Time . zone . today + 1 . day , tutorial_stream : tutorial_stream )
943- assert_not td . nil?
949+ td = FactoryBot . create (
950+ :task_definition ,
951+ unit : unit ,
952+ tutorial_stream : tutorial_stream ,
953+ target_grade : 0 ,
954+ outcome_count : 0
955+ )
956+ td . update! ( due_date : Time . zone . today + 1 . day )
944957
945958 student1 = FactoryBot . create ( :user , :student )
946959 student2 = FactoryBot . create ( :user , :student )
@@ -951,29 +964,20 @@ def test_resubmission_doesnt_change_submission_date
951964 project1 . enrol_in ( tutorial )
952965 project2 . enrol_in ( tutorial )
953966
967+ task1 = project1 . task_for_task_definition ( td )
968+ task2 = project2 . task_for_task_definition ( td )
969+
954970 tasks = unit . tasks_for_task_inbox ( tutor , false )
955971
956972 assert tasks . to_a . empty?
957973
958974 # Submit a task before the due date (student 1)
959- add_auth_header_for ( user : student1 )
960- data_to_post = {
961- trigger : 'ready_for_feedback'
962- }
963- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
964- post "/api/projects/#{ project1 . id } /task_def_id/#{ td . id } /submission" , data_to_post
965- assert_equal 201 , last_response . status , last_response_body
975+ task1 . submit ( student1 )
966976
967977 travel 10 . minutes
968978
969979 # Submit a task before the due date (student 2)
970- add_auth_header_for ( user : student2 )
971- data_to_post = {
972- trigger : 'ready_for_feedback'
973- }
974- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
975- post "/api/projects/#{ project2 . id } /task_def_id/#{ td . id } /submission" , data_to_post
976- assert_equal 201 , last_response . status , last_response_body
980+ task2 . submit ( student2 )
977981
978982 tasks = unit . tasks_for_task_inbox ( tutor , false )
979983
@@ -982,80 +986,57 @@ def test_resubmission_doesnt_change_submission_date
982986 assert_equal project1 . id , tasks . first . project . id , "First task in inbox should be project1's task"
983987 assert_equal project2 . id , tasks . second . project . id , "Second task in inbox should be project2's task"
984988
985- task1 = project1 . task_for_task_definition ( td )
986- task2 = project2 . task_for_task_definition ( td )
987-
988989 assert_equal TaskStatus . ready_for_feedback , task1 . task_status
989990 assert_equal TaskStatus . ready_for_feedback , task2 . task_status
990991
991992 assert task2 . submission_date > task1 . submission_date
993+ original_submission_date = task1 . submission_date
992994
993995 # Submit the task again, ensure the submission_date hasn't changed (student1)
994996 travel 10 . minutes
995997
996- # Submit a task before the due date (student 1)
997- add_auth_header_for ( user : student1 )
998- data_to_post = {
999- trigger : 'ready_for_feedback'
1000- }
1001- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
1002- post "/api/projects/#{ project1 . id } /task_def_id/#{ td . id } /submission" , data_to_post
1003- assert_equal 201 , last_response . status , last_response_body
998+ task1 . submit ( student1 )
1004999
10051000 tasks = unit . tasks_for_task_inbox ( tutor , false )
10061001
10071002 assert_equal project1 . id , tasks . first . project . id , "First task in inbox should be project1's task"
10081003 assert_equal project2 . id , tasks . second . project . id , "Second task in inbox should be project2's task"
10091004
1010- task1 = project1 . task_for_task_definition ( td )
1011- task2 = project2 . task_for_task_definition ( td )
1005+ task1 . reload
10121006 assert task2 . submission_date > task1 . submission_date
1007+ assert_equal original_submission_date , task1 . submission_date
10131008 assert TaskStatus . ready_for_feedback , task1 . task_status
10141009
10151010 # Submit the task again after the duedate, ensure the submission_date hasn't changed (student1)
10161011 travel 2 . days
10171012
1018- # Submit a task before the due date (student 1)
1019- add_auth_header_for ( user : student1 )
1020- data_to_post = {
1021- trigger : 'ready_for_feedback'
1022- }
1023- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
1024- post "/api/projects/#{ project1 . id } /task_def_id/#{ td . id } /submission" , data_to_post
1025- assert_equal 201 , last_response . status , last_response_body
1013+ task1 . submit ( student1 )
10261014
10271015 tasks = unit . tasks_for_task_inbox ( tutor , false )
10281016
10291017 assert_equal project1 . id , tasks . first . project . id , "First task in inbox should be project1's task"
10301018 assert_equal project2 . id , tasks . second . project . id , "Second task in inbox should be project2's task"
10311019
1032- task1 = project1 . task_for_task_definition ( td )
1033- task2 = project2 . task_for_task_definition ( td )
1020+ task1 . reload
10341021 assert task2 . submission_date > task1 . submission_date
1022+ assert_equal original_submission_date , task1 . submission_date
10351023 assert TaskStatus . ready_for_feedback , task1 . task_status
10361024
10371025 task1 . update ( task_status_id : TaskStatus . fix_and_resubmit . id )
10381026
10391027 # Submit the task again, now expecting submission date to update
10401028 travel 10 . minutes
10411029
1042- # Submit a task before the due date (student 1)
1043- add_auth_header_for ( user : student1 )
1044- data_to_post = {
1045- trigger : 'ready_for_feedback'
1046- }
1047- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
1048- post "/api/projects/#{ project1 . id } /task_def_id/#{ td . id } /submission" , data_to_post
1049- assert_equal 201 , last_response . status , last_response_body
1030+ task1 . submit ( student1 )
10501031
10511032 tasks = unit . tasks_for_task_inbox ( tutor , false )
10521033
10531034 assert_equal project2 . id , tasks . first . project . id , "First task in inbox should be project1's task"
10541035 assert_equal project1 . id , tasks . second . project . id , "Second task in inbox should be project2's task"
10551036
1056- task1 = project1 . task_for_task_definition ( td )
1057- task2 = project2 . task_for_task_definition ( td )
1037+ task1 . reload
10581038 assert task1 . submission_date > task2 . submission_date
1039+ assert task1 . submission_date > original_submission_date
10591040 end
10601041 end
10611042
0 commit comments