Sha256: 1fc87e2bc73878e9356da208f1ec1949c1c08c96a6c8a3818bd9325e6f713a56

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'


module ManyAssociationSpec
  include MongoMapper::Plugins::Associations
  describe "ManyAssociation" do

    context "class_name" do
      it "should camelize the name" do
        ManyAssociation.new(:smart_people).class_name.should == 'SmartPerson'
      end

      it "should be changeable using class_name option" do
        base = ManyAssociation.new(:smart_people, :class_name => 'IntelligentPerson')
        base.class_name.should == 'IntelligentPerson'
      end
    end

    context "type_key_name" do
      it "should be _type" do
        ManyAssociation.new(:foos).type_key_name.should == '_type'
      end
    end

    context "embeddable?" do
      it "should be true if class is embeddable" do
        base = ManyAssociation.new(:medias)
        base.embeddable?.should be_true
      end

      it "should be false if class is not embeddable" do
        base = ManyAssociation.new(:statuses)
        base.embeddable?.should be_false
      end
    end

    context "proxy_class" do
      it "should be ManyDocumentsProxy for many" do
        base = ManyAssociation.new(:statuses)
        base.proxy_class.should == ManyDocumentsProxy
      end

      it "should be ManyPolymorphicProxy for polymorphic many" do
        base = ManyAssociation.new(:messages, :polymorphic => true)
        base.proxy_class.should == ManyPolymorphicProxy
      end

      it "should be ManyEmbeddedProxy for many embedded" do
        base = ManyAssociation.new(:medias)
        base.proxy_class.should == ManyEmbeddedProxy
      end

      it "should be ManyEmbeddedPolymorphicProxy for polymorphic many embedded" do
        base = ManyAssociation.new(:medias, :polymorphic => true)
        base.proxy_class.should == ManyEmbeddedPolymorphicProxy
      end

      it "should be InArrayProxy for many with :in option" do
        base = ManyAssociation.new(:messages, :in => :message_ids)
        base.proxy_class.should == InArrayProxy
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongo_mapper-0.13.1 spec/unit/associations/many_association_spec.rb
mongo_mapper-0.13.0 spec/unit/associations/many_association_spec.rb
mongo_mapper-0.13.0.beta2 spec/unit/associations/many_association_spec.rb
mongo_mapper-0.13.0.beta1 spec/unit/associations/many_association_spec.rb