Skip to content

Commit

Permalink
Set value to be the default for static fields
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jun 25, 2018
1 parent adb2759 commit 0a705d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/models/dialog_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def extract_dynamic_values
end

def initialize_value_context
@value = values_from_automate if dynamic && @value.blank?
if @value.blank?
@value = dynamic ? values_from_automate : default_value
end
end

def initialize_with_values(dialog_values)
Expand Down
23 changes: 19 additions & 4 deletions spec/models/dialog_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

describe "#initialize_value_context" do
let(:field) { described_class.new(:dynamic => dynamic, :value => value) }
let(:field_with_default) { described_class.new(:dynamic => dynamic, :value => value, :default_value => "drew_was_here") }

context "when the field is dynamic" do
let(:dynamic) { true }
Expand Down Expand Up @@ -138,11 +139,25 @@

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

it "does not adjust the value" do
field.initialize_value_context
expect(field.instance_variable_get(:@value)).to eq("not dynamic")
context "with a user-adjusted value" do
let(:value) { "not dynamic" }

it "does not adjust the value" do
field.initialize_value_context
expect(field.instance_variable_get(:@value)).to eq("not dynamic")
end
end

context "without a user-adjusted value" do
context "with a default value" do
let(:value) { nil }

it "does adjust the value" do
field_with_default.initialize_value_context
expect(field_with_default.instance_variable_get(:@value)).to eq("drew_was_here")
end
end
end
end
end
Expand Down

0 comments on commit 0a705d3

Please sign in to comment.