Skip to content
Permalink
Browse files

Merge pull request #262 from hanami/deprecate-parsed_request_body

deprecate parsed_request_body
  • Loading branch information...
GustavoCaso committed Jul 3, 2018
2 parents 49d206a + 5a5a6b8 commit f135f837943d1e1191937dbfa2b02d3b837860ef
Showing with 26 additions and 1 deletion.
  1. +1 −0 Gemfile
  2. +4 −0 lib/hanami/action/rack.rb
  3. +21 −1 spec/unit/hanami/action_spec.rb
@@ -13,4 +13,5 @@ group :validations do
gem 'hanami-validations', '~> 1.3.beta', require: false, git: 'https://github.com/hanami/validations.git', branch: 'develop'
end

gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
gem 'coveralls', require: false
@@ -3,6 +3,7 @@
require 'hanami/action/base_params'
require 'hanami/action/rack/callable'
require 'hanami/action/rack/file'
require 'hanami/utils/deprecation'

module Hanami
module Action
@@ -245,7 +246,10 @@ def request
end

# Return parsed request body
#
# @deprecated
def parsed_request_body
Hanami::Utils::Deprecation.new('#parsed_request_body is deprecated and it will be removed in future versions')
@_env.fetch(ROUTER_PARSED_BODY, nil)
end

@@ -1,3 +1,5 @@
require "hanami/devtools/unit"

RSpec.describe Hanami::Action do
describe ".configuration" do
after do
@@ -136,7 +138,7 @@ def call(_)
end

describe "#parsed_request_body" do
it "exposes the body of the request parsed by router body parsers" do
it "exposes the body of the request parsed by router body parsers", silence_deprecations: true do
action_class = Class.new do
include Hanami::Action

@@ -154,6 +156,24 @@ def call(_)
parsed_request_body = action.request_body
expect(parsed_request_body).to eq('a' => 'foo')
end

it "shows deprecation message" do
action_class = Class.new do
include Hanami::Action

expose :request_body

def call(_)
@request_body = parsed_request_body
end
end

action = action_class.new
env = Rack::MockRequest.env_for('http://example.com/foo',
'router.parsed_body' => { 'a' => 'foo' })

expect { action.call(env) }.to output(/#parsed_request_body is deprecated and it will be removed in future versions/).to_stderr
end
end

describe "Method visibility" do

0 comments on commit f135f83

Please sign in to comment.
You can’t perform that action at this time.