Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set value of static text box to default when default exists #17631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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