active-fedora 13.1.2 → 13.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,22 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe ActiveFedora::Reflection::OrdersReflection do
|
|
4
|
-
let(:orders_reflection) { described_class.new(name, scope, options, active_fedora) }
|
|
5
|
-
let(:macro) { :orders }
|
|
6
|
-
let(:name) { "ordered_member_proxies" }
|
|
7
|
-
let(:options) { {} }
|
|
8
|
-
let(:scope) { nil }
|
|
9
|
-
let(:active_fedora) { instance_double(ActiveFedora::Base) }
|
|
10
|
-
|
|
11
|
-
describe "#klass" do
|
|
12
|
-
it "is a proxy" do
|
|
13
|
-
expect(orders_reflection.klass).to eq ActiveFedora::Orders::ListNode
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#class_name" do
|
|
18
|
-
it "is a list node" do
|
|
19
|
-
expect(orders_reflection.class_name).to eq "ActiveFedora::Orders::ListNode"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
data/spec/unit/pathing_spec.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Base do
|
|
4
|
-
describe ".uri_prefix" do
|
|
5
|
-
before do
|
|
6
|
-
class FooHistory < ActiveFedora::Base
|
|
7
|
-
def uri_prefix
|
|
8
|
-
"foo"
|
|
9
|
-
end
|
|
10
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after do
|
|
15
|
-
Object.send(:remove_const, :FooHistory)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
subject(:history) { FooHistory.new(title: ["Root foo"]) }
|
|
19
|
-
let(:path) { "foo" }
|
|
20
|
-
|
|
21
|
-
it { is_expected.to have_uri_prefix }
|
|
22
|
-
|
|
23
|
-
it "uses the root path in the uri" do
|
|
24
|
-
expect(history.uri_prefix).to eql path
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "when the object is saved" do
|
|
28
|
-
before { history.save }
|
|
29
|
-
|
|
30
|
-
it "persists the path in the uri" do
|
|
31
|
-
expect(history.uri.to_s).to include(path)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Persistence do
|
|
4
|
-
describe '#new_record?' do
|
|
5
|
-
context 'with an new object' do
|
|
6
|
-
subject(:persistence) { ActiveFedora::Base.new }
|
|
7
|
-
it { is_expected.to be_new_record }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context 'with an destroyed object' do
|
|
11
|
-
subject(:persistence) { ActiveFedora::Base.create }
|
|
12
|
-
before { persistence.delete }
|
|
13
|
-
it { is_expected.not_to be_new_record }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe '.delete' do
|
|
18
|
-
context 'with an unsaved object' do
|
|
19
|
-
subject(:persistence) { ActiveFedora::Base.new }
|
|
20
|
-
before { persistence.delete }
|
|
21
|
-
it { is_expected.to eq persistence }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'with a saved object' do
|
|
25
|
-
subject(:persistence) { ActiveFedora::Base.create! }
|
|
26
|
-
before { persistence.delete }
|
|
27
|
-
it { is_expected.to be_frozen }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe '.create' do
|
|
32
|
-
context 'when a block is provided' do
|
|
33
|
-
it 'passes the block to initialize' do
|
|
34
|
-
expect_any_instance_of(ActiveFedora::Base).to receive(:save)
|
|
35
|
-
expect { |b| ActiveFedora::Base.create(&b) }.to yield_with_args(an_instance_of(ActiveFedora::Base))
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "when trying to create it again" do
|
|
40
|
-
let(:object) { ActiveFedora::Base.create! }
|
|
41
|
-
|
|
42
|
-
it "raises an error" do
|
|
43
|
-
expect { ActiveFedora::Base.create(id: object.id) }.to raise_error(ActiveFedora::IllegalOperation, "Attempting to recreate existing ldp_source: `#{object.uri}'")
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe '.destroy' do
|
|
49
|
-
subject(:persistence) { ActiveFedora::Base.create! }
|
|
50
|
-
context 'with no options' do
|
|
51
|
-
before { persistence.destroy }
|
|
52
|
-
it 'does not clear the id' do
|
|
53
|
-
expect(persistence.id).not_to be_nil
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context 'with option eradicate: true' do
|
|
58
|
-
it 'deletes the tombstone' do
|
|
59
|
-
expect(persistence.class).to receive(:eradicate).with(persistence.id).and_return(true)
|
|
60
|
-
persistence.destroy(eradicate: true)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe "save" do
|
|
66
|
-
subject(:persistence) { ActiveFedora::Base.new }
|
|
67
|
-
|
|
68
|
-
context "when called with option update_index: false" do
|
|
69
|
-
context "on a new record" do
|
|
70
|
-
it "does not update the index" do
|
|
71
|
-
expect(persistence).to_not receive(:update_index)
|
|
72
|
-
persistence.save(update_index: false)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context "on a persisted record" do
|
|
77
|
-
before do
|
|
78
|
-
allow(persistence).to receive(:new_record?) { false }
|
|
79
|
-
allow_any_instance_of(Ldp::Orm).to receive(:save) { true }
|
|
80
|
-
allow(persistence).to receive(:update_modified_date)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "does not update the index" do
|
|
84
|
-
expect(persistence).to_not receive(:update_index)
|
|
85
|
-
persistence.save(update_index: false)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
context "when called with option :update_index=>true" do
|
|
91
|
-
context "on create" do
|
|
92
|
-
before { allow(persistence).to receive(:create_needs_index?) { false } }
|
|
93
|
-
|
|
94
|
-
it "does not override `create_needs_index?'" do
|
|
95
|
-
expect(persistence).to_not receive(:update_index)
|
|
96
|
-
persistence.save(update_index: true)
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
context "on update" do
|
|
101
|
-
before do
|
|
102
|
-
allow(persistence).to receive(:new_record?) { false }
|
|
103
|
-
allow_any_instance_of(Ldp::Orm).to receive(:save) { true }
|
|
104
|
-
allow(persistence).to receive(:update_needs_index?) { false }
|
|
105
|
-
allow(persistence).to receive(:update_modified_date)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "does not override `update_needs_index?'" do
|
|
109
|
-
expect(persistence).to_not receive(:update_index)
|
|
110
|
-
persistence.save(update_index: true)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Base do
|
|
4
|
-
describe ".property" do
|
|
5
|
-
context "when the same predicate is used for two properties" do
|
|
6
|
-
let(:warningMsg) { "Same predicate (http://purl.org/dc/terms/title) used for properties title1 and title2" }
|
|
7
|
-
|
|
8
|
-
it "warns" do
|
|
9
|
-
# Note that the expect test must be before the class is parsed.
|
|
10
|
-
expect(described_class.logger).to receive(:warn).with(warningMsg)
|
|
11
|
-
|
|
12
|
-
module TestModel1
|
|
13
|
-
class Book < ActiveFedora::Base
|
|
14
|
-
property :title1, predicate: ::RDF::Vocab::DC.title
|
|
15
|
-
property :title2, predicate: ::RDF::Vocab::DC.title
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "when properties are created with different predicates" do
|
|
22
|
-
it "does not warn" do
|
|
23
|
-
# Note that the expect test must be before the class is parsed.
|
|
24
|
-
expect(described_class.logger).to_not receive(:warn)
|
|
25
|
-
|
|
26
|
-
module TestModel2
|
|
27
|
-
class Book < ActiveFedora::Base
|
|
28
|
-
property :title1, predicate: ::RDF::Vocab::DC.title
|
|
29
|
-
property :title2, predicate: ::RDF::Vocab::DC.creator
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
data/spec/unit/property_spec.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Property do
|
|
4
|
-
before do
|
|
5
|
-
@test_property = described_class.new(instance_double(ActiveFedora::Base), "file_name", :string)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it 'provides .new' do
|
|
9
|
-
expect(described_class).to respond_to(:new)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'provides .name' do
|
|
13
|
-
expect(described_class).to respond_to(:name)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'provides .instance_variable_name' do
|
|
17
|
-
expect(@test_property).to respond_to(:instance_variable_name)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '.instance_variable_name' do
|
|
21
|
-
it 'returns the value of the name attribute with an @ appended' do
|
|
22
|
-
expect(@test_property.instance_variable_name).to eql("@#{@test_property.name}")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::QueryResultBuilder do
|
|
4
|
-
describe "reify solr results" do
|
|
5
|
-
before(:all) do
|
|
6
|
-
class AudioRecord < ActiveFedora::Base
|
|
7
|
-
attr_accessor :id
|
|
8
|
-
def self.connection_for_id(_id); end
|
|
9
|
-
end
|
|
10
|
-
@sample_solr_hits = [{ "id" => "my:_ID1_", ActiveFedora.index_field_mapper.solr_name("has_model", :symbol) => ["AudioRecord"] },
|
|
11
|
-
{ "id" => "my:_ID2_", ActiveFedora.index_field_mapper.solr_name("has_model", :symbol) => ["AudioRecord"] },
|
|
12
|
-
{ "id" => "my:_ID3_", ActiveFedora.index_field_mapper.solr_name("has_model", :symbol) => ["AudioRecord"] }]
|
|
13
|
-
end
|
|
14
|
-
describe ".reify_solr_results" do
|
|
15
|
-
it "uses AudioRecord.find to instantiate objects" do
|
|
16
|
-
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
|
17
|
-
expect(AudioRecord).to receive(:find).with("my:_ID2_", cast: true)
|
|
18
|
-
expect(AudioRecord).to receive(:find).with("my:_ID3_", cast: true)
|
|
19
|
-
described_class.reify_solr_results(@sample_solr_hits)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
describe ".lazy_reify_solr_results" do
|
|
23
|
-
it "lazilies reify solr results" do
|
|
24
|
-
expect(AudioRecord).to receive(:find).with("my:_ID1_", cast: true)
|
|
25
|
-
expect(AudioRecord).to receive(:find).with("my:_ID2_", cast: true)
|
|
26
|
-
expect(AudioRecord).to receive(:find).with("my:_ID3_", cast: true)
|
|
27
|
-
described_class.lazy_reify_solr_results(@sample_solr_hits).each { |r| r }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
data/spec/unit/query_spec.rb
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::Base do
|
|
4
|
-
before(:all) do
|
|
5
|
-
module SpecModel
|
|
6
|
-
class Basic < ActiveFedora::Base
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
let(:sort_query) { ActiveFedora.index_field_mapper.solr_name("system_create", :stored_sortable, type: :date) + ' asc' }
|
|
11
|
-
let(:model_query) { "_query_:\"{!raw f=has_model_ssim}SpecModel::Basic\"" }
|
|
12
|
-
|
|
13
|
-
after(:all) do
|
|
14
|
-
Object.send(:remove_const, :SpecModel)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe ":all" do
|
|
18
|
-
before { allow(described_class).to receive(:relation).and_return(relation) }
|
|
19
|
-
describe "called on a concrete class" do
|
|
20
|
-
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
|
21
|
-
|
|
22
|
-
it "queries solr for all objects with has_model_ssim of self.class" do
|
|
23
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:30", nil)
|
|
24
|
-
.and_return("Fake Object1")
|
|
25
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:22", nil)
|
|
26
|
-
.and_return("Fake Object2")
|
|
27
|
-
mock_docs = [{ "id" => "changeme:30" }, { "id" => "changeme:22" }]
|
|
28
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
29
|
-
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate)
|
|
30
|
-
.with(1, 1000, 'select',
|
|
31
|
-
params: { q: model_query, qt: 'standard', sort: [sort_query], fl: 'id' })
|
|
32
|
-
.and_return('response' => { 'docs' => mock_docs })
|
|
33
|
-
expect(SpecModel::Basic.all).to eq ["Fake Object1", "Fake Object2"]
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe "called without a specific class" do
|
|
38
|
-
let(:relation) { ActiveFedora::Relation.new(described_class) }
|
|
39
|
-
it "specifies a q parameter" do
|
|
40
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:30", true)
|
|
41
|
-
.and_return("Fake Object1")
|
|
42
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:22", true)
|
|
43
|
-
.and_return("Fake Object2")
|
|
44
|
-
mock_docs = [{ "id" => "changeme:30" }, { "id" => "changeme:22" }]
|
|
45
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
46
|
-
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate)
|
|
47
|
-
.with(1, 1000, 'select',
|
|
48
|
-
params: { q: '*:*', qt: 'standard', sort: [sort_query], fl: 'id' })
|
|
49
|
-
.and_return('response' => { 'docs' => mock_docs })
|
|
50
|
-
expect(described_class.all).to eq ["Fake Object1", "Fake Object2"]
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
describe '#find' do
|
|
56
|
-
describe "with :cast false" do
|
|
57
|
-
describe "and an id is specified" do
|
|
58
|
-
it "raises an exception if it is not found" do
|
|
59
|
-
expect { SpecModel::Basic.find("_ID_") }.to raise_error ActiveFedora::ObjectNotFoundError, "Couldn't find SpecModel::Basic with 'id'=_ID_"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context "with a blank string" do
|
|
65
|
-
it 'raises ActiveFedora::ObjectNotFoundError' do
|
|
66
|
-
expect {
|
|
67
|
-
SpecModel::Basic.find('')
|
|
68
|
-
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe "#where" do
|
|
74
|
-
before do
|
|
75
|
-
allow(described_class).to receive(:relation).and_return(relation)
|
|
76
|
-
allow(relation).to receive(:clone).and_return(relation)
|
|
77
|
-
end
|
|
78
|
-
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
|
79
|
-
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
|
80
|
-
let(:expected_query) { "#{model_query} AND " \
|
|
81
|
-
"_query_:\"{!field f=foo}bar\" AND " \
|
|
82
|
-
"(_query_:\"{!field f=baz}quix\" OR " \
|
|
83
|
-
"_query_:\"{!field f=baz}quack\")" }
|
|
84
|
-
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
|
85
|
-
let(:expected_sort_params) { { params: { sort: ["title_t desc"], fl: 'id', q: expected_query, qt: 'standard' } } }
|
|
86
|
-
let(:mock_docs) { [{ "id" => "changeme:30" }, { "id" => "changeme:22" }] }
|
|
87
|
-
|
|
88
|
-
it "filters by the provided fields" do
|
|
89
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
|
90
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
|
91
|
-
|
|
92
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
93
|
-
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_params).and_return('response' => { 'docs' => mock_docs })
|
|
94
|
-
expect(SpecModel::Basic.where(foo: 'bar', baz: ['quix', 'quack'])).to eq ["Fake Object1", "Fake Object2"]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "queries for empty strings" do
|
|
98
|
-
expect(SpecModel::Basic.where(has_model_ssim: '').count).to eq 0
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it 'queries for empty arrays' do
|
|
102
|
-
expect(SpecModel::Basic.where(has_model_ssim: []).count).to eq 0
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "adds options" do
|
|
106
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:30", nil)
|
|
107
|
-
.and_return("Fake Object1")
|
|
108
|
-
expect(relation).to receive(:load_from_fedora).with("changeme:22", nil)
|
|
109
|
-
.and_return("Fake Object2")
|
|
110
|
-
|
|
111
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
112
|
-
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_sort_params)
|
|
113
|
-
.and_return('response' => { 'docs' => mock_docs })
|
|
114
|
-
expect(SpecModel::Basic.where(foo: 'bar', baz: ['quix', 'quack'])
|
|
115
|
-
.order('title_t desc')).to eq ["Fake Object1", "Fake Object2"]
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
describe '#find_each' do
|
|
120
|
-
before { allow(described_class).to receive(:relation).and_return(relation) }
|
|
121
|
-
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
|
122
|
-
it "queries solr for all objects with :has_model_ssim of self.class" do
|
|
123
|
-
mock_docs = [{ "id" => "changeme-30" }, { "id" => "changeme-22" }]
|
|
124
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
125
|
-
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate)
|
|
126
|
-
.with(1, 1000, 'select',
|
|
127
|
-
params: { q: model_query, qt: 'standard', sort: [sort_query], fl: 'id' })
|
|
128
|
-
.and_return('response' => { 'docs' => mock_docs })
|
|
129
|
-
|
|
130
|
-
allow(relation).to receive(:load_from_fedora).with("changeme-30", nil)
|
|
131
|
-
.and_return(SpecModel::Basic.new(id: 'changeme-30'))
|
|
132
|
-
allow(relation).to receive(:load_from_fedora).with("changeme-22", nil)
|
|
133
|
-
.and_return(SpecModel::Basic.new(id: 'changeme-22'))
|
|
134
|
-
SpecModel::Basic.find_each { |obj| obj.class == SpecModel::Basic }
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe "with conditions" do
|
|
138
|
-
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
|
139
|
-
let(:expected_query) { "#{model_query} AND " \
|
|
140
|
-
"_query_:\"{!field f=foo}bar\" AND " \
|
|
141
|
-
"(_query_:\"{!field f=baz}quix\" OR " \
|
|
142
|
-
"_query_:\"{!field f=baz}quack\")" }
|
|
143
|
-
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
|
144
|
-
let(:mock_docs) { [{ "id" => "changeme-30" }, { "id" => "changeme-22" }] }
|
|
145
|
-
|
|
146
|
-
it "filters by the provided fields" do
|
|
147
|
-
expect(relation).to receive(:load_from_fedora).with("changeme-30", nil).and_return(SpecModel::Basic.new(id: 'changeme-30'))
|
|
148
|
-
expect(relation).to receive(:load_from_fedora).with("changeme-22", nil).and_return(SpecModel::Basic.new(id: 'changeme-22'))
|
|
149
|
-
|
|
150
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
151
|
-
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_params).and_return('response' => { 'docs' => mock_docs })
|
|
152
|
-
SpecModel::Basic.find_each(foo: 'bar', baz: ['quix', 'quack']) { |obj| obj.class == SpecModel::Basic }
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
describe '#search_in_batches' do
|
|
158
|
-
describe "with conditions hash" do
|
|
159
|
-
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
|
160
|
-
let(:expected_query) { "#{model_query} AND " \
|
|
161
|
-
"_query_:\"{!field f=foo}bar\" AND " \
|
|
162
|
-
"(_query_:\"{!field f=baz}quix\" OR " \
|
|
163
|
-
"_query_:\"{!field f=baz}quack\")" }
|
|
164
|
-
let(:expected_params) { { params: { sort: [sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
|
165
|
-
let(:mock_docs) { double('docs') }
|
|
166
|
-
|
|
167
|
-
it "filters by the provided fields" do
|
|
168
|
-
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
169
|
-
expect(solr).to receive(:paginate).with(1, 1002, 'select', expected_params).and_return('response' => { 'docs' => mock_docs })
|
|
170
|
-
yielded = double("yielded method")
|
|
171
|
-
expect(yielded).to receive(:run).with(mock_docs)
|
|
172
|
-
SpecModel::Basic.search_in_batches({ foo: 'bar', baz: ['quix', 'quack'] }, batch_size: 1002, fl: 'id') { |group| yielded.run group }
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe '#count' do
|
|
178
|
-
let(:mock_result) { { 'response' => { 'numFound' => 7 } } }
|
|
179
|
-
|
|
180
|
-
it "returns a count" do
|
|
181
|
-
expect(ActiveFedora::SolrService).to receive(:get)
|
|
182
|
-
.with(model_query, rows: 0)
|
|
183
|
-
.and_return(mock_result)
|
|
184
|
-
expect(SpecModel::Basic.count).to eq 7
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it "allows conditions" do
|
|
188
|
-
expect(ActiveFedora::SolrService).to receive(:get)
|
|
189
|
-
.with("#{model_query} AND (foo:bar)", rows: 0)
|
|
190
|
-
.and_return(mock_result)
|
|
191
|
-
expect(SpecModel::Basic.count(conditions: 'foo:bar')).to eq 7
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
it "counts without a class specified" do
|
|
195
|
-
expect(ActiveFedora::SolrService).to receive(:get)
|
|
196
|
-
.with("(foo:bar)", rows: 0)
|
|
197
|
-
.and_return(mock_result)
|
|
198
|
-
expect(described_class.count(conditions: 'foo:bar')).to eq 7
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
describe '#last' do
|
|
203
|
-
describe 'with multiple objects' do
|
|
204
|
-
before do
|
|
205
|
-
SpecModel::Basic.create!(id: '0001')
|
|
206
|
-
SpecModel::Basic.create!(id: '0002')
|
|
207
|
-
@c = SpecModel::Basic.create!(id: '0003')
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it 'returns the last object sorted by id' do
|
|
211
|
-
expect(SpecModel::Basic.last).to eq @c
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
describe 'with one object' do
|
|
216
|
-
it 'equals the first object when there is only one' do
|
|
217
|
-
SpecModel::Basic.create!
|
|
218
|
-
expect(SpecModel::Basic.first).to eq SpecModel::Basic.last
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
describe '#first' do
|
|
224
|
-
describe 'with multiple objects' do
|
|
225
|
-
before do
|
|
226
|
-
@a = SpecModel::Basic.create!(id: '0001')
|
|
227
|
-
SpecModel::Basic.create!(id: '0002')
|
|
228
|
-
SpecModel::Basic.create!(id: '0003')
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it 'returns the first object sorted by id' do
|
|
232
|
-
expect(SpecModel::Basic.first).to eq @a
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
describe 'with one object' do
|
|
237
|
-
it 'equals the first object when there is only one' do
|
|
238
|
-
SpecModel::Basic.create!
|
|
239
|
-
expect(SpecModel::Basic.first).to eq SpecModel::Basic.last
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
describe '#search_with_conditions' do
|
|
245
|
-
subject(:search_with_conditions) { klass.search_with_conditions(conditions) }
|
|
246
|
-
let(:mock_result) { double('Result') }
|
|
247
|
-
let(:klass) { SpecModel::Basic }
|
|
248
|
-
|
|
249
|
-
before do
|
|
250
|
-
expect(ActiveFedora::SolrService).to receive(:query)
|
|
251
|
-
.with(expected_query, sort: [sort_query]).and_return(mock_result)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
context "with a hash of conditions" do
|
|
255
|
-
let(:expected_query) { "#{model_query} AND " \
|
|
256
|
-
"_query_:\"{!field f=foo}bar\" AND " \
|
|
257
|
-
"(_query_:\"{!field f=baz}quix\" OR " \
|
|
258
|
-
"_query_:\"{!field f=baz}quack\")" }
|
|
259
|
-
let(:conditions) { { foo: 'bar', baz: ['quix', 'quack'] } }
|
|
260
|
-
|
|
261
|
-
it "makes a query to solr and returns the results" do
|
|
262
|
-
expect(search_with_conditions).to eq mock_result
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
context "with quotes in the params" do
|
|
267
|
-
let(:expected_query) { "#{model_query} AND " \
|
|
268
|
-
"_query_:\"{!field f=foo}9\\\" Nails\" AND " \
|
|
269
|
-
"(_query_:\"{!field f=baz}7\\\" version\" OR " \
|
|
270
|
-
"_query_:\"{!field f=baz}quack\")" }
|
|
271
|
-
let(:conditions) { { foo: '9" Nails', baz: ['7" version', 'quack'] } }
|
|
272
|
-
|
|
273
|
-
it "escapes quotes" do
|
|
274
|
-
expect(search_with_conditions).to eq mock_result
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
context "called on AF::Base" do
|
|
279
|
-
let(:klass) { described_class }
|
|
280
|
-
|
|
281
|
-
context "with a hash" do
|
|
282
|
-
let(:conditions) { { baz: 'quack' } }
|
|
283
|
-
let(:expected_query) { "_query_:\"{!field f=baz}quack\"" }
|
|
284
|
-
it "doesn't use the class if it's called on AF:Base " do
|
|
285
|
-
expect(search_with_conditions).to eq mock_result
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
context "called with a string" do
|
|
290
|
-
let(:conditions) { 'chunky:monkey' }
|
|
291
|
-
let(:expected_query) { '(chunky:monkey)' }
|
|
292
|
-
it "uses the query string if it's provided and wrap it in parentheses" do
|
|
293
|
-
expect(search_with_conditions).to eq mock_result
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
describe "#load_from_fedora" do
|
|
300
|
-
let(:relation) { ActiveFedora::Relation.new(described_class) }
|
|
301
|
-
before { @obj = SpecModel::Basic.create(id: "test_123") }
|
|
302
|
-
after { @obj.destroy }
|
|
303
|
-
it "casts when klass == ActiveFedora::Base and cast argument is nil" do
|
|
304
|
-
expect(relation.send(:load_from_fedora, "test_123", nil)).to be_a SpecModel::Basic
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
end
|