module Pathway::Rspec::FormSchemaHelpers

Public Instance Methods

accepting_null_list() click to toggle source
# 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?() click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 60
def defined
  @defined ||= @fields & rules.keys
end
not_accepting_null_list() click to toggle source
# 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?() click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 56
def not_defined
  @not_defined ||= @fields - defined
end
not_defined_list() click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 52
def not_optional
  @not_optional ||= defined - optional
end
not_required() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 48
def not_required
  @not_required ||= defined - required
end
null_value_allowed() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 36
def optional
  @optional ||= @fields.select { |field| optional?(field) }
end
optional?(field) click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 32
def required
  @required ||= @fields.select { |field| required?(field) }
end
required?(field) click to toggle source
# 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() click to toggle source
# File lib/pathway/rspec/matchers/form_schema_helpers.rb, line 11
def rules
  @form.schema.rules
end