Sha256: ccf45f0466d089f3d3610615ab3d0a9a12cb6dcfb5123660e2f93113f2ba314f

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before :all do
    class Library < ActiveFedora::Base
      has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf
    end
    class Book < ActiveFedora::Base; end
  end
  after :all do
    Object.send(:remove_const, :Library)
    Object.send(:remove_const, :Book)
  end

  subject { Library.all }

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

  before :each do
    Library.create
    @library = Library.create
  end

  let(:library1) { @library }

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

    it "should be loaded" do
      expect(subject).to be_loaded
    end
    it "shouldn't reload" do
      expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
      subject[0]
    end
  end

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-9.0.0.rc3 spec/integration/relation_spec.rb
active-fedora-9.0.0.rc2 spec/integration/relation_spec.rb
active-fedora-9.0.0.rc1 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta8 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta7 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta6 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta5 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta4 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta3 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta2 spec/integration/relation_spec.rb
active-fedora-9.0.0.beta1 spec/integration/relation_spec.rb