Skip to content

Commit

Permalink
Merge pull request #19696 from himdel/dialog-tag-multi
Browse files Browse the repository at this point in the history
DialogFieldTagControl - don't add <None> for multiselects
  • Loading branch information
bdunne authored Jan 13, 2020
2 parents 5d34943 + 20f9bed commit 9ce9b3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/models/dialog_field_tag_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def force_multi_value
!single_value?
end

def multiselect?
force_multi_value
end

def self.allowed_tag_categories
tag_cats = Classification.is_category.where(:show => true, :read_only => false).includes(:tag).to_a

Expand Down Expand Up @@ -64,7 +68,7 @@ def values
end

empty = required? ? "<Choose>" : "<None>"
blank_value = [{:id => nil, :name => empty, :description => empty}]
blank_value = multiselect? ? [] : [{:id => nil, :name => empty, :description => empty}]

return blank_value + available_tags if sort_field == :none

Expand Down
19 changes: 16 additions & 3 deletions spec/models/dialog_field_tag_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ def add_entry(cat, options)

describe "#values" do
let(:dialog_field) { described_class.new(:options => options, :data_type => data_type, :required => required) }
let(:options) { {:category_id => category_id, :sort_by => sort_by, :sort_order => sort_order} }
let(:options) { {:category_id => category_id, :sort_by => sort_by, :sort_order => sort_order, :force_single_value => single?} }
let(:category_id) { 123 }
let(:required) { false }
let(:sort_by) { :none }
let(:sort_order) { :ascending }
let(:data_type) { "string" }
let(:single?) { true }

before do
allow(Classification).to receive(:find_by).with(:id => category_id).and_return(classification)
Expand All @@ -165,8 +166,20 @@ def add_entry(cat, options)
shared_examples_for "DialogFieldTagControl#values when required is true" do
let(:required) { true }

it "the blank value uses 'Choose' for its name and description" do
expect(dialog_field.values[0]).to eq(:id => nil, :name => "<Choose>", :description => "<Choose>")
context "singlevalue" do
let(:single?) { true }

it "the blank value uses 'Choose' for its name and description" do
expect(dialog_field.values[0]).to eq(:id => nil, :name => "<Choose>", :description => "<Choose>")
end
end

context "multi value" do
let(:single?) { false }

it "has no blank value" do
expect(%w[<Choose> <None>]).to_not include(dialog_field.values[0][:name])
end
end
end

Expand Down

0 comments on commit 9ce9b3d

Please sign in to comment.