Sha256: 0e15f99c73ef57e831c95d1e1af2f884ba0fc0e24de7d4c7682f8b53816d01ab

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

require File.join(File.dirname(__FILE__), "/../../../spec_helper.rb")

describe Mongoid::Associations::AssociationFactory do

  describe "#create" do

    before do
      @document = Person.new
    end

    context "when type is has_many" do

      it "returns a HasManyAssociationProxy" do
        association = Mongoid::Associations::AssociationFactory.create(:has_many, :addresses, @document)
        association.should be_a_kind_of(Mongoid::Associations::HasManyAssociation)
      end

    end

    context "when type is has_one" do

      it "returns a HashOneAssociationProxy" do
        association = Mongoid::Associations::AssociationFactory.create(:has_one, :name, @document)
        association.should be_a_kind_of(Mongoid::Associations::HasOneAssociation)
      end

    end

    context "when type is belongs_to" do

      it "returns a BelongsToAssociationProxy" do
        association = Mongoid::Associations::AssociationFactory.create(:belongs_to, :person, @document)
        association.should be_a_kind_of(Mongoid::Associations::BelongsToAssociation)
      end

    end

    context "when type is invalid" do

      it "should raise a InvalidAssociationError" do
        lambda { Mongoid::Associations::AssociationFactory.create(:something, :person, @document) }.should raise_error
      end

    end

  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
durran-mongoid-0.2.0 spec/unit/mongoid/associations/association_factory_spec.rb
durran-mongoid-0.2.2 spec/unit/mongoid/associations/association_factory_spec.rb
durran-mongoid-0.2.3 spec/unit/mongoid/associations/association_factory_spec.rb
durran-mongoid-0.2.4 spec/unit/mongoid/associations/association_factory_spec.rb
mongoid-0.2.7 spec/unit/mongoid/associations/association_factory_spec.rb
mongoid-0.2.6 spec/unit/mongoid/associations/association_factory_spec.rb
mongoid-0.2.5 spec/unit/mongoid/associations/association_factory_spec.rb