Sha256: e2afaf97eca16cff41375ccf1acc8903f6b63d394c98ce2dabbb9e3cd13ada73

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 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
    Book.delete_all
    Library.delete_all
    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
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active-fedora-9.0.0.beta2 spec/integration/collection_association_spec.rb
active-fedora-9.0.0.beta1 spec/integration/collection_association_spec.rb