active-fedora 13.1.2 → 13.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github_changelog_generator +2 -0
- data/CHANGELOG.md +3362 -0
- data/CONTRIBUTING.md +23 -1
- data/README.md +4 -0
- data/active-fedora.gemspec +14 -13
- data/lib/active_fedora/version.rb +1 -1
- metadata +104 -206
- data/spec/config_helper.rb +0 -17
- data/spec/fixtures/dino.jpg +0 -0
- data/spec/fixtures/dino_jpg_no_file_ext +0 -0
- data/spec/fixtures/minivan.jpg +0 -0
- data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
- data/spec/fixtures/rails_root/config/fedora.yml +0 -12
- data/spec/fixtures/rails_root/config/solr.yml +0 -15
- data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
- data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
- data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
- data/spec/integration/associations/rdf_spec.rb +0 -61
- data/spec/integration/associations_spec.rb +0 -680
- data/spec/integration/attached_files_spec.rb +0 -146
- data/spec/integration/attributes_spec.rb +0 -73
- data/spec/integration/autosave_association_spec.rb +0 -24
- data/spec/integration/base_spec.rb +0 -184
- data/spec/integration/basic_contains_association_spec.rb +0 -121
- data/spec/integration/belongs_to_association_spec.rb +0 -260
- data/spec/integration/caching_spec.rb +0 -59
- data/spec/integration/clean_connection_spec.rb +0 -21
- data/spec/integration/collection_association_spec.rb +0 -166
- data/spec/integration/date_time_properties_spec.rb +0 -41
- data/spec/integration/delete_all_spec.rb +0 -64
- data/spec/integration/direct_container_spec.rb +0 -250
- data/spec/integration/directly_contains_one_association_spec.rb +0 -96
- data/spec/integration/eradicate_spec.rb +0 -52
- data/spec/integration/fedora_solr_sync_spec.rb +0 -30
- data/spec/integration/file_fixity_spec.rb +0 -36
- data/spec/integration/file_spec.rb +0 -221
- data/spec/integration/generators/fedora_generator_spec.rb +0 -26
- data/spec/integration/generators/solr_generator_spec.rb +0 -23
- data/spec/integration/gone_spec.rb +0 -41
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
- data/spec/integration/has_many_associations_spec.rb +0 -436
- data/spec/integration/has_subresource_spec.rb +0 -34
- data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
- data/spec/integration/indexing_spec.rb +0 -110
- data/spec/integration/indirect_container_spec.rb +0 -290
- data/spec/integration/json_serialization_spec.rb +0 -32
- data/spec/integration/marshal_spec.rb +0 -39
- data/spec/integration/nested_attribute_spec.rb +0 -177
- data/spec/integration/nested_hash_resources_spec.rb +0 -43
- data/spec/integration/persistence_spec.rb +0 -37
- data/spec/integration/query_result_builder_spec.rb +0 -37
- data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
- data/spec/integration/relation_delegation_spec.rb +0 -52
- data/spec/integration/relation_spec.rb +0 -117
- data/spec/integration/scoped_query_spec.rb +0 -134
- data/spec/integration/scoping_spec.rb +0 -48
- data/spec/integration/solr_hit_spec.rb +0 -32
- data/spec/integration/versionable_spec.rb +0 -256
- data/spec/integration/with_metadata_spec.rb +0 -111
- data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +0 -106
- data/spec/support/an_active_model.rb +0 -29
- data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
- data/spec/unit/active_fedora_spec.rb +0 -118
- data/spec/unit/aggregation/list_source_spec.rb +0 -134
- data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
- data/spec/unit/association_hash_spec.rb +0 -64
- data/spec/unit/attached_files_spec.rb +0 -218
- data/spec/unit/attributes_spec.rb +0 -146
- data/spec/unit/base_active_model_spec.rb +0 -28
- data/spec/unit/base_cma_spec.rb +0 -15
- data/spec/unit/base_extra_spec.rb +0 -33
- data/spec/unit/base_spec.rb +0 -328
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
- data/spec/unit/callback_spec.rb +0 -65
- data/spec/unit/change_set_spec.rb +0 -60
- data/spec/unit/checksum_spec.rb +0 -25
- data/spec/unit/code_configurator_spec.rb +0 -41
- data/spec/unit/collection_proxy_spec.rb +0 -25
- data/spec/unit/config_spec.rb +0 -18
- data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
- data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
- data/spec/unit/core/logger_spec.rb +0 -18
- data/spec/unit/core_spec.rb +0 -242
- data/spec/unit/default_model_mapper_spec.rb +0 -39
- data/spec/unit/fedora_spec.rb +0 -31
- data/spec/unit/file/streaming_spec.rb +0 -33
- data/spec/unit/file_configurator_spec.rb +0 -295
- data/spec/unit/file_io_spec.rb +0 -137
- data/spec/unit/file_path_builder_spec.rb +0 -18
- data/spec/unit/file_spec.rb +0 -489
- data/spec/unit/files_hash_spec.rb +0 -52
- data/spec/unit/filter_spec.rb +0 -133
- data/spec/unit/finder_methods_spec.rb +0 -154
- data/spec/unit/fixity_service_spec.rb +0 -128
- data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
- data/spec/unit/has_many_association_spec.rb +0 -131
- data/spec/unit/indexers/global_indexer_spec.rb +0 -41
- data/spec/unit/indexing/map/index_object_spec.rb +0 -25
- data/spec/unit/indexing/map_spec.rb +0 -27
- data/spec/unit/indexing_service_spec.rb +0 -28
- data/spec/unit/indexing_spec.rb +0 -86
- data/spec/unit/inheritance_spec.rb +0 -60
- data/spec/unit/ldp_resource_spec.rb +0 -15
- data/spec/unit/loadable_from_json_spec.rb +0 -40
- data/spec/unit/logger_spec.rb +0 -19
- data/spec/unit/model_classifier_spec.rb +0 -49
- data/spec/unit/ordered_spec.rb +0 -367
- data/spec/unit/orders/list_node_spec.rb +0 -151
- data/spec/unit/orders/ordered_list_spec.rb +0 -335
- data/spec/unit/orders/reflection_spec.rb +0 -22
- data/spec/unit/pathing_spec.rb +0 -35
- data/spec/unit/persistence_spec.rb +0 -115
- data/spec/unit/property_predicate_spec.rb +0 -35
- data/spec/unit/property_spec.rb +0 -25
- data/spec/unit/query_result_builder_spec.rb +0 -31
- data/spec/unit/query_spec.rb +0 -307
- data/spec/unit/querying_spec.rb +0 -24
- data/spec/unit/rdf/indexing_service_spec.rb +0 -114
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/readonly_spec.rb +0 -24
- data/spec/unit/reflection_spec.rb +0 -42
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
- data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
- data/spec/unit/scoping_spec.rb +0 -67
- data/spec/unit/serializers_spec.rb +0 -19
- data/spec/unit/solr_config_options_spec.rb +0 -57
- data/spec/unit/solr_hit_spec.rb +0 -57
- data/spec/unit/solr_query_builder_spec.rb +0 -18
- data/spec/unit/solr_service_spec.rb +0 -165
- data/spec/unit/sparql_insert_spec.rb +0 -31
- data/spec/unit/validations_spec.rb +0 -92
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
- data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Objects should be serialized to JSON" do
|
4
|
-
it "has json results" do
|
5
|
-
expect(ActiveFedora::Base.new.to_json).to eq "{\"id\":null}"
|
6
|
-
end
|
7
|
-
|
8
|
-
context "with properties" do
|
9
|
-
before do
|
10
|
-
class Foo < ActiveFedora::Base
|
11
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
12
|
-
property :description, predicate: ::RDF::Vocab::DC.description, multiple: false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
after do
|
17
|
-
Object.send(:remove_const, :Foo)
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:obj) { Foo.new(title: ['My Title'], description: 'Wonderful stuff') }
|
21
|
-
|
22
|
-
before { allow(obj).to receive(:id).and_return('test-123') }
|
23
|
-
|
24
|
-
let(:json) { JSON.parse(obj.to_json) }
|
25
|
-
|
26
|
-
it "has to_json" do
|
27
|
-
expect(json['id']).to eq "test-123"
|
28
|
-
expect(json['title']).to eq ["My Title"]
|
29
|
-
expect(json['description']).to eq "Wonderful stuff"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Marshalling and loading" do
|
4
|
-
before do
|
5
|
-
class Post < ActiveFedora::Base
|
6
|
-
has_many :comments
|
7
|
-
property :text, predicate: ::RDF::URI('http://example.com/text')
|
8
|
-
end
|
9
|
-
|
10
|
-
class Comment < ActiveFedora::Base
|
11
|
-
belongs_to :post, predicate: ::RDF::URI('http://example.com/post')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
Object.send(:remove_const, :Post)
|
17
|
-
Object.send(:remove_const, :Comment)
|
18
|
-
end
|
19
|
-
|
20
|
-
context "persisted records" do
|
21
|
-
let(:post) { Post.create(text: ['serialize me']) }
|
22
|
-
it "marshals them" do
|
23
|
-
marshalled = Marshal.dump(post)
|
24
|
-
loaded = Marshal.load(marshalled)
|
25
|
-
|
26
|
-
expect(loaded.attributes).to eq post.attributes
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "with associations" do
|
31
|
-
let(:post) { Post.create(comments: [Comment.new]) }
|
32
|
-
it "marshals associations" do
|
33
|
-
marshalled = Marshal.dump(post)
|
34
|
-
loaded = Marshal.load(marshalled)
|
35
|
-
|
36
|
-
expect(loaded.comments.size).to eq 1
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,177 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "NestedAttribute behavior" do
|
4
|
-
before do
|
5
|
-
class Bar < ActiveFedora::Base
|
6
|
-
belongs_to :car, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasMember
|
7
|
-
property :uno, predicate: ::RDF::URI('http://example.com/uno'), multiple: false
|
8
|
-
property :dos, predicate: ::RDF::URI('http://example.com/dos'), multiple: false
|
9
|
-
end
|
10
|
-
|
11
|
-
# base Car class, used in test for association updates and :allow_destroy flag
|
12
|
-
class Car < ActiveFedora::Base
|
13
|
-
has_many :bars, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasMember
|
14
|
-
accepts_nested_attributes_for :bars, allow_destroy: true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
after do
|
18
|
-
Object.send(:remove_const, :Bar)
|
19
|
-
Object.send(:remove_const, :Car)
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:car_class) { Car }
|
23
|
-
let(:car) { car_class.create }
|
24
|
-
let(:bar1) { Bar.create(car: car) }
|
25
|
-
let(:bar2) { Bar.create(car: car) }
|
26
|
-
|
27
|
-
it "has _destroy" do
|
28
|
-
expect(Bar.new._destroy).to be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "updates the child objects" do
|
32
|
-
car.update bars_attributes: [{ id: bar1.id, uno: "bar1 uno" }, { uno: "newbar uno" }, { id: bar2.id, _destroy: '1', uno: 'bar2 uno' }]
|
33
|
-
expect(Bar.all.map(&:uno)).to match_array ['bar1 uno', 'newbar uno']
|
34
|
-
|
35
|
-
bars = car.bars(true)
|
36
|
-
expect(bars).to include(bar1)
|
37
|
-
expect(bars).to_not include(bar2)
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when reject_if: :all_blank" do
|
41
|
-
before do
|
42
|
-
class CarAllBlank < Car
|
43
|
-
accepts_nested_attributes_for :bars, reject_if: :all_blank
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
let(:car_class) { CarAllBlank }
|
48
|
-
after { Object.send(:remove_const, :CarAllBlank) }
|
49
|
-
let(:car) { car_class.create }
|
50
|
-
let!(:bar1) { Bar.create(car: car) }
|
51
|
-
let!(:bar2) { Bar.create(car: car) }
|
52
|
-
|
53
|
-
it "rejects attributes when all blank" do
|
54
|
-
expect(car.bars.count).to eq 2
|
55
|
-
car.update bars_attributes: [{}, { id: bar1.id, uno: "bar1 uno" }]
|
56
|
-
expect(car.bars(true).count).to eq 2
|
57
|
-
|
58
|
-
bar1.reload
|
59
|
-
expect(bar1.uno).to eq "bar1 uno"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when reject_if attribute is supplied with a proc" do
|
64
|
-
before do
|
65
|
-
class CarProc < Car
|
66
|
-
accepts_nested_attributes_for :bars, reject_if: ->(attributes) { attributes['uno'].blank? }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
after { Object.send(:remove_const, :CarProc) }
|
71
|
-
let(:car_class) { CarProc }
|
72
|
-
|
73
|
-
context "and the reject_if proc evaluates to false" do
|
74
|
-
before do
|
75
|
-
car.update bars_attributes: [{}, { id: bar1.id, uno: "bar1 uno" }]
|
76
|
-
end
|
77
|
-
it "updates attributes" do
|
78
|
-
expect(bar1.reload.uno).to eq "bar1 uno"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "and the reject_if proc evaluates to true" do
|
83
|
-
before do
|
84
|
-
car.update bars_attributes: [{}, { id: bar1.id, dos: "bar1 uno" }]
|
85
|
-
end
|
86
|
-
it "rejects attributes" do
|
87
|
-
expect(bar1.reload.dos).to be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "and `allow_destroy: false`" do
|
92
|
-
context "and the reject_if proc evaluates to true" do
|
93
|
-
before do
|
94
|
-
car.update bars_attributes: [{}, { id: bar1.id, dos: "bar1 uno", _destroy: "1" }]
|
95
|
-
end
|
96
|
-
it "rejects attributes (_destroy doesn't affect the outcome)" do
|
97
|
-
expect(bar1.reload.dos).to be_nil
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "a record with the destroy flag and without an id" do
|
102
|
-
it "creates a new record" do
|
103
|
-
expect {
|
104
|
-
car.update bars_attributes: [{ uno: "bar1 uno", _destroy: "1" }]
|
105
|
-
}.to change { car.bars(true).count }.by(1)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "does not create a new record if reject_if conditions are triggered" do
|
109
|
-
expect {
|
110
|
-
car.update bars_attributes: [{ uno: "", _destroy: "1" }]
|
111
|
-
}.not_to change { car.bars(true).count }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "reject_if: with a symbol" do
|
118
|
-
before do
|
119
|
-
# class used in test for reject_if: with method name as symbol
|
120
|
-
class CarSymbol < Car
|
121
|
-
accepts_nested_attributes_for :bars, reject_if: :uno_blank
|
122
|
-
|
123
|
-
def uno_blank(attributes)
|
124
|
-
attributes['uno'].blank?
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
after { Object.send(:remove_const, :CarSymbol) }
|
130
|
-
let(:car_class) { CarSymbol }
|
131
|
-
|
132
|
-
it "rejects attributes based on method name" do
|
133
|
-
car.update bars_attributes: [{}, { id: bar1.id, uno: "bar1 uno" }, { id: bar2.id, dos: "bar2 dos" }]
|
134
|
-
bar1.reload
|
135
|
-
bar2.reload
|
136
|
-
expect(bar1.uno).to eq "bar1 uno"
|
137
|
-
expect(bar2.dos).to be_nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "allow_destroy: true" do
|
142
|
-
before do
|
143
|
-
class CarDestroy < Car
|
144
|
-
accepts_nested_attributes_for :bars, allow_destroy: true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
let(:car_class) { CarDestroy }
|
149
|
-
after { Object.send(:remove_const, :CarDestroy) }
|
150
|
-
|
151
|
-
it "doesn't create a new record if _destroy is set" do
|
152
|
-
expect {
|
153
|
-
car.update bars_attributes: [{ uno: "new uno", _destroy: "1" }]
|
154
|
-
}.not_to change { car.bars(true).count }
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "limit" do
|
159
|
-
before do
|
160
|
-
class CarWithLimit < Car
|
161
|
-
accepts_nested_attributes_for :bars, limit: 1
|
162
|
-
end
|
163
|
-
end
|
164
|
-
after { Object.send(:remove_const, :CarWithLimit) }
|
165
|
-
|
166
|
-
let(:car_class) { CarWithLimit }
|
167
|
-
it "throws TooManyRecords" do
|
168
|
-
expect {
|
169
|
-
car.attributes = { bars_attributes: [{}] }
|
170
|
-
}.to_not raise_exception
|
171
|
-
|
172
|
-
expect {
|
173
|
-
car.attributes = { bars_attributes: [{}, {}] }
|
174
|
-
}.to raise_exception(ActiveFedora::NestedAttributes::TooManyRecords)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "nested hash resources" do
|
4
|
-
before do
|
5
|
-
class NestedResource < ActiveTriples::Resource
|
6
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
7
|
-
## Necessary to get AT to create hash URIs.
|
8
|
-
def initialize(uri, parent)
|
9
|
-
if uri.try(:node?)
|
10
|
-
uri = RDF::URI("#nested_#{uri.to_s.gsub('_:', '')}")
|
11
|
-
elsif uri.start_with?("#")
|
12
|
-
uri = RDF::URI(uri)
|
13
|
-
end
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def final_parent
|
18
|
-
parent
|
19
|
-
end
|
20
|
-
end
|
21
|
-
class ExampleOwner < ActiveFedora::Base
|
22
|
-
property :relation, predicate: ::RDF::Vocab::DC.relation, class_name: NestedResource
|
23
|
-
accepts_nested_attributes_for :relation
|
24
|
-
end
|
25
|
-
end
|
26
|
-
after do
|
27
|
-
Object.send(:remove_const, :NestedResource)
|
28
|
-
Object.send(:remove_const, :ExampleOwner)
|
29
|
-
end
|
30
|
-
it "is able to nest resources" do
|
31
|
-
obj = ExampleOwner.new
|
32
|
-
obj.attributes = {
|
33
|
-
relation_attributes: [
|
34
|
-
{
|
35
|
-
title: "Test"
|
36
|
-
}
|
37
|
-
]
|
38
|
-
}
|
39
|
-
obj.save!
|
40
|
-
|
41
|
-
expect(obj.reload.relation.first.title).to eq ["Test"]
|
42
|
-
end
|
43
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "persisting objects" do
|
4
|
-
describe "#create!" do
|
5
|
-
before do
|
6
|
-
class MockAFBaseRelationship < ActiveFedora::Base
|
7
|
-
property :name, predicate: ::RDF::Vocab::DC.title, multiple: false
|
8
|
-
validates :name, presence: true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
Object.send(:remove_const, :MockAFBaseRelationship)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "validates" do
|
17
|
-
expect { MockAFBaseRelationship.create! }.to raise_error ActiveFedora::RecordInvalid, "Validation failed: Name can't be blank"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#save" do
|
22
|
-
context "With undefined contains associations" do
|
23
|
-
let(:f1) { ActiveFedora::Base.create }
|
24
|
-
let!(:f2) { ActiveFedora::Base.create(id: "#{f1.id}/part2") }
|
25
|
-
|
26
|
-
before do
|
27
|
-
f1.reload # so it learns about f2
|
28
|
-
end
|
29
|
-
|
30
|
-
it "doesn't load the children" do
|
31
|
-
allow(f1).to receive(:update_index) # solrizing can load the attached files.
|
32
|
-
expect(ActiveFedora::File).not_to receive(:new)
|
33
|
-
f1.save
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::QueryResultBuilder do
|
4
|
-
describe "#reify_solr_results" do
|
5
|
-
before do
|
6
|
-
class FooObject < ActiveFedora::Base
|
7
|
-
def self.id_namespace
|
8
|
-
"foo"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:test_object) { ActiveFedora::Base.create }
|
14
|
-
let(:foo_object) { FooObject.create }
|
15
|
-
|
16
|
-
after do
|
17
|
-
Object.send(:remove_const, :FooObject)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns an array of objects that are of the class stored in active_fedora_model_s" do
|
21
|
-
query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([test_object.id, foo_object.id])
|
22
|
-
solr_result = ActiveFedora::SolrService.query(query, rows: 10)
|
23
|
-
result = described_class.reify_solr_results(solr_result)
|
24
|
-
expect(result.length).to eq 2
|
25
|
-
result.each do |r|
|
26
|
-
expect((r.class == ActiveFedora::Base || r.class == FooObject)).to be true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it '#reifies a lightweight object as a new instance' do
|
31
|
-
query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([foo_object.id])
|
32
|
-
solr_result = ActiveFedora::SolrService.query(query, rows: 10)
|
33
|
-
result = described_class.reify_solr_results(solr_result, load_from_solr: true)
|
34
|
-
expect(result.first).to be_instance_of FooObject
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Nesting attribute behavior of RDF resources" do
|
4
|
-
before do
|
5
|
-
class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
|
6
|
-
property :Topic
|
7
|
-
property :Name
|
8
|
-
property :Source
|
9
|
-
end
|
10
|
-
|
11
|
-
class CustomName < ActiveFedora::Base
|
12
|
-
property :pref_label, predicate: ::RDF::Vocab::SKOS.prefLabel, multiple: false
|
13
|
-
end
|
14
|
-
|
15
|
-
class CustomSource < ActiveFedora::Base
|
16
|
-
end
|
17
|
-
|
18
|
-
class ComplexResource < ActiveFedora::Base
|
19
|
-
property :topic, predicate: DummyMADS.Topic, class_name: "ComplexResource::Topic"
|
20
|
-
property :name, predicate: DummyMADS.Name, class_name: "CustomName" do |index|
|
21
|
-
index.as :stored_searchable, using: :pref_label
|
22
|
-
end
|
23
|
-
property :source, predicate: DummyMADS.Source, class_name: "CustomSource" do |index|
|
24
|
-
index.as :stored_searchable
|
25
|
-
end
|
26
|
-
|
27
|
-
class Topic < ActiveTriples::Resource
|
28
|
-
property :subject, predicate: ::RDF::Vocab::DC.subject
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
after do
|
34
|
-
Object.send(:remove_const, :ComplexResource)
|
35
|
-
Object.send(:remove_const, :DummyMADS)
|
36
|
-
Object.send(:remove_const, :CustomName)
|
37
|
-
Object.send(:remove_const, :CustomSource)
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with an AT resource as a property" do
|
41
|
-
subject(:complex_resource) { ComplexResource.new }
|
42
|
-
|
43
|
-
let(:params) { [{ subject: 'Foo' }, { subject: 'Bar' }] }
|
44
|
-
|
45
|
-
before do
|
46
|
-
ComplexResource.accepts_nested_attributes_for(*args)
|
47
|
-
complex_resource.topic_attributes = params
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when no options are set" do
|
51
|
-
let(:args) { [:topic] }
|
52
|
-
|
53
|
-
it "sets the attributes" do
|
54
|
-
expect(complex_resource.topic.size).to eq 2
|
55
|
-
expect(complex_resource.topic.map(&:subject)).to contain_exactly ['Foo'], ['Bar']
|
56
|
-
end
|
57
|
-
|
58
|
-
it "marks the attributes as changed" do
|
59
|
-
expect(complex_resource.changed_attributes.keys).to eq ["topic"]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when reject_if is set" do
|
64
|
-
let(:args) { [:topic, reject_if: reject_proc] }
|
65
|
-
let(:reject_proc) { lambda { |attributes| attributes[:subject] == 'Bar' } }
|
66
|
-
let(:params) { [{ subject: 'Foo' }, { subject: 'Bar' }] }
|
67
|
-
|
68
|
-
it "does not add terms for which the proc is true" do
|
69
|
-
expect(complex_resource.topic.map(&:subject)).to eq [['Foo']]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "with an AF::Base object as a property" do
|
75
|
-
describe "#to_solr" do
|
76
|
-
let(:name) { CustomName.create(pref_label: "Joe Schmo") }
|
77
|
-
let(:source) { CustomSource.create }
|
78
|
-
let(:solr_doc) { ComplexResource.new(name: [name], source: [source]).to_solr }
|
79
|
-
it "indexes the value of the properties accordingly" do
|
80
|
-
expect(solr_doc).to include("name_tesim" => ["Joe Schmo"])
|
81
|
-
expect(solr_doc).to include("source_tesim" => [source.uri])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|