Sha256: acd021f2cd101cd87294d933cff6a5f227d0d07916c5b29687d2e8b3ee788572

Contents?: true

Size: 949 Bytes

Versions: 9

Compression:

Stored size: 949 Bytes

Contents

module DataMapper
  module Matchers

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

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

        relation and
        relation.is_a?(DataMapper::Associations::OneToMany::Relationship) and
        relation.parent_model == parent_class
      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

9 entries across 9 versions & 2 rubygems

Version Path
dm-rspec-0.2.4 lib/dm/matchers/have_many.rb
dm-rspec2-0.3.0 lib/dm/matchers/have_many.rb
dm-rspec-0.2.3 lib/dm/matchers/have_many.rb
dm-rspec-0.2.2 lib/dm/matchers/have_many.rb
dm-rspec2-0.2.4 lib/dm/matchers/have_many.rb
dm-rspec2-0.2.3 lib/dm/matchers/have_many.rb
dm-rspec2-0.2.2 lib/dm/matchers/have_many.rb
dm-rspec2-0.2.1 lib/dm/matchers/have_many.rb
dm-rspec-0.2.1 lib/dm/matchers/have_many.rb