Fix tests that fail due to humanization of "29 days" vs "1 month"
Summary
These two tests:
- spec/controllers/groups/group_members_controller_spec.rb:175
- spec/controllers/projects/group_links_controller_spec.rb:267
Depend on the humanization of 1.month.from_now.to_date
being exactly 1 month
, but near the end of January (like right now) it's possible to get a humanization of 29 days
instead.
Steps to reproduce
Run the following at around 6:00pm EST:
bin/rspec spec/controllers/groups/group_members_controller_spec.rb:175 spec/controllers/projects/group_links_controller_spec.rb:267
Relevant logs and/or screenshots
Failures:
1) Groups::GroupMembersController PUT update expiration date when `expires_at` is set returns correct json response
Failure/Error:
expect(json_response).to eq({
"expires_in" => "about 1 month",
"expires_soon" => false,
"expires_at_formatted" => expiry_date.to_time.in_time_zone.to_s(:medium)
})
expected: {"expires_at_formatted"=>"Feb 28, 2021 8:00am", "expires_in"=>"about 1 month", "expires_soon"=>false}
got: {"expires_at_formatted"=>"Feb 28, 2021 8:00am", "expires_in"=>"29 days", "expires_soon"=>false}
(compared using ==)
Diff:
@@ -1,4 +1,4 @@
"expires_at_formatted" => "Feb 28, 2021 8:00am",
-"expires_in" => "about 1 month",
+"expires_in" => "29 days",
"expires_soon" => false,
# ./spec/controllers/groups/group_members_controller_spec.rb:268:in `block (5 levels) in <top (required)>'
# ./spec/spec_helper.rb:321:in `block (3 levels) in <top (required)>'
# ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
# ./spec/spec_helper.rb:312:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (2 levels) in <top (required)>'
2) Projects::GroupLinksController#update when `expires_at` is set returns correct json response
Failure/Error: expect(json_response).to eq({ "expires_in" => "about 1 month", "expires_soon" => false })
expected: {"expires_in"=>"about 1 month", "expires_soon"=>false}
got: {"expires_in"=>"29 days", "expires_soon"=>false}
(compared using ==)
Diff:
@@ -1 +1 @@
-"expires_in" => "about 1 month",
+"expires_in" => "29 days",
# ./spec/controllers/projects/group_links_controller_spec.rb:176:in `block (4 levels) in <main>'
# ./spec/spec_helper.rb:321:in `block (3 levels) in <top (required)>'
# ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
# ./spec/spec_helper.rb:312:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:308:in `block (2 levels) in <top (required)>'
Finished in 5.8 seconds (files took 38.32 seconds to load)
2 examples, 2 failures
Failed examples:
rspec ./spec/controllers/groups/group_members_controller_spec.rb:267 # Groups::GroupMembersController PUT update expiration date when `expires_at` is set returns correct json response
rspec ./spec/controllers/projects/group_links_controller_spec.rb:175 # Projects::GroupLinksController#update when `expires_at` is set returns correct json response
Possible fixes
Just use non-relative datetimes.
Edited by Amy Troschinetz