Sha256: d4b9a27c99861cfc0ad5d2b716d226598103f4e08b10b3f7f463c5d7c0051d8c
Contents?: true
Size: 1.74 KB
Versions: 23
Compression:
Stored size: 1.74 KB
Contents
require 'spec_helper' describe ActiveFedora::ModelClassifier do module ParentClass class SiblingClass end class OtherSiblingClass end class SubclassClass < SiblingClass end end let(:class_names) { ["ParentClass::SiblingClass", "ParentClass::OtherSiblingClass", "ParentClass::SubclassClass", "ParentClass::NoSuchClass"] } subject { described_class.new class_names } describe ".class_from_string" do it "returns class constants based on strings" do expect(described_class.class_from_string("Om")).to eq Om 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(subject.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(subject.best_model(default: nil)).to eq ParentClass::SubclassClass end it 'filters models to subclasses of the default' do expect(subject.best_model(default: ActiveFedora::Base)).to eq ActiveFedora::Base end end end
Version data entries
23 entries across 23 versions & 1 rubygems
Version | Path |
---|---|
active-fedora-9.10.0 | spec/unit/model_classifier_spec.rb |
active-fedora-9.10.0.pre2 | spec/unit/model_classifier_spec.rb |
active-fedora-9.10.0.pre1 | spec/unit/model_classifier_spec.rb |