Skip to content

Commit

Permalink
Grape 1.4 (#15)
Browse files Browse the repository at this point in the history
Besides upgraded Grape, it changes the response body for 204 HTTP status,
now it is an empty string instead of an empty hash.

Rack introduced lazy body initialization (rack/rack@8c62821)
which only works with strings. However, when 204 HTTP status is returned, Grape
doesn't stringify the response (https://github.com/ruby-grape/grape/blob/master/lib/grape/middleware/formatter.rb#L27-L29),
thus, a hash is returned as a response body. `Rack::MockResponse` fails with

    TypeError (no implicit conversion of Hash into String)

It could be a bug in the JsonAPI resources gem, why does it return an empty hash
for 204 HTTP status?!. Definetly, it isn't a bug in Grape, nor Rack.
The logic for formatting the reponse body in Grape hasn't changed for 5 years.

The main motivation for this upgrade is a fix for memory leak
ruby-grape/grape#2084
  • Loading branch information
dnesteryuk committed Jul 22, 2020
1 parent 18429e2 commit 2ef9e2f
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 136 deletions.
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.6

Style/SignalException:
EnforcedStyle: semantic

Metrics/BlockLength:
Enabled: false

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
196 changes: 99 additions & 97 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,176 +1,178 @@
PATH
remote: .
specs:
grape-jsonapi (0.0.1)
grape (~> 1.3.0)
jsonapi-resources (~> 0.9.10)
grape-jsonapi (0.0.2)
grape (~> 1.4.0)
jsonapi-resources (~> 0.9.11)

GEM
remote: https://rubygems.org/
specs:
actionpack (5.0.7.2)
actionview (= 5.0.7.2)
activesupport (= 5.0.7.2)
rack (~> 2.0)
rack-test (~> 0.6.3)
actionpack (6.0.3.2)
actionview (= 6.0.3.2)
activesupport (= 6.0.3.2)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.7.2)
activesupport (= 5.0.7.2)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionview (6.0.3.2)
activesupport (= 6.0.3.2)
builder (~> 3.1)
erubis (~> 2.7.0)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activemodel (5.0.7.2)
activesupport (= 5.0.7.2)
activerecord (5.0.7.2)
activemodel (= 5.0.7.2)
activesupport (= 5.0.7.2)
arel (~> 7.0)
activesupport (5.0.7.2)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (6.0.3.2)
activesupport (= 6.0.3.2)
activerecord (6.0.3.2)
activemodel (= 6.0.3.2)
activesupport (= 6.0.3.2)
activesupport (6.0.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
arel (7.1.4)
ast (2.4.0)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.1)
builder (3.2.4)
byebug (9.0.6)
coderay (1.1.1)
concurrent-ruby (1.1.5)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.6)
crass (1.0.6)
diff-lcs (1.3)
docile (1.1.5)
dry-configurable (0.9.0)
diff-lcs (1.4.4)
docile (1.3.2)
dry-configurable (0.11.6)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4, >= 0.4.7)
dry-equalizer (~> 0.2)
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.9)
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-inflector (0.2.0)
dry-logic (1.0.5)
dry-logic (1.0.6)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-types (1.2.2)
dry-types (1.4.0)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
dry-equalizer (~> 0.3)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
erubis (2.7.0)
grape (1.3.0)
erubi (1.9.0)
grape (1.4.0)
activesupport
builder
dry-types (>= 1.1)
mustermann-grape (~> 1.0.0)
rack (>= 1.3.0)
rack-accept
hashie (3.6.0)
hashie (4.1.0)
hashie-forbidden_attributes (0.1.1)
hashie (>= 3.0)
i18n (1.8.2)
i18n (1.8.4)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
json (2.0.3)
json-schema (2.8.0)
json-schema (2.8.1)
addressable (>= 2.4)
jsonapi-resources (0.9.11)
activerecord (>= 4.1)
concurrent-ruby
railties (>= 4.1)
loofah (2.4.0)
loofah (2.6.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
method_source (0.8.2)
method_source (1.0.0)
mini_portile2 (2.4.0)
minitest (5.14.0)
minitest (5.14.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
mustermann-grape (1.0.1)
mustermann (>= 1.0.0)
nokogiri (1.10.7)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
otr-activerecord (1.2.1)
activerecord (>= 4.0, < 5.1)
otr-activerecord (1.4.1)
activerecord (>= 4.0, < 6.1)
hashie-forbidden_attributes (~> 0.1)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.2)
byebug (~> 9.0)
pry (~> 0.10)
public_suffix (2.0.5)
rack (2.1.1)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.5)
rack (2.2.3)
rack-accept (0.4.5)
rack (>= 0.4)
rack-test (0.6.3)
rack (>= 1.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (5.0.7.2)
actionpack (= 5.0.7.2)
activesupport (= 5.0.7.2)
railties (6.0.3.2)
actionpack (= 6.0.3.2)
activesupport (= 6.0.3.2)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (12.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
rake (13.0.1)
regexp_parser (1.7.1)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
rspec-support (~> 3.9.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.3)
rubocop (0.88.0)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.1.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.2.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
ruby2_keywords (0.0.2)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
sqlite3 (1.3.13)
simplecov (0.18.5)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.2)
sqlite3 (1.4.2)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)
unicode-display_width (1.7.0)
zeitwerk (2.4.0)

