diff --git a/app/models/dialog_field_serializer.rb b/app/models/dialog_field_serializer.rb index 07472948e3e..b07a7fc79de 100644 --- a/app/models/dialog_field_serializer.rb +++ b/app/models/dialog_field_serializer.rb @@ -27,6 +27,7 @@ def serialize(dialog_field, all_attributes = false) dialog_field.options[:force_single_value] = dialog_field.options[:force_single_value] || category.single_value end end - included_attributes(dialog_field.as_json(:methods => [:type, :values]), all_attributes).merge(extra_attributes) + json_options = dialog_field.dynamic? ? {:methods => [:type], :except => [:values]} : {:methods => %i(type values)} + included_attributes(dialog_field.as_json(json_options), all_attributes).merge(extra_attributes) end end diff --git a/spec/models/dialog_field_serializer_spec.rb b/spec/models/dialog_field_serializer_spec.rb index ea7aeaa1480..394ead51d0e 100644 --- a/spec/models/dialog_field_serializer_spec.rb +++ b/spec/models/dialog_field_serializer_spec.rb @@ -4,6 +4,7 @@ describe "#serialize" do let(:dialog_field) { DialogFieldTextBox.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders)) } + let(:dialog_field_with_values) { DialogFieldTextBox.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders, :values => "drew")) } let(:type) { "DialogFieldTextBox" } let(:resource_action) { ResourceAction.new } let(:dialog_field_responders) { [] } @@ -80,6 +81,18 @@ )) end end + + let(:all_attributes) { true } + + it 'does not call values' do + expect(dialog_field_serializer.serialize(dialog_field_with_values, all_attributes)) + .to include(expected_serialized_values.merge( + 'id' => dialog_field.id, + 'resource_action' => 'serialized resource action', + 'dialog_field_responders' => [], + 'values' => nil + )) + end end context "when the dialog_field is not dynamic" do