Skip to content

Commit

Permalink
Use correct value for force_single_value when serializing TagControl
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarizio committed Feb 6, 2018
1 parent 8be29c6 commit d1d5161
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def serialize(dialog_field, all_attributes = false)

if dialog_field.type == "DialogFieldTagControl"
category = Category.find_by(:id => dialog_field.category)
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description) if category
if category
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description)
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)
end
Expand Down
14 changes: 10 additions & 4 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@

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, :dialog_field_responders => dialog_field_responders))
DialogFieldTagControl.new(expected_serialized_values.merge(
:resource_action => resource_action,
:dialog_field_responders => dialog_field_responders
))
end

let(:type) { "DialogFieldTagControl" }
let(:options) { {:category_id => "123"} }
let(:options) { {:category_id => "123", :force_single_value => false} }
let(:dynamic) { false }
let(:category) { double("Category", :name => "best category ever", :description => "best category ever") }
let(:category) do
double("Category", :name => "best category ever", :description => "best category ever", :single_value => true)
end

before do
allow(Category).to receive(:find_by).with(:id => "123").and_return(category)
Expand All @@ -149,7 +154,8 @@
"options" => {
:category_id => "123",
:category_name => "best category ever",
:category_description => "best category ever"
:category_description => "best category ever",
:force_single_value => true
},
"default_value" => "[\"one\", \"two\"]"
))
Expand Down

0 comments on commit d1d5161

Please sign in to comment.