Skip to content

Commit e55f6c5

Browse files
committed
spec: make date(time) checks less brittle
format date(time)s the same way we do in the code; fixes several failing specs on master caused by date strings conditionally including the year. Change-Id: I4ab8f767be2fac08543c3dda8bc37740e82cf16a Reviewed-on: https://gerrit.instructure.com/69450 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
1 parent 6a9a460 commit e55f6c5

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

spec/selenium/helpers/assignment_overrides.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module AssignmentOverridesSeleniumHelper
2+
include TextHelper
23

34
def visit_new_assignment_page
45
get "/courses/#{@course.id}/assignments/new"
@@ -112,12 +113,9 @@ def assign_dates_for_last_override_section(opts = {})
112113
end
113114

114115
def find_vdd_time(override_context)
115-
@due_at_time = override_context.due_at.strftime('%b %-d at %-l:%M') <<
116-
override_context.lock_at.strftime('%p').downcase
117-
@lock_at_time = override_context.lock_at.strftime('%b %-d at %-l:%M') <<
118-
override_context.lock_at.strftime('%p').downcase
119-
@unlock_at_time = override_context.unlock_at.strftime('%b %-d at %-l:%M') <<
120-
override_context.unlock_at.strftime('%p').downcase
116+
@due_at_time = format_time_for_view(override_context.due_at)
117+
@lock_at_time = format_time_for_view(override_context.lock_at)
118+
@unlock_at_time = format_time_for_view(override_context.unlock_at)
121119
end
122120

123121
def add_due_date_override(assignment, due_at = Time.zone.now.advance(days:1))
@@ -274,21 +272,13 @@ def set_quiz_dates_for_section_b
274272
end
275273

276274
# Formatted output: Mmm d, e.g. 'Jan 1'
277-
def format_date_for_view(date)
278-
date.strftime('%b %-d')
275+
def format_date_for_view(date, format = :short)
276+
I18n.l(date.to_date, format: format)
279277
end
280278

281279
# Formatted output: Mmm d at h:mm, e.g. 'Jan 1 at 1:01pm'
282-
# Note: Removes on-the-hour minutes, e.g. '5:00pm' becomes '5pm'
283280
def format_time_for_view(time)
284-
formatter = '%b %-d at %-l'
285-
formatted_time = time.strftime(formatter)
286-
287-
on_the_hour = true if time.strftime(':%M') == ':00'
288-
formatted_time << time.strftime(':%M') unless on_the_hour
289-
290-
# append 'am' or 'pm'
291-
formatted_time << time.strftime('%p').downcase
281+
datetime_string(time, :no_words).gsub(/ +/, ' ')
292282
end
293283

294284
def obtain_due_date(section)
@@ -344,4 +334,4 @@ def create_assignment_override(assignment, section, due_date)
344334
override.due_at = due_date.days.from_now
345335
override.save!
346336
end
347-
end
337+
end

spec/selenium/quizzes/varied_due_dates/quizzes_vdd_index_page_student_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
it 'shows the availability dates for Section A', priority: "1", test_id: 282389 do
2323
expect(f('.date-available')).to include_text("Available until "\
24-
"#{format_date_for_view(@lock_at_a)}")
24+
"#{date_string(@lock_at_a, :no_words)}")
2525
end
2626
end
2727

@@ -39,7 +39,7 @@
3939

4040
it 'shows the availability dates for Section B', priority: "1", test_id: 282391 do
4141
expect(f('.date-available')).to include_text("Not available until "\
42-
"#{format_date_for_view(@unlock_at_b)}")
42+
"#{date_string(@unlock_at_b, :no_words)}")
4343
end
4444
end
4545
end

0 commit comments

Comments
 (0)