Sha256: 28fbd72f19414bc5d29ccd0cf1e30773ff663fc8f2f760bf966357502aed1215

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

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

  let(:library) { Library.create! }
  let!(:book1) { Book.create!(library: library) }
  let!(:book2) { Book.create!(library: library) }

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

  describe "load_from_solr" do
    it "should set rows to count, if not specified" do
      expect(library.books(response_format: :solr).size).to eq 2
    end

    it "should limit rows returned if option passed" do
      expect(library.books(response_format: :solr, rows: 1).size).to eq 1
    end

    it "should not query solr if rows is 0" do
      expect(ActiveFedora::SolrService).not_to receive(:query)
      expect(library.books(response_format: :solr, rows: 0)).to eq []
    end
  end

  describe "#delete_all" do
    it "should delete em" do
      expect {
        library.books.delete_all
      }.to change { library.books.count }.by(-2)
    end
  end

  describe "#destroy_all" do
    it "should delete em" do
      expect {
        library.books.destroy_all
      }.to change { library.books.count }.by(-2)
    end
  end

  describe "#find" do
    it "should find the record that matches" do
      expected = library.books.find(book1.id)
      expect(expected).to eq book1
    end
    describe "with some records that aren't part of the collection" do
      let!(:book3) { Book.create }
      it "should find no records" do
        expect(library.books.find(book3.id)).to be_nil
      end
    end
  end

  # TODO: Bug described in issue #609
  describe "#select" do
    it "should choose a subset of objects in the relationship" do
      pending "method has private visibility"
      expect(library.books.select([:id])).to include(book1.id)
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active-fedora-9.0.0.rc3 spec/integration/collection_association_spec.rb
active-fedora-9.0.0.rc2 spec/integration/collection_association_spec.rb
active-fedora-9.0.0.rc1 spec/integration/collection_association_spec.rb
active-fedora-9.0.0.beta8 spec/integration/collection_association_spec.rb
active-fedora-9.0.0.beta7 spec/integration/collection_association_spec.rb