Skip to content

Commit

Permalink
Validate bools with inclusion, since presence fails: false.blank? => …
Browse files Browse the repository at this point in the history
…true
  • Loading branch information
d-m-u committed Jun 26, 2019
1 parent 0dea2f8 commit 65e367a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DialogField < ApplicationRecord

default_value_for :required, false
default_value_for(:visible) { true }
validates :visible, :presence => true
validates :visible, inclusion: { in: [ true, false ] }
default_value_for :load_values_on_init, true

serialize :values
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_field_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def import_field(dialog_field_attributes, export_version = DialogImportService::
if dialog_field_attributes["type"] == "DialogFieldTagControl"
set_category_for_tag_control(dialog_field, dialog_field_attributes)
end
dialog_field.save
dialog_field.save!

dialog_field
elsif dialog_field_attributes["type"].nil?
Expand Down
24 changes: 24 additions & 0 deletions spec/models/dialog_field_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@
end
end

context "#visible?" do
let(:dialog_field) do
{
"type" => "DialogFieldTextBox",
"name" => "Something else"
}
end

it "without visible setting defaults to true" do
dialog_field_importer.import_field(dialog_field)
expect(DialogField.first.visible?).to eq(true)
end

it "false" do
dialog_field_importer.import_field(dialog_field.merge("visible" => false))
expect(DialogField.first.visible?).to eq(false)
end

it "true" do
dialog_field_importer.import_field(dialog_field.merge("visible" => true))
expect(DialogField.first.visible?).to eq(true)
end
end

context "when the type of the dialog field is not included in DIALOG_FIELD_TYPES and not nil" do
let(:type) { "potato" }

Expand Down

0 comments on commit 65e367a

Please sign in to comment.