diff --git a/app/controllers/administrate/application_controller.rb b/app/controllers/administrate/application_controller.rb index c70d8c3ee6..f07a015753 100644 --- a/app/controllers/administrate/application_controller.rb +++ b/app/controllers/administrate/application_controller.rb @@ -163,6 +163,8 @@ def read_param_value(data) else raise "Unrecognised param data: #{data.inspect}" end + elsif data.is_a?(ActionController::Parameters) + data.transform_values { |v| read_param_value(v) } else data end diff --git a/spec/controllers/admin/log_entries_controller_spec.rb b/spec/controllers/admin/log_entries_controller_spec.rb index 8060ab7537..729fbef478 100644 --- a/spec/controllers/admin/log_entries_controller_spec.rb +++ b/spec/controllers/admin/log_entries_controller_spec.rb @@ -26,6 +26,52 @@ def post_create(action: "create", logeable: create(:customer)) post_create expect(response).to redirect_to([:admin, LogEntry.last]) end + + it "parses nested polymorphic resources" do + customer = create(:customer) + + resource_params = attributes_for(:log_entry).merge( + arbitrarily: { + nested: { + params: { + logeable: { + type: "Administrate::Field::Polymorphic", + value: customer.to_global_id.to_s, + }, + }, + }, + }, + ) + + allow_any_instance_of( + LogEntryDashboard, + ).to receive(:permitted_attributes).and_return( + [ + arbitrarily: { + nested: { + params: { + logeable: [ + :type, + :value, + ], + }, + }, + }, + ], + ) + + LogEntry.attr_accessor :arbitrarily + + post :create, log_entry: resource_params + + logeable_in_params = subject.send(:resource_params).dig( + :arbitrarily, + :nested, + :params, + :logeable, + ) + expect(logeable_in_params).to eq(customer) + end end describe "with invalid params" do