Skip to content

Commit

Permalink
Set checkbox on load, sans default, to be false, not nil
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Aug 8, 2018
1 parent a63ea70 commit 6192982
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
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

0 comments on commit 6192982

Please sign in to comment.