mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 20:57:23 +08:00
add tests
This commit is contained in:
parent
75c645453d
commit
50911b2579
@ -222,6 +222,31 @@ RSpec.describe HasCustomFields do
|
|||||||
).to eq(1)
|
).to eq(1)
|
||||||
end
|
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
|
it "supports type coercion" do
|
||||||
test_item = CustomFieldsTestItem.new
|
test_item = CustomFieldsTestItem.new
|
||||||
CustomFieldsTestItem.register_custom_field_type("bool", :boolean)
|
CustomFieldsTestItem.register_custom_field_type("bool", :boolean)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user