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 differing behavior in DialogFieldTagControl multi/single drop downs #16955

Merged
merged 1 commit into from
Feb 6, 2018
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: 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