fix: no-method-error with Grape::Entity < 0.5.0#9
fix: no-method-error with Grape::Entity < 0.5.0#9brlo wants to merge 2 commits intodawanda:masterfrom brlo:patch-1
Conversation
|
Thank you for the PR. Can you provide a spec? I am not using Grape and the previous introduction of this feature was not tested. I also updated the ruby version(s) for Travis on master. Can you rebase so we can run the build? |
|
@brlo just pinging since I didn't mention you in the original comment. |
|
No problem, but need a few days more. |
|
Thanks a lot! |
| entity.represent({ping: :pong}).to_json | ||
| end | ||
| get '/ping?rack-profiler' | ||
| expect(JSON.parse(last_response.body)['response']['body']).to eql(sample_hash.to_json) |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [92/80]
| subject.get '/ping' do | ||
| entity.represent({ping: :pong}).to_json | ||
| end | ||
| get '/ping?rack-profiler' |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| entity = Class.new(Grape::Entity) { expose :ping } | ||
|
|
||
| subject.get '/ping' do | ||
| entity.represent({ping: :pong}).to_json |
There was a problem hiding this comment.
Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.
| it 'working with Grape::Entity' do | ||
| entity = Class.new(Grape::Entity) { expose :ping } | ||
|
|
||
| subject.get '/ping' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| expect(JSON.parse(last_response.body)['response']['body']).to eql(sample_hash.to_json) | ||
| end | ||
|
|
||
| it 'working with Grape::Entity' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| present Object.new, with: entity_mock | ||
| end | ||
| get '/ping?rack-profiler' | ||
| expect(JSON.parse(last_response.body)['response']['body']).to eql(sample_hash.to_json) |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [92/80]
| subject.get '/ping' do | ||
| present Object.new, with: entity_mock | ||
| end | ||
| get '/ping?rack-profiler' |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| entity_mock = Object.new | ||
| allow(entity_mock).to receive(:represent).and_return(sample_hash.to_json) | ||
|
|
||
| subject.get '/ping' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| expect(JSON.parse(last_response.body)['response']['body']).to eql('') | ||
| end | ||
|
|
||
| it 'working with #present' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| nil | ||
| end | ||
| get '/ping?rack-profiler' | ||
| expect(JSON.parse(last_response.body)['response']['body']).to eql('') |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| subject.get '/ping' do | ||
| nil | ||
| end | ||
| get '/ping?rack-profiler' |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| end | ||
|
|
||
| it 'working with NULL' do | ||
| subject.get '/ping' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| expect(JSON.parse(last_response.body)['response']['body']).to eql('pong') | ||
| end | ||
|
|
||
| it 'working with NULL' do |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| 'pong' | ||
| end | ||
| get '/ping?rack-profiler' | ||
| expect(JSON.parse(last_response.body)['response']['body']).to eql('pong') |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| subject.get '/ping' do | ||
| 'pong' | ||
| end | ||
| get '/ping?rack-profiler' |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
|
|
||
| it 'working with String' do | ||
| subject.get '/ping' do | ||
| 'pong' |
There was a problem hiding this comment.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
| describe Rack::Grape::EndpointJson do | ||
| include Rack::Test::Methods | ||
| subject { Class.new(Grape::API) } | ||
| let(:sample_hash){ {ping: :pong} } |
There was a problem hiding this comment.
Space missing to the left of {.
Space inside { missing.
Space inside } missing.
| @@ -0,0 +1,59 @@ | |||
| require "json" | |||
There was a problem hiding this comment.
Missing frozen string literal comment.
lib/rack/profiler.rb
Outdated
|
|
||
| if defined?(::Grape::Endpoint) | ||
| # This patch is required because of bug with Grape-Entity which is fixed in version 0.5.0 | ||
| if defined?(::Grape::Endpoint) && defined?(GrapeEntity::VERSION) && (Gem::Version.new(GrapeEntity::VERSION) < Gem::Version.new("0.5.0")) |
lib/rack/profiler.rb
Outdated
| block.call(self) if block_given? | ||
|
|
||
| if defined?(::Grape::Endpoint) | ||
| # This patch is required because of bug with Grape-Entity which is fixed in version 0.5.0 |
| if defined?(::Grape::Endpoint) | ||
| # This patch is required because of bug with Grape-Entity | ||
| # which is fixed in version 0.5.0 | ||
| if (defined?(::Grape::Endpoint) && |
There was a problem hiding this comment.
Don't use parentheses around the condition of an if.
|
The bug appears only if you are using library grape-entity version less than 0.5.0. In this case, Body can be anything and #to_hash not work in most cases. You can check it in https://github.com/ruby-grape/grape-on-rack |
There is no method 'to_hash' for Grape::Entity instance. Just call 'as_json' directly.
https://github.com/ruby-grape/grape-entity/blob/07bdc590754a35750a17554beedf3b8025fc4c08/lib/grape_entity/entity.rb#L488