Skip to content

Commit

Permalink
Allow dynamic drop down list to be submitted on first entry
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarizio committed May 29, 2015
1 parent 36b3dbf commit 020529b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions vmdb/app/models/dialog_field_drop_down_list.rb
Expand Up @@ -39,6 +39,10 @@ def load_values_on_init?

def raw_values
@raw_values ||= dynamic ? values_from_automate : super
@default_value ||= @raw_values.first.first
self.value = @default_value

@raw_values
end

def values_from_automate
Expand Down
34 changes: 31 additions & 3 deletions vmdb/spec/models/dialog_field_drop_down_list_spec.rb
Expand Up @@ -90,22 +90,50 @@
end
end

describe "#raw_values" do
describe "#refresh_json_value" do
let(:dialog_field) { described_class.new(:dynamic => dynamic) }

context "when the dialog_field is dynamic" do
let(:dynamic) { true }

it "returns the values from automate" do
before do
DynamicDialogFieldValueProcessor.stub(:values_from_automate).with(dialog_field).and_return(
[["123", 456], ["789", 101]]
)
dialog_field.value = "123"
end

it "sets the value" do
dialog_field.refresh_json_value("789")
expect(dialog_field.value).to eq("789")
end

it "returns the values from automate" do
expect(dialog_field.refresh_json_value("789")).to eq(
:refreshed_values => [["789", 101], ["123", 456]],
:checked_value => "789"
)
end
end

context "when the dialog_field is not dynamic" do
let(:dynamic) { false }

it "returns the values" do
before do
dialog_field.values = [["123", 456], ["789", 101]]
dialog_field.value = "123"
end

it "sets the value" do
dialog_field.refresh_json_value("789")
expect(dialog_field.value).to eq("789")
end

it "returns the values" do
expect(dialog_field.refresh_json_value("789")).to eq(
:refreshed_values => [["789", 101], ["123", 456]],
:checked_value => "789"
)
end
end
end
Expand Down

0 comments on commit 020529b

Please sign in to comment.