Sha256: e6b565cb176ca13a93c1bf0efc25ef840ad462d87f5ceff7d51769fcefb32159

Contents?: true

Size: 1.77 KB

Versions: 28

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe ActiveFedora::ModelClassifier do
  module ParentClass
    class SiblingClass
    end
    class OtherSiblingClass
    end
    class SubclassClass < SiblingClass
    end
  end

  subject(:classifier) { described_class.new class_names }
  let(:class_names) { ["ParentClass::SiblingClass", "ParentClass::OtherSiblingClass", "ParentClass::SubclassClass", "ParentClass::NoSuchClass"] }

  describe ".class_from_string" do
    it "returns class constants based on strings" do
      expect(described_class.class_from_string("String")).to eq String
      expect(described_class.class_from_string("ActiveFedora::RDF::IndexingService")).to eq ActiveFedora::RDF::IndexingService
      expect(described_class.class_from_string("IndexingService", ActiveFedora::RDF)).to eq ActiveFedora::RDF::IndexingService
    end

    it "finds sibling classes" do
      expect(described_class.class_from_string("SiblingClass", ParentClass::OtherSiblingClass)).to eq ParentClass::SiblingClass
    end

    it "raises a NameError if the class isn't found" do
      expect {
        described_class.class_from_string("FooClass", ParentClass::OtherSiblingClass)
      }.to raise_error NameError, /uninitialized constant (Object::)?FooClass/
    end
  end

  describe '#models' do
    it 'converts class names to classes' do
      expect(classifier.models).to match_array [ParentClass::SiblingClass, ParentClass::OtherSiblingClass, ParentClass::SubclassClass]
    end
  end

  describe '#best_model' do
    it 'selects the most specific matching model' do
      expect(classifier.best_model(default: nil)).to eq ParentClass::SubclassClass
    end

    it 'filters models to subclasses of the default' do
      expect(classifier.best_model(default: ActiveFedora::Base)).to eq ActiveFedora::Base
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/unit/model_classifier_spec.rb
active-fedora-12.2.3 spec/unit/model_classifier_spec.rb
active-fedora-11.5.6 spec/unit/model_classifier_spec.rb
active-fedora-12.2.2 spec/unit/model_classifier_spec.rb
active-fedora-11.2.1 spec/unit/model_classifier_spec.rb
active-fedora-12.2.1 spec/unit/model_classifier_spec.rb
active-fedora-12.0.3 spec/unit/model_classifier_spec.rb
active-fedora-11.5.5 spec/unit/model_classifier_spec.rb
active-fedora-13.1.2 spec/unit/model_classifier_spec.rb
active-fedora-13.1.1 spec/unit/model_classifier_spec.rb
active-fedora-13.1.0 spec/unit/model_classifier_spec.rb
active-fedora-13.0.0 spec/unit/model_classifier_spec.rb
active-fedora-12.1.1 spec/unit/model_classifier_spec.rb
active-fedora-12.1.0 spec/unit/model_classifier_spec.rb
active-fedora-11.5.4 spec/unit/model_classifier_spec.rb
active-fedora-11.5.3 spec/unit/model_classifier_spec.rb
active-fedora-12.0.2 spec/unit/model_classifier_spec.rb
active-fedora-12.0.1 spec/unit/model_classifier_spec.rb
active-fedora-11.5.2 spec/unit/model_classifier_spec.rb
active-fedora-12.0.0 spec/unit/model_classifier_spec.rb