module ShouldaMatchersMysqlUuidFix

Public Instance Methods

attribute_type_for(scope) click to toggle source
# File lib/shoulda/matchers/uuid.rb, line 37
def attribute_type_for(scope)
  return unless model.respond_to?(:attribute_types)

  model.attribute_types[scope.to_s]
end
next_scalar_value_for(scope, previous_value) click to toggle source
# File lib/shoulda/matchers/uuid.rb, line 11
def next_scalar_value_for(scope, previous_value)
  if uuid?(scope)
    SecureRandom.uuid
  elsif defined_as_enum?(scope)
    available_values = available_enum_values_for(scope, previous_value)
    available_values.keys.last
  elsif polymorphic_type_attribute?(scope, previous_value)
    ::Shoulda::Matchers::ActiveRecord::Uniqueness::TestModels.create(previous_value).to_s
  elsif previous_value.respond_to?(:next)
    previous_value.next
  elsif previous_value.respond_to?(:to_datetime)
    previous_value.to_datetime.next
  elsif boolean_value?(previous_value)
    !previous_value
  else
    previous_value.to_s.next
  end
end
uuid?(scope) click to toggle source
# File lib/shoulda/matchers/uuid.rb, line 30
def uuid?(scope)
  [
    column_for(scope),
    attribute_type_for(scope)
  ].compact.map(&:type).include? :uuid
end