class MigrationValidators::Spec::Matchers::DBMatchers::BaseDbMatcher

Attributes

last_exception[R]
last_operation[R]
last_value[R]

Public Class Methods

new(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 6
def initialize *values
  update_and_insert *values
  @all = true
end

Public Instance Methods

all(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 46
def all *values
  @values = values.flatten
  @all = true
  self
end
Also aliased as: for_all_from, for_all
all?() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 63
def all?
  @all
end
and_message(message)
Alias for: with_message
at_least_one(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 54
def at_least_one *values
  @values = values.flatten
  @all = false
  self
end
at_least_one?() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 67
def at_least_one?
  !all?
end
for_all(*values)
Alias for: all
for_all_from(*values)
Alias for: all
for_at_least_one(*values)
Alias for: at_least_one
for_at_least_one_from(*values)
Alias for: at_least_one
from(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 32
def from *values
  @values = values.flatten
  self
end
from_initial(*values)
Alias for: initial
initial(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 11
def initial *values
  @initial = values
  self
end
Also aliased as: from_initial, with_initial
insert(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 25
def insert *values
  @values = values.flatten
  @update = false
  @insert = true
  self
end
insert?() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 42
def insert?
  @insert
end
insert_and_update(*values)
Alias for: update_and_insert
matches?(column_wrapper) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 103
def matches? column_wrapper
  column_wrapper.insert(@initial) if @initial
  
  MigrationValidators::Spec::Support::ColumnWrapper.to_array(values).each do |value|
    passed = true

    if insert?
      column_wrapper.insert value
      passed = check_result(value, column_wrapper.last_exception, :insert)
    end

    if update? && passed
      column_wrapper.update value
      passed = check_result(value, column_wrapper.last_exception, :update)
    end

    return false if all? && !passed
    return true if passed && at_least_one?
  end

  all?
end
message() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 99
def message
  @message || ""
end
operations_array() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 84
def operations_array
  res = []

  res << :update if update?
  res << :insert if insert?

  res
end
update(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 18
def update *values
  @values = values.flatten
  @update = true
  @insert = false
  self
end
update?() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 37
def update?
  @update
end
update_and_insert(*values) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 75
def update_and_insert *values
  @values = values.flatten
  @update = true
  @insert = true
  self
end
Also aliased as: insert_and_update
values() click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 71
def values
  @values
end
with_initial(*values)
Alias for: initial
with_message(message) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 93
def with_message message
  @message = message
  self
end
Also aliased as: and_message

Protected Instance Methods

check_result(value, exception, operation) click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 133
def check_result value, exception, operation
  @last_operation = operation
  @last_value = value
  @last_exception = exception

  true
end
compose_message() { |operations_name, elements_name, last_message, expected_message| ... } click to toggle source
# File lib/migration_validators/spec/matchers/db_matchers.rb, line 141
def compose_message &block
        
  operations_name = operations_array.join(' and operation ')
  elements_name = all? ? 'all_elements' : 'at least one element'
  last_message = last_exception ? "'#{last_exception.message}'" : ""
  expected_message = message.blank? ?  "" : "with message '#{message.kind_of?(Regexp) ?  message.source : message.inspect  }'"

  yield operations_name, elements_name, last_message, expected_message
end