Sha256: 3b3a1e98a90cbe794344b3197f2c39443a50f94bcc88a689723fb517bd78a2fe

Contents?: true

Size: 902 Bytes

Versions: 4

Compression:

Stored size: 902 Bytes

Contents

module DataMapper
  module Matchers

    class HaveMany
      def initialize(children)
        @children = children
      end

      def matches?(parent)
        @parent = parent
        relation = @parent.relationships[@children.to_s]

        relation and
        relation.is_a?(DataMapper::Associations::OneToMany::Relationship) and
        relation.parent_model == parent
      end

      # called only when the next syntax is used:
      #   Book.should have_many(:tags).trough(:tagging)
      def through(broker)
        HaveManyThrough.new(@children, broker)
      end

      def failure_message
        "expected to have many #{@children}"
      end

      def negative_failure_message
        "expected to not have many #{@children}"
      end
      
      def description
        "has many #{@children}"
      end
    end


    def have_many(name)
      HaveMany.new(name)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dm-rspec-0.2.0 lib/dm/matchers/have_many.rb
dm-rspec-0.1.2 lib/dm/matchers/have_many.rb
dm-rspec-0.1.1 lib/dm/matchers/have_many.rb
dm-rspec-0.1.0 lib/dm/matchers/have_many.rb