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,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before do
|
5
|
-
class MyDS < ActiveFedora::File
|
6
|
-
end
|
7
|
-
|
8
|
-
class MySample < ActiveFedora::File
|
9
|
-
end
|
10
|
-
|
11
|
-
class MyDeepSample < MySample
|
12
|
-
end
|
13
|
-
|
14
|
-
class Foo < ActiveFedora::Base
|
15
|
-
has_subresource 'foostream', class_name: 'MyDS'
|
16
|
-
has_subresource 'dcstream', class_name: 'MySample'
|
17
|
-
end
|
18
|
-
|
19
|
-
class Bar < ActiveFedora::Base
|
20
|
-
has_subresource 'barstream', class_name: 'MyDS'
|
21
|
-
end
|
22
|
-
|
23
|
-
class Baz < Bar
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
subject(:attached_files) { f.attached_files }
|
28
|
-
let(:f) { Foo.new }
|
29
|
-
|
30
|
-
it "doesn't overwrite stream specs" do
|
31
|
-
expect(attached_files.values).to match_array [MyDS, MySample]
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'base_class' do
|
35
|
-
it 'shallow < Base' do
|
36
|
-
expect(Bar.base_class).to eq(Bar)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'deep < Base' do
|
40
|
-
expect(Baz.base_class).to eq(Bar)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'shallow < File' do
|
44
|
-
expect(MySample.base_class).to eq(ActiveFedora::File)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'deep < File' do
|
48
|
-
expect(MyDeepSample.base_class).to eq(ActiveFedora::File)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
after do
|
53
|
-
Object.send(:remove_const, :Baz)
|
54
|
-
Object.send(:remove_const, :Bar)
|
55
|
-
Object.send(:remove_const, :Foo)
|
56
|
-
Object.send(:remove_const, :MyDS)
|
57
|
-
Object.send(:remove_const, :MyDeepSample)
|
58
|
-
Object.send(:remove_const, :MySample)
|
59
|
-
end
|
60
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::LdpResource do
|
4
|
-
let(:obj) { ActiveFedora::Base.create! }
|
5
|
-
let!(:r1) { described_class.new(ActiveFedora.fedora.connection, obj.uri) }
|
6
|
-
let!(:r2) { described_class.new(ActiveFedora.fedora.connection, obj.uri) }
|
7
|
-
|
8
|
-
it "caches requests" do
|
9
|
-
expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_call_original
|
10
|
-
ActiveFedora::Base.cache do
|
11
|
-
r1.get
|
12
|
-
r2.get
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::LoadableFromJson::SolrBackedResource do
|
4
|
-
before do
|
5
|
-
class Foo < ActiveFedora::Base
|
6
|
-
belongs_to :bar, predicate: ::RDF::Vocab::DC.extent
|
7
|
-
end
|
8
|
-
|
9
|
-
class Bar < ActiveFedora::Base
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
Object.send(:remove_const, :Foo)
|
15
|
-
Object.send(:remove_const, :Bar)
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:resource) { described_class.new(Foo) }
|
19
|
-
|
20
|
-
before do
|
21
|
-
resource.insert [nil, ::RDF::Vocab::DC.extent, RDF::URI('http://example.org/123')]
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#query" do
|
25
|
-
describe "a known relationship" do
|
26
|
-
subject(:resources) { resource.query(predicate: ::RDF::Vocab::DC.extent) }
|
27
|
-
|
28
|
-
it "is enumerable" do
|
29
|
-
expect(resources.map(&:object)).to eq [RDF::URI('http://example.org/123')]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "a unknown relationship" do
|
34
|
-
subject(:resources) { resource.query(predicate: ::RDF::Vocab::DC.accrualPeriodicity) }
|
35
|
-
it "raises an error" do
|
36
|
-
expect { resources }.to raise_error "Unable to find reflection for http://purl.org/dc/terms/accrualPeriodicity in Foo"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/spec/unit/logger_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
let(:logger1) { instance_double(::Logger, debug?: false) }
|
5
|
-
|
6
|
-
before do
|
7
|
-
@initial_logger = described_class.logger
|
8
|
-
described_class.logger = logger1
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
described_class.logger = @initial_logger
|
13
|
-
end
|
14
|
-
|
15
|
-
it "Allows loggers to be set" do
|
16
|
-
expect(logger1).to receive(:warn).with("Hey")
|
17
|
-
described_class.new.logger.warn "Hey"
|
18
|
-
end
|
19
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::ModelClassifier do
|
4
|
-
module ParentClass
|
5
|
-
class SiblingClass
|
6
|
-
end
|
7
|
-
class OtherSiblingClass
|
8
|
-
end
|
9
|
-
class SubclassClass < SiblingClass
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
subject(:classifier) { described_class.new class_names }
|
14
|
-
let(:class_names) { ["ParentClass::SiblingClass", "ParentClass::OtherSiblingClass", "ParentClass::SubclassClass", "ParentClass::NoSuchClass"] }
|
15
|
-
|
16
|
-
describe ".class_from_string" do
|
17
|
-
it "returns class constants based on strings" do
|
18
|
-
expect(described_class.class_from_string("String")).to eq String
|
19
|
-
expect(described_class.class_from_string("ActiveFedora::RDF::IndexingService")).to eq ActiveFedora::RDF::IndexingService
|
20
|
-
expect(described_class.class_from_string("IndexingService", ActiveFedora::RDF)).to eq ActiveFedora::RDF::IndexingService
|
21
|
-
end
|
22
|
-
|
23
|
-
it "finds sibling classes" do
|
24
|
-
expect(described_class.class_from_string("SiblingClass", ParentClass::OtherSiblingClass)).to eq ParentClass::SiblingClass
|
25
|
-
end
|
26
|
-
|
27
|
-
it "raises a NameError if the class isn't found" do
|
28
|
-
expect {
|
29
|
-
described_class.class_from_string("FooClass", ParentClass::OtherSiblingClass)
|
30
|
-
}.to raise_error NameError, /uninitialized constant (Object::)?FooClass/
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#models' do
|
35
|
-
it 'converts class names to classes' do
|
36
|
-
expect(classifier.models).to match_array [ParentClass::SiblingClass, ParentClass::OtherSiblingClass, ParentClass::SubclassClass]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#best_model' do
|
41
|
-
it 'selects the most specific matching model' do
|
42
|
-
expect(classifier.best_model(default: nil)).to eq ParentClass::SubclassClass
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'filters models to subclasses of the default' do
|
46
|
-
expect(classifier.best_model(default: ActiveFedora::Base)).to eq ActiveFedora::Base
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/spec/unit/ordered_spec.rb
DELETED
@@ -1,367 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Orders do
|
4
|
-
subject(:image) { Image.new }
|
5
|
-
before do
|
6
|
-
class Member < ActiveFedora::Base
|
7
|
-
end
|
8
|
-
class BadClass < ActiveFedora::Base
|
9
|
-
end
|
10
|
-
class Image < ActiveFedora::Base
|
11
|
-
ordered_aggregation :members, through: :list_source
|
12
|
-
end
|
13
|
-
end
|
14
|
-
after do
|
15
|
-
Object.send(:remove_const, :Image)
|
16
|
-
Object.send(:remove_const, :Member)
|
17
|
-
Object.send(:remove_const, :BadClass)
|
18
|
-
end
|
19
|
-
describe "<<" do
|
20
|
-
it "does not accept base objects" do
|
21
|
-
member = Member.new
|
22
|
-
expect { image.ordered_member_proxies << member }.to raise_error ActiveFedora::AssociationTypeMismatch
|
23
|
-
expect(image).not_to be_changed
|
24
|
-
expect(image.list_source).not_to be_changed
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "ordered_by" do
|
29
|
-
let(:image) { Image.new }
|
30
|
-
|
31
|
-
context "an element aggregated by one record" do
|
32
|
-
it "can find the record that contains it" do
|
33
|
-
m = Member.create
|
34
|
-
image.ordered_members << m
|
35
|
-
image.save
|
36
|
-
|
37
|
-
expect(m.ordered_by.to_a).to eq [image]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "a new element" do
|
42
|
-
it "returns an empty array" do
|
43
|
-
m = Member.new
|
44
|
-
expect(m.ordered_by.to_a).to eq []
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "an element aggregated by multiple records" do
|
49
|
-
let(:image2) { Image.new }
|
50
|
-
it "can find all of the records that contain it" do
|
51
|
-
m = Member.create
|
52
|
-
image.ordered_members << m
|
53
|
-
image2.ordered_members << m
|
54
|
-
image.save
|
55
|
-
image2.save
|
56
|
-
expect(m.ordered_by).to contain_exactly(image2, image)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#ordered_members" do
|
62
|
-
describe "<<" do
|
63
|
-
it "appends" do
|
64
|
-
member = Member.new
|
65
|
-
image.save!
|
66
|
-
expect(image.ordered_members << member).to eq [member]
|
67
|
-
expect(image.ordered_members).to eq [member]
|
68
|
-
expect(image.members).to eq [member]
|
69
|
-
expect(image.ordered_member_proxies.to_a.length).to eq 1
|
70
|
-
image.save!
|
71
|
-
expect(image.head).not_to be_blank
|
72
|
-
expect(image.reload.head).not_to be_blank
|
73
|
-
end
|
74
|
-
it "maintains member associations" do
|
75
|
-
member = Member.create
|
76
|
-
image.ordered_members << member
|
77
|
-
image.save
|
78
|
-
image.reload
|
79
|
-
expect(image.members).to eq [member]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
describe "#=" do
|
83
|
-
it "sets ordered members" do
|
84
|
-
member = Member.new
|
85
|
-
member_2 = Member.new
|
86
|
-
image.ordered_members << member
|
87
|
-
expect(image.ordered_members).to eq [member]
|
88
|
-
image.ordered_members = [member_2, member_2]
|
89
|
-
expect(image.ordered_members).to eq [member_2, member_2]
|
90
|
-
# Removing from ordering is not the same as removing from aggregation.
|
91
|
-
expect(image.members).to contain_exactly member, member_2
|
92
|
-
end
|
93
|
-
end
|
94
|
-
describe "+=" do
|
95
|
-
it "appends ordered members" do
|
96
|
-
member = Member.new
|
97
|
-
member_2 = Member.new
|
98
|
-
image.ordered_members << member
|
99
|
-
expect(image.ordered_members += [member, member_2]).to eq [member, member, member_2]
|
100
|
-
expect(image.ordered_members).to eq [member, member, member_2]
|
101
|
-
expect(image.ordered_member_proxies.map(&:target)).to eq [member, member, member_2]
|
102
|
-
end
|
103
|
-
end
|
104
|
-
describe "#delete_at" do
|
105
|
-
it "deletes that position" do
|
106
|
-
member = Member.new
|
107
|
-
member_2 = Member.new
|
108
|
-
image.ordered_members += [member, member_2]
|
109
|
-
|
110
|
-
expect(image.ordered_members.delete_at(0)).to eq member
|
111
|
-
expect(image.ordered_members).to eq [member_2]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#delete" do
|
116
|
-
let(:member) { Member.create }
|
117
|
-
let(:member_2) { Member.create }
|
118
|
-
before do
|
119
|
-
image.ordered_members += [member, member_2, member]
|
120
|
-
image.save!
|
121
|
-
end
|
122
|
-
|
123
|
-
context "with an object found in the list" do
|
124
|
-
it "deletes all occurences of the object" do
|
125
|
-
expect(image.ordered_members.delete(member)).to eq member
|
126
|
-
expect(image.ordered_members.to_a).to eq [member_2]
|
127
|
-
end
|
128
|
-
it "can delete all" do
|
129
|
-
expect(image.ordered_members.delete(member)).to eq member
|
130
|
-
expect(image.ordered_members.delete(member_2)).to eq member_2
|
131
|
-
image.save!
|
132
|
-
expect(image.reload.ordered_members.to_a).to eq []
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "with an object not found in the list" do
|
137
|
-
it "returns nil" do
|
138
|
-
expect(image.ordered_members.delete(Member.create)).to be_nil
|
139
|
-
expect(image.ordered_members.to_a).to eq [member, member_2, member]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "#insert_at" do
|
145
|
-
it "adds at a given position" do
|
146
|
-
member = Member.new
|
147
|
-
member_2 = Member.new
|
148
|
-
image.ordered_members += [member, member_2]
|
149
|
-
|
150
|
-
image.ordered_members.insert_at(0, member_2)
|
151
|
-
expect(image.ordered_members).to eq [member_2, member, member_2]
|
152
|
-
end
|
153
|
-
it "adds a proxy_in statement" do
|
154
|
-
member = Member.new
|
155
|
-
member_2 = Member.new
|
156
|
-
image.ordered_members += [member, member_2]
|
157
|
-
|
158
|
-
image.ordered_members.insert_at(0, member_2)
|
159
|
-
expect(image.ordered_member_proxies.map(&:proxy_in).uniq).to eq [image]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
describe "lazy loading" do
|
163
|
-
it "does not instantiate every record on append" do
|
164
|
-
member = Member.new
|
165
|
-
member_2 = Member.new
|
166
|
-
image.ordered_members += [member, member_2]
|
167
|
-
image.save
|
168
|
-
allow(ActiveFedora::Base).to receive(:find).and_call_original
|
169
|
-
|
170
|
-
reloaded = image.class.find(image.id)
|
171
|
-
reloaded.ordered_members << member
|
172
|
-
|
173
|
-
expect(ActiveFedora::Base).not_to have_received(:find).with(member_2.id)
|
174
|
-
end
|
175
|
-
it "does not instantiate every record on #insert_at" do
|
176
|
-
member = Member.new
|
177
|
-
member_2 = Member.new
|
178
|
-
image.ordered_members += [member, member_2]
|
179
|
-
image.save
|
180
|
-
allow(ActiveFedora::Base).to receive(:find).and_call_original
|
181
|
-
|
182
|
-
reloaded = image.class.find(image.id)
|
183
|
-
reloaded.ordered_members.insert_at(0, member)
|
184
|
-
|
185
|
-
expect(ActiveFedora::Base).not_to have_received(:find).with(member_2.id)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
describe "append_target" do
|
190
|
-
it "doesn't add all members" do
|
191
|
-
member = Member.new
|
192
|
-
image.members << member
|
193
|
-
expect(image.ordered_members).to eq []
|
194
|
-
end
|
195
|
-
it "can handle adding many objects" do
|
196
|
-
member = Member.new
|
197
|
-
60.times do
|
198
|
-
image.ordered_member_proxies.append_target member
|
199
|
-
end
|
200
|
-
expect(image.ordered_member_proxies.to_a.length).to eq 60
|
201
|
-
end
|
202
|
-
it "can't add items not accepted by indirect container" do
|
203
|
-
bad_class = BadClass.new
|
204
|
-
expect { image.ordered_member_proxies.append_target bad_class }.to raise_error ActiveFedora::AssociationTypeMismatch
|
205
|
-
end
|
206
|
-
it "adds a member if it doesn't exist in members" do
|
207
|
-
member = Member.new
|
208
|
-
image.ordered_member_proxies.append_target member
|
209
|
-
expect(image.members).to eq [member]
|
210
|
-
expect(image.ordered_members).to eq [member]
|
211
|
-
end
|
212
|
-
it "doesn't add a member twice" do
|
213
|
-
member = Member.new
|
214
|
-
image.ordered_member_proxies.append_target member
|
215
|
-
image.ordered_member_proxies.append_target member
|
216
|
-
expect(image.members).to eq [member]
|
217
|
-
expect(image.ordered_members).to eq [member, member]
|
218
|
-
end
|
219
|
-
it "survives persistence" do
|
220
|
-
member = Member.new
|
221
|
-
image.ordered_member_proxies.append_target member
|
222
|
-
image.ordered_member_proxies.append_target member
|
223
|
-
image.save
|
224
|
-
image.reload
|
225
|
-
expect(image.ordered_members).to eq [member, member]
|
226
|
-
expect(image.ordered_member_ids).to eq [member.id, member.id]
|
227
|
-
expect(image.list_source.resource.query([nil, ::RDF::Vocab::ORE.proxyIn, image.resource.rdf_subject]).to_a.length).to eq 2
|
228
|
-
expect(image.head_ids).to eq image.list_source.head_id
|
229
|
-
expect(image.tail_ids).to eq image.list_source.tail_id
|
230
|
-
end
|
231
|
-
it "can add already persisted items" do
|
232
|
-
member = Member.create
|
233
|
-
image.ordered_member_proxies.append_target member
|
234
|
-
image.save
|
235
|
-
image.reload
|
236
|
-
expect(image.ordered_members).to eq [member]
|
237
|
-
end
|
238
|
-
it "can append to a pre-persisted item" do
|
239
|
-
member = Member.new
|
240
|
-
image.ordered_member_proxies.append_target member
|
241
|
-
image.save
|
242
|
-
image.reload
|
243
|
-
member_2 = Member.new
|
244
|
-
image.ordered_member_proxies.append_target member_2
|
245
|
-
image.save
|
246
|
-
image.reload
|
247
|
-
expect(image.ordered_members).to eq [member, member_2]
|
248
|
-
end
|
249
|
-
end
|
250
|
-
describe "insert_target_at" do
|
251
|
-
it "can add between items" do
|
252
|
-
member = Member.new
|
253
|
-
member2 = Member.new
|
254
|
-
image.ordered_member_proxies.append_target member
|
255
|
-
image.ordered_member_proxies.append_target member
|
256
|
-
image.ordered_member_proxies.insert_target_at(1, member2)
|
257
|
-
expect(image.ordered_members).to eq [member, member2, member]
|
258
|
-
image.save
|
259
|
-
image.reload
|
260
|
-
expect(image.ordered_members).to eq [member, member2, member]
|
261
|
-
image.ordered_member_proxies.insert_target_at(2, member2)
|
262
|
-
image.save
|
263
|
-
image.reload
|
264
|
-
expect(image.ordered_members).to eq [member, member2, member2, member]
|
265
|
-
end
|
266
|
-
end
|
267
|
-
describe "insert_target_id_at" do
|
268
|
-
it "can add between items" do
|
269
|
-
member = Member.create
|
270
|
-
member2 = Member.create
|
271
|
-
image.ordered_members += [member, member2]
|
272
|
-
|
273
|
-
allow(ActiveFedora::Base).to receive(:find).and_call_original
|
274
|
-
image.ordered_member_proxies.insert_target_id_at(1, member2.id)
|
275
|
-
expect(ActiveFedora::Base).not_to have_received(:find).with(member2.id)
|
276
|
-
expect(image.ordered_members).to eq [member, member2, member2]
|
277
|
-
expect(ActiveFedora::Base).to have_received(:find).with(member2.id)
|
278
|
-
end
|
279
|
-
context "when given a nil id" do
|
280
|
-
it "raises an ArgumentError" do
|
281
|
-
expect { image.ordered_member_proxies.insert_target_id_at(0, nil) }.to raise_error ArgumentError, "ID can not be nil"
|
282
|
-
end
|
283
|
-
end
|
284
|
-
context "when given an ID not in members" do
|
285
|
-
it "raises an ArgumentError" do
|
286
|
-
expect { image.ordered_member_proxies.insert_target_id_at(0, "test") }.to raise_error "test is not a part of members"
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
describe "-=" do
|
291
|
-
it "can remove proxies" do
|
292
|
-
member = Member.new
|
293
|
-
image.ordered_member_proxies.append_target member
|
294
|
-
image.ordered_member_proxies -= [image.ordered_member_proxies.last]
|
295
|
-
expect(image.ordered_members).to eq []
|
296
|
-
expect(image.list_source.resource.statements.to_a.length).to eq 1
|
297
|
-
end
|
298
|
-
it "can remove proxies in the middle" do
|
299
|
-
member = Member.new
|
300
|
-
member_2 = Member.new
|
301
|
-
image.ordered_member_proxies.append_target member
|
302
|
-
image.ordered_member_proxies.append_target member_2
|
303
|
-
image.ordered_member_proxies.append_target member
|
304
|
-
image.ordered_member_proxies -= [image.ordered_member_proxies[1]]
|
305
|
-
expect(image.ordered_members).to eq [member, member]
|
306
|
-
end
|
307
|
-
it "can remove proxies post-create" do
|
308
|
-
member = Member.new
|
309
|
-
image.ordered_member_proxies.append_target member
|
310
|
-
image.ordered_member_proxies.append_target member
|
311
|
-
image.ordered_member_proxies.append_target member
|
312
|
-
image.save
|
313
|
-
image.reload
|
314
|
-
image.ordered_member_proxies -= [image.ordered_member_proxies[1]]
|
315
|
-
expect(image.ordered_members).to eq [member, member]
|
316
|
-
image.save
|
317
|
-
image.reload
|
318
|
-
expect(image.ordered_members).to eq [member, member]
|
319
|
-
# THIS NEEDS TO PASS - can't delete fragment URI resources via sparql
|
320
|
-
# update?
|
321
|
-
# Blocked by https://jira.duraspace.org/browse/FCREPO-1764
|
322
|
-
# expect(image.list_source.resource.subjects.to_a.length).to eq 5
|
323
|
-
end
|
324
|
-
end
|
325
|
-
describe ".delete_at" do
|
326
|
-
it "can remove in the middle" do
|
327
|
-
member = Member.new
|
328
|
-
image.ordered_member_proxies.append_target member
|
329
|
-
image.ordered_member_proxies.append_target member
|
330
|
-
image.ordered_member_proxies.append_target member
|
331
|
-
image.ordered_member_proxies.delete_at(1)
|
332
|
-
expect(image.ordered_members).to eq [member, member]
|
333
|
-
end
|
334
|
-
it "returns the node" do
|
335
|
-
member = Member.new
|
336
|
-
image.ordered_members << member
|
337
|
-
image.ordered_members << member
|
338
|
-
second_node = image.ordered_member_proxies[1]
|
339
|
-
expect(image.ordered_member_proxies.delete_at(1)).to eq second_node
|
340
|
-
end
|
341
|
-
context "when the node doesn't exist" do
|
342
|
-
it "returns nil" do
|
343
|
-
expect(image.ordered_member_proxies.delete_at(0)).to eq nil
|
344
|
-
end
|
345
|
-
end
|
346
|
-
it "doesn't do anything if passed a bad value" do
|
347
|
-
member = Member.new
|
348
|
-
image.ordered_member_proxies.append_target member
|
349
|
-
image.ordered_member_proxies.append_target member
|
350
|
-
image.ordered_member_proxies.append_target member
|
351
|
-
image.ordered_member_proxies.delete_at(3)
|
352
|
-
image.ordered_member_proxies.delete_at(nil)
|
353
|
-
expect(image.ordered_members).to eq [member, member, member]
|
354
|
-
end
|
355
|
-
it "can persist a deletion" do
|
356
|
-
member = Member.new
|
357
|
-
image.ordered_member_proxies.append_target member
|
358
|
-
image.ordered_member_proxies.append_target member
|
359
|
-
image.ordered_member_proxies.append_target member
|
360
|
-
expect(image.ordered_members).to eq [member, member, member]
|
361
|
-
image.ordered_member_proxies.delete_at(1)
|
362
|
-
image.save
|
363
|
-
image.reload
|
364
|
-
expect(image.ordered_members).to eq [member, member]
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|