Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for incorrect key sent back for dynamic non sorted items #18650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def serialize(dialog_field, all_attributes = false)
}

if dialog_field.dynamic?
extra_attributes["values"] = dialog_field.extract_dynamic_values
key_to_update = dialog_field.kind_of?(DialogFieldSortedItem) ? "values" : "default_value"

extra_attributes[key_to_update] = dialog_field.extract_dynamic_values
end

if dialog_field.type == "DialogFieldTagControl"
Expand Down
128 changes: 101 additions & 27 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
let(:dialog_field_serializer) { described_class.new(resource_action_serializer) }

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) { [] }
let(:options) { {"options" => true} }
Expand All @@ -26,7 +23,6 @@
"required_method_options" => {"required method options" => true},
"show_refresh_button" => false,
"default_value" => "default value",
"values" => "values",
"values_method" => "values method",
"values_method_options" => {"values method options" => true},
"options" => options,
Expand All @@ -51,52 +47,96 @@
context "when the dialog_field is dynamic" do
let(:dynamic) { true }

before do
allow(dialog_field).to receive(:extract_dynamic_values).and_return("dynamic values")
end
context "when the field is a sorted item type" do
let(:type) { "DialogFieldDropDownList" }
let(:dialog_field) { DialogFieldDropDownList.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders)) }

context 'when wanting the excluded set of attributes' do
let(:all_attributes) { false }
before do
allow(dialog_field).to receive(:extract_dynamic_values).and_return("dynamic values")
end

it 'serializes the dialog_field with the correct attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
context 'when wanting the excluded set of attributes' do
let(:all_attributes) { false }

it 'serializes the dialog_field with the correct attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"values" => "dynamic values",
"dialog_field_responders" => dialog_field_responders
))
end
end
end

context 'when wanting all attributes' do
let(:all_attributes) { true }
context 'when wanting all attributes' do
let(:all_attributes) { true }

it 'serializes the dialog_field with all attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
it 'serializes the dialog_field with all attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to include(expected_serialized_values.merge(
'id' => dialog_field.id,
'resource_action' => 'serialized resource action',
'dialog_field_responders' => [],
'values' => 'dynamic values'
))
end
end

let(:all_attributes) { true }
let(:dialog_field_with_values) { DialogFieldDropDownList.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders, :values => "drew")) }

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

let(:all_attributes) { true }
context "when the field is not a sorted item type" do
let(:dialog_field) { DialogFieldTextBox.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders)) }
let(:type) { "DialogFieldTextBox" }

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
))
before do
allow(dialog_field).to receive(:extract_dynamic_values).and_return("automate default value")
end

context 'when wanting the excluded set of attributes' do
let(:all_attributes) { false }

it 'serializes the dialog_field with the correct attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders,
"default_value" => "automate default value",
))
end
end

context 'when wanting all attributes' do
let(:all_attributes) { true }

it 'serializes the dialog_field with all attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to include(expected_serialized_values.merge(
'id' => dialog_field.id,
'resource_action' => 'serialized resource action',
'dialog_field_responders' => [],
"default_value" => "automate default value"
))
end
end
end
end

context "when the dialog_field is not dynamic" do
let(:dynamic) { false }
let(:dialog_field) { DialogFieldTextBox.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders)) }
let(:type) { "DialogFieldTextBox" }

context 'when wanting the excluded set of attributes' do
let(:all_attributes) { false }
Expand All @@ -105,7 +145,8 @@
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders
"dialog_field_responders" => dialog_field_responders,
"values" => nil
))
end
end
Expand Down Expand Up @@ -134,6 +175,38 @@
end
end
end

context "when the dialog field is a drop down list" do
let(:dynamic) { false }
let(:dialog_field) { DialogFieldDropDownList.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders, :values => [%w[one one], %w[two two]])) }
let(:type) { "DialogFieldDropDownList" }

context 'when wanting the excluded set of attributes' do
let(:all_attributes) { false }

it "serializes the dialog_field with the correct values" do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders,
"values" => [[nil, "<None>"], %w[one one], %w[two two]]
))
end
end

context 'when wanting all attributes' do
let(:all_attributes) { true }

it 'serializes the dialog_field with all attributes' do
expect(dialog_field_serializer.serialize(dialog_field, all_attributes))
.to include(expected_serialized_values.merge(
'id' => dialog_field.id,
'resource_action' => 'serialized resource action',
'dialog_field_responders' => []
))
end
end
end
end

context "when the dialog_field is a tag control type" do
Expand Down Expand Up @@ -170,7 +243,8 @@
:category_description => "best category ever",
:force_single_value => true
},
"default_value" => "[\"one\", \"two\"]"
"default_value" => "[\"one\", \"two\"]",
"values" => "values"
))
end
end
Expand Down