|
| 1 | +# The reminder day (the #{form_prefix}_reminder_schedule_service_day_of_month field ) has to be less than or equal to 28. |
| 2 | +# These functions are implemented to calculate dates prior or after a given date that do not fall on a |
| 3 | +# date with a day greater than 28. |
| 4 | +# It is recommended to use these functions to calculate, from now, inputs for the reminder day and deadline day fields if |
| 5 | +# your test cares about the text created by the deadline_day_controller.js controller as there isn't an easy way to spoof |
| 6 | +# the current time in the test browser and different behavior could occur if the test is run on different days. |
| 7 | +def safe_add_days(date, num) |
| 8 | + result = date + num.days |
| 9 | + if result.day > 28 |
| 10 | + result = result.change({day: 1 + num}) |
| 11 | + result += 1.month |
| 12 | + end |
| 13 | + result |
| 14 | +end |
| 15 | + |
| 16 | +def safe_subtract_days(date, num) |
| 17 | + result = date - num.days |
| 18 | + if result.day > 28 |
| 19 | + result = result.change({day: 28 - num}) |
| 20 | + result -= 1.month |
| 21 | + end |
| 22 | + result |
| 23 | +end |
| 24 | + |
1 | 25 | RSpec.shared_examples_for "deadline and reminder form" do |form_prefix, save_button, post_form_submit| |
2 | 26 | it "can set a reminder on a day of the month" do |
3 | 27 | choose "Day of Month" |
|
34 | 58 | expect(page).to_not have_content("Your next reminder date is") |
35 | 59 | expect(page).to_not have_content("The deadline on your next reminder email will be") |
36 | 60 |
|
37 | | - |
38 | 61 | fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: "-1" |
39 | 62 | expect(page).to have_content("Reminder day must be between 1 and 28") |
40 | 63 | fill_in "#{form_prefix}_reminder_schedule_service_day_of_month", with: "20" |
|
52 | 75 | end |
53 | 76 |
|
54 | 77 | describe "reported reminder and deadline dates" do |
55 | | - # The reminder day (the #{form_prefix}_reminder_schedule_service_day_of_month field ) has to be less than or equal to 28. |
56 | | - # These functions are implemented to calculate dates prior or after @now that do not fall on a |
57 | | - # date with a day greater than 28. |
58 | | - def safe_add_days(date, num) |
59 | | - result = date + num.days |
60 | | - if result.day > 28 |
61 | | - result = result.change({day: 1 + num}) |
62 | | - result += 1.month |
63 | | - end |
64 | | - result |
65 | | - end |
66 | | - |
67 | | - def safe_subtract_days(date, num) |
68 | | - result = date - num.days |
69 | | - if result.day > 28 |
70 | | - result = result.change({day: 28 - num}) |
71 | | - result -= 1.month |
72 | | - end |
73 | | - result |
74 | | - end |
75 | | - |
76 | 78 | context "when the reminder is a day of the month" do |
77 | 79 | before do |
78 | 80 | choose "Day of Month" |
|
0 commit comments