Sha256: 813f8a3a5a152c46415c7edaff28eec9025e412137a391429ff043b933ba70d4

Contents?: true

Size: 745 Bytes

Versions: 1

Compression:

Stored size: 745 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 negative_failure_message
        "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.2.0 lib/dm/matchers/belong_to.rb