Module: Veneer::Lint::Properties

Includes:
Base
Defined in:
lib/veneer/lint/properties.rb

Instance Method Summary collapse

Methods included from Base

#test_should_setup_the_veneer_lint_class_wrapper_with_a_klass

Instance Method Details

#property_by_name(name) ⇒ Object



73
74
75
# File 'lib/veneer/lint/properties.rb', line 73

def property_by_name(name)
  Veneer(@klass).properties.find { |prop| prop.name == name } or raise "Couldn't find property #{name}."
end

#test_constraintsObject



45
46
47
48
49
# File 'lib/veneer/lint/properties.rb', line 45

def test_constraints
  Veneer(@klass).properties.each do |property|
    assert_not_nil property[:constraints]
  end
end

#test_lengthObject



51
52
53
54
55
# File 'lib/veneer/lint/properties.rb', line 51

def test_length
  @properties_with_length.each do |name, length|
    assert_equal length, property_by_name(name).constraints[:length], "Expected #{name}.length to be #{length}."
  end
end

#test_primary_keysObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/veneer/lint/properties.rb', line 31

def test_primary_keys
  wrapped = Veneer(@klass)
  properties = wrapped.properties
  primary_keys = wrapped.primary_keys
  
  assert_equal @primary_keys, wrapped.primary_keys


  desired_primary_keys = properties.select { |property| primary_keys.include? property.name }
  assert_equal primary_keys.size, desired_primary_keys.size
  
  desired_primary_keys.each { |key| assert key.primary? }
end

#test_propertiesObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/veneer/lint/properties.rb', line 20

def test_properties
  result = Veneer(@klass).properties
  assert result.kind_of?(Array)
  assert result.size > 0
  property = result.first
  assert_kind_of Veneer::Base::Property, property
  assert_kind_of Class, property.type
  assert_kind_of Symbol, property.name
  assert_not_nil property.primary?
end

#test_should_setup_expected_primary_keysObject



15
16
17
18
# File 'lib/veneer/lint/properties.rb', line 15

def test_should_setup_expected_primary_keys
  assert_not_nil @primary_keys
  assert_kind_of Array, @primary_keys
end

#test_should_setup_properties_mappingObject



6
7
8
9
10
11
12
13
# File 'lib/veneer/lint/properties.rb', line 6

def test_should_setup_properties_mapping
  assert_not_nil @properties_mapping
  assert_kind_of Hash, @properties_mapping
  @properties_mapping.each do |k, v|
    assert_kind_of Symbol, k
    assert_kind_of Class, v
  end
end

#test_types_conversionObject



57
58
59
60
61
# File 'lib/veneer/lint/properties.rb', line 57

def test_types_conversion
  @properties_mapping.each do |name, expected_normalized_type|
    assert_equal expected_normalized_type, property_by_name(name).type, "Expected #{name} to be #{expected_normalized_type}."
  end
end

#test_validationsObject



63
64
65
66
67
68
69
70
71
# File 'lib/veneer/lint/properties.rb', line 63

def test_validations
  @properties_with_validations.each do |name, validator_classes|
    validators = Veneer(@klass).validators_on(name)
    assert_equal validator_classes.size, validators.size
    validators.zip(validator_classes).each do |validator, expected_class|
      assert_kind_of expected_class, validator
    end
  end
end