From 555a798ae536d158b7656a2f60a4e4f945f7a02d Mon Sep 17 00:00:00 2001 From: umututku03 Date: Fri, 26 Jul 2024 12:50:36 -0400 Subject: [PATCH 1/6] Using assignment release date as the default date for token start time --- app/controllers/assignments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index ae4159555d..dbbcb21777 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -229,7 +229,7 @@ def create @assignment.transaction do begin @assignment = process_assignment_form(@assignment) - @assignment.token_start_date = @assignment.due_date + @assignment.token_start_date = Time.current @assignment.token_period = 1 rescue StandardError => e @assignment.errors.add(:base, e.message) From 3bb66e29534854208051f89f1402fcbe83c701cd Mon Sep 17 00:00:00 2001 From: umututku03 Date: Fri, 2 Aug 2024 03:02:59 -0400 Subject: [PATCH 2/6] Default date for token start date --- app/assets/javascripts/Components/autotest_manager.jsx | 1 + app/controllers/assignments_controller.rb | 1 - app/controllers/automated_tests_controller.rb | 2 -- config/locales/views/automated_tests/en.yml | 1 + spec/models/assignment_spec.rb | 5 +++++ 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/Components/autotest_manager.jsx b/app/assets/javascripts/Components/autotest_manager.jsx index f8fedb91cd..4200b65676 100644 --- a/app/assets/javascripts/Components/autotest_manager.jsx +++ b/app/assets/javascripts/Components/autotest_manager.jsx @@ -365,6 +365,7 @@ class AutotestManager extends React.Component { id="token_start_date" value={this.state.token_start_date} onChange={this.handleTokenStartDateChange} + placeholder={I18n.t("automated_tests.use_assignment_release_date")} options={{ altInput: true, altFormat: I18n.t("time.format_string.flatpickr"), diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index dbbcb21777..9d7a298ec9 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -229,7 +229,6 @@ def create @assignment.transaction do begin @assignment = process_assignment_form(@assignment) - @assignment.token_start_date = Time.current @assignment.token_period = 1 rescue StandardError => e @assignment.errors.add(:base, e.message) diff --git a/app/controllers/automated_tests_controller.rb b/app/controllers/automated_tests_controller.rb index 58d3513d5e..8e09913e76 100644 --- a/app/controllers/automated_tests_controller.rb +++ b/app/controllers/automated_tests_controller.rb @@ -105,8 +105,6 @@ def populate_autotest_manager test_specs = autotest_settings_for(assignment) assignment_data = assignment.assignment_properties.attributes.slice(*required_params.map(&:to_s)) - assignment_data['token_start_date'] ||= Time.current - assignment_data['token_start_date'] = assignment_data['token_start_date'].iso8601 data = { schema: schema_data, files: files_data, formData: test_specs }.merge(assignment_data) render json: data end diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index 3e05e34ae4..789e7cefad 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -69,3 +69,4 @@ en: timeout: Timeout (s) title: Automated Testing use_assignment_due_date: Leave blank to use assignment due date + use_assignment_release_date: Leave blank to use assignment release date diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb index 7cd108efd5..ecc8196212 100644 --- a/spec/models/assignment_spec.rb +++ b/spec/models/assignment_spec.rb @@ -66,6 +66,11 @@ expect(@assignment.parent_assessment_id).to be_nil expect(@assignment.is_peer_review?).to be false end + + it 'sets default token_start_date to current time if not provided' do + assignment = build(:assignment_for_student_tests) + expect(assignment.token_start_date).to be_within(1.second).of(Time.current) + end end it 'should catch an invalid date' do From 9c7c94e5c1b65e8187d88ecbb4c945dcea137f05 Mon Sep 17 00:00:00 2001 From: umututku03 Date: Fri, 2 Aug 2024 03:12:06 -0400 Subject: [PATCH 3/6] Update the CHANGELOG.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index b82ef143b9..b66730229c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,7 @@ - Ensure user params are passed as keyword arguments to database queries (#7040) - Added a progress bar for when a student uploads a file for submission (#7078) - Added validations to the `TextAnnotation` model to ensure `line_start` and `line_end` are >= 1, and `column_start` and `column_end` are >= 0. (#7081) +- Set the default date for "Tokens available on" to the current time (#7173). ### 🐛 Bug fixes From 2d06bfb329b19e471653841b64ee5e65be7f07fa Mon Sep 17 00:00:00 2001 From: umututku03 Date: Tue, 6 Aug 2024 22:06:07 -0400 Subject: [PATCH 4/6] fixing milisecond issue in token start time --- app/controllers/automated_tests_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/automated_tests_controller.rb b/app/controllers/automated_tests_controller.rb index 8e09913e76..8c5c3ce3ce 100644 --- a/app/controllers/automated_tests_controller.rb +++ b/app/controllers/automated_tests_controller.rb @@ -105,6 +105,8 @@ def populate_autotest_manager test_specs = autotest_settings_for(assignment) assignment_data = assignment.assignment_properties.attributes.slice(*required_params.map(&:to_s)) + assignment_data['token_period'] = assignment_data['token_period'].to_i + assignment_data['token_start_date'] = assignment_data['token_start_date']&.change(usec: 0)&.iso8601 data = { schema: schema_data, files: files_data, formData: test_specs }.merge(assignment_data) render json: data end From b3a3799e280341af12bcd71181ebdb10640cc11d Mon Sep 17 00:00:00 2001 From: Utku Egemen Umut <121046082+umututku03@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:07:55 -0400 Subject: [PATCH 5/6] Update Changelog.md --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 01329fde11..7e04bf1462 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,7 +21,7 @@ - Added a progress bar for when a student uploads a file for submission (#7078) - Added validations to the `TextAnnotation` model to ensure `line_start` and `line_end` are >= 1, and `column_start` and `column_end` are >= 0. (#7081) - Calculate and display the exact future time for the next token generation to help students plan their test runs more effectively. (#7127) -- - Set the default date for "Tokens available on" to the current time (#7173). +- Set the default date for "Tokens available on" to the current time (#7173). ### 🐛 Bug fixes From 5a26e43cbb4fcd308fb694c881373169cef64fe5 Mon Sep 17 00:00:00 2001 From: umututku03 Date: Wed, 7 Aug 2024 18:29:33 -0400 Subject: [PATCH 6/6] non-nil default start date for token period --- Changelog.md | 2 +- .../Components/autotest_manager.jsx | 1 - app/controllers/assignments_controller.rb | 1 + app/controllers/automated_tests_controller.rb | 4 ++-- config/locales/views/automated_tests/en.yml | 1 - spec/models/assignment_spec.rb | 24 +++++++++++++++++-- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 01329fde11..7e04bf1462 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,7 +21,7 @@ - Added a progress bar for when a student uploads a file for submission (#7078) - Added validations to the `TextAnnotation` model to ensure `line_start` and `line_end` are >= 1, and `column_start` and `column_end` are >= 0. (#7081) - Calculate and display the exact future time for the next token generation to help students plan their test runs more effectively. (#7127) -- - Set the default date for "Tokens available on" to the current time (#7173). +- Set the default date for "Tokens available on" to the current time (#7173). ### 🐛 Bug fixes diff --git a/app/assets/javascripts/Components/autotest_manager.jsx b/app/assets/javascripts/Components/autotest_manager.jsx index 4200b65676..f8fedb91cd 100644 --- a/app/assets/javascripts/Components/autotest_manager.jsx +++ b/app/assets/javascripts/Components/autotest_manager.jsx @@ -365,7 +365,6 @@ class AutotestManager extends React.Component { id="token_start_date" value={this.state.token_start_date} onChange={this.handleTokenStartDateChange} - placeholder={I18n.t("automated_tests.use_assignment_release_date")} options={{ altInput: true, altFormat: I18n.t("time.format_string.flatpickr"), diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index 9d7a298ec9..dbbcb21777 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -229,6 +229,7 @@ def create @assignment.transaction do begin @assignment = process_assignment_form(@assignment) + @assignment.token_start_date = Time.current @assignment.token_period = 1 rescue StandardError => e @assignment.errors.add(:base, e.message) diff --git a/app/controllers/automated_tests_controller.rb b/app/controllers/automated_tests_controller.rb index 95d01c34d3..cf5642e704 100644 --- a/app/controllers/automated_tests_controller.rb +++ b/app/controllers/automated_tests_controller.rb @@ -114,8 +114,8 @@ def populate_autotest_manager test_specs = autotest_settings_for(assignment) assignment_data = assignment.assignment_properties.attributes.slice(*required_params.map(&:to_s)) - assignment_data['token_period'] = assignment_data['token_period'].to_i - assignment_data['token_start_date'] = assignment_data['token_start_date']&.change(usec: 0)&.iso8601 + assignment_data['token_start_date'] ||= Time.current + assignment_data['token_start_date'] = assignment_data['token_start_date'].iso8601 data = { schema: schema_data, files: files_data, formData: test_specs }.merge(assignment_data) render json: data end diff --git a/config/locales/views/automated_tests/en.yml b/config/locales/views/automated_tests/en.yml index 7567a99eba..f96f6f30e9 100644 --- a/config/locales/views/automated_tests/en.yml +++ b/config/locales/views/automated_tests/en.yml @@ -70,4 +70,3 @@ en: timeout: Timeout (s) title: Automated Testing use_assignment_due_date: Leave blank to use assignment due date - use_assignment_release_date: Leave blank to use assignment release date diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb index ecc8196212..c021e70543 100644 --- a/spec/models/assignment_spec.rb +++ b/spec/models/assignment_spec.rb @@ -1,4 +1,6 @@ describe Assignment do + include ActiveSupport::Testing::TimeHelpers + describe 'ActiveRecord associations' do it { is_expected.to have_one(:submission_rule).dependent(:destroy) } it { is_expected.to validate_presence_of(:submission_rule) } @@ -68,8 +70,26 @@ end it 'sets default token_start_date to current time if not provided' do - assignment = build(:assignment_for_student_tests) - expect(assignment.token_start_date).to be_within(1.second).of(Time.current) + travel_to Time.zone.local(2024, 8, 6, 22, 0, 0) do + assignment = build(:assignment_for_student_tests) + expect(assignment.token_start_date).to eq(Time.current) + end + end + + it 'sets token_start_date to the provided date' do + travel_to Time.zone.local(2024, 12, 25, 10, 0, 0) do + provided_date = Time.current + assignment = build(:assignment_for_student_tests, token_start_date: provided_date) + expect(assignment.token_start_date).to eq(provided_date) + end + end + + it 'does not overwrite token_start_date if already set' do + initial_date = Time.zone.local(2024, 5, 20, 15, 0, 0) + travel_to initial_date do + assignment = build(:assignment_for_student_tests, token_start_date: initial_date) + expect(assignment.token_start_date).to eq(initial_date) + end end end