Sha256: 1d9fdd9758a412bc338f2a2fa98984d497123f8f39bce3b1c2c7c5b48d39f3e4

Contents?: true

Size: 1.36 KB

Versions: 14

Compression:

Stored size: 1.36 KB

Contents

require "spec_helper"

describe Mongoid::Association::Embedded::EmbedsOne::Binding do

  let(:person) do
    Person.new
  end

  let(:target) do
    Name.new
  end

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

  describe "#bind" do

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

    context "when the document is bindable" do

      before do
        binding.bind_one
      end

      it "parentizes the documents" do
        expect(target._parent).to eq(person)
      end

      it "sets the inverse relation" do
        expect(target.namable).to eq(person)
      end
    end

    context "when the document is not bindable" do

      before do
        target.namable = person
      end

      it "does nothing" do
        expect(person).to receive(:name=).never
        binding.bind_one
      end
    end
  end

  describe "#unbind" do

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

    context "when the document is unbindable" do

      before do
        binding.bind_one
        binding.unbind_one
      end

      it "removes the inverse relation" do
        expect(target.namable).to be_nil
      end
    end

    context "when the document is not unbindable" do

      it "does nothing" do
        expect(person).to receive(:name=).never
        binding.unbind_one
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongoid-7.0.13 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.12 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.11 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.10 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.8 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.7 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.6 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.5 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.4 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.3 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.2 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.1 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.0 spec/mongoid/association/embedded/embeds_one/binding_spec.rb
mongoid-7.0.0.beta spec/mongoid/association/embedded/embeds_one/binding_spec.rb