Sha256: d4026a4be425dfe0761c9a6def0c4e3708b53186d08f5accbc6a26821a0a3ee2

Contents?: true

Size: 1.34 KB

Versions: 54

Compression:

Stored size: 1.34 KB

Contents

require "spec_helper"

describe Mongoid::Relations::Bindings::Embedded::One do

  let(:person) do
    Person.new
  end

  let(:target) do
    Name.new
  end

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

  describe "#bind" do

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

54 entries across 49 versions & 3 rubygems

Version Path
mongoid-6.4.8 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.7 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.5 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-5.4.1 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.4 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.2 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.1 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-5.4.0 spec/mongoid/relations/bindings/embedded/one_spec.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.4.0 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.3.0 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.2.1 spec/mongoid/relations/bindings/embedded/one_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/one_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/relations/bindings/embedded/one_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.2.0 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.1.1 spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-5.2.1 spec/mongoid/relations/bindings/embedded/one_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/spec/mongoid/relations/bindings/embedded/one_spec.rb
mongoid-6.1.0 spec/mongoid/relations/bindings/embedded/one_spec.rb