Skip to content

Commit

Permalink
Treat result of to_h to be hashes recursively
Browse files Browse the repository at this point in the history
Config gem version 3.0 removed the dot access from .to_h resulting values intentionally.
See: https://www.github.com/rubyconfig/config/issues/217

In config 2.2.3, the result of:

```
Api::ApiConfig.collections.to_h
```

was:

```
(byebug) Api::ApiConfig.collections.to_h
{:accounts=>#<Config::Options description="Accounts", options=[:subcollection], verbs=[:get], klass="Account">, :actions=>#<Config::Options description="Actions", identifier="miq_action", options=[:collection], verbs=[:get, :put, :post,
...
```

With values being Config::Options objects.

In config gem 5.5.2, they're hashes all the way down:

```
(byebug) Api::ApiConfig.collections.to_h
{:accounts=>{:description=>"Accounts", :options=>[:subcollection], :verbs=>[:get], :klass=>"Account"}, :actions=>{:description=>"Actions", :identifier=>"miq_action", :options=>[:collection], :verbs=>[:get, :put, :post, :patch, :delete],
...
```

Note, if you don't convert to hash, you retain the Config::Options structure and API:

```
(byebug) Api::ApiConfig.collections
...
```

It's easy enough to change the access to assume nested hashes all the way down, which is also compatible with existing Config::Options behavior.
  • Loading branch information
jrafanie committed Nov 26, 2024
1 parent cb23be0 commit c64b6d9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

get api_entrypoint_url

collection_names = Api::ApiConfig.collections.to_h.select { |_, v| v.options.include?(:collection) }.keys
collection_names = Api::ApiConfig.collections.to_h.select { |_, v| v[:options].include?(:collection) }.keys
hrefs = collection_names.collect { |name| url_for(:controller => name, :action => "index") }
expected = {
"collections" => a_collection_containing_exactly(
Expand Down

0 comments on commit c64b6d9

Please sign in to comment.