Sha256: a1f85c2770a629bb6803e2cfb93eafeac8a151f08b118644af1ca6a18b71db86

Contents?: true

Size: 997 Bytes

Versions: 25

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

require "spec_helper"

describe Mongoid::Association::Embedded::EmbedsMany::Binding do

  let(:person) do
    Person.new
  end

  let(:address) do
    Address.new
  end

  let(:target) do
    [ address ]
  end

  let(:association) do
    Person.relations["addresses"]
  end

  describe "#bind_one" do

    let(:binding) do
      described_class.new(person, target, association)
    end

    context "when the document is bindable" do

      let(:address_two) do
        Address.new
      end

      before do
        binding.bind_one(address_two)
      end

      it "parentizes the document" do
        expect(address_two._parent).to eq(person)
      end

      it "sets the inverse relation" do
        expect(address_two.addressable).to eq(person)
      end
    end

    context "when the document is not bindable" do

      it "does nothing" do
        expect(person.addresses).to receive(:<<).never
        binding.bind_one(address)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mongoid-8.1.8 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.7 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.6 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.8 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.5 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.4 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.7 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.3 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.2 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.6 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-7.5.4 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.1 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.5 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.1.0 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-7.5.3 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.4 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.3 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-7.5.2 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-8.0.2 spec/mongoid/association/embedded/embeds_many/binding_spec.rb
mongoid-7.5.1 spec/mongoid/association/embedded/embeds_many/binding_spec.rb