Skip to content

Commit

Permalink
Merge pull request #15455 from eclarizio/BZ1463827
Browse files Browse the repository at this point in the history
Fix for Drop Down List Dialog does not keep default value for Integer type
(cherry picked from commit 65ae59e)

https://bugzilla.redhat.com/show_bug.cgi?id=1468370
  • Loading branch information
gmcculloug authored and simaishi committed Jul 6, 2017
1 parent 6a1647e commit c85ed6c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog_field_sorted_item.rb
Expand Up @@ -102,7 +102,7 @@ def use_first_value_as_default
end

def default_value_included_in_raw_values?
@raw_values.collect { |value_pair| value_pair[0] }.include?(default_value.send(value_modifier))
@raw_values.collect { |value_pair| value_pair[0].send(value_modifier) }.include?(default_value.send(value_modifier))
end

def static_raw_values
Expand Down
4 changes: 2 additions & 2 deletions spec/models/dialog_field_drop_down_list_spec.rb
Expand Up @@ -221,9 +221,9 @@
expect(dialog_field.values).to eq([[0, "zero"], [10, "ten"], [5, "five"]])
end

it "sets the value to the first value" do
it "sets the value to the default value as a string" do
dialog_field.values
expect(dialog_field.value).to eq("0")
expect(dialog_field.value).to eq("5")
end
end
end
Expand Down
36 changes: 34 additions & 2 deletions spec/models/dialog_field_sorted_item_spec.rb
Expand Up @@ -189,8 +189,40 @@
end

context "when the field is not required" do
it "returns the values with the first option being a nil 'None' option" do
expect(dialog_field.values).to eq([[nil, "<None>"], %w(test test), %w(abc abc)])
context "when the data type is an integer" do
let(:data_type) { "integer" }

before do
dialog_field.data_type = data_type
end

context "when there is a default value that matches a value in the values list" do
let(:default_value) { "2" }
let(:values) { [%w(1 1), %w(2 2), %w(3 3)] }

it "sets the default value to the matching value" do
dialog_field.values
expect(dialog_field.default_value).to eq("2")
end

it "returns the values with the first option being a nil 'None' option" do
expect(dialog_field.values).to eq([[nil, "<None>"], %w(1 1), %w(2 2), %w(3 3)])
end
end

context "when there is a default value that does not match a value in the values list" do
let(:default_value) { "4" }
let(:values) { [%w(1 1), %w(2 2), %w(3 3)] }

it "sets the default value to nil" do
dialog_field.values
expect(dialog_field.default_value).to eq(nil)
end

it "returns the values with the first option being a nil 'None' option" do
expect(dialog_field.values).to eq([[nil, "<None>"], %w(1 1), %w(2 2), %w(3 3)])
end
end
end
end
end
Expand Down

0 comments on commit c85ed6c

Please sign in to comment.