Sha256: 889305d25674f33b8ca9457ef55d7368a3e8e3778b583c9d5c555bef87ab8ff2

Contents?: true

Size: 743 Bytes

Versions: 1

Compression:

Stored size: 743 Bytes

Contents

module DataMapper
  module Matchers

    class BelongTo
      def initialize(parent)
        @parent = parent
      end

      def matches?(child)
        child_class = child.is_a?(Class) ? child : child.class
        relation = child_class.relationships[@parent.to_s]

        relation and
        relation.is_a?(DataMapper::Associations::ManyToOne::Relationship) and
        relation.child_model == child_class
      end

      def failure_message
        "expected to belong to #{@parent}"
      end

      def failure_message_when_negated
        "expected to not belong to #{@parent}"
      end

      def description
        "belongs to #{@parent}"
      end
    end


    def belong_to(name)
      BelongTo.new(name)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-rspec-0.3.0 lib/dm/matchers/belong_to.rb