active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,30 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Persistence do
|
4
|
-
context "internal methods" do
|
5
|
-
before :all do
|
6
|
-
class SpecNode
|
7
|
-
include ActiveFedora::Persistence
|
8
|
-
end
|
9
|
-
end
|
10
|
-
after :all do
|
11
|
-
Object.send(:remove_const, :SpecNode)
|
12
|
-
end
|
13
|
-
|
14
|
-
subject { SpecNode.new }
|
15
|
-
|
16
|
-
describe "#create_needs_index?" do
|
17
|
-
it "should be true" do
|
18
|
-
expect(subject.send(:create_needs_index?)).to be_truthy
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#update_needs_index?" do
|
23
|
-
it "should be true" do
|
24
|
-
expect(subject.send(:update_needs_index?)).to be_truthy
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
4
|
|
29
5
|
describe "an unsaved object" do
|
30
6
|
subject { ActiveFedora::Base.new }
|
@@ -33,6 +9,15 @@ describe ActiveFedora::Persistence do
|
|
33
9
|
end
|
34
10
|
end
|
35
11
|
|
12
|
+
describe ".create" do
|
13
|
+
context "when a block is provided" do
|
14
|
+
it "should pass the block to initialize" do
|
15
|
+
expect_any_instance_of(ActiveFedora::Base).to receive(:save)
|
16
|
+
expect { |b| ActiveFedora::Base.create(&b) }.to yield_with_args(an_instance_of ActiveFedora::Base)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
36
21
|
describe "a saved object" do
|
37
22
|
subject { ActiveFedora::Base.create! }
|
38
23
|
describe "that is deleted" do
|
@@ -47,48 +32,57 @@ describe ActiveFedora::Persistence do
|
|
47
32
|
|
48
33
|
describe "destroy" do
|
49
34
|
subject { ActiveFedora::Base.create! }
|
50
|
-
it "should not clear the
|
35
|
+
it "should not clear the id" do
|
51
36
|
subject.destroy
|
52
|
-
expect(subject.
|
37
|
+
expect(subject.id).not_to be_nil
|
53
38
|
end
|
54
39
|
end
|
55
40
|
|
56
41
|
describe "save" do
|
57
42
|
subject { ActiveFedora::Base.new }
|
58
|
-
|
43
|
+
|
44
|
+
context "when called with option update_index: false" do
|
59
45
|
context "on a new record" do
|
60
46
|
it "should not update the index" do
|
61
|
-
expect(subject).
|
47
|
+
expect(subject).to_not receive(:update_index)
|
62
48
|
subject.save(update_index: false)
|
63
49
|
end
|
64
50
|
end
|
51
|
+
|
65
52
|
context "on a persisted record" do
|
66
53
|
before do
|
67
54
|
allow(subject).to receive(:new_record?) { false }
|
68
|
-
|
55
|
+
allow_any_instance_of(Ldp::Orm).to receive(:save) { true }
|
56
|
+
allow(subject).to receive(:update_modified_date)
|
69
57
|
end
|
58
|
+
|
70
59
|
it "should not update the index" do
|
71
|
-
expect(subject).
|
60
|
+
expect(subject).to_not receive(:update_index)
|
72
61
|
subject.save(update_index: false)
|
73
|
-
end
|
62
|
+
end
|
74
63
|
end
|
75
64
|
end
|
65
|
+
|
76
66
|
context "when called with option :update_index=>true" do
|
77
67
|
context "on create" do
|
78
68
|
before { allow(subject).to receive(:create_needs_index?) { false } }
|
69
|
+
|
79
70
|
it "should not override `create_needs_index?'" do
|
80
|
-
expect(subject).
|
71
|
+
expect(subject).to_not receive(:update_index)
|
81
72
|
subject.save(update_index: true)
|
82
73
|
end
|
83
74
|
end
|
75
|
+
|
84
76
|
context "on update" do
|
85
77
|
before do
|
86
78
|
allow(subject).to receive(:new_record?) { false }
|
87
|
-
|
79
|
+
allow_any_instance_of(Ldp::Orm).to receive(:save) { true }
|
88
80
|
allow(subject).to receive(:update_needs_index?) { false }
|
81
|
+
allow(subject).to receive(:update_modified_date)
|
89
82
|
end
|
83
|
+
|
90
84
|
it "should not override `update_needs_index?'" do
|
91
|
-
expect(subject).
|
85
|
+
expect(subject).to_not receive(:update_index)
|
92
86
|
subject.save(update_index: true)
|
93
87
|
end
|
94
88
|
end
|
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Predicates do
|
4
4
|
describe "#short_predicate" do
|
5
5
|
it 'should parse strings' do
|
6
|
-
expect(ActiveFedora::Predicates.short_predicate('http://www.openarchives.org/OAI/2.0/itemID')).to eq
|
6
|
+
expect(ActiveFedora::Predicates.short_predicate('http://www.openarchives.org/OAI/2.0/itemID')).to eq :oai_item_id
|
7
7
|
end
|
8
8
|
it 'should parse uris' do
|
9
|
-
expect(ActiveFedora::Predicates.short_predicate(RDF::DC.creator)).to eq
|
10
|
-
expect(ActiveFedora::Predicates.short_predicate(RDF::SKOS.hasTopConcept)).to eq
|
9
|
+
expect(ActiveFedora::Predicates.short_predicate(RDF::DC.creator)).to eq 'dc_terms_creator'
|
10
|
+
expect(ActiveFedora::Predicates.short_predicate(RDF::SKOS.hasTopConcept)).to eq '2004_02_skos_core_has_top_concept'
|
11
11
|
end
|
12
|
-
before
|
12
|
+
before do
|
13
13
|
@original_mapping = ActiveFedora::Predicates.predicate_config[:predicate_mapping]
|
14
14
|
end
|
15
|
-
after
|
15
|
+
after do
|
16
16
|
ActiveFedora::Predicates.predicate_config[:predicate_mapping] = @original_mapping
|
17
17
|
end
|
18
18
|
it "should find predicates regardless of order loaded or shared namespace prefixes" do
|
@@ -21,14 +21,14 @@ describe ActiveFedora::Predicates do
|
|
21
21
|
"http://example.org/zoo/wolves/"=>{:alpha => 'Manager'},
|
22
22
|
"http://example.org/zoo/"=>{:keeper => 'Manager'}
|
23
23
|
}
|
24
|
-
expect(ActiveFedora::Predicates.short_predicate("http://example.org/zoo/Manager")).to eq
|
25
|
-
expect(ActiveFedora::Predicates.short_predicate("http://example.org/zoo/wolves/Manager")).to eq
|
26
|
-
expect(ActiveFedora::Predicates.short_predicate("http://example.org/Manager")).to eq
|
24
|
+
expect(ActiveFedora::Predicates.short_predicate("http://example.org/zoo/Manager")).to eq :keeper
|
25
|
+
expect(ActiveFedora::Predicates.short_predicate("http://example.org/zoo/wolves/Manager")).to eq :alpha
|
26
|
+
expect(ActiveFedora::Predicates.short_predicate("http://example.org/Manager")).to eq :ceo
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should provide .default_predicate_namespace' do
|
31
|
-
expect(ActiveFedora::Predicates.default_predicate_namespace).to eq
|
31
|
+
expect(ActiveFedora::Predicates.default_predicate_namespace).to eq 'http://fedora.info/definitions/v4/rels-ext#'
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "#predicate_mappings" do
|
@@ -37,8 +37,8 @@ describe ActiveFedora::Predicates do
|
|
37
37
|
expect(ActiveFedora::Predicates.predicate_mappings).to be_kind_of Hash
|
38
38
|
end
|
39
39
|
|
40
|
-
it "should provide mappings to the fedora ontology via the info
|
41
|
-
expect(ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace)).to
|
40
|
+
it "should provide mappings to the fedora ontology via the http://fedora.info/definitions/v4/rels-ext# default namespace mapping" do
|
41
|
+
expect(ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace)).to be true
|
42
42
|
expect(ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace]).to be_kind_of Hash
|
43
43
|
end
|
44
44
|
|
@@ -68,25 +68,25 @@ describe ActiveFedora::Predicates do
|
|
68
68
|
:has_model => "hasModel"]
|
69
69
|
desired_mappings.each_pair do |k,v|
|
70
70
|
expect(ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace]).to have_key(k)
|
71
|
-
expect(ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace][k]).to eq
|
71
|
+
expect(ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace][k]).to eq v
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'should provide #predicate_lookup that maps symbols to common RELS-EXT predicates' do
|
77
77
|
expect(ActiveFedora::Predicates).to respond_to(:predicate_lookup)
|
78
|
-
expect(ActiveFedora::Predicates.predicate_lookup(:is_part_of)).to eq
|
79
|
-
expect(ActiveFedora::Predicates.predicate_lookup(:is_member_of)).to eq
|
80
|
-
expect(ActiveFedora::Predicates.predicate_lookup("isPartOfCollection")).to eq
|
78
|
+
expect(ActiveFedora::Predicates.predicate_lookup(:is_part_of)).to eq "isPartOf"
|
79
|
+
expect(ActiveFedora::Predicates.predicate_lookup(:is_member_of)).to eq "isMemberOf"
|
80
|
+
expect(ActiveFedora::Predicates.predicate_lookup("isPartOfCollection")).to eq "isPartOfCollection"
|
81
81
|
ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({"some_namespace"=>{:has_foo=>"hasFOO"}})
|
82
|
-
expect(ActiveFedora::Predicates.find_predicate(:has_foo)).to eq
|
83
|
-
expect(ActiveFedora::Predicates.predicate_lookup(:has_foo,"some_namespace")).to eq
|
84
|
-
expect { ActiveFedora::Predicates.predicate_lookup(:has_foo) }.to raise_error ActiveFedora::UnregisteredPredicateError
|
82
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_foo)).to eq ["hasFOO","some_namespace"]
|
83
|
+
expect(ActiveFedora::Predicates.predicate_lookup(:has_foo,"some_namespace")).to eq "hasFOO"
|
84
|
+
expect(lambda { ActiveFedora::Predicates.predicate_lookup(:has_foo) }).to raise_error ActiveFedora::UnregisteredPredicateError
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'initialization' do
|
88
88
|
before :each do
|
89
|
-
@old_predicate_config = ActiveFedora::Predicates.predicate_config
|
89
|
+
@old_predicate_config = Marshal.load(Marshal.dump(ActiveFedora::Predicates.predicate_config))
|
90
90
|
end
|
91
91
|
|
92
92
|
after :each do
|
@@ -94,36 +94,36 @@ describe ActiveFedora::Predicates do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should allow explicit initialization of predicates' do
|
97
|
-
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq
|
97
|
+
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq ["isPartOf", "http://fedora.info/definitions/v4/rels-ext#"]
|
98
98
|
ActiveFedora::Predicates.predicate_config = {
|
99
99
|
:default_namespace => 'http://example.com/foo',
|
100
100
|
:predicate_mapping => {
|
101
101
|
'http://example.com/foo' => { :has_bar => 'hasBAR' }
|
102
102
|
}
|
103
103
|
}
|
104
|
-
expect(ActiveFedora::Predicates.find_predicate(:has_bar)).to eq
|
105
|
-
expect { ActiveFedora::Predicates.find_predicate(:is_part_of) }.to raise_error ActiveFedora::UnregisteredPredicateError
|
104
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_bar)).to eq ["hasBAR", "http://example.com/foo"]
|
105
|
+
expect(lambda { ActiveFedora::Predicates.find_predicate(:is_part_of) }).to raise_error ActiveFedora::UnregisteredPredicateError
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should ensure that the configuration has the correct keys' do
|
109
|
-
expect { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }.to raise_error TypeError
|
109
|
+
expect(lambda { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }).to raise_error TypeError
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should allow adding predicates without wiping out existing predicates" do
|
113
113
|
ActiveFedora::Predicates.set_predicates({
|
114
114
|
"http://projecthydra.org/ns/relations#"=>{has_profile:"hasProfile"},
|
115
|
-
"info
|
115
|
+
"http://fedora.info/definitions/v4/rels-ext#"=>{
|
116
116
|
references:"references",
|
117
117
|
has_derivation: "cameFrom"
|
118
118
|
},
|
119
119
|
})
|
120
120
|
# New & Modified Predicates
|
121
|
-
expect(ActiveFedora::Predicates.find_predicate(:has_profile)).to eq
|
122
|
-
expect(ActiveFedora::Predicates.find_predicate(:references)).to eq
|
123
|
-
expect(ActiveFedora::Predicates.find_predicate(:has_derivation)).to eq
|
121
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_profile)).to eq ["hasProfile", "http://projecthydra.org/ns/relations#"]
|
122
|
+
expect(ActiveFedora::Predicates.find_predicate(:references)).to eq ["references", "http://fedora.info/definitions/v4/rels-ext#"]
|
123
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_derivation)).to eq ["cameFrom", "http://fedora.info/definitions/v4/rels-ext#"]
|
124
124
|
# Pre-Existing predicates should be unharmed
|
125
|
-
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq
|
126
|
-
expect(ActiveFedora::Predicates.find_predicate(:is_governed_by)).to eq
|
125
|
+
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq ["isPartOf", "http://fedora.info/definitions/v4/rels-ext#"]
|
126
|
+
expect(ActiveFedora::Predicates.find_predicate(:is_governed_by)).to eq ["isGovernedBy", "http://projecthydra.org/ns/relations#"]
|
127
127
|
end
|
128
128
|
|
129
129
|
end
|
data/spec/unit/property_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'active_fedora/model'
|
|
5
5
|
|
6
6
|
describe ActiveFedora::Property do
|
7
7
|
|
8
|
-
before(:
|
8
|
+
before(:each) do
|
9
9
|
@test_property = ActiveFedora::Property.new(double("model_stub"),"file_name", :string)
|
10
10
|
end
|
11
11
|
|
@@ -19,8 +19,6 @@ describe ActiveFedora::Property do
|
|
19
19
|
|
20
20
|
|
21
21
|
it 'should provide .instance_variable_name' do
|
22
|
-
#ActiveFedora::Property.should respond_to(:instance_variable_name)
|
23
|
-
|
24
22
|
expect(@test_property).to respond_to(:instance_variable_name)
|
25
23
|
end
|
26
24
|
|
@@ -8,9 +8,8 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
8
8
|
require File.join( File.dirname(__FILE__), "..", "samples","oral_history_sample_model" )
|
9
9
|
@dc_terms = []
|
10
10
|
end
|
11
|
-
|
12
|
-
|
13
|
-
@sample_xml = "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
|
11
|
+
|
12
|
+
let(:sample_xml) do "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
|
14
13
|
<dcterms:type xsi:type='DCMITYPE'>sound</dcterms:type>
|
15
14
|
<dcterms:medium>medium</dcterms:medium>
|
16
15
|
<dcterms:rights>rights</dcterms:rights>
|
@@ -37,60 +36,54 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
37
36
|
<dcterms:description>desc</dcterms:description>
|
38
37
|
<dcterms:date>datestr</dcterms:date>
|
39
38
|
</dc>"
|
40
|
-
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(@sample_xml )
|
41
|
-
|
42
39
|
end
|
43
|
-
|
44
|
-
|
40
|
+
before do
|
41
|
+
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
|
42
|
+
@test_ds.content = sample_xml
|
45
43
|
end
|
46
44
|
|
47
45
|
it "should create the right number of fields" do
|
48
|
-
expect(ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size).to eq
|
46
|
+
expect(ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size).to eq 54
|
49
47
|
end
|
50
48
|
|
51
49
|
it "should have unmodifiable constants" do
|
52
|
-
expect {ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS<<:foo}.to raise_error(
|
53
|
-
|
50
|
+
expect { ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS<<:foo }.to raise_error(RuntimeError, /can't modify frozen array/i)
|
54
51
|
end
|
55
52
|
|
56
53
|
it "should default dc elements to :multiple=>true" do
|
57
54
|
@test_ds.fields.values.each do |s|
|
58
|
-
expect(s.has_key?(:multiple)).to
|
55
|
+
expect(s.has_key?(:multiple)).to be true
|
59
56
|
end
|
60
57
|
end
|
61
|
-
|
62
|
-
after(:each) do
|
63
|
-
end
|
64
|
-
|
58
|
+
|
65
59
|
describe '#new' do
|
66
60
|
it 'should provide #new' do
|
67
61
|
expect(ActiveFedora::QualifiedDublinCoreDatastream).to respond_to(:new)
|
68
62
|
end
|
69
|
-
|
70
|
-
|
71
|
-
describe "model methods" do
|
63
|
+
|
64
|
+
|
65
|
+
describe "model methods" do
|
72
66
|
|
73
67
|
DC_ELEMENTS.each do |el|
|
74
68
|
it "should respond to getters and setters for #{el} element" do
|
75
69
|
pending if el == :type
|
76
70
|
value = "Hey #{el}"
|
77
|
-
@test_ds.send("#{el.to_s}=", value)
|
78
|
-
expect(@test_ds.send(el).first).to eq
|
71
|
+
@test_ds.send("#{el.to_s}=", value)
|
72
|
+
expect(@test_ds.send(el).first).to eq value #Looking at first because creator has 2 nodes
|
79
73
|
end
|
80
74
|
end
|
81
75
|
end
|
82
76
|
end
|
83
|
-
|
77
|
+
|
84
78
|
describe '.to_xml' do
|
85
79
|
it 'should output the fields hash as Qualified Dublin Core XML' do
|
86
|
-
#@test_ds.should_receive(:new?).and_return(true).twice
|
87
80
|
sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:title>title1</dcterms:title><dcterms:publisher>publisher1</dcterms:publisher><dcterms:creator>creator1</dcterms:creator><dcterms:creator>creator2</dcterms:creator></dc>"
|
88
|
-
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
|
81
|
+
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
|
89
82
|
|
90
83
|
@test_ds.field :publisher
|
91
84
|
@test_ds.field :creator
|
92
85
|
@test_ds.field :title
|
93
|
-
|
86
|
+
|
94
87
|
@test_ds.publisher= ["publisher1"]
|
95
88
|
@test_ds.creator= ["creator1", "creator2"]
|
96
89
|
@test_ds.title= ["title1"]
|
@@ -107,28 +100,30 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
107
100
|
|
108
101
|
describe "#to_solr" do
|
109
102
|
it "should have title" do
|
110
|
-
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
|
103
|
+
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
|
111
104
|
@test_ds.title = "War and Peace"
|
112
105
|
solr = @test_ds.to_solr
|
113
|
-
expect(solr[ActiveFedora::SolrService.solr_name('title', type: :string)]).to eq
|
106
|
+
expect(solr[ActiveFedora::SolrService.solr_name('title', type: :string)]).to eq "War and Peace"
|
114
107
|
end
|
115
108
|
|
116
109
|
end
|
117
110
|
|
118
111
|
describe 'custom fields' do
|
112
|
+
subject { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
119
113
|
it 'should grab the term' do
|
120
114
|
sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:cust>custom</dcterms:cust></dc>"
|
121
|
-
|
122
|
-
|
123
|
-
expect(
|
115
|
+
subject.content = sample_xml
|
116
|
+
subject.field :cust
|
117
|
+
expect(subject.cust).to eq ['custom']
|
124
118
|
end
|
125
119
|
end
|
126
120
|
|
127
121
|
describe "#field should accept :path option" do
|
122
|
+
subject { ActiveFedora::QualifiedDublinCoreDatastream.new }
|
128
123
|
it "should be able to map :dc_type to the path 'type'" do
|
129
|
-
|
130
|
-
|
131
|
-
expect(
|
124
|
+
subject.content = sample_xml
|
125
|
+
subject.field :dc_type, :string, path: "type", multiple: true
|
126
|
+
expect(subject.dc_type).to eq ['sound']
|
132
127
|
end
|
133
128
|
end
|
134
129
|
|
data/spec/unit/query_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
module SpecModel
|
7
7
|
class Basic < ActiveFedora::Base
|
8
8
|
end
|
9
9
|
end
|
10
|
-
@model_query = "_query_:\"{!raw f=" + ActiveFedora::SolrService.solr_name("has_model", :symbol) + "}
|
10
|
+
@model_query = "_query_:\"{!raw f=" + ActiveFedora::SolrService.solr_name("has_model", :symbol) + "}SpecModel::Basic" + "\""
|
11
11
|
@sort_query = ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date) + ' asc'
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
after(:all) do
|
15
15
|
Object.send(:remove_const, :SpecModel)
|
16
16
|
end
|
17
17
|
|
18
18
|
describe ":all" do
|
19
|
-
before { allow(ActiveFedora::Base).to
|
19
|
+
before { allow(ActiveFedora::Base).to receive(:relation).and_return(relation) }
|
20
20
|
describe "called on a concrete class" do
|
21
21
|
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
22
22
|
it "should query solr for all objects with :has_model_s of self.class" do
|
@@ -25,7 +25,7 @@ describe ActiveFedora::Base do
|
|
25
25
|
mock_docs = [{"id" => "changeme:30"}, {"id" => "changeme:22"}]
|
26
26
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
27
27
|
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
28
|
-
expect(SpecModel::Basic.all).to eq
|
28
|
+
expect(SpecModel::Basic.all).to eq ["Fake Object1", "Fake Object2"]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
describe "called without a specific class" do
|
@@ -36,153 +36,112 @@ describe ActiveFedora::Base do
|
|
36
36
|
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
37
37
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
38
38
|
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate).with(1, 1000, 'select', :params=>{:q=>'*:*', :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
39
|
-
expect(ActiveFedora::Base.all).to eq
|
39
|
+
expect(ActiveFedora::Base.all).to eq ["Fake Object1", "Fake Object2"]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe '#find' do
|
45
45
|
describe "with :cast false" do
|
46
|
-
describe "and
|
47
|
-
it "should use SpecModel::Basic.allocate.init_with_object to instantiate an object" do
|
48
|
-
allow_any_instance_of(SpecModel::Basic).to receive(:init_with_object).and_return(SpecModel::Basic.new )
|
49
|
-
expect(ActiveFedora::DigitalObject).to receive(:find).and_return(double("inner obj", :'new?'=>false))
|
50
|
-
expect(SpecModel::Basic.find("_PID_", cast: false)).to be_a SpecModel::Basic
|
51
|
-
end
|
46
|
+
describe "and an id is specified" do
|
52
47
|
it "should raise an exception if it is not found" do
|
53
|
-
|
54
|
-
expect(SpecModel::Basic).to receive(:connection_for_pid).with("_PID_")
|
55
|
-
expect {SpecModel::Basic.find("_PID_")}.to raise_error ActiveFedora::ObjectNotFoundError
|
48
|
+
expect { SpecModel::Basic.find("_ID_") }.to raise_error ActiveFedora::ObjectNotFoundError
|
56
49
|
end
|
57
50
|
end
|
58
51
|
end
|
59
|
-
describe "
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
describe "using an options hash" do
|
53
|
+
before do
|
54
|
+
Deprecation.default_deprecation_behavior = :raise
|
55
|
+
end
|
56
|
+
it "should be deprecated" do
|
57
|
+
expect { SpecModel::Basic.find(id: "_ID_") }.to raise_error RuntimeError
|
64
58
|
end
|
65
59
|
end
|
60
|
+
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
62
|
+
describe "#where" do
|
63
|
+
before do
|
64
|
+
allow(ActiveFedora::Base).to receive(:relation).and_return(relation)
|
65
|
+
allow(relation).to receive(:clone).and_return(relation)
|
66
|
+
end
|
67
|
+
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
68
|
+
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
69
|
+
let(:expected_query) { "#{@model_query} AND foo:bar AND baz:quix AND baz:quack" }
|
70
|
+
let(:expected_params) { { params: { sort: [@sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
71
|
+
let(:expected_sort_params) { { params: { sort: ["title_t desc"], fl: 'id', q: expected_query, qt: 'standard' } } }
|
72
|
+
let(:mock_docs) { [{"id" => "changeme:30"},{"id" => "changeme:22"}] }
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
page == 1 &&
|
81
|
-
rows == 1000 &&
|
82
|
-
method == 'select' &&
|
83
|
-
hash[:params] &&
|
84
|
-
hash[:params][:sort] == [@sort_query] &&
|
85
|
-
hash[:params][:fl] == 'id' &&
|
86
|
-
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
87
|
-
hash[:params][:q].split(" AND ").include?("foo:bar") &&
|
88
|
-
hash[:params][:q].split(" AND ").include?("baz:quix") &&
|
89
|
-
hash[:params][:q].split(" AND ").include?("baz:quack")
|
90
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
91
|
-
expect(SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']})).to eq(["Fake Object1", "Fake Object2"])
|
92
|
-
end
|
74
|
+
it "should filter by the provided fields" do
|
75
|
+
expect(relation).to receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
76
|
+
expect(relation).to receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
93
77
|
|
94
|
-
|
95
|
-
|
96
|
-
|
78
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
79
|
+
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_params).and_return('response'=>{'docs'=>mock_docs})
|
80
|
+
expect(SpecModel::Basic.where({:foo=>'bar', :baz=>['quix','quack']})).to eq ["Fake Object1", "Fake Object2"]
|
81
|
+
end
|
97
82
|
|
98
|
-
|
99
|
-
|
100
|
-
|
83
|
+
it "should correctly query for empty strings" do
|
84
|
+
expect(SpecModel::Basic.where( :active_fedora_model_ssi => '').count).to eq 0
|
85
|
+
end
|
101
86
|
|
102
|
-
|
103
|
-
|
104
|
-
|
87
|
+
it 'should correctly query for empty arrays' do
|
88
|
+
expect(SpecModel::Basic.where( :active_fedora_model_ssi => []).count).to eq 0
|
89
|
+
end
|
105
90
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
hash[:params][:fl] == 'id' &&
|
114
|
-
hash[:params][:sort] == [@sort_query] &&
|
115
|
-
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
116
|
-
hash[:params][:q].split(" AND ").include?("foo:bar") &&
|
117
|
-
hash[:params][:q].split(" AND ").include?("baz:quix") &&
|
118
|
-
hash[:params][:q].split(" AND ").include?("baz:quack")
|
119
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
120
|
-
expect(SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}, :sort=>'title_t desc')).to eq(["Fake Object1", "Fake Object2"])
|
121
|
-
end
|
91
|
+
it "should add options" do
|
92
|
+
expect(relation).to receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
93
|
+
expect(relation).to receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
94
|
+
|
95
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
96
|
+
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_sort_params).and_return('response'=>{'docs'=>mock_docs})
|
97
|
+
expect(SpecModel::Basic.where(:foo=>'bar', :baz=>['quix','quack']).order('title_t desc')).to eq ["Fake Object1", "Fake Object2"]
|
122
98
|
end
|
123
99
|
end
|
124
100
|
|
125
101
|
|
126
102
|
describe '#find_each' do
|
127
|
-
before { allow(ActiveFedora::Base).to
|
103
|
+
before { allow(ActiveFedora::Base).to receive(:relation).and_return(relation) }
|
128
104
|
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
129
105
|
it "should query solr for all objects with :active_fedora_model_s of self.class" do
|
130
|
-
mock_docs = [{"id" => "changeme
|
106
|
+
mock_docs = [{"id" => "changeme-30"},{"id" => "changeme-22"}]
|
131
107
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
132
108
|
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
expect(yielded).to receive(:run).twice { |obj| obj.class == SpecModel::Basic}
|
138
|
-
SpecModel::Basic.find_each(){|obj| yielded.run(obj) }
|
109
|
+
|
110
|
+
allow(relation).to receive(:load_from_fedora).with("changeme-30", nil).and_return(SpecModel::Basic.new('changeme-30'))
|
111
|
+
allow(relation).to receive(:load_from_fedora).with("changeme-22", nil).and_return(SpecModel::Basic.new('changeme-22'))
|
112
|
+
SpecModel::Basic.find_each(){ |obj| obj.class == SpecModel::Basic }
|
139
113
|
end
|
114
|
+
|
140
115
|
describe "with conditions" do
|
116
|
+
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
117
|
+
let(:expected_query) { "#{@model_query} AND foo:bar AND baz:quix AND baz:quack" }
|
118
|
+
let(:expected_params) { { params: { sort: [@sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
119
|
+
let(:mock_docs) { [{"id" => "changeme-30"}, {"id" => "changeme-22"}] }
|
120
|
+
|
141
121
|
it "should filter by the provided fields" do
|
142
|
-
expect(relation).to receive(:load_from_fedora).with("changeme
|
143
|
-
expect(relation).to receive(:load_from_fedora).with("changeme
|
122
|
+
expect(relation).to receive(:load_from_fedora).with("changeme-30", nil).and_return(SpecModel::Basic.new('changeme-30'))
|
123
|
+
expect(relation).to receive(:load_from_fedora).with("changeme-22", nil).and_return(SpecModel::Basic.new('changeme-22'))
|
144
124
|
|
145
|
-
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
146
125
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
147
|
-
expect(
|
148
|
-
|
149
|
-
rows == 1000 &&
|
150
|
-
method == 'select' &&
|
151
|
-
hash[:params] &&
|
152
|
-
hash[:params][:sort] == [@sort_query] &&
|
153
|
-
hash[:params][:fl] == 'id' &&
|
154
|
-
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
155
|
-
hash[:params][:q].split(" AND ").include?("foo:bar") &&
|
156
|
-
hash[:params][:q].split(" AND ").include?("baz:quix") &&
|
157
|
-
hash[:params][:q].split(" AND ").include?("baz:quack")
|
158
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
159
|
-
yielded = double("yielded method")
|
160
|
-
expect(yielded).to receive(:run).twice { |obj| obj.class == SpecModel::Basic}
|
161
|
-
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| yielded.run(obj) }
|
126
|
+
expect(solr).to receive(:paginate).with(1, 1000, 'select', expected_params).and_return('response'=>{'docs'=>mock_docs})
|
127
|
+
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| obj.class == SpecModel::Basic }
|
162
128
|
end
|
163
129
|
end
|
164
130
|
end
|
165
131
|
|
166
132
|
describe '#find_in_batches' do
|
167
133
|
describe "with conditions hash" do
|
134
|
+
let(:solr) { ActiveFedora::SolrService.instance.conn }
|
135
|
+
let(:expected_query) { "#{@model_query} AND foo:bar AND baz:quix AND baz:quack" }
|
136
|
+
let(:expected_params) { { params: { sort: [@sort_query], fl: 'id', q: expected_query, qt: 'standard' } } }
|
137
|
+
let(:mock_docs) { double('docs') }
|
138
|
+
|
168
139
|
it "should filter by the provided fields" do
|
169
|
-
mock_docs = double('docs')
|
170
140
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
171
|
-
expect(
|
172
|
-
page == 1 &&
|
173
|
-
rows == 1002 &&
|
174
|
-
method == 'select' &&
|
175
|
-
hash[:params] &&
|
176
|
-
hash[:params][:sort] == [@sort_query] &&
|
177
|
-
hash[:params][:fl] == 'id' &&
|
178
|
-
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
179
|
-
hash[:params][:q].split(" AND ").include?("foo:bar") &&
|
180
|
-
hash[:params][:q].split(" AND ").include?("baz:quix") &&
|
181
|
-
hash[:params][:q].split(" AND ").include?("baz:quack")
|
182
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
141
|
+
expect(solr).to receive(:paginate).with(1, 1002, 'select', expected_params).and_return('response'=>{'docs'=>mock_docs})
|
183
142
|
yielded = double("yielded method")
|
184
143
|
expect(yielded).to receive(:run).with(mock_docs)
|
185
|
-
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'})
|
144
|
+
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'}){|group| yielded.run group }
|
186
145
|
end
|
187
146
|
end
|
188
147
|
end
|
@@ -192,30 +151,30 @@ describe ActiveFedora::Base do
|
|
192
151
|
it "should return a count" do
|
193
152
|
mock_result = {'response'=>{'numFound'=>7}}
|
194
153
|
expect(ActiveFedora::SolrService).to receive(:query).with(@model_query, :rows=>0, :raw=>true).and_return(mock_result)
|
195
|
-
expect(SpecModel::Basic.count).to eq
|
154
|
+
expect(SpecModel::Basic.count).to eq 7
|
196
155
|
end
|
197
156
|
it "should allow conditions" do
|
198
157
|
mock_result = {'response'=>{'numFound'=>7}}
|
199
158
|
expect(ActiveFedora::SolrService).to receive(:query).with("#{@model_query} AND (foo:bar)", :rows=>0, :raw=>true).and_return(mock_result)
|
200
|
-
expect(SpecModel::Basic.count(:conditions=>'foo:bar')).to eq
|
159
|
+
expect(SpecModel::Basic.count(:conditions=>'foo:bar')).to eq 7
|
201
160
|
end
|
202
161
|
|
203
162
|
it "should count without a class specified" do
|
204
163
|
mock_result = {'response'=>{'numFound'=>7}}
|
205
164
|
expect(ActiveFedora::SolrService).to receive(:query).with("(foo:bar)", :rows=>0, :raw=>true).and_return(mock_result)
|
206
|
-
expect(ActiveFedora::Base.count(:conditions=>'foo:bar')).to eq
|
165
|
+
expect(ActiveFedora::Base.count(:conditions=>'foo:bar')).to eq 7
|
207
166
|
end
|
208
167
|
end
|
209
168
|
|
210
169
|
describe '#last' do
|
211
170
|
describe 'with multiple objects' do
|
212
|
-
before(:
|
171
|
+
before(:each) do
|
213
172
|
(@a, @b, @c) = 3.times {SpecModel::Basic.create!}
|
214
173
|
end
|
215
174
|
it 'should return one object' do
|
216
175
|
SpecModel::Basic.class == SpecModel::Basic
|
217
176
|
end
|
218
|
-
it 'should return the last object sorted by
|
177
|
+
it 'should return the last object sorted by id' do
|
219
178
|
SpecModel::Basic.last == @c
|
220
179
|
SpecModel::Basic.last != @a
|
221
180
|
end
|
@@ -230,13 +189,13 @@ describe ActiveFedora::Base do
|
|
230
189
|
|
231
190
|
describe '#first' do
|
232
191
|
describe 'with multiple objects' do
|
233
|
-
before(:
|
192
|
+
before(:each) do
|
234
193
|
(@a, @b, @c) = 3.times {SpecModel::Basic.create!}
|
235
194
|
end
|
236
195
|
it 'should return one object' do
|
237
196
|
SpecModel::Basic.class == SpecModel::Basic
|
238
197
|
end
|
239
|
-
it 'should return the last object sorted by
|
198
|
+
it 'should return the last object sorted by id' do
|
240
199
|
SpecModel::Basic.first == @a
|
241
200
|
SpecModel::Basic.first != @c
|
242
201
|
end
|
@@ -250,48 +209,56 @@ describe ActiveFedora::Base do
|
|
250
209
|
end
|
251
210
|
|
252
211
|
describe '#find_with_conditions' do
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
q.split(" AND ").include?("foo:bar") &&
|
260
|
-
q.split(" AND ").include?("baz:quix") &&
|
261
|
-
q.split(" AND ").include?("baz:quack")
|
262
|
-
}.and_return(mock_result)
|
263
|
-
expect(SpecModel::Basic.find_with_conditions(:foo=>'bar', :baz=>['quix','quack'])).to eq(mock_result)
|
212
|
+
let(:mock_result) { double('Result') }
|
213
|
+
let(:klass) { SpecModel::Basic }
|
214
|
+
subject { klass.find_with_conditions(conditions) }
|
215
|
+
|
216
|
+
before do
|
217
|
+
expect(ActiveFedora::SolrService).to receive(:query).with(expected_query, sort: [@sort_query]).and_return(mock_result)
|
264
218
|
end
|
265
219
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
q.split(" AND ").include?('foo:9\\"\\ Nails') &&
|
274
|
-
q.split(" AND ").include?('baz:7\\"\\ version') &&
|
275
|
-
q.split(" AND ").include?('baz:quack')
|
276
|
-
}.and_return(mock_result)
|
277
|
-
expect(SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack'])).to eq(mock_result)
|
220
|
+
context "with a hash of conditions" do
|
221
|
+
let(:expected_query) { "#{@model_query} AND foo:bar AND baz:quix AND baz:quack" }
|
222
|
+
let(:conditions) { { foo: 'bar', baz: ['quix', 'quack'] } }
|
223
|
+
|
224
|
+
it "should make a query to solr and return the results" do
|
225
|
+
expect(subject).to eq mock_result
|
226
|
+
end
|
278
227
|
end
|
279
228
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
229
|
+
context "with quotes in the params" do
|
230
|
+
let(:expected_query) { "#{@model_query} AND foo:9\\\"\\ Nails AND baz:7\\\"\\ version AND baz:quack" }
|
231
|
+
let(:conditions) { { foo: '9" Nails', baz: ['7" version', 'quack']} }
|
232
|
+
|
233
|
+
it "should escape quotes" do
|
234
|
+
expect(subject).to eq mock_result
|
235
|
+
end
|
284
236
|
end
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
237
|
+
|
238
|
+
context "called on AF::Base" do
|
239
|
+
let(:klass) { ActiveFedora::Base }
|
240
|
+
|
241
|
+
context "with a hash" do
|
242
|
+
let(:conditions) { {:baz=>'quack'} }
|
243
|
+
let(:expected_query) { 'baz:quack' }
|
244
|
+
it "shouldn't use the class if it's called on AF:Base " do
|
245
|
+
expect(subject).to eq mock_result
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context "called with a string" do
|
250
|
+
let(:conditions) { 'chunky:monkey' }
|
251
|
+
let(:expected_query) { '(chunky:monkey)' }
|
252
|
+
it "should use the query string if it's provided and wrap it in parentheses" do
|
253
|
+
expect(subject).to eq mock_result
|
254
|
+
end
|
255
|
+
end
|
289
256
|
end
|
290
257
|
end
|
291
258
|
|
292
259
|
describe "#load_from_fedora" do
|
293
260
|
let(:relation) { ActiveFedora::Relation.new(ActiveFedora::Base) }
|
294
|
-
before { @obj = SpecModel::Basic.create(
|
261
|
+
before { @obj = SpecModel::Basic.create(id: "test:123") }
|
295
262
|
after { @obj.destroy }
|
296
263
|
it "should cast when klass == ActiveFedora::Base and cast argument is nil" do
|
297
264
|
expect(relation.send(:load_from_fedora, "test:123", nil)).to be_a SpecModel::Basic
|