Module: CanonicalIntegrationCases::ClassMethods

Defined in:
lib/predicated/test_integration/canonical_integration_cases.rb

Instance Method Summary collapse

Instance Method Details

#create_canonical_tests(attrs) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/predicated/test_integration/canonical_integration_cases.rb', line 14

def create_canonical_tests(attrs)
  tests = {
    "simple eq" => { Predicate{ Eq(attrs[:id], 101) } => [101] },
    "string eq" => { Predicate{ Eq(attrs[:eye_color],"blue") } => [102] },
    "simple gt" => { Predicate{ Gt(attrs[:cats], 1) } => [102, 103] },
    "simple lt" => { Predicate{ Lt(attrs[:cats], 3) } => [101, 102] },
    "simple gte" => { Predicate{ Gte(attrs[:cats], 2) } => [102, 103] },
    "simple lte" => { Predicate{ Lte(attrs[:cats], 2) } => [101, 102] },
    "simple not" => { Predicate{ Not(Eq(attrs[:eye_color],"blue")) } => [101, 103] },
    "simple and / or" => {
      Predicate{And(Eq(attrs[:height],"tall"),Eq(attrs[:age],"old"))} => [102],
      Predicate{And(Eq(attrs[:height],"short"),Eq(attrs[:age],"old"))} => [101],
      Predicate{Or(Eq(attrs[:height],"short"),Eq(attrs[:age],"young")) } => [101, 103]
    },
    "complex and / or" => {
      
      Predicate{ 
        Or(
          And(
            Eq(attrs[:height],"short"),
            Eq(attrs[:age],"young")
          ),
          Eq(attrs[:eye_color],"red")
        ) 
      } => [101, 103],
      
      Predicate{ 
        Or(
          And(
            Eq(attrs[:height],"tall"),
            Eq(attrs[:age],"old")
          ),
          Eq(attrs[:eye_color],"green")
        ) 
      } => [102, 103]
    }
  }
  
  tests.each do |test_name, cases|
    test test_name do
      cases.each do |predicate, expected_ids|
        actual_ids = yield(predicate).sort
        assert { actual_ids == expected_ids }
      end
    end
  end
end