Sha256: 464ecee29dfb710ea88de400654827f2e45100cc1ba928d3cf40684013cca047

Contents?: true

Size: 1022 Bytes

Versions: 6

Compression:

Stored size: 1022 Bytes

Contents

module Remarkable
  module MongoMapper
    module Matchers
      class ValidatePresenceOfMatcher < Remarkable::MongoMapper::Base
        arguments :collection => :attributes, :as => :attribute
        optional  :message

        collection_assertions :allow_nil?
        default_options :message => "can't be empty"

        protected

          def allow_nil?
            bad?(nil, :message)
          end

      end
      
      # Ensures that the model cannot be saved if one of the attributes listed is not present.
      #
      # == Options
      #
      # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
      #   Regexp, string or symbol. Default = "can't be empty"
      #
      # == Examples
      #
      #   should_validate_presence_of :name, :phone_number
      #   it { should validate_presence_of(:name, :phone_number) }
      #
      def validate_presence_of(*args, &block)
        ValidatePresenceOfMatcher.new(*args, &block).spec(self)
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
yeastymobs-remarkable_mongomapper-0.1.1 lib/remarkable_mongomapper/matchers/validate_presence_of_matcher.rb
remarkable_mongo-0.1.4 lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb
remarkable_mongo-0.1.3 lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb
remarkable_mongo_ign-0.1.2 lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb
ippy04-remarkable_mongo-0.1.3 lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb
remarkable_mongo-0.1.2 lib/remarkable/mongo_mapper/matchers/validate_presence_of_matcher.rb