Возможно, вы разрешили это как permit(..., :to_time, :act_ids)
, но массив должен быть разрешен через act_ids: []
, который у вас уже есть в вашем timetable_params
коде
В чистом приложении это работает правильно:
#!/usr/bin/env ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile(!!ENV['INSTALL']) do
source "https://rubygems.org"
gem 'rails', '5.2.2'
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.eager_load = false
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
end
TestApp.initialize!
TestApp.routes.draw{ resources :timetables, only: :update }
class TimetablesController < ActionController::Base
include Rails.application.routes.url_helpers
wrap_parameters format: [:json, :xml]
def update
render json: timetable_params
end
def timetable_params
params.require(:timetable).permit(:weekday,
:is_only_private,
:is_allow_forced,
:from_time,
:to_time,
act_ids: [])
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
payload = {
"id"=>"10172", "weekday"=>1, "is_only_private"=>false, "is_allow_forced"=>false,
"from_time"=>"08:00", "to_time"=>"09:00",
"act_ids"=>[10001, 10002],
"customer_id"=>"10000", "consultation_id"=>"10000"
}
patch "/timetables/10172.json", payload.to_json, { 'CONTENT_TYPE' => 'application/json' }
assert last_response.ok?
puts "resp body: #{last_response.body}"
resp = JSON.parse(last_response.body)
assert_includes(resp.keys, "act_ids")
end
private def app
Rails.application
end
end
производит
Run options: --seed 62182
# Running:
I, [2019-06-14T16:04:02.967561 #44749] INFO -- : Started PATCH "/timetables/10172.json" for 127.0.0.1 at 2019-06-14 16:04:02 +0300
I, [2019-06-14T16:04:02.971039 #44749] INFO -- : Processing by TimetablesController#update as JSON
I, [2019-06-14T16:04:02.971161 #44749] INFO -- : Parameters: {"id"=>"10172", "weekday"=>1, "is_only_private"=>false, "is_allow_forced"=>false, "from_time"=>"08:00", "to_time"=>"09:00", "act_ids"=>[10001, 10002], "customer_id"=>"10000", "consultation_id"=>"10000", "timetable"=>{"id"=>"10172", "weekday"=>1, "is_only_private"=>false, "is_allow_forced"=>false, "from_time"=>"08:00", "to_time"=>"09:00", "act_ids"=>[10001, 10002], "customer_id"=>"10000", "consultation_id"=>"10000"}}
D, [2019-06-14T16:04:02.971850 #44749] DEBUG -- : Unpermitted parameters: :id, :customer_id, :consultation_id
I, [2019-06-14T16:04:02.972484 #44749] INFO -- : Completed 200 OK in 1ms (Views: 0.4ms)
resp body: {"weekday":1,"is_only_private":false,"is_allow_forced":false,"from_time":"08:00","to_time":"09:00","act_ids":[10001,10002]}
.
Finished in 0.020124s, 49.6919 runs/s, 149.0757 assertions/s.
1 runs, 3 assertions, 0 failures, 0 errors, 0 skips