Sha256: 236502c996f974149072a0a7e1f1ecd2a964e8219da6e678c4595a84a16dd2af

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

require "spec_helper"

describe Mongoid::Relations::Proxy do

  describe "#find" do
    let(:person) do
      Person.create
    end

    let(:messages) do
      person.messages
    end

    let(:msg1) do
      messages.create(body: 'msg1')
    end

    it "returns nil with no arguments" do
      expect(messages.find).to be_nil
      expect(messages.send(:find)).to be_nil
      expect(messages.__send__(:find)).to be_nil
      expect(messages.public_send(:find)).to be_nil
    end

    it "returns the object corresponding to the id" do
      expect(messages.find(msg1.id)).to eq(msg1)
      expect(messages.send(:find, msg1.id)).to eq(msg1)
      expect(messages.__send__(:find, msg1.id)).to eq(msg1)
      expect(messages.public_send(:find, msg1.id)).to eq(msg1)
    end
  end

  describe "#extend" do

    before(:all) do
      Person.reset_callbacks(:validate)
      module Testable
      end
    end

    after(:all) do
      Object.send(:remove_const, :Testable)
    end

    let(:person) do
      Person.create
    end

    let(:name) do
      person.build_name
    end

    before do
      name.namable.extend(Testable)
    end

    it "extends the proxied object" do
      expect(person).to be_a(Testable)
    end

    context "when extending from the relation definition" do

      let!(:address) do
        person.addresses.create(street: "hobrecht")
      end

      let(:found) do
        person.addresses.find_by_street("hobrecht")
      end

      it "extends the proxy" do
        expect(found).to eq(address)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-5.0.0 spec/mongoid/relations/proxy_spec.rb
mongoid-5.0.0.rc0 spec/mongoid/relations/proxy_spec.rb
mongoid-5.0.0.beta spec/mongoid/relations/proxy_spec.rb