| Class | ActiveMatchers::Matchers::ValidationMatcher |
| In: |
lib/matchers/validation_matcher.rb
|
| Parent: | Object |
# File lib/matchers/validation_matcher.rb, line 4 4: def initialize(type, *attributes) 5: @type = type 6: @attributes = attributes 7: end
# File lib/matchers/validation_matcher.rb, line 25
25: def failure_message
26: "Error: #{@error}"
27: end
# File lib/matchers/validation_matcher.rb, line 39
39: def if(&block)
40: @if = block
41: self
42: end
# File lib/matchers/validation_matcher.rb, line 9
9: def matches?(model)
10: @model = model
11: case @type
12: when :require
13: confirm_required(&@if)
14: when :unique
15: confirm_unique
16: when :one_of_many
17: confirm_one_of_many
18: when :length
19: confirm_length
20: else
21: false
22: end
23: end
# File lib/matchers/validation_matcher.rb, line 44
44: def one_of(*attributes)
45: @attributes = attributes
46: @type = :one_of_many
47: self
48: end
# File lib/matchers/validation_matcher.rb, line 55
55: def starting_with(base)
56: @base = base
57: self
58: end
# File lib/matchers/validation_matcher.rb, line 50
50: def to(length)
51: @length = length
52: self
53: end
# File lib/matchers/validation_matcher.rb, line 29
29: def to_be_unique
30: @type = :unique
31: self
32: end