Skip to content

Commit

Permalink
Replace time-warp gem with newer, maintained timecop gem (#7234)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu authored Sep 28, 2024
1 parent 0c21a3c commit e25fe1b
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 179 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Add test cases for the student model to cover Group or Grouping save method failure (#7218)
- Create tests for overtime messages of the submission rule classes (#7216)
- Fix flaky `check_repo_permissions` test (#7223)
- Replace time-warp gem with newer, maintained timecop gem (#7234)

## [v2.5.2]

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ group :test do
gem 'shoulda-matchers', '~> 6.0'
gem 'simplecov', require: false
gem 'simplecov-lcov', require: false
gem 'time-warp'
gem 'timecop'
gem 'webmock'
end

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ GEM
execjs (>= 0.3.0, < 3)
thor (1.3.2)
tilt (2.3.0)
time-warp (1.0.15)
timecop (0.9.10)
timeout (0.4.1)
ttfunk (1.8.0)
bigdecimal (~> 3.1)
Expand Down Expand Up @@ -549,7 +549,7 @@ DEPENDENCIES
sprockets
sprockets-rails
terser
time-warp
timecop
unicorn
webmock

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/automated_tests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@
end

it 'should calculate the next token generation time' do
travel 14.hours do
Timecop.freeze(assignment.token_start_date + 30.hours) do
get_as student, :student_interface, params: params
assignment.reload
token_start_time = assignment.token_start_date
Expand Down
19 changes: 6 additions & 13 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,18 @@
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
Timecop.freeze 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)
Timecop.freeze Time.zone.local(2024, 12, 25, 10, 0, 0) do
provided_date = 1.day.from_now
assignment = build(:assignment_for_student_tests,
assignment_properties_attributes: { token_start_date: provided_date })
expect(assignment.reload.token_start_date).to eq(provided_date)
end
end
end
Expand Down
37 changes: 15 additions & 22 deletions spec/models/grace_period_submission_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
end

context 'when the student did not submit any files' do
before do
pretend_now_is(collection_time) { grouping }
end

let(:grouping_creation_time) { collection_time }
let(:submission) { create(:version_used_submission, grouping: grouping, is_empty: true) }
let(:collection_time) { due_date - 5.days }

Expand All @@ -30,23 +27,21 @@
end

it 'has an overtime message mentioning the number of credits remaining and the number of credits to use' do
pretend_now_is(due_date - 1.day)
apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'grace_period_submission_rules.overtime_message_with_credits_left',
grace_credits_remaining: 1, grace_credits_to_use: 0
expect(rule_overtime_message).to eq expected_overtime_message
Timecop.freeze(due_date - 1.day) do
apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'grace_period_submission_rules.overtime_message_with_credits_left',
grace_credits_remaining: 1, grace_credits_to_use: 0
expect(rule_overtime_message).to eq expected_overtime_message
end
end
end
end

context 'when the group submitted during the first penalty period' do
include_context 'submission_rule_during_first'
context 'when the student did not submit any files' do
before do
pretend_now_is(collection_time) { grouping }
end

let(:grouping_creation_time) { collection_time }
let(:submission) { create(:version_used_submission, grouping: grouping, is_empty: true) }
let(:collection_time) { due_date + 12.hours }

Expand Down Expand Up @@ -98,7 +93,6 @@
context 'when submitting on time before grace period of previous assignment is over' do
before do
# The Student submits their files before the due date
pretend_now_is(due_date - 3.days) { grouping }
submit_file_at_time(assignment, grouping.group, 'test', (due_date - 2.days).to_s, 'TestFile.java',
'Some contents for TestFile.java')

Expand All @@ -116,8 +110,6 @@
context 'when submitting overtime before the grace period of previous assignment is over' do
before do
# The Student submits their files before the due date
pretend_now_is(due_date - 3.days) { grouping }

submit_file_at_time(assignment, grouping.group, 'test', (due_date + 10.hours).to_s, 'OvertimeFile1.java',
'Some overtime contents')

Expand Down Expand Up @@ -160,11 +152,12 @@
end

it 'has an overtime message mentioning that there are no credits remaining' do
pretend_now_is(due_date + 5.days)
apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'grace_period_submission_rules.overtime_message_without_credits_left'
expect(rule_overtime_message).to eq expected_overtime_message
Timecop.freeze(due_date + 5.days) do
apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'grace_period_submission_rules.overtime_message_without_credits_left'
expect(rule_overtime_message).to eq expected_overtime_message
end
end
end

Expand Down
203 changes: 97 additions & 106 deletions spec/models/grouping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1099,130 +1099,121 @@ def expect_updated_criteria_coverage_count_eq(expected_count)
end

describe '#submitted_after_collection_date?' do
context 'with an assignment' do
before do
@assignment = create(:assignment, due_date: Time.zone.parse('July 22 2009 5:00PM'))
@group = create(:group, course: @assignment.course)
pretend_now_is(Time.zone.parse('July 21 2009 5:00PM')) do
@grouping = create(:grouping, assignment: @assignment, group: @group)
end
let(:due_date) { 3.days.ago }
let(:assignment) { create(:assignment, due_date: due_date) }
let(:group) { create(:group, course: assignment.course) }
let!(:grouping) do
g = nil
Timecop.freeze(due_date - 3.days) do
g = create(:grouping, assignment: assignment, group: group)
end
g
end

teardown do
destroy_repos
end
teardown do
destroy_repos
end

context 'without sections before due date' do
it 'returns false' do
submit_file_at_time(@assignment, @group, 'test', 'July 20 2009 5:00PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be false
end
context 'without sections before due date' do
it 'returns false' do
submit_file_at_time(assignment, group, 'test', (due_date - 2.days).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be false
end
end

context 'with sections before due date' do
before do
@assignment.section_due_dates_type = true
@assignment.save
@section = create(:section, course: @assignment.course)
create(:inviter_student_membership,
role: create(:student, section: @section),
grouping: @grouping,
membership_status: StudentMembership::STATUSES[:inviter])
end

it 'returns false when before section due date' do
AssessmentSectionProperties.create(
section: @section,
assessment: @assignment,
due_date: Time.zone.parse('July 24 2009 5:00PM')
)
submit_file_at_time(@assignment, @group, 'test', 'July 20 2009 5:00PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be false
end
context 'with sections before due date' do
before do
assignment.update(section_due_dates_type: true)
@section = create(:section, course: assignment.course)
create(:inviter_student_membership,
role: create(:student, section: @section),
grouping: grouping,
membership_status: StudentMembership::STATUSES[:inviter])
end

it 'returns false when after section duedate' do
AssessmentSectionProperties.create(
section: @section,
assessment: @assignment,
due_date: Time.zone.parse('July 18 2009 5:00PM')
)
submit_file_at_time(@assignment, @group, 'test', 'July 20 2009 5:00PM', 'my_file', 'Hello, World!')
expect(@grouping.reload.submitted_after_collection_date?).to be true
end
it 'returns false when before section due date' do
AssessmentSectionProperties.create(
section: @section,
assessment: assignment,
due_date: due_date + 2.days
)
submit_file_at_time(assignment, group, 'test', (due_date - 2.days).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be false
end

context 'without sections after due date' do
before do
@assignment = create(:assignment, due_date: Time.zone.parse('July 22 2009 5:00PM'))
@group = create(:group, course: @assignment.course)
pretend_now_is(Time.zone.parse('July 28 2009 5:00PM')) do
@grouping = create(:grouping, assignment: @assignment, group: @group)
end
end
it 'returns false when after section due date' do
AssessmentSectionProperties.create(
section: @section,
assessment: assignment,
due_date: due_date - 2.days
)
submit_file_at_time(assignment, group, 'test', (due_date - 1.day).to_s, 'my_file', 'Hello, World!')
expect(grouping.reload.submitted_after_collection_date?).to be true
end
end

it 'returns true after due date' do
submit_file_at_time(@assignment, @group, 'test', 'July 28 2009 5:00PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be true
end
context 'without sections after due date' do
it 'returns true after due date' do
submit_file_at_time(assignment, group, 'test', (due_date + 1.day).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be true
end
end

context 'with sections after due date' do
before do
@assignment.section_due_dates_type = true
@assignment.save
@section = create(:section)
create(:inviter_student_membership,
role: create(:student, section: @section),
grouping: @grouping,
membership_status: StudentMembership::STATUSES[:inviter])
end
context 'with sections after due date' do
before do
assignment.update(section_due_dates_type: true)
@section = create(:section)
create(:inviter_student_membership,
role: create(:student, section: @section),
grouping: grouping,
membership_status: StudentMembership::STATUSES[:inviter])
end

it 'returns false when before section due_date' do
AssessmentSectionProperties.create(
section: @section,
assessment: @assignment,
due_date: Time.zone.parse('July 30 2009 5:00PM')
)
submit_file_at_time(@assignment, @group, 'test', 'July 28 2009 1:00PM', 'my_file', 'Hello, World!')
expect(@grouping.reload.submitted_after_collection_date?).to be false
end
it 'returns false when before section due_date' do
AssessmentSectionProperties.create(
section: @section,
assessment: assignment,
due_date: due_date + 1.day
)
submit_file_at_time(assignment, group, 'test', (due_date + 5.hours).to_s, 'my_file', 'Hello, World!')
expect(grouping.reload.submitted_after_collection_date?).to be false
end

it 'returns true when after section due_date' do
AssessmentSectionProperties.create(
section: @section,
assessment: @assignment,
due_date: Time.zone.parse('July 20 2009 5:00PM')
)
submit_file_at_time(@assignment, @group, 'test', 'July 28 2009 1:00PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be true
end
it 'returns true when after section due_date' do
AssessmentSectionProperties.create(
section: @section,
assessment: assignment,
due_date: due_date + 1.day
)
submit_file_at_time(assignment, group, 'test', (due_date + 2.days).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be true
end
end

context 'with late penalty' do
before do
@assignment.update(submission_rule: PenaltyPeriodSubmissionRule.create(
periods_attributes: [{
hours: 1,
deduction: 10,
interval: 1
}]
))
end
context 'with late penalty' do
before do
assignment.update(submission_rule: PenaltyPeriodSubmissionRule.create(
periods_attributes: [{
hours: 1,
deduction: 10,
interval: 1
}]
))
end

it 'returns false when before due date' do
submit_file_at_time(@assignment, @group, 'test', 'July 20 2009 5:00PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be false
end
it 'returns false when before due date' do
submit_file_at_time(assignment, group, 'test', (due_date - 30.minutes).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be false
end

it 'returns false when after due date but before penalty period' do
submit_file_at_time(@assignment, @group, 'test', 'July 22 2009 5:30PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be false
end
it 'returns false when after due date but before penalty period' do
submit_file_at_time(assignment, group, 'test', (due_date + 30.minutes).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be false
end

it 'returns true when after penalty period' do
submit_file_at_time(@assignment, @group, 'test', 'July 22 2009 6:30PM', 'my_file', 'Hello, World!')
expect(@grouping.submitted_after_collection_date?).to be true
end
it 'returns true when after penalty period' do
submit_file_at_time(assignment, group, 'test', (due_date + 90.minutes).to_s, 'my_file', 'Hello, World!')
expect(grouping.submitted_after_collection_date?).to be true
end
end
end
Expand Down
Loading

0 comments on commit e25fe1b

Please sign in to comment.