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,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before(:all) do
|
5
|
-
class TestClass < ActiveFedora::Base
|
6
|
-
property :foo, predicate: ::RDF::URI('http://example.com/foo')
|
7
|
-
property :bar, predicate: ::RDF::URI('http://example.com/bar') do |index|
|
8
|
-
index.as :stored_searchable
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_solr(doc = {})
|
12
|
-
doc = super
|
13
|
-
doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
|
14
|
-
doc
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
after(:all) do
|
20
|
-
Object.send(:remove_const, :TestClass)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "with multiple objects" do
|
24
|
-
let!(:instance1) { TestClass.create!(foo: ['Beta'], bar: ['Chips']) }
|
25
|
-
let!(:instance2) { TestClass.create!(foo: ['Alpha'], bar: ['Peanuts']) }
|
26
|
-
let!(:instance3) { TestClass.create!(foo: ['Sigma'], bar: ['Peanuts']) }
|
27
|
-
|
28
|
-
subject(:peanuts) { TestClass.where(bar: 'Peanuts') }
|
29
|
-
|
30
|
-
it "maps" do
|
31
|
-
expect(peanuts.map(&:id)).to contain_exactly instance2.id, instance3.id
|
32
|
-
end
|
33
|
-
|
34
|
-
it "collects" do
|
35
|
-
expect(peanuts.collect(&:id)).to contain_exactly instance2.id, instance3.id
|
36
|
-
end
|
37
|
-
|
38
|
-
it "has each" do
|
39
|
-
expect(peanuts.each.to_a.length).to eq 2
|
40
|
-
end
|
41
|
-
|
42
|
-
it "has all?" do
|
43
|
-
expect(peanuts.all? { |t| t.foo == ['Alpha'] }).to be false
|
44
|
-
expect(peanuts.all? { |t| t.bar == ['Peanuts'] }).to be true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "has include?" do
|
48
|
-
expect(peanuts.include?(instance1)).to be false
|
49
|
-
expect(peanuts.include?(instance2)).to be true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Base do
|
4
|
-
before :all do
|
5
|
-
class Library < ActiveFedora::Base
|
6
|
-
has_many :books
|
7
|
-
end
|
8
|
-
class Book < ActiveFedora::Base
|
9
|
-
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
Object.send(:remove_const, :Library)
|
15
|
-
Object.send(:remove_const, :Book)
|
16
|
-
end
|
17
|
-
|
18
|
-
subject(:libraries) { Library.all }
|
19
|
-
|
20
|
-
it "is a relation" do
|
21
|
-
expect(libraries.class).to be ActiveFedora::Relation
|
22
|
-
end
|
23
|
-
|
24
|
-
it { is_expected.to respond_to(:each_with_index) }
|
25
|
-
it { expect(libraries.any?).to eq false }
|
26
|
-
it { is_expected.to be_blank }
|
27
|
-
it { is_expected.to be_empty }
|
28
|
-
it { is_expected.not_to be_present }
|
29
|
-
|
30
|
-
context "when some records exist" do
|
31
|
-
before do
|
32
|
-
Library.create
|
33
|
-
end
|
34
|
-
|
35
|
-
let!(:library1) { Library.create }
|
36
|
-
|
37
|
-
describe "is cached" do
|
38
|
-
before do
|
39
|
-
libraries.to_a # trigger initial load
|
40
|
-
end
|
41
|
-
|
42
|
-
it { is_expected.to be_loaded }
|
43
|
-
|
44
|
-
it "does not reload" do
|
45
|
-
expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
|
46
|
-
libraries[0]
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does not reload" do
|
50
|
-
expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
|
51
|
-
libraries.each { |l| l.id }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it { expect(libraries.any?).to eq true }
|
56
|
-
it { is_expected.not_to be_blank }
|
57
|
-
it { is_expected.not_to be_empty }
|
58
|
-
it { is_expected.to be_present }
|
59
|
-
|
60
|
-
describe '#each' do
|
61
|
-
before { Book.create }
|
62
|
-
|
63
|
-
it 'returns an enumerator' do
|
64
|
-
expect(libraries.each).to be_a Enumerator
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'yields the items' do
|
68
|
-
expect { |b| libraries.each(&b) }
|
69
|
-
.to yield_successive_args(*Library.all.to_a)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'when called from Base yields all items' do
|
73
|
-
expect { |b| ActiveFedora::Base.all.each(&b) }
|
74
|
-
.to yield_successive_args(*(Library.all.to_a + Book.all.to_a))
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when cached' do
|
78
|
-
it 'returns an enumerator' do
|
79
|
-
expect(libraries.each).to be_a Enumerator
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'yields the items' do
|
83
|
-
expect { |b| libraries.each(&b) }
|
84
|
-
.to yield_successive_args(*Library.all.to_a)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#find" do
|
90
|
-
it "finds one of them" do
|
91
|
-
expect(libraries.find(library1.id)).to eq library1
|
92
|
-
end
|
93
|
-
it "finds with a block" do
|
94
|
-
expect(libraries.find { |l| l.id == library1.id }).to eq library1
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#select" do
|
99
|
-
it "finds with a block" do
|
100
|
-
expect(libraries.select { |l| l.id == library1.id }).to eq [library1]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "unpermitted methods" do
|
105
|
-
it "excludes them" do
|
106
|
-
expect { libraries.sort! }.to raise_error NoMethodError
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when limit is applied" do
|
111
|
-
subject(:libraries) { Library.create books: [Book.create, Book.create] }
|
112
|
-
it "limits the number of books" do
|
113
|
-
expect(libraries.books.limit(1).size).to eq 1
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Querying do
|
4
|
-
before do
|
5
|
-
module ModelIntegrationSpec
|
6
|
-
class Basic < ActiveFedora::Base
|
7
|
-
property :foo, predicate: ::RDF::URI('http://example.com/foo') do |index|
|
8
|
-
index.as :stored_searchable
|
9
|
-
end
|
10
|
-
property :bar, predicate: ::RDF::URI('http://example.com/bar') do |index|
|
11
|
-
index.as :stored_searchable
|
12
|
-
end
|
13
|
-
property :baz, predicate: ::RDF::URI('http://example.com/baz')
|
14
|
-
|
15
|
-
def to_solr(doc = {})
|
16
|
-
doc = super
|
17
|
-
doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
|
18
|
-
doc
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
after do
|
25
|
-
Object.send(:remove_const, :ModelIntegrationSpec)
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "When there is one object in the store" do
|
29
|
-
let!(:test_instance) { ModelIntegrationSpec::Basic.create! }
|
30
|
-
|
31
|
-
after do
|
32
|
-
test_instance.delete
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".all" do
|
36
|
-
it "returns an array of instances of the calling Class" do
|
37
|
-
result = ModelIntegrationSpec::Basic.all.to_a
|
38
|
-
expect(result).to be_instance_of(Array)
|
39
|
-
# this test is meaningless if the array length is zero
|
40
|
-
expect(result.length).to be > 0
|
41
|
-
expect(result).to all(be_an(ModelIntegrationSpec::Basic))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe ".first" do
|
46
|
-
it "returns one instance of the calling class" do
|
47
|
-
expect(ModelIntegrationSpec::Basic.first).to eq test_instance
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "with multiple objects" do
|
53
|
-
let!(:test_instance1) { ModelIntegrationSpec::Basic.create!(foo: ['Beta'], bar: ['Chips']) }
|
54
|
-
let!(:test_instance2) { ModelIntegrationSpec::Basic.create!(foo: ['Alpha'], bar: ['Peanuts']) }
|
55
|
-
let!(:test_instance3) { ModelIntegrationSpec::Basic.create!(foo: ['Sigma'], bar: ['Peanuts']) }
|
56
|
-
|
57
|
-
describe "when the objects are in fedora" do
|
58
|
-
after do
|
59
|
-
test_instance1.delete
|
60
|
-
test_instance2.delete
|
61
|
-
test_instance3.delete
|
62
|
-
end
|
63
|
-
|
64
|
-
it "queries" do
|
65
|
-
field = ActiveFedora.index_field_mapper.solr_name('foo', type: :string)
|
66
|
-
expect(ModelIntegrationSpec::Basic.where(field => 'Beta')).to eq [test_instance1]
|
67
|
-
expect(ModelIntegrationSpec::Basic.where('foo' => 'Beta')).to eq [test_instance1]
|
68
|
-
expect(ModelIntegrationSpec::Basic.where('foo' => ['Beta', 'Alpha'])).to eq [test_instance1, test_instance2]
|
69
|
-
end
|
70
|
-
it "orders" do
|
71
|
-
expect(ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')).to contain_exactly test_instance2, test_instance1, test_instance3
|
72
|
-
end
|
73
|
-
it "limits" do
|
74
|
-
expect(ModelIntegrationSpec::Basic.limit(1)).to eq [test_instance1]
|
75
|
-
end
|
76
|
-
it "offsets" do
|
77
|
-
expect(ModelIntegrationSpec::Basic.offset(1)).to contain_exactly test_instance2, test_instance3
|
78
|
-
end
|
79
|
-
|
80
|
-
it "chains queries" do
|
81
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc').limit(1)).to eq [test_instance2]
|
82
|
-
end
|
83
|
-
|
84
|
-
it "wraps string conditions with parentheses" do
|
85
|
-
expect(ModelIntegrationSpec::Basic.where("foo:bar OR bar:baz").where_values).to eq ["(foo:bar OR bar:baz)"]
|
86
|
-
end
|
87
|
-
|
88
|
-
it "chains where queries" do
|
89
|
-
first_condition = { ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts' }
|
90
|
-
second_condition = "foo_tesim:bar"
|
91
|
-
where_values = ModelIntegrationSpec::Basic.where(first_condition)
|
92
|
-
.where(second_condition).where_values
|
93
|
-
expect(where_values).to eq ["_query_:\"{!field f=bar_tesim}Peanuts\"",
|
94
|
-
"(foo_tesim:bar)"]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "chains count" do
|
98
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts').count).to eq 2
|
99
|
-
end
|
100
|
-
|
101
|
-
it "calling first should not affect the relation's ability to get all results later" do
|
102
|
-
relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
|
103
|
-
expect { relation.first }.not_to change { relation.to_a.size }
|
104
|
-
end
|
105
|
-
|
106
|
-
it "calling where should not affect the relation's ability to get all results later" do
|
107
|
-
relation = ModelIntegrationSpec::Basic.where(ActiveFedora.index_field_mapper.solr_name('bar', type: :string) => 'Peanuts')
|
108
|
-
expect { relation.where(ActiveFedora.index_field_mapper.solr_name('foo', type: :string) => 'bar') }.not_to change { relation.to_a.size }
|
109
|
-
end
|
110
|
-
|
111
|
-
it "calling order should not affect the original order of the relation later" do
|
112
|
-
relation = ModelIntegrationSpec::Basic.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' asc')
|
113
|
-
expect { relation.order(ActiveFedora.index_field_mapper.solr_name('foo', :sortable) + ' desc') }.not_to change { relation.to_a }
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "when one of the objects in solr isn't in fedora" do
|
118
|
-
let!(:id) { test_instance2.id }
|
119
|
-
before { Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, test_instance2.uri).delete }
|
120
|
-
after do
|
121
|
-
ActiveFedora::SolrService.instance.conn.tap do |conn|
|
122
|
-
conn.delete_by_query "id:\"#{id}\""
|
123
|
-
conn.commit
|
124
|
-
end
|
125
|
-
test_instance1.delete
|
126
|
-
test_instance3.delete
|
127
|
-
end
|
128
|
-
it "logs an error" do
|
129
|
-
expect(ActiveFedora::Base.logger).to receive(:error).with("Although #{id} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch.")
|
130
|
-
expect(ModelIntegrationSpec::Basic.all).to contain_exactly test_instance1, test_instance3
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Scoping::Named do
|
4
|
-
before(:all) do
|
5
|
-
class TestClass < ActiveFedora::Base; end
|
6
|
-
class OtherClass < ActiveFedora::Base; end
|
7
|
-
end
|
8
|
-
after(:all) do
|
9
|
-
Object.send(:remove_const, :TestClass)
|
10
|
-
Object.send(:remove_const, :OtherClass)
|
11
|
-
end
|
12
|
-
|
13
|
-
let!(:test_instance) { TestClass.create! }
|
14
|
-
after { test_instance.delete }
|
15
|
-
|
16
|
-
describe "#all" do
|
17
|
-
it "returns an array of instances of the calling Class" do
|
18
|
-
result = TestClass.all.to_a
|
19
|
-
expect(result).to be_instance_of(Array)
|
20
|
-
# this test is meaningless if the array length is zero
|
21
|
-
expect(result).to_not be_empty
|
22
|
-
result.each do |obj|
|
23
|
-
expect(obj.class).to eq TestClass
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#find' do
|
29
|
-
describe "a valid id without cast" do
|
30
|
-
subject { ActiveFedora::Base.find(test_instance.id) }
|
31
|
-
it { is_expected.to be_instance_of TestClass }
|
32
|
-
end
|
33
|
-
describe "a valid id with cast of false" do
|
34
|
-
subject { ActiveFedora::Base.find(test_instance.id, cast: false) }
|
35
|
-
it { is_expected.to be_instance_of ActiveFedora::Base }
|
36
|
-
end
|
37
|
-
describe "a valid id without cast on a model extending Base" do
|
38
|
-
subject { TestClass.find(test_instance.id) }
|
39
|
-
it { is_expected.to be_instance_of TestClass }
|
40
|
-
end
|
41
|
-
it "a valid id on an incompatible class raises ModelMismatch" do
|
42
|
-
expect { OtherClass.find(test_instance.id) }.to raise_error(ActiveFedora::ModelMismatch)
|
43
|
-
end
|
44
|
-
it "invalid id raises ObjectNotFoundError" do
|
45
|
-
expect { TestClass.find('some_unused_identifier') }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::SolrHit do
|
4
|
-
before do
|
5
|
-
class Foo < ActiveFedora::Base
|
6
|
-
property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Object.send(:remove_const, :Foo)
|
12
|
-
end
|
13
|
-
|
14
|
-
subject(:solr_hit) { described_class.new(doc) }
|
15
|
-
let(:another) { Foo.create }
|
16
|
-
|
17
|
-
let!(:obj) { Foo.create!(
|
18
|
-
id: 'test-123',
|
19
|
-
title: 'My Title'
|
20
|
-
) }
|
21
|
-
|
22
|
-
let(:doc) { obj.to_solr }
|
23
|
-
|
24
|
-
describe "#reify" do
|
25
|
-
let(:solr_reified) { solr_hit.reify }
|
26
|
-
|
27
|
-
it "finds the document in solr" do
|
28
|
-
expect(solr_reified).to be_instance_of Foo
|
29
|
-
expect(solr_reified.title).to eq 'My Title'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,256 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveFedora::Versionable do
|
4
|
-
context "For ActiveFedora::Base" do
|
5
|
-
before do
|
6
|
-
class WithVersions < ActiveFedora::Base
|
7
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
Object.send(:remove_const, :WithVersions)
|
13
|
-
end
|
14
|
-
|
15
|
-
subject(:object) { WithVersions.new }
|
16
|
-
|
17
|
-
let(:current_year) { DateTime.now.year.to_s }
|
18
|
-
|
19
|
-
context "saved with no versions" do
|
20
|
-
it "does not have versions" do
|
21
|
-
object.update(title: ["Greetings Earthlings"])
|
22
|
-
expect(object).not_to have_versions
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "saved with versions" do
|
27
|
-
it "has versions" do
|
28
|
-
object.update(title: ["Greetings Earthlings"])
|
29
|
-
object.create_version
|
30
|
-
expect(object).to have_versions
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'sorting versions' do
|
35
|
-
subject(:graph) { ActiveFedora::VersionsGraph.new }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow(graph).to receive(:fedora_versions) { versions }
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:version1) { instance_double(ActiveFedora::VersionsGraph::ResourceVersion, uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e711aa993d-e1d2-4a65-93ee-3a12fc9541ab', label: 'version1', created: '2015-04-02T19:54:45.962Z') }
|
42
|
-
let(:version2) { instance_double(ActiveFedora::VersionsGraph::ResourceVersion, uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2', created: '2015-04-02T19:54:45.96Z') }
|
43
|
-
let(:versions) { [version1, version2] }
|
44
|
-
|
45
|
-
it 'sorts by DateTime' do
|
46
|
-
expect(graph.first).to eq version2
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with an unparseable created date' do
|
50
|
-
let(:version2) { instance_double(ActiveFedora::VersionsGraph::ResourceVersion, uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2', created: '') }
|
51
|
-
|
52
|
-
it 'raises an exception' do
|
53
|
-
expect { graph.first }.to raise_error(ActiveFedora::VersionLacksCreateDate)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with a missing created date' do
|
58
|
-
before do
|
59
|
-
# Because mocks raise RSpec::Mocks::MockExpectationError instead
|
60
|
-
allow(version2).to receive(:created) { raise NoMethodError }
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:version2) { instance_double(ActiveFedora::VersionsGraph::ResourceVersion, uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2') }
|
64
|
-
|
65
|
-
it 'raises an exception' do
|
66
|
-
expect { graph.first }.to raise_error(ActiveFedora::VersionLacksCreateDate)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "after saving" do
|
72
|
-
before do
|
73
|
-
object.title = ["Greetings Earthlings"]
|
74
|
-
object.save
|
75
|
-
object.create_version
|
76
|
-
end
|
77
|
-
|
78
|
-
it { is_expected.to have_versions }
|
79
|
-
|
80
|
-
it "has one version" do
|
81
|
-
expect(object.versions).to be_kind_of ActiveFedora::VersionsGraph
|
82
|
-
expect(object.versions.all.first).to be_kind_of ActiveFedora::VersionsGraph::ResourceVersion
|
83
|
-
expect(object.versions.all.first.label).to eql "version1"
|
84
|
-
expect(object.versions.all.first.created).to start_with current_year
|
85
|
-
end
|
86
|
-
|
87
|
-
context "two times" do
|
88
|
-
before do
|
89
|
-
object.title = ["Surrender and prepare to be boarded"]
|
90
|
-
object.save
|
91
|
-
object.create_version
|
92
|
-
end
|
93
|
-
|
94
|
-
it "has two versions" do
|
95
|
-
expect(object.versions.all.size).to eq 2
|
96
|
-
object.versions.all.each_index do |index|
|
97
|
-
expect(object.versions.all[index].label).to end_with "version" + (index + 1).to_s
|
98
|
-
expect(object.versions.all[index].created).to start_with current_year
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "then restoring" do
|
103
|
-
let(:first_version) { "version1" }
|
104
|
-
before do
|
105
|
-
object.restore_version(first_version)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "will return to the first version's values" do
|
109
|
-
expect(object.title).to eq(["Greetings Earthlings"])
|
110
|
-
end
|
111
|
-
|
112
|
-
context "and creating additional versions" do
|
113
|
-
before do
|
114
|
-
object.title = ["Now, surrender and prepare to be boarded"]
|
115
|
-
object.save!
|
116
|
-
object.create_version
|
117
|
-
end
|
118
|
-
|
119
|
-
it "has three versions" do
|
120
|
-
expect(object.versions.all.size).to eq 3
|
121
|
-
expect(object.title).to eq(["Now, surrender and prepare to be boarded"])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe ActiveFedora::File do
|
130
|
-
before(:all) do
|
131
|
-
class BinaryDatastream < ActiveFedora::File
|
132
|
-
end
|
133
|
-
|
134
|
-
class MockAFBase < ActiveFedora::Base
|
135
|
-
has_subresource "content", class_name: 'BinaryDatastream', autocreate: true
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
after(:all) do
|
140
|
-
Object.send(:remove_const, :MockAFBase)
|
141
|
-
Object.send(:remove_const, :BinaryDatastream)
|
142
|
-
end
|
143
|
-
|
144
|
-
let(:content) { test_object.content }
|
145
|
-
|
146
|
-
let(:current_year) { DateTime.now.year.to_s }
|
147
|
-
|
148
|
-
context "that exists in the repository" do
|
149
|
-
let(:test_object) { MockAFBase.create }
|
150
|
-
|
151
|
-
context "before creating the file" do
|
152
|
-
it "does not have versions" do
|
153
|
-
expect(content.versions).to be_empty
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "after creating the file" do
|
158
|
-
let(:first_file) { File.new(File.join(File.dirname(__FILE__), "../fixtures/dino.jpg")) }
|
159
|
-
let(:first_name) { "dino.jpg" }
|
160
|
-
before do
|
161
|
-
content.content = first_file
|
162
|
-
content.original_name = first_name
|
163
|
-
content.save
|
164
|
-
content.create_version
|
165
|
-
end
|
166
|
-
|
167
|
-
it "links to versions endpoint" do
|
168
|
-
expect(content.metadata.ldp_source.graph.query(predicate: ::RDF::Vocab::Fcrepo4.hasVersions).objects).to_not be_empty
|
169
|
-
end
|
170
|
-
|
171
|
-
it "has one version" do
|
172
|
-
expect(content.versions.all.size).to eq 1
|
173
|
-
expect(content.original_name).to eql(first_name)
|
174
|
-
expect(content.content.size).to eq first_file.size
|
175
|
-
expect(content.versions.first.label).to eql "version1"
|
176
|
-
expect(content.versions.first.created).to start_with current_year
|
177
|
-
end
|
178
|
-
|
179
|
-
context "two times" do
|
180
|
-
let(:second_file) { File.new(File.join(File.dirname(__FILE__), "../fixtures/minivan.jpg")) }
|
181
|
-
let(:second_name) { "minivan.jpg" }
|
182
|
-
before do
|
183
|
-
content.content = second_file
|
184
|
-
content.original_name = second_name
|
185
|
-
content.save
|
186
|
-
content.create_version
|
187
|
-
end
|
188
|
-
|
189
|
-
it "has two unique versions" do
|
190
|
-
expect(content.versions.all.size).to eq 2
|
191
|
-
expect(content.original_name).to eql(second_name)
|
192
|
-
expect(content.content.size).to eq second_file.size
|
193
|
-
content.versions.all.each_index do |index|
|
194
|
-
expect(content.versions.all[index].label).to end_with "version" + (index + 1).to_s
|
195
|
-
expect(content.versions.all[index].created).to start_with current_year
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
context "with fixity checking" do
|
200
|
-
let(:results) do
|
201
|
-
results = []
|
202
|
-
content.versions.all.each do |version|
|
203
|
-
results << ActiveFedora::FixityService.new(version.uri).check
|
204
|
-
end
|
205
|
-
return results
|
206
|
-
end
|
207
|
-
|
208
|
-
it "reports on the fixity of each version" do
|
209
|
-
results.each do |result|
|
210
|
-
expect(result).to be true
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context "then restoring" do
|
216
|
-
let(:first_version) { "version1" }
|
217
|
-
before do
|
218
|
-
content.restore_version(first_version)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "stills have two unique versions" do
|
222
|
-
expect(content.versions.all.size).to eq 2
|
223
|
-
end
|
224
|
-
|
225
|
-
it "loads the restored file's content" do
|
226
|
-
expect(content.content.size).to eq first_file.size
|
227
|
-
end
|
228
|
-
|
229
|
-
it "loads the restored file's original name" do
|
230
|
-
expect(content.original_name).to eql(first_name)
|
231
|
-
end
|
232
|
-
|
233
|
-
context "and creating additional versions" do
|
234
|
-
before do
|
235
|
-
content.content = first_file
|
236
|
-
content.original_name = first_name
|
237
|
-
content.save
|
238
|
-
content.create_version
|
239
|
-
end
|
240
|
-
|
241
|
-
it "has three unique versions" do
|
242
|
-
expect(content.versions.all.size).to eq 3
|
243
|
-
expect(content.original_name).to eql(first_name)
|
244
|
-
expect(content.content.size).to eq first_file.size
|
245
|
-
content.versions.all.each_index do |index|
|
246
|
-
expect(content.versions.all[index].label).to end_with "version" + (index + 1).to_s
|
247
|
-
expect(content.versions.all[index].created).to start_with current_year
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|