class MR::TestHelpers::AssociationSavedAssertionBase

Constants

NULL_MODEL
NullModel
NullRecord
NullRecordClass

Public Class Methods

new(model, association, expected_value) click to toggle source
# File lib/mr/test_helpers.rb, line 67
def initialize(model, association, expected_value)
  reflection = model.record.association(association).reflection
  if reflection.macro != :belongs_to
    raise ArgumentError, "association must be a belongs to"
  end
  @expected_value = expected_value || NULL_MODEL
  # use `record.class` instead of `record_class` here, the configured
  # `record_class` won't match the actual `record` class because `record` is
  # a fake record
  expected_foreign_type = @expected_value.record.class.to_s
  expected_foreign_key  = @expected_value.id
  @assertions = [
    build_assertion(model, reflection.foreign_type, expected_foreign_type),
    build_assertion(model, reflection.foreign_key,  expected_foreign_key)
  ].compact
end

Public Instance Methods

run(context) click to toggle source
# File lib/mr/test_helpers.rb, line 84
def run(context)
  @assertions.each{ |a| a.run(context) }
end

Private Instance Methods

build_assertion(model, field, expected_value) click to toggle source
# File lib/mr/test_helpers.rb, line 90
def build_assertion(model, field, expected_value)
  return unless field
  self.field_assertion_class.new(model, field, expected_value)
end