Skip to content

Commit 1b18256

Browse files
Combined multiple asserts into larger it blocks for the sake of performance
1 parent 3931110 commit 1b18256

1 file changed

Lines changed: 14 additions & 25 deletions

File tree

spec/support/deadline_day_fields_shared_example.rb

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,32 @@
2626
expect(page).to have_content("Monthly on the 1st Sunday")
2727
end
2828

29-
it "warns the user if they enter the same reminder and deadline day" do
29+
it "warns the user if they enter an invalid reminder or deadline day", :aggregate_failures do
3030
choose "Day of Month"
3131
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: 15
3232
fill_in "Deadline day in reminder email", with: 15
3333
expect(page).to have_content("Reminder day cannot be the same as deadline day.")
3434
expect(page).to_not have_content("Your next reminder date is")
3535
expect(page).to_not have_content("The deadline on your next reminder email will be")
36-
end
3736

38-
it "warns the user if the reminder day is outside the range of 1 to 28" do
39-
choose "Day of Month"
37+
4038
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: "-1"
4139
expect(page).to have_content("Reminder day must be between 1 and 28")
4240
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: "20"
4341
expect(page).to_not have_content("Reminder day must be between 1 and 28")
4442
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: "100"
4543
expect(page).to have_content("Reminder day must be between 1 and 28")
46-
end
47-
48-
it "warns the user if the deadline day is outside the range of 1 to 28" do
49-
choose "Day of Month"
5044
fill_in "Deadline day in reminder email", with: "-1"
5145
expect(page).to have_content("Deadline day must be between 1 and 28")
5246
fill_in "Deadline day in reminder email", with: "20"
5347
expect(page).to_not have_content("Deadline day must be between 1 and 28")
5448
fill_in "Deadline day in reminder email", with: "100"
49+
expect(page).to have_content("Reminder day cannot be the same as deadline day.")
50+
fill_in "Deadline day in reminder email", with: "101"
5551
expect(page).to have_content("Deadline day must be between 1 and 28")
5652
end
5753

58-
describe "calculates the reminder and deadline dates" do
54+
describe "reported reminder and deadline dates" do
5955
# The reminder day (the #{form_prefix}_reminder_schedule_service_day_of_month field ) has to be less than or equal to 28.
6056
# These functions are implemented to calculate dates prior or after @now that do not fall on a
6157
# date with a day greater than 28.
@@ -83,25 +79,24 @@ def safe_subtract_days(date, num)
8379
@now = safe_add_days(Time.zone.now, 0)
8480
end
8581

86-
it "prior to the current date and start date" do
82+
it "calculates the reminder and deadline dates", :aggregate_failures do
83+
# Prior
8784
reminder_date = safe_subtract_days(@now, 2)
8885
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: reminder_date.day
8986
expect(page).to have_content("Your next reminder date is")
9087
schedule = IceCube::Schedule.new(@now)
9188
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_month(reminder_date.day))
9289
expect(page).to have_content(schedule.next_occurrence.strftime("%b %d %Y"))
93-
end
9490

95-
it "after the current date and start date" do
91+
# After
9692
reminder_date = safe_add_days(@now, 2)
9793
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: reminder_date.day
9894
expect(page).to have_content("Your next reminder date is")
9995
schedule = IceCube::Schedule.new(@now)
10096
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_month(reminder_date.day))
10197
expect(page).to have_content(schedule.next_occurrence.strftime("%b %d %Y"))
102-
end
10398

104-
it "same as the start and current date" do
99+
# Same
105100
fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: @now.day
106101
expect(page).to have_content("Your next reminder date is")
107102
schedule = IceCube::Schedule.new(@now)
@@ -124,48 +119,42 @@ def calc_every_nth_day(target_date)
124119
every_nth_day
125120
end
126121

127-
it "prior to the current date and start date" do
122+
it "calculates the reminder and deadline dates", :aggregate_failures do
123+
# Prior
128124
target_date = @now - 2.days
129125
every_nth_day = calc_every_nth_day(target_date)
130126
select(ReminderScheduleService::NTH_TO_WORD_MAP[every_nth_day], from: "#{form_prefix}_reminder_schedule_service_every_nth_day")
131127
select(ReminderScheduleService::DAY_OF_WEEK_COLLECTION[target_date.wday][0], from: "#{form_prefix}_reminder_schedule_service_day_of_week")
132-
133128
expect(page).to have_content("Your next reminder date is")
134129
schedule = IceCube::Schedule.new(@now)
135130
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_week(target_date.wday => [every_nth_day]))
136131
expect(page).to have_content(schedule.next_occurrence.strftime("%b %d %Y"))
137-
end
138132

139-
it "after the current date and start date" do
133+
# After
140134
target_date = @now + 2.days
141135
every_nth_day = calc_every_nth_day(target_date)
142136
select(ReminderScheduleService::NTH_TO_WORD_MAP[every_nth_day], from: "#{form_prefix}_reminder_schedule_service_every_nth_day")
143137
select(ReminderScheduleService::DAY_OF_WEEK_COLLECTION[target_date.wday][0], from: "#{form_prefix}_reminder_schedule_service_day_of_week")
144-
145138
expect(page).to have_content("Your next reminder date is")
146139
schedule = IceCube::Schedule.new(@now)
147140
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_week(target_date.wday => [every_nth_day]))
148141
expect(page).to have_content(schedule.next_occurrence.strftime("%b %d %Y"))
149-
end
150142

151-
it "same as the start and current date" do
143+
# Same
152144
target_date = @now
153145
every_nth_day = calc_every_nth_day(target_date)
154146
select(ReminderScheduleService::NTH_TO_WORD_MAP[every_nth_day], from: "#{form_prefix}_reminder_schedule_service_every_nth_day")
155147
select(ReminderScheduleService::DAY_OF_WEEK_COLLECTION[target_date.wday][0], from: "#{form_prefix}_reminder_schedule_service_day_of_week")
156-
157148
expect(page).to have_content("Your next reminder date is")
158149
schedule = IceCube::Schedule.new(@now)
159150
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_week(target_date.wday => [every_nth_day]))
160151
expect(page).to have_content(schedule.next_occurrence.strftime("%b %d %Y"))
161-
end
162152

163-
it "at the very end of the month" do
153+
# End of the month
164154
target_date = @now.end_of_month
165155
every_nth_day = calc_every_nth_day(target_date)
166156
select(ReminderScheduleService::NTH_TO_WORD_MAP[every_nth_day], from: "#{form_prefix}_reminder_schedule_service_every_nth_day")
167157
select(ReminderScheduleService::DAY_OF_WEEK_COLLECTION[target_date.wday][0], from: "#{form_prefix}_reminder_schedule_service_day_of_week")
168-
169158
expect(page).to have_content("Your next reminder date is")
170159
schedule = IceCube::Schedule.new(@now)
171160
schedule.add_recurrence_rule(IceCube::Rule.monthly.day_of_week(target_date.wday => [every_nth_day]))

0 commit comments

Comments
 (0)