Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controller test broken: eval error: undefined method `keys' for nil:NilClass #199

Closed
fwolfst opened this issue Oct 23, 2023 · 3 comments · Fixed by #202
Closed

controller test broken: eval error: undefined method `keys' for nil:NilClass #199

fwolfst opened this issue Oct 23, 2023 · 3 comments · Fixed by #202

Comments

@fwolfst
Copy link

fwolfst commented Oct 23, 2023

We have a pretty straight forward controller test that breaks execution

   context 'with the user not logged in' do
      context 'when the operation name contains "private"' do
         it 'returns a 403' do
           post :execute, as: :json, params: { query:, operationName: 'whatever-private' }

           expect(response).to be_forbidden # < boom; and response.forbidden? is false
         end
      end

The exception bubble up from ruby/gems/3.2.0/gems/super_diff-0.10.0/lib/super_diff/object_inspection/inspection_tree.rb:72 in `insert_hash_inspection_of'.

@jas14
Copy link
Collaborator

jas14 commented Nov 3, 2023

This looks like a duplicate of #163 based on the last stack trace frame, does that seem right @fwolfst ?

@jas14
Copy link
Collaborator

jas14 commented Nov 3, 2023

I was able to reproduce with a very simple app and may have found the culprit: ActiveSupport::OrderedOptions. This class specifically defines respond_to_missing? as true for everything. Thus, SuperDiff's InspectionTreeBuilders::CustomObject will be mistakenly applied to OrderedOptions, which will call insert_hash_inspection_of(nil), which will raise as described.

mcmire pushed a commit that referenced this issue Nov 13, 2023
I believe this fixes #199 and, I suspect, fixes #163. See
#199 (comment)
for more background. You can reproduce errors like those raised in the
aforementioned issues by checking out
26e1f6c and running `bundle exec rspec
spec/unit/active_support/object_inspection_spec.rb`.

The solution I opted for here was to create a hash-like inspector for
`ActiveSupport::OrderedOptions` that takes precedence over the default
`CustomObject` inspector, which in turn [takes precedence
over](https://github.com/mcmire/super_diff/blob/fb6718a2b60bc8135424295cc069a4b984983f77/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb#L5-L7)
the `Hash` inspector.

The `OrderedOptions` inspection tree is basically a copy-paste of the
one for `HashWithIndifferentAccess` – let me know if I should try to DRY
those up.
@fwolfst
Copy link
Author

fwolfst commented Nov 15, 2023

Sorry for having been mute. Awesome @jas14 and @mcmire ; thank you.

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 a pull request may close this issue.

2 participants