Sha256: b4aa7ed308f617520901641fa600bb7b60f4ccf59b0280db006d2f6aa3c8f660

Contents?: true

Size: 1.72 KB

Versions: 27

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before :all do
    class Library < ActiveFedora::Base
      has_many :books
    end
    class Book < ActiveFedora::Base
      belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
    end
  end

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

  subject(:libraries) { Library.all }

  it "is a relation" do
    expect(libraries.class).to be ActiveFedora::Relation
  end

  it { is_expected.to respond_to(:each_with_index) }

  context "when some records exist" do
    before do
      Library.create
    end

    let!(:library1) { Library.create }

    describe "is cached" do
      before do
        libraries.to_a # trigger initial load
      end

      it { is_expected.to be_loaded }

      it "does not reload" do
        expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
        libraries[0]
      end
    end

    describe "#find" do
      it "finds one of them" do
        expect(libraries.find(library1.id)).to eq library1
      end
      it "finds with a block" do
        expect(libraries.find { |l| l.id == library1.id }).to eq library1
      end
    end

    describe "#select" do
      it "finds with a block" do
        expect(libraries.select { |l| l.id == library1.id }).to eq [library1]
      end
    end

    context "unpermitted methods" do
      it "excludes them" do
        expect { libraries.sort! }.to raise_error NoMethodError
      end
    end

    context "when limit is applied" do
      subject(:libraries) { Library.create books: [Book.create, Book.create] }
      it "limits the number of books" do
        expect(libraries.books.limit(1).size).to eq 1
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
active-fedora-11.2.1 spec/integration/relation_spec.rb
active-fedora-12.0.3 spec/integration/relation_spec.rb
active-fedora-12.0.2 spec/integration/relation_spec.rb
active-fedora-12.0.1 spec/integration/relation_spec.rb
active-fedora-11.5.2 spec/integration/relation_spec.rb
active-fedora-12.0.0 spec/integration/relation_spec.rb
active-fedora-11.5.0 spec/integration/relation_spec.rb
active-fedora-11.4.1 spec/integration/relation_spec.rb
active-fedora-11.4.0 spec/integration/relation_spec.rb
active-fedora-11.3.1 spec/integration/relation_spec.rb
active-fedora-11.3.0 spec/integration/relation_spec.rb
active-fedora-11.2.0 spec/integration/relation_spec.rb
active-fedora-11.1.6 spec/integration/relation_spec.rb
active-fedora-11.1.5 spec/integration/relation_spec.rb
active-fedora-11.1.4 spec/integration/relation_spec.rb
active-fedora-11.1.3 spec/integration/relation_spec.rb
active-fedora-11.1.2 spec/integration/relation_spec.rb
active-fedora-11.1.1 spec/integration/relation_spec.rb
active-fedora-11.1.0 spec/integration/relation_spec.rb
active-fedora-11.0.1 spec/integration/relation_spec.rb