PLATFORMS
ruby
Expand All @@ -189,4 +191,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.1.2
2.1.4
12 changes: 6 additions & 6 deletions grape-jsonapi.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
# frozen_string_literal: true
$LOAD_PATH.push File.expand_path('../lib', __FILE__)

$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'grape/jsonapi/version'

Gem::Specification.new do |spec|
Expand All @@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
.reject { |f| f.match(%r{^spec/}) }
spec.require_paths = ['lib']

%w(
%w[
bundler otr-activerecord rake rspec rubocop pry-byebug simplecov sqlite3
rspec-rails json-schema
).each do |gem|
].each do |gem|
spec.add_development_dependency gem
end

spec.add_runtime_dependency 'grape', '~> 1.3.0'
spec.add_runtime_dependency 'jsonapi-resources', '~> 0.9.10'
spec.add_runtime_dependency 'grape', '~> 1.4.0'
spec.add_runtime_dependency 'jsonapi-resources', '~> 0.9.11'
end
1 change: 1 addition & 0 deletions lib/grape/jsonapi.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'action_controller'
require 'active_record'
require 'rails'
Expand Down
3 changes: 3 additions & 0 deletions lib/grape/jsonapi/api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative 'relationships'
require_relative 'error_renderer'

Expand Down Expand Up @@ -31,6 +32,7 @@ def jsonapi_resource
resource_class._routed = true
end

# rubocop:disable Metrics/AbcSize
def declare_base_route
resource name.demodulize.underscore.dasherize do
helpers { include Helpers }
Expand All @@ -45,6 +47,7 @@ def declare_base_route
declare_id_route
end
end
# rubocop:enable Metrics/AbcSize

def declare_id_route
route_param :id do
Expand Down
1 change: 1 addition & 0 deletions lib/grape/jsonapi/error_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative 'rendering'

module Grape
Expand Down
3 changes: 2 additions & 1 deletion lib/grape/jsonapi/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative 'rendering'
require_relative 'resources'

Expand Down Expand Up @@ -55,7 +56,7 @@ def transaction_block
end

def rollback_action
->() { fail ActiveRecord::Rollback }
-> { fail ActiveRecord::Rollback }
end

def forbidden_operation
Expand Down
1 change: 1 addition & 0 deletions lib/grape/jsonapi/relationships.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative 'resources'

module Grape
Expand Down
Loading

0 comments on commit 2ef9e2f

Please sign in to comment.