Sha256: 1c5ead73aeb50de152d35aa08fcb4ac8d18aa8821b27b905e82e6b59ccd14f8f

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 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, property: :has_member
    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

8 entries across 8 versions & 1 rubygems

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