Sha256: 4e2b54346eed58efe6651517978535befe4ecb85489eb365815035662df18dd5

Contents?: true

Size: 953 Bytes

Versions: 54

Compression:

Stored size: 953 Bytes

Contents

require "spec_helper"

describe Mongoid::Relations::Bindings::Embedded::Many do

  let(:person) do
    Person.new
  end

  let(:address) do
    Address.new
  end

  let(:target) do
    [ address ]
  end

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

  describe "#bind_one" do

    let(:binding) do
      described_class.new(person, target, metadata)
    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

54 entries across 49 versions & 3 rubygems

Version Path
mongoid-6.4.8 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.7 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.5 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-5.4.1 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.4 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.2 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.1 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-5.4.0 spec/mongoid/relations/bindings/embedded/many_spec.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.4.0 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.3.0 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.2.1 spec/mongoid/relations/bindings/embedded/many_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/relations/bindings/embedded/many_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/relations/bindings/embedded/many_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.2.0 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.1.1 spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-5.2.1 spec/mongoid/relations/bindings/embedded/many_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/relations/bindings/embedded/many_spec.rb
mongoid-6.1.0 spec/mongoid/relations/bindings/embedded/many_spec.rb