Sha256: 9e001b551cc60618de3cadec1cc8e1e6d1591de5895a2642597397c7b5c87c13

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Mongoid
  module Matchers
    module Validations
      class ValidateUniquenessMatcher < HaveValidationMatcher
        def initialize(field)
          super(field, :uniqueness)
        end

        def case_insensitive
          @case_insensitive = true
          self
        end

        def matches?(klass)
          return false unless @result = super(klass)

          check_case_sensivity if @case_insensitive

          @result
        end

        def check_case_sensivity
          if @validator.options[:case_sensitive] == false
            @positive_message << " with case insensitive values"
          else
            @negative_message << " without case insensitive values"
            @result = false
          end
        end

        def description
          desc =  []
          desc << " allowing case insensitive values" if @case_insensitive
          super << desc.to_sentence
        end
      end

      def validate_uniqueness_of(field)
        ValidateUniquenessMatcher.new(field)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-minitest-0.0.1 lib/matchers/validations/uniqueness_of.rb