Sha256: f22ae254545df5fd4f5c822f48a3a68b713071b2756e90b022cf16ea3a8c8e5f

Contents?: true

Size: 955 Bytes

Versions: 3

Compression:

Stored size: 955 Bytes

Contents

module Remarkable
  module MongoMapper
    module Matchers
      class HaveKeyMatcher < Remarkable::MongoMapper::Base
        
        arguments :type, :collection => :attributes, :as => :attribute
        
        collection_assertions :has_key?
        
        # before_assert do
        #   @type = @options[:type]
        # end

        protected

          def has_key?
            @subject.respond_to?(@attribute) && @subject.class.keys[@attribute] == ::MongoMapper::Key.new(@attribute, @type)
          end

      end
      
      # Ensures that a key of the database actually exists.
      #
      # == Examples
      #
      #   should_have_key :name, String
      #
      #   it { should have_key(:name, String) }
      #   it { should have_keys(:name, :phone_number, String) }
      #
      def have_key(*args, &block)
        HaveKeyMatcher.new(args.pop, *args, &block).spec(self)
      end
      alias :have_keys :have_key

    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
yeastymobs-remarkable_mongomapper-0.1.0 lib/remarkable_mongomapper/matchers/have_key_matcher.rb
yeastymobs-remarkable_mongomapper-0.1.1 lib/remarkable_mongomapper/matchers/have_key_matcher.rb
remarkable_mongo-0.1.2 lib/remarkable/mongo_mapper/matchers/have_key_matcher.rb