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 25, 2019
1 parent 09a089d commit 947ceb9
Show file tree
Hide file tree
Showing 3 changed files with 36 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
4 changes: 3 additions & 1 deletion app/models/dialog_field_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def import_field(dialog_field_attributes, export_version = DialogImportService::
end
end



if DialogField::DIALOG_FIELD_TYPES.include?(dialog_field_attributes["type"])
dialog_field_type_class = dialog_field_attributes["type"].constantize
resource_action_attributes = dialog_field_attributes.delete("resource_action")
Expand All @@ -28,7 +30,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
32 changes: 32 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,38 @@
end
end

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

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

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

context "set to false" do
let(:visible) { false }
it "false" do
dialog_field_importer.import_field(dialog_field)
expect(DialogField.first.visible).to eq(false)
end
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 947ceb9

Please sign in to comment.