2016-02-12 23:52:43 +08:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class CustomFieldTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@custom_field = custom_fields(:volume)
|
|
|
|
end
|
|
|
|
|
2016-10-11 14:25:32 +08:00
|
|
|
should validate_presence_of(:name)
|
2016-10-17 19:21:10 +08:00
|
|
|
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
2016-10-11 14:25:32 +08:00
|
|
|
should validate_exclusion_of(:name)
|
|
|
|
.in_array(['Assigned',
|
|
|
|
'Sample name',
|
|
|
|
'Sample type',
|
|
|
|
'Sample group',
|
|
|
|
'Added on',
|
|
|
|
'Added by'])
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
test "should validate with correct data" do
|
|
|
|
assert @custom_field.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should not validate with non existent user" do
|
|
|
|
@custom_field.user_id = 11231231
|
|
|
|
assert_not @custom_field.valid?
|
|
|
|
@custom_field.user = nil
|
|
|
|
assert_not @custom_field.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should not validate with non existent organization" do
|
|
|
|
@custom_field.organization_id = 1231231
|
|
|
|
assert_not @custom_field.valid?
|
|
|
|
@custom_field.organization = nil
|
|
|
|
assert_not @custom_field.valid?
|
|
|
|
end
|
|
|
|
end
|