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

Dynamic declared class #1631

Closed
wants to merge 1 commit into from

Conversation

thogg4
Copy link
Contributor

@thogg4 thogg4 commented May 10, 2017

#1610 causes the params to be passed to declared in the correct class, but once they get there that method only returns a Hash

@dblock
Copy link
Member

dblock commented May 12, 2017

Makes sense, but needs a test/changelog/etc., please.

CHANGELOG.md Outdated
@@ -8,6 +8,7 @@

#### Fixes

* [#1631](https://github.com/ruby-grape/grape/pull/1631): Dynamic declared class - [@thogg4](https://github.com/thogg4).
Copy link
Member

@dblock dblock May 12, 2017

Choose a reason for hiding this comment

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

Maybe something more useful that explains the behavior change? Like declared now returns ...

''
end

puts d
Copy link
Contributor

@nbulaj nbulaj May 18, 2017

Choose a reason for hiding this comment

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

I think there is no need in that piece of code, and the same for above (lines 316, 335)

optional :second, default: 'second-default'
end
subject.get '/declared' do
d = declared(params, include_missing: true)
Copy link
Member

@dblock dblock May 18, 2017

Choose a reason for hiding this comment

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

Since this is an API, you should return the declared output and compare that, don't use a variable out of scope, it works but is hard to follow and is a hack we stay away from.

Copy link
Contributor Author

@thogg4 thogg4 May 18, 2017

Choose a reason for hiding this comment

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

@dblock what is returned by the api call is always a json string. What we are testing here is what is returned by declared inside of the endpoint. Is there a better place to put this to test just that?

Copy link
Member

Choose a reason for hiding this comment

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

Have the API return d.class as JSON or a string and compare the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dblock duh, im not sure why i didn't think of that. thanks 😄

@@ -298,6 +298,65 @@ def app
end
end

context 'when params are not built with default class' do
it 'should return an object that corresponds with the params class - hash with indifferent access' do
Copy link
Member

Choose a reason for hiding this comment

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

Instead of "should return", just say "returns"

subject.params do
build_with Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder

requires :first
Copy link
Member

Choose a reason for hiding this comment

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

The actual parameters are not material for the tests, remove them. Make this as short as possible.

@dblock
Copy link
Member

dblock commented May 19, 2017

Looks like there's a legit failure with one of the builds, check it out until this build is green please.

@dblock
Copy link
Member

dblock commented Jun 12, 2017

This looks good, just needs a rebase/squash please.

@thogg4 thogg4 force-pushed the dynamic-declared-class branch 2 times, most recently from 01e4e40 to 57a1f2e Compare June 12, 2017 21:05
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.

3 participants