Permalink
Browse files

Alter the merge order on Hanami::Action::Params#_params (#227)

  • Loading branch information...
mereghost authored and jodosha committed Jun 5, 2017
1 parent 9008fb6 commit 8e6f8d14d125c0a9a40ab0eafbbd850d77adab55
Showing with 18 additions and 3 deletions.
  1. +1 −1 lib/hanami/action/params.rb
  2. +10 −2 spec/integration/hanami/controller/routing_spec.rb
  3. +7 −0 spec/support/fixtures.rb
@@ -146,7 +146,7 @@ def to_h

# @api private
def _params
@result.output.merge(_router_params)
_router_params.merge(@result.output)
end
end
end
@@ -1,6 +1,6 @@
require 'hanami/router'

Routes = Hanami::Router.new do
Routes = Hanami::Router.new(parsers: :json) do
get '/', to: 'root'
get '/team', to: 'about#team'
get '/contacts', to: 'about#contacts'
@@ -141,7 +141,15 @@
response = app.request("PATCH", "/painters/23", params: { painter: { first_name: "Gustav", last_name: "Klimt" } })

expect(response.status).to be(200)
expect(response.body).to eq(%({:painter=>{:first_name=>"Gustav", :last_name=>"Klimt"}, :id=>"23"}))
expect(response.body).to eq(%({:id=>"23", :painter=>{:first_name=>"Gustav", :last_name=>"Klimt"}}))
end

it "doesn't replace parsed params with router params" do
json = { painter: { first_name: 'Gustav', last_name: 'Klimt', paintings: [{ name: "The Kiss" }, { name: "The Maiden" }] } }.to_json
response = app.request('PATCH', '/painters/23', 'CONTENT_TYPE' => 'application/json', input: json)

expect(response.status).to be(200)
expect(response.body).to eq(%({:painter=>{:first_name=>"Gustav", :last_name=>"Klimt", :paintings=>[{:name=>"The Kiss"}, {:name=>"The Maiden"}]}, :id=>"23"}))
end
end
end
@@ -878,6 +878,13 @@ class Update
required(:painter).schema do
required(:first_name).filled(:str?)
required(:last_name).filled(:str?)
optional(:paintings).maybe do
each do
schema do
required(:name).filled
end
end
end
end
end

0 comments on commit 8e6f8d1

Please sign in to comment.