Skip to content

Conversation

@seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Jan 5, 2025

Follow-up to rails/rails#53962

As of abdbff5, calls to Hash#to_query with nil values will omit the joining = character.

This change resolves CI failures for Rails past rails@8.1 like:

  1) Failure:
BaseTest#test_collection_path_with_parameters [test/cases/base_test.rb:779]:
Expected: "/people.json?gender="
  Actual: "/people.json?gender"

  2) Failure:
SingletonTest#test_singleton_path_with_parameters [test/singleton_test.rb:44]:
Expected: "/weather.json?degrees="
  Actual: "/weather.json?degrees"

Follow-up to rails/rails#53962

As of [abdbff4][], calls to [Hash#to_query][] with `nil` values will
omit the joining `=` character.

This change resolves [CI failures][] for Rails past `rails@8.1` like:

```
  1) Failure:
BaseTest#test_collection_path_with_parameters [test/cases/base_test.rb:779]:
Expected: "/people.json?gender="
  Actual: "/people.json?gender"

  2) Failure:
SingletonTest#test_singleton_path_with_parameters [test/singleton_test.rb:44]:
Expected: "/weather.json?degrees="
  Actual: "/weather.json?degrees"
```

[abdbff5]: rails/rails@abdbff5
[Hash#to_query]: https://edgeapi.rubyonrails.org/classes/Hash.html#method-i-to_query
[CI failures]: https://github.com/rails/activeresource/actions/runs/12606260018/job/35136128961?pr=411#step:4:17
assert_equal "/people.json?gender=male", Person.collection_path(gender: "male")
assert_equal "/people.json?gender=false", Person.collection_path(gender: false)
assert_equal "/people.json?gender=", Person.collection_path(gender: nil)
if ActiveSupport::VERSION::MAJOR < 8 || ActiveSupport::VERSION::MINOR < 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to version checking, I also considered an explicit { key: nil }.to_query == "key", but felt that was too verbose and harder to grep for in the future when these branches are no longer necessary.

@rafaelfranca rafaelfranca merged commit e25a521 into rails:main Sep 10, 2025
19 checks passed
@seanpdoyle seanpdoyle deleted the rails-8-test-failures branch September 10, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants