Module: Pathway::Rspec::FormSchemaHelpers
- Includes:
- FieldListHelpers
- Defined in:
- lib/pathway/rspec/matchers/form_schema_helpers.rb
Instance Method Summary
collapse
#field_list, #pluralize_fields, #were_was
#as_list, #as_sentence
Instance Method Details
#accepting_null_list ⇒ Object
24
25
26
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 24
def accepting_null_list
"#{as_list(null_value_allowed)} #{were_was(null_value_allowed)} accepting null values" if @not_allowing_null_values && null_value_allowed.any?
end
|
#allowing_null_values_matches? ⇒ Boolean
80
81
82
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 80
def allowing_null_values_matches?
@allowing_null_values ? @fields.all? { |field| null_value_allowed?(field) } : true
end
|
#defined ⇒ Object
60
61
62
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 60
def defined
@defined ||= @fields & rules.keys
end
|
#not_accepting_null_list ⇒ Object
28
29
30
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 28
def not_accepting_null_list
"#{as_list(null_value_disallowed)} #{were_was(null_value_disallowed)} not accepting null values" if @allowing_null_values && null_value_disallowed.any?
end
|
#not_allowing_null_values_matches? ⇒ Boolean
84
85
86
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 84
def not_allowing_null_values_matches?
@not_allowing_null_values ? @fields.all? { |field| null_value_disallowed?(field) } : true
end
|
#not_defined ⇒ Object
56
57
58
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 56
def not_defined
@not_defined ||= @fields - defined
end
|
#not_defined_list ⇒ Object
20
21
22
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 20
def not_defined_list
"#{as_list(not_defined)} #{were_was(not_defined)} not defined" if not_defined.any?
end
|
#not_optional ⇒ Object
52
53
54
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 52
def not_optional
@not_optional ||= defined - optional
end
|
#not_required ⇒ Object
48
49
50
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 48
def not_required
@not_required ||= defined - required
end
|
#null_value_allowed ⇒ Object
40
41
42
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 40
def null_value_allowed
@null_value_allowed ||= @fields.select { |field| null_value_allowed?(field) }
end
|
#null_value_allowed?(field) ⇒ Boolean
88
89
90
91
92
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 88
def null_value_allowed?(field)
rule = rules[field]&.right&.rule
predicate = rule&.left
predicate.present? && predicate.type == :not && predicate.rules&.first&.name == :nil?
end
|
#null_value_disallowed ⇒ Object
44
45
46
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 44
def null_value_disallowed
@null_value_disallowed ||= @fields.select { |field| null_value_disallowed?(field) }
end
|
#null_value_disallowed?(field) ⇒ Boolean
94
95
96
97
98
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 94
def null_value_disallowed?(field)
rule = rules[field]&.right&.rule
predicate = rule&.left
predicate.present? && predicate.type == :predicate && predicate.name == :filled?
end
|
#optional ⇒ Object
36
37
38
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 36
def optional
@optional ||= @fields.select { |field| optional?(field) }
end
|
#optional?(field) ⇒ Boolean
64
65
66
67
68
69
70
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 64
def optional?(field)
if rules[field]&.type == :implication
left = rules[field].left
left.type == :predicate && left.name == :key? && left.args.first == field
end
end
|
#required ⇒ Object
32
33
34
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 32
def required
@required ||= @fields.select { |field| required?(field) }
end
|
#required?(field) ⇒ Boolean
72
73
74
75
76
77
78
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 72
def required?(field)
if rules[field]&.type == :and
left = rules[field].left
left.type == :predicate && left.name == :key? && left.args.first == field
end
end
|
#rules ⇒ Object
11
12
13
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 11
def rules
@form.schema.rules
end
|