Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Def tokens available on #7173

Merged
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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).

### 🐛 Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down Expand Up @@ -66,6 +68,29 @@
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
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

it 'should catch an invalid date' do
Expand Down