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,146 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::AttachedFiles do
|
4
|
-
describe "#has_subresource" do
|
5
|
-
before do
|
6
|
-
class FooHistory < ActiveFedora::Base
|
7
|
-
has_subresource 'child'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
after do
|
11
|
-
Object.send(:remove_const, :FooHistory)
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when the object exists" do
|
15
|
-
let!(:o) { FooHistory.create }
|
16
|
-
before do
|
17
|
-
o.child.content = "HMMM"
|
18
|
-
o.save
|
19
|
-
end
|
20
|
-
|
21
|
-
it "does not need to do a head on the children" do
|
22
|
-
f = FooHistory.find(o.id)
|
23
|
-
expect(f.ldp_source.client).not_to receive(:head)
|
24
|
-
f.child.content
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "Datastreams synched together" do
|
30
|
-
before do
|
31
|
-
class DSTest < ActiveFedora::Base
|
32
|
-
def load_attached_files
|
33
|
-
super
|
34
|
-
return if attached_files.keys.include? :test_ds
|
35
|
-
add_file("XXX", path: 'test_ds', mime_type: 'text/html')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
subject { ds.content }
|
41
|
-
let(:file) { DSTest.create }
|
42
|
-
let(:ds) { file.test_ds }
|
43
|
-
|
44
|
-
after do
|
45
|
-
Object.send(:remove_const, :DSTest)
|
46
|
-
end
|
47
|
-
|
48
|
-
it { is_expected.to eq('XXX') }
|
49
|
-
|
50
|
-
context "After updating" do
|
51
|
-
before do
|
52
|
-
ds.content = "Foobar"
|
53
|
-
file.save!
|
54
|
-
end
|
55
|
-
|
56
|
-
it "updates datastream" do
|
57
|
-
expect(DSTest.find(file.id).attached_files['test_ds'].content).to eq 'Foobar'
|
58
|
-
expect(DSTest.find(file.id).test_ds.content).to eq 'Foobar'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "an instance of ActiveFedora::Base" do
|
64
|
-
let(:obj) { ActiveFedora::Base.new }
|
65
|
-
|
66
|
-
describe ".attached_files" do
|
67
|
-
subject(:attached_files) { obj.attached_files }
|
68
|
-
it "returns a Hash of datastreams from fedora" do
|
69
|
-
expect(attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
|
70
|
-
expect(attached_files).to be_empty
|
71
|
-
end
|
72
|
-
|
73
|
-
it "initializes the datastream pointers with @new_object=false" do
|
74
|
-
attached_files.each_value do |ds|
|
75
|
-
expect(ds).to_not be_new
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe ".metadata_streams" do
|
81
|
-
before do
|
82
|
-
class Metadata < ActiveFedora::File
|
83
|
-
def metadata?
|
84
|
-
true
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
obj.attach_file(mds1, 'md1')
|
89
|
-
obj.attach_file(mds2, 'qdc')
|
90
|
-
obj.attach_file(fds, 'fds')
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:mds1) { Metadata.new }
|
94
|
-
let(:mds2) { Metadata.new }
|
95
|
-
let(:fds) { ActiveFedora::File.new }
|
96
|
-
|
97
|
-
after do
|
98
|
-
Object.send(:remove_const, :Metadata)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns all of the datastreams from the object that are kinds of OmDatastream" do
|
102
|
-
expect(obj.metadata_streams).to match_array [mds1, mds2]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#add_file' do
|
107
|
-
before do
|
108
|
-
f = File.new(File.join(File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext"))
|
109
|
-
obj.add_file(f, mime_type: "image/jpeg")
|
110
|
-
obj.save
|
111
|
-
end
|
112
|
-
|
113
|
-
it "sets the correct mime_type if :mime_type is passed in and path does not contain correct extension" do
|
114
|
-
expect(obj.reload.attached_files["DS1"].mime_type).to eq "image/jpeg"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '.attach_file' do
|
119
|
-
let(:ds) { ActiveFedora::File.new }
|
120
|
-
|
121
|
-
it "is able to add datastreams" do
|
122
|
-
expect(obj.attach_file(ds, 'DS1')).to eq 'DS1'
|
123
|
-
end
|
124
|
-
|
125
|
-
it "adding and saving should add the datastream to the datastreams array" do
|
126
|
-
ds.content = fixture('dino.jpg').read
|
127
|
-
expect(obj.attached_files).to_not have_key(:DS1)
|
128
|
-
obj.attach_file(ds, 'DS1')
|
129
|
-
obj.save
|
130
|
-
expect(obj.attached_files).to have_key(:DS1)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "retrieving datastream content" do
|
135
|
-
let(:obj) { ActiveFedora::Base.create }
|
136
|
-
after { obj.destroy }
|
137
|
-
|
138
|
-
let(:ds) { ActiveFedora::File.new(obj.uri + '/DS1') { |ds| ds.content = "foo"; ds.save } }
|
139
|
-
|
140
|
-
it "retrieves blobs that match the saved blobs" do
|
141
|
-
obj.attach_file(ds, 'DS1')
|
142
|
-
expect(obj.reload.attached_files["DS1"].content).to eq "foo"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "delegating attributes" do
|
4
|
-
before :all do
|
5
|
-
class TitledObject < ActiveFedora::Base
|
6
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
7
|
-
end
|
8
|
-
|
9
|
-
class RdfObject < ActiveFedora::Base
|
10
|
-
property :resource_type, predicate: ::RDF::Vocab::DC.type do |index|
|
11
|
-
index.as :stored_searchable, :facetable
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
after :all do
|
17
|
-
Object.send(:remove_const, :TitledObject)
|
18
|
-
Object.send(:remove_const, :RdfObject)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#index_config" do
|
22
|
-
context "on a class with properties" do
|
23
|
-
subject(:index_config) { RdfObject.index_config }
|
24
|
-
it "has configuration" do
|
25
|
-
expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when a class inherits properties" do
|
30
|
-
before do
|
31
|
-
class InheritedObject < RdfObject
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
after do
|
36
|
-
Object.send(:remove_const, :InheritedObject)
|
37
|
-
end
|
38
|
-
|
39
|
-
subject(:index_config) { InheritedObject.index_config }
|
40
|
-
|
41
|
-
it "has configuration" do
|
42
|
-
expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when the inherited config is modifed" do
|
46
|
-
before do
|
47
|
-
InheritedObject.index_config[:resource_type].behaviors.delete(:stored_searchable)
|
48
|
-
end
|
49
|
-
subject(:index_config) { RdfObject.index_config }
|
50
|
-
|
51
|
-
it "the parent config is unchanged" do
|
52
|
-
expect(index_config[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "previous_changes" do
|
59
|
-
subject(:titled_object) { TitledObject.create(title: ["Hydra for Dummies"]) }
|
60
|
-
it "keeps a list of changes after a successful save" do
|
61
|
-
expect(titled_object.previous_changes).to_not be_empty
|
62
|
-
expect(titled_object.previous_changes.keys).to include("title")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#changes" do
|
67
|
-
let(:titled_object) { TitledObject.create(title: ["Hydra for Dummies"]) }
|
68
|
-
it "cleans out changes" do
|
69
|
-
expect(titled_object).to_not be_title_changed
|
70
|
-
expect(titled_object.changes).to be_empty
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before :all do
|
5
|
-
class MockAFBaseRelationship < ActiveFedora::Base
|
6
|
-
end
|
7
|
-
end
|
8
|
-
after :all do
|
9
|
-
Object.send(:remove_const, :MockAFBaseRelationship)
|
10
|
-
end
|
11
|
-
|
12
|
-
subject(:relationship) { MockAFBaseRelationship.new }
|
13
|
-
|
14
|
-
context '#changed_for_autosave?' do
|
15
|
-
before do
|
16
|
-
expect(relationship).to receive(:new_record?).and_return(false)
|
17
|
-
expect(relationship).to receive(:changed?).and_return(false)
|
18
|
-
expect(relationship).to receive(:marked_for_destruction?).and_return(false)
|
19
|
-
end
|
20
|
-
it {
|
21
|
-
expect { relationship.changed_for_autosave? }.to_not raise_error
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before(:all) do
|
5
|
-
class Foo < ActiveFedora::Base
|
6
|
-
property :person, predicate: ::RDF::Vocab::DC.creator
|
7
|
-
end
|
8
|
-
end
|
9
|
-
after(:all) { Object.send(:remove_const, :Foo) }
|
10
|
-
|
11
|
-
describe '#reload' do
|
12
|
-
context "when persisted" do
|
13
|
-
let(:object) { Foo.create(person: ['bob']) }
|
14
|
-
let(:object2) { Foo.find(object.id) }
|
15
|
-
before { object2.update(person: ['dave']) }
|
16
|
-
|
17
|
-
it 're-queries Fedora' do
|
18
|
-
object.reload
|
19
|
-
expect(object.person).to eq ['dave']
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when not persisted" do
|
24
|
-
it 'raises an error' do
|
25
|
-
expect { Foo.new.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "a saved object" do
|
31
|
-
before(:all) do
|
32
|
-
class Book < ActiveFedora::Base
|
33
|
-
type [::RDF::URI("http://www.example.com/Book")]
|
34
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
35
|
-
end
|
36
|
-
end
|
37
|
-
after(:all) { Object.send(:remove_const, :Book) }
|
38
|
-
after { obj.destroy unless obj.destroyed? }
|
39
|
-
let!(:obj) { Book.create }
|
40
|
-
|
41
|
-
describe "#errors" do
|
42
|
-
subject { obj.errors }
|
43
|
-
it { is_expected.to be_empty }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#id" do
|
47
|
-
subject { obj.id }
|
48
|
-
it { is_expected.to_not be_nil }
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when updated with changes after one second" do
|
52
|
-
before do
|
53
|
-
obj.title = ['sample']
|
54
|
-
sleep 1
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'updates the modification time field in solr' do
|
58
|
-
expect { obj.save }.to change {
|
59
|
-
ActiveFedora::SolrService.query("id:\"#{obj.id}\"").first['system_modified_dtsi']
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#create_date" do
|
65
|
-
subject { obj.create_date }
|
66
|
-
it { is_expected.to_not be_nil }
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#modified_date" do
|
70
|
-
subject { obj.modified_date }
|
71
|
-
it { is_expected.to_not be_nil }
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "delete" do
|
75
|
-
it "deletes the object from Fedora and Solr" do
|
76
|
-
expect {
|
77
|
-
obj.delete
|
78
|
-
}.to change { described_class.exists?(obj.id) }.from(true).to(false)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#type" do
|
83
|
-
subject { obj.type }
|
84
|
-
it { is_expected.to include(::RDF::URI("http://www.example.com/Book")) }
|
85
|
-
context "when adding additional types" do
|
86
|
-
before do
|
87
|
-
t = obj.get_values(:type)
|
88
|
-
t << ::RDF::URI("http://www.example.com/Novel")
|
89
|
-
obj.set_value(:type, t)
|
90
|
-
end
|
91
|
-
it { is_expected.to include(::RDF::URI("http://www.example.com/Novel")) }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#apply_schema" do
|
97
|
-
before do
|
98
|
-
class ExampleSchema < ActiveTriples::Schema
|
99
|
-
property :title, predicate: RDF::Vocab::DC.title
|
100
|
-
end
|
101
|
-
class ExampleBase < ActiveFedora::Base
|
102
|
-
apply_schema ExampleSchema, ActiveFedora::SchemaIndexingStrategy.new(ActiveFedora::Indexers::GlobalIndexer.new(:symbol))
|
103
|
-
end
|
104
|
-
end
|
105
|
-
after do
|
106
|
-
Object.send(:remove_const, :ExampleSchema)
|
107
|
-
Object.send(:remove_const, :ExampleBase)
|
108
|
-
end
|
109
|
-
let(:obj) { ExampleBase.new }
|
110
|
-
it "configures properties and solrize them" do
|
111
|
-
obj.title = ["Test"]
|
112
|
-
expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name("title", :symbol)]).to eq ["Test"]
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
shared_examples 'ActiveFedora::Base#exists?' do
|
117
|
-
let(:obj) { test_class.create }
|
118
|
-
it "returns true for objects that exist" do
|
119
|
-
expect(test_class.exists?(obj)).to be true
|
120
|
-
end
|
121
|
-
it "returns true for ids that exist" do
|
122
|
-
expect(test_class.exists?(obj.id)).to be true
|
123
|
-
end
|
124
|
-
it "returns false for ids that don't exist" do
|
125
|
-
expect(test_class.exists?('test_missing_object')).to be false
|
126
|
-
end
|
127
|
-
it "returns false for nil, false and empty" do
|
128
|
-
expect(test_class.exists?(nil)).to be false
|
129
|
-
expect(test_class.exists?(false)).to be false
|
130
|
-
expect(test_class.exists?('')).to be false
|
131
|
-
end
|
132
|
-
context "when passed a hash of conditions" do
|
133
|
-
let(:conditions) { { foo: "bar" } }
|
134
|
-
context "and at least one object matches the conditions" do
|
135
|
-
it "returns true" do
|
136
|
-
allow(ActiveFedora::SolrService).to receive(:query) { [instance_double(RSolr::HashWithResponse)] }
|
137
|
-
expect(test_class.exists?(conditions)).to be true
|
138
|
-
end
|
139
|
-
end
|
140
|
-
context "and no object matches the conditions" do
|
141
|
-
it "returns false" do
|
142
|
-
allow(ActiveFedora::SolrService).to receive(:query) { [] }
|
143
|
-
expect(test_class.exists?(conditions)).to be false
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'base class' do
|
150
|
-
let(:test_class) { described_class }
|
151
|
-
it_behaves_like 'ActiveFedora::Base#exists?'
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'subclass' do
|
155
|
-
let(:test_class) { Foo }
|
156
|
-
it_behaves_like 'ActiveFedora::Base#exists?'
|
157
|
-
|
158
|
-
it 'does not mistake other fedora objects for subclass' do
|
159
|
-
obj = described_class.create
|
160
|
-
expect { test_class.exists?(obj.id) }.not_to raise_error
|
161
|
-
expect(test_class.exists?(obj.id)).to be false
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "overriding resource_class_factory" do
|
166
|
-
subject(:test_base) { TestBase.new }
|
167
|
-
before do
|
168
|
-
class TestResource < ActiveTriples::Resource
|
169
|
-
end
|
170
|
-
class TestBase < ActiveFedora::Base
|
171
|
-
def self.resource_class_factory
|
172
|
-
TestResource
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
after do
|
177
|
-
Object.send(:remove_const, :TestResource)
|
178
|
-
Object.send(:remove_const, :TestBase)
|
179
|
-
end
|
180
|
-
it "uses that factory for #resource" do
|
181
|
-
expect(test_base.resource.class.ancestors).to include TestResource
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Associations::BasicContainsAssociation do
|
4
|
-
context "with a file" do
|
5
|
-
before do
|
6
|
-
class Source < ActiveFedora::Base
|
7
|
-
is_a_container
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:model) { Source.new }
|
12
|
-
|
13
|
-
after do
|
14
|
-
Object.send(:remove_const, :Source)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'is empty' do
|
18
|
-
expect(model.contains).to eq []
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'can build a child' do
|
22
|
-
child = model.contains.build
|
23
|
-
expect(child).to be_kind_of ActiveFedora::File
|
24
|
-
child.content = "hello"
|
25
|
-
model.save!
|
26
|
-
expect(child).to be_persisted
|
27
|
-
expect(child.uri.to_s).to include model.uri.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'can create a child on a persisted parent' do
|
31
|
-
model.save!
|
32
|
-
child = model.contains.build
|
33
|
-
expect(child).to be_kind_of ActiveFedora::File
|
34
|
-
child.content = "hello"
|
35
|
-
model.save!
|
36
|
-
expect(child).to be_persisted
|
37
|
-
expect(child.uri.to_s).to include model.uri.to_s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "with an AF::Base object" do
|
42
|
-
before do
|
43
|
-
class Thing < ActiveFedora::Base
|
44
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
45
|
-
end
|
46
|
-
class Source < ActiveFedora::Base
|
47
|
-
is_a_container class_name: 'Thing'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
after do
|
51
|
-
Object.send(:remove_const, :Source)
|
52
|
-
Object.send(:remove_const, :Thing)
|
53
|
-
end
|
54
|
-
|
55
|
-
let(:model) { Source.new }
|
56
|
-
|
57
|
-
it 'is empty' do
|
58
|
-
expect(model.contains).to eq []
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "creating" do
|
62
|
-
it 'can build a child' do
|
63
|
-
child = model.contains.build
|
64
|
-
expect(model.contains.build(title: ['my title'])).to be_kind_of Thing
|
65
|
-
model.save!
|
66
|
-
expect(child).to be_persisted
|
67
|
-
expect(child.uri.to_s).to include model.uri.to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'can create a child on a persisted parent' do
|
71
|
-
model.save!
|
72
|
-
child = model.contains.create(title: ['my title'])
|
73
|
-
expect(child).to be_kind_of Thing
|
74
|
-
expect(child).to be_persisted
|
75
|
-
expect(child.uri.to_s).to include model.uri.to_s
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "loading" do
|
80
|
-
before do
|
81
|
-
model.save!
|
82
|
-
model.contains.create(title: ['title 1'])
|
83
|
-
model.contains.create(title: ['title 2'])
|
84
|
-
model.reload
|
85
|
-
end
|
86
|
-
|
87
|
-
it "has the two contained objects" do
|
88
|
-
expect(model.contains.size).to eq 2
|
89
|
-
expect(model.contains.map(&:title)).to contain_exactly ['title 1'], ['title 2']
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "#destroy_all" do
|
94
|
-
before do
|
95
|
-
model.save!
|
96
|
-
model.contains.create(title: ['title 1'])
|
97
|
-
model.contains.create(title: ['title 2'])
|
98
|
-
model.reload
|
99
|
-
end
|
100
|
-
|
101
|
-
it "destroys the two contained objects" do
|
102
|
-
expect { model.contains.destroy_all }
|
103
|
-
.to change { model.contains.size }.by(-2)
|
104
|
-
.and change { Thing.count }.by(-2)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#reload" do
|
109
|
-
before do
|
110
|
-
model.save!
|
111
|
-
child = model.contains.create(title: ['title 1'])
|
112
|
-
model.reload # Cause the model to load its graph that contains the child ids.
|
113
|
-
ActiveFedora::Base.find(child.id).destroy
|
114
|
-
end
|
115
|
-
|
116
|
-
it "can reload without attempting to load any deleted objects" do
|
117
|
-
expect { model.contains.reload }.not_to raise_error
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|