-
Notifications
You must be signed in to change notification settings - Fork 124
/
orm_converter_spec.rb
76 lines (61 loc) · 2.61 KB
/
orm_converter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true
require 'wings_helper'
require 'wings/orm_converter'
RSpec.describe Wings::OrmConverter, :active_fedora do
describe '.to_valkyrie_resource_class' do
context 'when given a ActiveFedora class (eg. a constant that responds to #properties)' do
context 'for the returned object (e.g. a class)' do
subject(:klass) { described_class.to_valkyrie_resource_class(klass: GenericWork) }
it 'will be Hyrax::Resource build' do
expect(subject.new).to be_a Hyrax::Resource
end
it 'has a to_s instance that delegates to the given klass' do
expect(subject.to_s).to eq(GenericWork.to_s)
end
it 'has a internal_resource instance that is the given klass' do
expect(subject.internal_resource).to eq(GenericWork.to_s)
end
it 'has a name' do
expect(klass.name).to eq 'Hyrax::Work'
end
it 'includes name in instance inspect' do
expect(klass.new.inspect).to start_with '#<Hyrax::Work'
end
it 'has a to_model for route resolution' do
expect(klass.new.to_model)
.to have_attributes(model_name: an_instance_of(Hyrax::Name),
to_partial_path: 'hyrax/generic_works/generic_work')
end
end
context 'for a custom class' do
subject(:klass) { described_class.to_valkyrie_resource_class(klass: Hyrax::Test::Book) }
it 'will be the registered resource class' do
expect(subject.new).to be_a Hyrax::Test::BookResource
end
it 'has a name' do
expect(klass.name).to eq 'Hyrax::Test::BookResource'
end
it 'includes name in instance inspect' do
expect(klass.new.inspect).to start_with '#<Hyrax::Test::BookResource'
end
it 'has a to_model for route resolution' do
expect(klass.new.to_model)
.to have_attributes(model_name: an_instance_of(ActiveModel::Name),
to_partial_path: 'hyrax/test/books/book')
end
end
end
context 'when given a non-ActiveFedora class' do
it 'raises an exception' do
expect { described_class.to_valkyrie_resource_class(klass: String) }.to raise_error(NoMethodError)
end
end
context 'when given a registered class' do
it 'returns a subclass of the corresponding native valkyrie resource' do
klass = Wings::ModelRegistry.lookup(Hyrax::Test::BookResource)
expect(described_class.to_valkyrie_resource_class(klass: klass).ancestors)
.to include Hyrax::Test::BookResource
end
end
end
end