add tests

This commit is contained in:
Daniel Waterworth 2024-01-05 13:18:55 -06:00 committed by Isaac Janzen
parent 75c645453d
commit 50911b2579
No known key found for this signature in database
GPG Key ID: D75AF9C21FD8EBCD
1 changed files with 25 additions and 0 deletions

View File

@ -222,6 +222,31 @@ RSpec.describe HasCustomFields do
).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)