diff --git a/app/models/dialog.rb b/app/models/dialog.rb index e841ab90130..70393a630bc 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -88,13 +88,19 @@ def validate_field_data result end - def init_fields_with_values(values) - dialog_field_hash.each do |key, field| + def load_values_into_fields(values) + dialog_field_hash.each_value do |field| field.dialog = self - values[key] = field.value + field.value = values[field.automate_key_name] || values[field.name] end - dialog_field_hash.each { |key, field| values[key] = field.initialize_with_values(values) } - dialog_field_hash.each { |_key, field| field.update_values(values) } + end + + def initialize_value_context(_values) + dialog_field_hash.each_value do |field| + field.dialog = self + end + + dialog_field_hash.each_value(&:initialize_value_context) end def init_fields_with_values_for_request(values) @@ -112,10 +118,6 @@ def content(target = nil, resource_action = nil, all_attributes = false) workflow = ResourceActionWorkflow.new({}, User.current_user, resource_action, :target => target) - workflow.dialog.dialog_fields.each do |dialog_field| - # Accessing dialog_field.values forces an update for any values coming from automate - dialog_field.values = dialog_field.values - end DialogSerializer.new.serialize(Array[workflow.dialog], all_attributes) end diff --git a/app/models/dialog_field.rb b/app/models/dialog_field.rb index 036495ee0df..5e08b1d9ede 100644 --- a/app/models/dialog_field.rb +++ b/app/models/dialog_field.rb @@ -91,8 +91,17 @@ def self.field_types FIELD_CONTROLS end + def extract_dynamic_values + value + end + + def initialize_value_context + @value = values_from_automate if dynamic && @value.blank? + end + def initialize_with_values(dialog_values) - @value = value_from_dialog_fields(dialog_values) || default_value + # override in subclasses + nil end def update_values(_dialog_values) @@ -122,9 +131,14 @@ def resource end def update_and_serialize_values + trigger_automate_value_updates DialogFieldSerializer.serialize(self) end + def trigger_automate_value_updates + @value = values_from_automate + end + def update_dialog_field_responders(id_list) dialog_field_responders.destroy_all diff --git a/app/models/dialog_field_check_box.rb b/app/models/dialog_field_check_box.rb index 3d74a9a3cc1..d73abc63a70 100644 --- a/app/models/dialog_field_check_box.rb +++ b/app/models/dialog_field_check_box.rb @@ -5,11 +5,6 @@ def checked? value == "t" end - def value - @value = values_from_automate if dynamic && @value.blank? - @value - end - def initial_values false end @@ -32,10 +27,6 @@ def refresh_json_value {:checked => checked?, :read_only => read_only?, :visible => visible?} end - def trigger_automate_value_updates - values_from_automate - end - private def required_value_error? diff --git a/app/models/dialog_field_date_control.rb b/app/models/dialog_field_date_control.rb index 4b1983f792e..f9179e0fb42 100644 --- a/app/models/dialog_field_date_control.rb +++ b/app/models/dialog_field_date_control.rb @@ -17,9 +17,8 @@ def automate_output_value end def value - @value = dynamic ? values_from_automate : default_time if @value.blank? - - Date.parse(@value).strftime("%m/%d/%Y") + value_to_parse = @value.presence || default_time + Date.parse(value_to_parse).strftime("%m/%d/%Y") end def normalize_automate_values(automate_hash) @@ -45,10 +44,6 @@ def refresh_json_value {:date => Date.parse(@value).strftime("%m/%d/%Y"), :read_only => read_only?, :visible => visible?} end - def trigger_automate_value_updates - values_from_automate - end - private def default_time diff --git a/app/models/dialog_field_date_time_control.rb b/app/models/dialog_field_date_time_control.rb index e4652745222..c4112c1f772 100644 --- a/app/models/dialog_field_date_time_control.rb +++ b/app/models/dialog_field_date_time_control.rb @@ -7,9 +7,8 @@ def automate_output_value end def value - @value = dynamic ? values_from_automate : default_time if @value.blank? - - Time.parse(@value).strftime("%m/%d/%Y %H:%M") + value_to_parse = @value.presence || default_time + Time.zone.parse(value_to_parse).strftime("%m/%d/%Y %H:%M") end def refresh_json_value diff --git a/app/models/dialog_field_serializer.rb b/app/models/dialog_field_serializer.rb index 6374a7a9b8b..07472948e3e 100644 --- a/app/models/dialog_field_serializer.rb +++ b/app/models/dialog_field_serializer.rb @@ -17,8 +17,7 @@ def serialize(dialog_field, all_attributes = false) } if dialog_field.dynamic? - dynamic_values = dialog_field.trigger_automate_value_updates - extra_attributes["values"] = dynamic_values + extra_attributes["values"] = dialog_field.extract_dynamic_values end if dialog_field.type == "DialogFieldTagControl" diff --git a/app/models/dialog_field_sorted_item.rb b/app/models/dialog_field_sorted_item.rb index a2f4d1d0dd7..7b9b03f34b5 100644 --- a/app/models/dialog_field_sorted_item.rb +++ b/app/models/dialog_field_sorted_item.rb @@ -1,6 +1,14 @@ class DialogFieldSortedItem < DialogField AUTOMATE_VALUE_FIELDS = %w(sort_by sort_order data_type default_value required read_only visible description).freeze + def initialize_value_context + if load_values_on_init? + raw_values + else + @raw_values = initial_values + end + end + def initialize_with_values(dialog_values) if load_values_on_init? raw_values @@ -36,6 +44,10 @@ def values raw_values end + def extract_dynamic_values + @raw_values + end + def get_default_value trigger_automate_value_updates default_value @@ -75,6 +87,11 @@ def refresh_json_value(checked_value) {:refreshed_values => refreshed_values, :checked_value => @value, :read_only => read_only?, :visible => visible?} end + def force_multi_value + # override in subclasses + nil + end + private def add_nil_option @@ -95,7 +112,7 @@ def sort_data(data_to_sort) data_to_sort end - def determine_selected_default_value + def determine_selected_value if dynamic? && force_multi_value && !default_value.kind_of?(Array) self.default_value = Array.wrap(default_value) end @@ -108,7 +125,7 @@ def raw_values reject_extraneous_nil_values unless dynamic? @raw_values = sort_data(@raw_values) add_nil_option unless dynamic? - determine_selected_default_value + determine_selected_value @raw_values end diff --git a/app/models/dialog_field_tag_control.rb b/app/models/dialog_field_tag_control.rb index b69e8d4bafb..9a8048990b2 100644 --- a/app/models/dialog_field_tag_control.rb +++ b/app/models/dialog_field_tag_control.rb @@ -1,4 +1,8 @@ class DialogFieldTagControl < DialogFieldSortedItem + def initialize_value_context + @value = get_default_value + end + def initialize_with_values(dialog_values) @value = value_from_dialog_fields(dialog_values) || get_default_value end diff --git a/app/models/dialog_field_text_box.rb b/app/models/dialog_field_text_box.rb index 313f3f82514..c4c220fd6ab 100644 --- a/app/models/dialog_field_text_box.rb +++ b/app/models/dialog_field_text_box.rb @@ -2,7 +2,6 @@ class DialogFieldTextBox < DialogField AUTOMATE_VALUE_FIELDS = %w(data_type protected required validator_rule validator_type read_only visible description).freeze def value - @value = values_from_automate if dynamic && @value.blank? return nil if @value.nil? convert_value_to_type end @@ -70,10 +69,6 @@ def refresh_json_value {:text => @value, :read_only => read_only?, :visible => visible?} end - def trigger_automate_value_updates - values_from_automate - end - private def convert_value_to_type diff --git a/app/models/resource_action_workflow.rb b/app/models/resource_action_workflow.rb index 9fe9b21df3b..9af525971f9 100644 --- a/app/models/resource_action_workflow.rb +++ b/app/models/resource_action_workflow.rb @@ -103,8 +103,10 @@ def load_dialog(resource_action, values, options) dialog.target_resource = @target if options[:display_view_only] dialog.init_fields_with_values_for_request(values) + elsif options[:refresh] + dialog.load_values_into_fields(values) else - dialog.init_fields_with_values(values) + dialog.initialize_value_context(values) end end dialog diff --git a/spec/models/dialog_field_check_box_spec.rb b/spec/models/dialog_field_check_box_spec.rb index 7d7f028cceb..281f66bc4f7 100644 --- a/spec/models/dialog_field_check_box_spec.rb +++ b/spec/models/dialog_field_check_box_spec.rb @@ -1,41 +1,4 @@ describe DialogFieldCheckBox do - describe "#value" do - let(:dialog_field) { described_class.new(:dynamic => dynamic, :value => value) } - - context "when the dialog field is dynamic" do - let(:dynamic) { true } - - context "when the current value is blank" do - let(:value) { "" } - - before do - allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return("processor") - end - - it "returns the values from the value processor" do - expect(dialog_field.value).to eq("processor") - end - end - - context "when the current value is not blank" do - let(:value) { "test" } - - it "returns the current value" do - expect(dialog_field.value).to eq("test") - end - end - end - - context "when the dialog field is not dynamic" do - let(:dynamic) { false } - let(:value) { "test" } - - it "returns the current value" do - expect(dialog_field.value).to eq("test") - end - end - end - describe "#checked?" do let(:dialog_field) { described_class.new(:value => value) } diff --git a/spec/models/dialog_field_date_control_spec.rb b/spec/models/dialog_field_date_control_spec.rb index f4bf119797b..6f4555a2512 100644 --- a/spec/models/dialog_field_date_control_spec.rb +++ b/spec/models/dialog_field_date_control_spec.rb @@ -25,25 +25,23 @@ context "when the value is blank" do let(:value) { "" } + before do + allow(described_class).to receive(:server_timezone).and_return("UTC") + end + context "when the field is dynamic" do let(:dynamic) { true } - before do - allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return("2015-01-02") - end - - it "returns the values from the value processor" do - expect(dialog_field.value).to eq("01/02/2015") + it "returns tomorrow's date" do + Timecop.freeze(Time.new(2015, 1, 2, 0, 0, 0, 0)) do + expect(dialog_field.value).to eq("01/03/2015") + end end end context "when the field is not dynamic" do let(:dynamic) { false } - before do - allow(described_class).to receive(:server_timezone).and_return("UTC") - end - it "returns tomorrow's date" do Timecop.freeze(Time.new(2015, 1, 2, 0, 0, 0, 0)) do expect(dialog_field.value).to eq("01/03/2015") diff --git a/spec/models/dialog_field_date_time_control_spec.rb b/spec/models/dialog_field_date_time_control_spec.rb index 706f47f0361..7d9420bd086 100644 --- a/spec/models/dialog_field_date_time_control_spec.rb +++ b/spec/models/dialog_field_date_time_control_spec.rb @@ -49,9 +49,10 @@ describe "#automate_output_value" do let(:dialog_field) { described_class.new(:value => value) } + let(:server) { double("MiqServer", :server_timezone => "UTC") } before do - allow(described_class).to receive(:server_timezone).and_return("UTC") + allow(MiqServer).to receive(:my_server).and_return(server) end context "when the dialog_field is blank" do @@ -83,6 +84,11 @@ describe "#value" do let(:dialog_field) { described_class.new(:dynamic => dynamic, :value => value) } + let(:server) { double("MiqServer", :server_timezone => "UTC") } + + before do + allow(MiqServer).to receive(:my_server).and_return(server) + end context "when the value is not blank" do let(:value) { "04/07/2015 00:00" } @@ -110,23 +116,16 @@ context "when the field is dynamic" do let(:dynamic) { true } - before do - allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate) - .with(dialog_field).and_return("2015-01-02") - end - - it "returns the values from the value processor" do - expect(dialog_field.value).to eq("01/02/2015 00:00") + it "returns tomorrow's date" do + Timecop.freeze(Time.utc(2015, 1, 2, 4, 30)) do + expect(dialog_field.value).to eq("01/03/2015 04:30") + end end end context "when the field is not dynamic" do let(:dynamic) { false } - before do - allow(described_class).to receive(:server_timezone).and_return("UTC") - end - it "returns tomorrow's date" do Timecop.freeze(Time.utc(2015, 1, 2, 4, 30)) do expect(dialog_field.value).to eq("01/03/2015 04:30") @@ -138,9 +137,10 @@ describe "#refresh_json_value" do let(:dialog_field) { described_class.new(:read_only => true) } + let(:server) { double("MiqServer", :server_timezone => "UTC") } before do - allow(described_class).to receive(:server_timezone).and_return("UTC") + allow(MiqServer).to receive(:my_server).and_return(server) allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate) .with(dialog_field).and_return("2015-02-03T18:50:00Z") end diff --git a/spec/models/dialog_field_serializer_spec.rb b/spec/models/dialog_field_serializer_spec.rb index 3ac470fcecb..ea7aeaa1480 100644 --- a/spec/models/dialog_field_serializer_spec.rb +++ b/spec/models/dialog_field_serializer_spec.rb @@ -51,7 +51,7 @@ let(:dynamic) { true } before do - allow(dialog_field).to receive(:trigger_automate_value_updates).and_return("dynamic values") + allow(dialog_field).to receive(:extract_dynamic_values).and_return("dynamic values") end context 'when wanting the excluded set of attributes' do diff --git a/spec/models/dialog_field_sorted_item_spec.rb b/spec/models/dialog_field_sorted_item_spec.rb index b3d40561866..b13c03fbb8f 100644 --- a/spec/models/dialog_field_sorted_item_spec.rb +++ b/spec/models/dialog_field_sorted_item_spec.rb @@ -1,4 +1,137 @@ describe DialogFieldSortedItem do + describe "#initialize_value_context" do + let(:dialog_field) do + described_class.new( + :name => "potato_name", + :default_value => default_value, + :dynamic => true, + :load_values_on_init => load_values_on_init, + :show_refresh_button => show_refresh_button, + :values => [%w(test test), %w(test2 test2)] + ) + end + let(:default_value) { "test2" } + let(:automate_values) { [%w(test1 test1), %w(test2 test2), %w(test3 test3)] } + + before do + allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).and_return(automate_values) + end + + context "when show_refresh_button is true" do + let(:show_refresh_button) { true } + + context "when load_values_on_init is true" do + let(:load_values_on_init) { true } + + context "when the default_value is not included in the list of values" do + let(:default_value) { "test4" } + + it "uses the first value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test1") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + + context "when the default_value is included in the list of values" do + let(:default_value) { "test2" } + + it "uses the given value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test2") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + end + + context "when load_values_on_init is false" do + let(:load_values_on_init) { false } + let(:dialog_values) { "potato" } + + it "sets the raw values to the initial values" do + dialog_field.initialize_value_context + expect(dialog_field.instance_variable_get(:@raw_values)).to eq([[nil, ""]]) + end + end + end + + context "when show_refresh_button is false" do + let(:show_refresh_button) { false } + + context "when load_values_on_init is true" do + let(:load_values_on_init) { true } + + context "when the default_value is not included in the list of values" do + let(:default_value) { "test4" } + + it "uses the first value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test1") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + + context "when the default_value is included in the list of values" do + let(:default_value) { "test2" } + + it "uses the given value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test2") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + end + + context "when load_values_on_init is false" do + let(:load_values_on_init) { false } + + context "when the default_value is not included in the list of values" do + let(:default_value) { "test4" } + + it "uses the first value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test1") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + + context "when the default_value is included in the list of values" do + let(:default_value) { "test2" } + + it "uses the given value as the default" do + dialog_field.initialize_value_context + expect(dialog_field.default_value).to eq("test2") + end + + it "sets the values to what should be returned from automate" do + dialog_field.initialize_value_context + expect(dialog_field.extract_dynamic_values).to eq(automate_values) + end + end + end + end + end + describe "#initialize_with_values" do let(:dialog_field) do described_class.new( diff --git a/spec/models/dialog_field_spec.rb b/spec/models/dialog_field_spec.rb index 13e62d0603f..98f99f1421b 100644 --- a/spec/models/dialog_field_spec.rb +++ b/spec/models/dialog_field_spec.rb @@ -104,38 +104,45 @@ end end end + end - describe "#initialize_with_values" do - it "uses #automate_key_name for extracting initial dialog values" do - dialog_value = "dummy dialog value" - df.initialize_with_values(df.automate_key_name => dialog_value) - expect(df.value).to eq(dialog_value) - end + describe "#initialize_value_context" do + let(:field) { described_class.new(:dynamic => dynamic, :value => value) } - it "initializes to nil with no initial value and no default value" do - initial_dialog_values = {} - df.initialize_with_values(initial_dialog_values) - expect(df.value).to be_nil - end + context "when the field is dynamic" do + let(:dynamic) { true } + + context "when the value is blank" do + let(:value) { "" } + let(:automate_value) { "some value from automate" } + + before do + allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).and_return(automate_value) + end - it "initializes to the default value with no initial value and a default value" do - initial_dialog_values = {} - df.default_value = "default_test" - df.initialize_with_values(initial_dialog_values) - expect(df.value).to eq("default_test") + it "sets the value to the automate value" do + field.initialize_value_context + expect(field.instance_variable_get(:@value)).to eq("some value from automate") + end end - it "initializes to the dialog value with a dialog value and no default value" do - initial_dialog_values = {df.automate_key_name => "test"} - df.initialize_with_values(initial_dialog_values) - expect(df.value).to eq("test") + context "when the value is not blank" do + let(:value) { "not blank" } + + it "does not adjust the value" do + field.initialize_value_context + expect(field.instance_variable_get(:@value)).to eq("not blank") + end end + end + + context "when the field is not dynamic" do + let(:dynamic) { false } + let(:value) { "not dynamic" } - it "initializes to the dialog value with a dialog value and a default value" do - initial_dialog_values = {df.automate_key_name => "test"} - df.default_value = "default_test" - df.initialize_with_values(initial_dialog_values) - expect(df.value).to eq("test") + it "does not adjust the value" do + field.initialize_value_context + expect(field.instance_variable_get(:@value)).to eq("not dynamic") end end end @@ -165,10 +172,14 @@ before do allow(DialogFieldSerializer).to receive(:serialize).with(dialog_field) + allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return( + "automate values" + ) end - it "serializes the dialog field" do - expect(DialogFieldSerializer).to receive(:serialize).with(dialog_field) + it "triggers an automate value update and then serializes the field" do + expect(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).ordered + expect(DialogFieldSerializer).to receive(:serialize).with(dialog_field).ordered dialog_field.update_and_serialize_values end end diff --git a/spec/models/dialog_field_text_box_spec.rb b/spec/models/dialog_field_text_box_spec.rb index 8a6e7b28047..002f0abe205 100644 --- a/spec/models/dialog_field_text_box_spec.rb +++ b/spec/models/dialog_field_text_box_spec.rb @@ -9,7 +9,7 @@ context "dialog field text box without options hash" do let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') } - + it "#protected?" do expect(df).not_to be_protected end @@ -18,15 +18,6 @@ df.protected = true expect(df).to be_protected end - - describe "#initialize_with_values" do - it "decrypts protected automate dialog values" do - password = "test" - df.protected = true - df.initialize_with_values(df.automate_key_name => MiqPassword.encrypt(password)) - expect(df.value).to eq(password) - end - end end context "dialog field text box without protected field" do @@ -160,92 +151,43 @@ end describe "#value" do - let(:dialog_field) { described_class.new(:dynamic => dynamic, :value => value, :data_type => data_type) } + let(:dialog_field) { described_class.new(:value => value, :data_type => data_type) } - context "when the dialog field is dynamic" do - let(:dynamic) { true } - - context "when the dialog field has a value already" do - let(:value) { "test" } - - context "when the data type is integer" do - let(:data_type) { "integer" } - - it "converts the data into an integer" do - expect(dialog_field.value).to eq(0) - end - end + context "when the value is nil" do + let(:value) { nil } - context "when the data type is string" do - let(:data_type) { "string" } + context "when the data_type is integer" do + let(:data_type) { "integer" } - it "returns the current value" do - expect(dialog_field.value).to eq("test") - end + it "returns nil" do + expect(dialog_field.value).to be_nil end end - context "when the dialog field does not have a value" do - let(:value) { "" } - - before do - allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return("processor") - end - - context "when the data type is an integer" do - let(:data_type) { "integer" } + context "when the data_type is string" do + let(:data_type) { "string" } - it "converts the data into an integer" do - expect(dialog_field.value).to eq(0) - end - end - - context "when the data type is a string" do - let(:data_type) { "string" } - - it "returns the values from the value processor" do - expect(dialog_field.value).to eq("processor") - end + it "returns nil" do + expect(dialog_field.value).to be_nil end end end - context "when the dialog field is not dynamic" do - let(:dynamic) { false } + context "when the value is not nil" do + let(:value) { "test" } - context "when the data type is integer" do + context "when the data_type is integer" do let(:data_type) { "integer" } - context "when the value is nil" do - let(:value) { nil } - - it "returns nil" do - expect(dialog_field.value).to eq(nil) - end - end - - context "when the value is not nil" do - let(:value) { "test" } - - it "converts the data into an integer" do - expect(dialog_field.value).to eq(0) - end - end - - context "when there is no value" do - let(:value) { nil } - - it "does not convert nil value to zero" do - expect(dialog_field.value).to be_nil - end + it "returns an integer converted value" do + expect(dialog_field.value).to eq(0) end end - context "when the data type is string" do + context "when the data_type is string" do let(:data_type) { "string" } - let(:value) { "test" } - it "returns the current value" do + it "returns the string" do expect(dialog_field.value).to eq("test") end end diff --git a/spec/models/resource_action_workflow_spec.rb b/spec/models/resource_action_workflow_spec.rb index 97458540489..a3803a55ea4 100644 --- a/spec/models/resource_action_workflow_spec.rb +++ b/spec/models/resource_action_workflow_spec.rb @@ -31,14 +31,6 @@ expect(@wf.dialog.id).to eq(@dialog.id) end - it "load default_value" do - @dialog_field.update_attribute(:default_value, "testing default") - @wf = ResourceActionWorkflow.new({}, admin, @resource_action) - expect(@wf.value(@dialog_field.name)).to eq("testing default") - df = @wf.dialog_field(@dialog_field.name) - expect(df.value).to eq("testing default") - end - it "field_name_exists?" do expect(@dialog.field_name_exist?('field_1')).to be_truthy expect(@dialog.field_name_exist?('field_11')).to be_falsey @@ -121,17 +113,17 @@ let(:resource_action) { instance_double("ResourceAction", :id => 123, :dialog => dialog) } let(:dialog) { instance_double("Dialog", :id => 321) } let(:values) { "the values" } - let(:options) { {:display_view_only => display_view_only} } before do allow(ResourceAction).to receive(:find).and_return(resource_action) - allow(dialog).to receive(:init_fields_with_values).with(values) + allow(dialog).to receive(:load_values_into_fields).with(values) + allow(dialog).to receive(:initialize_value_context).with(values) allow(dialog).to receive(:init_fields_with_values_for_request).with(values) allow(dialog).to receive(:target_resource=) end context "when the options set display_view_only to true" do - let(:display_view_only) { true } + let(:options) { {:display_view_only => true} } it "calls init_fields_with_values_for_request" do expect(dialog).to receive(:init_fields_with_values_for_request).with(values) @@ -139,11 +131,20 @@ end end - context "when the options set display_view_only to false" do - let(:display_view_only) { false } + context "when the options are set to a refresh request" do + let(:options) { {:refresh => true} } + + it "loads the values into fields" do + expect(dialog).to receive(:load_values_into_fields).with(values) + ResourceActionWorkflow.new(values, nil, resource_action, options) + end + end + + context "when neither display_view_only nor refresh are true" do + let(:options) { {} } - it "calls init_fields_with_values" do - expect(dialog).to receive(:init_fields_with_values).with(values) + it "initializes the value context" do + expect(dialog).to receive(:initialize_value_context).with(values) ResourceActionWorkflow.new(values, nil, resource_action, options) end end