Sha256: d8c4f1cd3a3f261f0aaf5aa9b94f1cccc6c70e3556783bdaa959da1d6fc170e0

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require "spec_helper"

describe Mongoid::Associations::RelatesToOne do

  describe ".initialize" do

    context "when related id has been set" do

      before do
        @document = stub(:game_id => "5")
        @options = Mongoid::Associations::Options.new(:name => :game)
        @related = stub
      end

      it "finds the object by id" do
        Game.expects(:find).with(@document.game_id).returns(@related)
        association = Mongoid::Associations::RelatesToOne.new(@document, @options)
        association.should == @related
      end

    end

  end

  describe ".macro" do

    it "returns :relates_to_one" do
      Mongoid::Associations::RelatesToOne.macro.should == :relates_to_one
    end

  end

  describe ".update" do

    before do
      @related = stub(:id => "5")
      @parent = Person.new
      @options = Mongoid::Associations::Options.new(:name => :game)
    end

    it "sets the related object id on the parent" do
      Mongoid::Associations::RelatesToOne.update(@related, @parent, @options)
      @parent.game_id.should == "5"
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-0.9.6 spec/unit/mongoid/associations/relates_to_one_spec.rb
mongoid-0.9.5 spec/unit/mongoid/associations/relates_to_one_spec.rb
mongoid-0.9.4 spec/unit/mongoid/associations/relates_to_one_spec.rb
mongoid-0.9.3 spec/unit/mongoid/associations/relates_to_one_spec.rb