cirandas.net

ref: master

test/unit/custom_field_values_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require_relative "../test_helper"

class CustomFieldValuesTest < ActiveSupport::TestCase

  should 'custom field value not be valid' do
    c = CustomField.create!(:name => "Blog", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    person = create_user('testinguser').person

    cv=CustomFieldValue.new(:customized => person, :custom_field => c, :value => "")
    refute cv.valid?
  end

  should 'return only public custom field values in public scope' do
    c = CustomField.create!(:name => "Blog", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    person = create_user('testinguser').person
    cfv = CustomFieldValue.create(:value => 'value1', :public => true, :customized => person, :custom_field => c)
    c = CustomField.create!(:name => "Another", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    CustomFieldValue.create(:value => 'value2', :public => false, :customized => person, :custom_field => c)
    assert_equal [cfv], CustomFieldValue.only_public
  end

  should 'return only non public custom field values in not_public scope' do
    c = CustomField.create!(:name => "Blog", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    person = create_user('testinguser').person
    CustomFieldValue.create(:value => 'value1', :public => true, :customized => person, :custom_field => c)
    c = CustomField.create!(:name => "Another", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    cfv = CustomFieldValue.create(:value => 'value2', :public => false, :customized => person, :custom_field => c)
    assert_equal [cfv], CustomFieldValue.not_public
  end

  should 'return custom field value by custom field name' do
    c = CustomField.create!(:name => "some", :format => "string", :customized_type => "Person", :active => true, :required => true, :environment => Environment.default)
    person = create_user('testinguser').person
    cfv = CustomFieldValue.create(:value => 'value1', :public => true, :customized => person, :custom_field => c)
    assert_equal [cfv], CustomFieldValue.by_field('some')
  end
end