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

[GAPRINDASHVILI] Set checkbox on load, sans default, to be false, not nil #17810

Merged
merged 1 commit into from
Aug 9, 2018
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
8 changes: 7 additions & 1 deletion app/models/dialog_field_check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ def checked?
value == "t"
end

def initialize_value_context
if @value.blank?
@value = dynamic ? values_from_automate : default_value.presence || initial_values
end
end

def initial_values
false
'f'
end

def script_error_values
Expand Down
39 changes: 37 additions & 2 deletions spec/models/dialog_field_check_box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,46 @@
end
end

describe "#initialize_value_context" do
context "dynamic" do
let(:dialog_field) { described_class.new(:dynamic => true) }
before do
allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return("f")
end

it "returns automate vals" do
dialog_field.initialize_value_context

expect(dialog_field.value).to eq('f')
end
end

context "not dynamic" do
context "with default" do
let(:dialog_field) { described_class.new(:default_value => "t") }
it "returns default" do
dialog_field.initialize_value_context

expect(dialog_field.value).to eq('t')
end
end

context "without default" do
let(:dialog_field) { described_class.new(:default_value => nil) }
it "returns initial vals" do
dialog_field.initialize_value_context

expect(dialog_field.value).to eq('f')
end
end
end
end

describe "#initial_values" do
let(:dialog_field) { described_class.new }

it "returns false" do
expect(dialog_field.initial_values).to be_falsey
expect(dialog_field.initial_values).to eq('f')
end
end

Expand Down Expand Up @@ -85,7 +120,7 @@
end

it "returns the initial values" do
expect(dialog_field.normalize_automate_values(automate_hash)).to eq(false)
expect(dialog_field.normalize_automate_values(automate_hash)).to eq('f')
end
end
end
Expand Down