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

Exports new DialogFieldAssociations data #15608

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
5 changes: 2 additions & 3 deletions app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def initialize(resource_action_serializer = ResourceActionSerializer.new)

def serialize(dialog_field, all_attributes = false)
serialized_resource_action = @resource_action_serializer.serialize(dialog_field.resource_action)

extra_attributes = {
"resource_action" => serialized_resource_action
"resource_action" => serialized_resource_action,
"dialog_field_responders" => dialog_field.dialog_field_responders.map(&:name)
}

if dialog_field.dynamic?
Expand All @@ -25,7 +25,6 @@ def serialize(dialog_field, all_attributes = false)
category = Category.find_by(:id => dialog_field.category)
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description)
end

included_attributes(dialog_field.as_json(:methods => [:type, :values]), all_attributes).merge(extra_attributes)
end
end
30 changes: 23 additions & 7 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
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)) }
let(:dialog_field) { DialogFieldTextBox.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders)) }
let(:type) { "DialogFieldTextBox" }
let(:resource_action) { ResourceAction.new }
let(:dialog_field_responders) { [] }
let(:options) { {"options" => true} }
let(:expected_serialized_values) do
{
Expand Down Expand Up @@ -59,8 +60,9 @@
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"
"resource_action" => "serialized resource action",
"values" => "dynamic values",
"dialog_field_responders" => dialog_field_responders
))
end
end
Expand Down Expand Up @@ -88,7 +90,8 @@
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"
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders
))
end
end
Expand All @@ -103,12 +106,24 @@
'resource_action' => 'serialized resource action',
))
end

context 'with associations' do
let(:dialog_field_responders) { [FactoryGirl.build(:dialog_field_text_box)] }

it 'serializes the dialog_field with all attributes and non_empty associations' do
expect(dialog_field_serializer.serialize(dialog_field, dialog_field_responders))
.to include(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"dialog_field_responders" => ["Dialog Field"]
))
end
end
end
end

context "when the dialog_field is a tag control type" do
let(:dialog_field) do
DialogFieldTagControl.new(expected_serialized_values.merge(:resource_action => resource_action))
DialogFieldTagControl.new(expected_serialized_values.merge(:resource_action => resource_action, :dialog_field_responders => dialog_field_responders))
end

let(:type) { "DialogFieldTagControl" }
Expand All @@ -124,8 +139,9 @@
it "serializes the category name and description" do
expect(dialog_field_serializer.serialize(dialog_field))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"options" => {
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders,
"options" => {
:category_id => "123",
:category_name => "best category ever",
:category_description => "best category ever"
Expand Down