class Shoulda::Matchers::ActiveRecord::HaveImplicitOrderColumnMatcher

@private

Attributes

column_name[R]
failure_message[R]
subject[R]

Public Class Methods

new(column_name) click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 33
def initialize(column_name)
  @column_name = column_name
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 61
def description
  expectation
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 55
def failure_message_when_negated
  Shoulda::Matchers.word_wrap(
    "Expected #{model.name} not to #{expectation}, but it did.",
  )
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 37
def matches?(subject)
  @subject = subject
  check_column_exists!
  check_implicit_order_column_matches!
  true
rescue SecondaryCheckFailedError => e
  @failure_message = Shoulda::Matchers.word_wrap(
    "Expected #{model.name} to #{expectation}, " +
    "but that could not be proved: #{e.message}.",
  )
  false
rescue PrimaryCheckFailedError => e
  @failure_message = Shoulda::Matchers.word_wrap(
    "Expected #{model.name} to #{expectation}, but #{e.message}.",
  )
  false
end

Private Instance Methods

check_column_exists!() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 69
def check_column_exists!
  matcher = HaveDbColumnMatcher.new(column_name)

  if !matcher.matches?(@subject)
    raise SecondaryCheckFailedError.new(
      "The :#{model.table_name} table does not have a " +
      ":#{column_name} column",
    )
  end
end
check_implicit_order_column_matches!() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 80
def check_implicit_order_column_matches!
  if model.implicit_order_column.to_s != column_name.to_s
    message =
      if model.implicit_order_column.nil?
        'implicit_order_column is not set'
      else
        "it is :#{model.implicit_order_column}"
      end

    raise PrimaryCheckFailedError.new(message)
  end
end
expectation() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 97
def expectation
  "have an implicit_order_column of :#{column_name}"
end
model() click to toggle source
# File lib/shoulda/matchers/active_record/have_implicit_order_column.rb, line 93
def model
  subject.class
end