Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwaterworth authored and janzenisaac committed Jan 8, 2024
1 parent 75c6454 commit 50911b2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/lib/concern/has_custom_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ class CustomFieldsTestItemCustomField < ActiveRecord::Base
).to eq(1)
end

it "stores boolean values in boolean fields as t or f" do
test_item = CustomFieldsTestItem.new
CustomFieldsTestItem.register_custom_field_type("bool", :boolean)

test_item.custom_fields["bool"] = "true"
test_item.save_custom_fields

expect(CustomFieldsTestItemCustomField.last.value).to eq("t")

test_item.custom_fields["bool"] = "false"
test_item.save_custom_fields

expect(CustomFieldsTestItemCustomField.last.value).to eq("f")
end

it "coerces non-integer values in integer fields" do
test_item = CustomFieldsTestItem.new
CustomFieldsTestItem.register_custom_field_type("int", :integer)

test_item.custom_fields["int"] = "true"
test_item.save_custom_fields

expect(CustomFieldsTestItemCustomField.last.value).to eq("0")
end

it "supports type coercion" do
test_item = CustomFieldsTestItem.new
CustomFieldsTestItem.register_custom_field_type("bool", :boolean)
Expand Down

0 comments on commit 50911b2

Please sign in to comment.