Sha256: 4d65a0284d25c04fdcbd4b04ee72093e4bb2c9bcd4d2db5cc2e7239e3da37da9

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe ActiveFedora::Scoping::Named do
  before(:all) do
    class TestClass < ActiveFedora::Base; end
    class OtherClass < ActiveFedora::Base; end
  end
  after(:all) do
    Object.send(:remove_const, :TestClass)
    Object.send(:remove_const, :OtherClass)
  end

  let!(:test_instance) { TestClass.create! }
  after { test_instance.delete }

  describe "#all" do
    it "returns an array of instances of the calling Class" do
      result = TestClass.all.to_a
      expect(result).to be_instance_of(Array)
      # this test is meaningless if the array length is zero
      expect(result).to_not be_empty
      result.each do |obj|
        expect(obj.class).to eq TestClass
      end
    end
  end

  describe '#find' do
    describe "a valid id without cast" do
      subject { ActiveFedora::Base.find(test_instance.id) }
      it { is_expected.to be_instance_of TestClass }
    end
    describe "a valid id with cast of false" do
      subject { ActiveFedora::Base.find(test_instance.id, cast: false) }
      it { is_expected.to be_instance_of ActiveFedora::Base }
    end
    describe "a valid id without cast on a model extending Base" do
      subject { TestClass.find(test_instance.id) }
      it { is_expected.to be_instance_of TestClass }
    end
    it "a valid id on an incompatible class raises ModelMismatch" do
      expect { OtherClass.find(test_instance.id) }.to raise_error(ActiveFedora::ModelMismatch)
    end
    it "invalid id raises ObjectNotFoundError" do
      expect { TestClass.find('some_unused_identifier') }.to raise_error(ActiveFedora::ObjectNotFoundError)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/integration/scoping_spec.rb
active-fedora-12.2.3 spec/integration/scoping_spec.rb
active-fedora-12.2.2 spec/integration/scoping_spec.rb
active-fedora-12.2.1 spec/integration/scoping_spec.rb
active-fedora-12.0.3 spec/integration/scoping_spec.rb
active-fedora-13.1.2 spec/integration/scoping_spec.rb
active-fedora-13.1.1 spec/integration/scoping_spec.rb
active-fedora-13.1.0 spec/integration/scoping_spec.rb
active-fedora-13.0.0 spec/integration/scoping_spec.rb
active-fedora-12.1.1 spec/integration/scoping_spec.rb
active-fedora-12.1.0 spec/integration/scoping_spec.rb
active-fedora-12.0.2 spec/integration/scoping_spec.rb
active-fedora-12.0.1 spec/integration/scoping_spec.rb
active-fedora-12.0.0 spec/integration/scoping_spec.rb