Sha256: 1787139c70695d125dd06a87505f485b89c787e2d795e138c0e89ad0d50151a7

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before :all do
    class Library < ActiveFedora::Base 
      has_many :books, property: :has_member
    end
    class Book < ActiveFedora::Base; end
  end
  after :all do
    Library.delete_all
    Object.send(:remove_const, :Library)
    Object.send(:remove_const, :Book)
  end

  subject { Library.all } 
  its(:class) {is_expected.to eq ActiveFedora::Relation }

  before :all 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).not_to 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

8 entries across 8 versions & 1 rubygems

Version Path
active-fedora-8.7.0 spec/integration/relation_spec.rb
active-fedora-8.6.0 spec/integration/relation_spec.rb
active-fedora-8.5.0 spec/integration/relation_spec.rb
active-fedora-8.4.2 spec/integration/relation_spec.rb
active-fedora-8.4.1 spec/integration/relation_spec.rb
active-fedora-8.4.0 spec/integration/relation_spec.rb
active-fedora-8.3.0 spec/integration/relation_spec.rb
active-fedora-8.2.2 spec/integration/relation_spec.rb