active-fedora 6.7.8 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +75 -69
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +59 -59
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -12,15 +12,15 @@ describe ActiveFedora::Persistence do
|
|
12
12
|
|
13
13
|
subject { SpecNode.new }
|
14
14
|
|
15
|
-
describe
|
16
|
-
it
|
17
|
-
subject.send(:create_needs_index?).
|
15
|
+
describe '#create_needs_index?' do
|
16
|
+
it 'should be true' do
|
17
|
+
expect(subject.send(:create_needs_index?)).to be_truthy
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
23
|
-
subject.send(:update_needs_index?).
|
21
|
+
describe '#update_needs_index?' do
|
22
|
+
it 'should be true' do
|
23
|
+
expect(subject.send(:update_needs_index?)).to be_truthy
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Predicates do
|
4
|
-
describe
|
4
|
+
describe '#short_predicate' do
|
5
5
|
it 'should parse strings' do
|
6
|
-
ActiveFedora::Predicates.short_predicate('http://www.openarchives.org/OAI/2.0/itemID').
|
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
|
-
ActiveFedora::Predicates.short_predicate(RDF::DC.creator).
|
10
|
-
ActiveFedora::Predicates.short_predicate(RDF::SKOS.hasTopConcept).
|
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
12
|
before(:all) do
|
13
13
|
@original_mapping = ActiveFedora::Predicates.predicate_config[:predicate_mapping]
|
@@ -15,117 +15,117 @@ describe ActiveFedora::Predicates do
|
|
15
15
|
after(:all) do
|
16
16
|
ActiveFedora::Predicates.predicate_config[:predicate_mapping] = @original_mapping
|
17
17
|
end
|
18
|
-
it
|
18
|
+
it 'should find predicates regardless of order loaded or shared namespace prefixes' do
|
19
19
|
ActiveFedora::Predicates.predicate_config[:predicate_mapping] = {
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
'http://example.org/' => {:ceo => 'Manager'},
|
21
|
+
'http://example.org/zoo/wolves/' => {:alpha => 'Manager'},
|
22
|
+
'http://example.org/zoo/' => {:keeper => 'Manager'}
|
23
23
|
}
|
24
|
-
ActiveFedora::Predicates.short_predicate(
|
25
|
-
ActiveFedora::Predicates.short_predicate(
|
26
|
-
ActiveFedora::Predicates.short_predicate(
|
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
|
-
ActiveFedora::Predicates.default_predicate_namespace.
|
31
|
+
expect(ActiveFedora::Predicates.default_predicate_namespace).to eq('info:fedora/fedora-system:def/relations-external#')
|
32
32
|
end
|
33
|
-
|
34
|
-
describe
|
33
|
+
|
34
|
+
describe '#predicate_mappings' do
|
35
35
|
|
36
36
|
it 'should return a hash' do
|
37
|
-
ActiveFedora::Predicates.predicate_mappings.
|
37
|
+
expect(ActiveFedora::Predicates.predicate_mappings).to be_kind_of Hash
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace).
|
42
|
-
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].
|
40
|
+
it 'should provide mappings to the fedora ontology via the info:fedora/fedora-system:def/relations-external default namespace mapping' do
|
41
|
+
expect(ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace)).to be_truthy
|
42
|
+
expect(ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace]).to be_kind_of Hash
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should provide predicate mappings for entire Fedora Relationship Ontology' do
|
46
|
-
desired_mappings = Hash[:is_member_of =>
|
47
|
-
:has_member =>
|
48
|
-
:is_part_of =>
|
49
|
-
:has_part =>
|
50
|
-
:is_member_of_collection =>
|
51
|
-
:has_collection_member =>
|
52
|
-
:is_constituent_of =>
|
53
|
-
:has_constituent =>
|
54
|
-
:is_subset_of =>
|
55
|
-
:has_subset =>
|
56
|
-
:is_derivation_of =>
|
57
|
-
:has_derivation =>
|
58
|
-
:is_dependent_of =>
|
59
|
-
:has_dependent =>
|
60
|
-
:is_description_of =>
|
61
|
-
:has_description =>
|
62
|
-
:is_metadata_for =>
|
63
|
-
:has_metadata =>
|
64
|
-
:is_annotation_of =>
|
65
|
-
:has_annotation =>
|
66
|
-
:has_equivalent =>
|
67
|
-
:conforms_to =>
|
68
|
-
:has_model =>
|
69
|
-
desired_mappings.each_pair do |k,v|
|
70
|
-
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].
|
71
|
-
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace][k].
|
46
|
+
desired_mappings = Hash[:is_member_of => 'isMemberOf',
|
47
|
+
:has_member => 'hasMember',
|
48
|
+
:is_part_of => 'isPartOf',
|
49
|
+
:has_part => 'hasPart',
|
50
|
+
:is_member_of_collection => 'isMemberOfCollection',
|
51
|
+
:has_collection_member => 'hasCollectionMember',
|
52
|
+
:is_constituent_of => 'isConstituentOf',
|
53
|
+
:has_constituent => 'hasConstituent',
|
54
|
+
:is_subset_of => 'isSubsetOf',
|
55
|
+
:has_subset => 'hasSubset',
|
56
|
+
:is_derivation_of => 'isDerivationOf',
|
57
|
+
:has_derivation => 'hasDerivation',
|
58
|
+
:is_dependent_of => 'isDependentOf',
|
59
|
+
:has_dependent => 'hasDependent',
|
60
|
+
:is_description_of => 'isDescriptionOf',
|
61
|
+
:has_description => 'hasDescription',
|
62
|
+
:is_metadata_for => 'isMetadataFor',
|
63
|
+
:has_metadata => 'hasMetadata',
|
64
|
+
:is_annotation_of => 'isAnnotationOf',
|
65
|
+
:has_annotation => 'hasAnnotation',
|
66
|
+
:has_equivalent => 'hasEquivalent',
|
67
|
+
:conforms_to => 'conformsTo',
|
68
|
+
:has_model => 'hasModel']
|
69
|
+
desired_mappings.each_pair do |k, v|
|
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(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
|
-
ActiveFedora::Predicates.
|
78
|
-
ActiveFedora::Predicates.predicate_lookup(:is_part_of).
|
79
|
-
ActiveFedora::Predicates.predicate_lookup(:is_member_of).
|
80
|
-
ActiveFedora::Predicates.predicate_lookup(
|
81
|
-
ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({
|
82
|
-
ActiveFedora::Predicates.find_predicate(:has_foo).
|
83
|
-
ActiveFedora::Predicates.predicate_lookup(:has_foo,
|
84
|
-
|
77
|
+
expect(ActiveFedora::Predicates).to respond_to(:predicate_lookup)
|
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
|
+
ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({'some_namespace' => {:has_foo => 'hasFOO'}})
|
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 { 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
89
|
@old_predicate_config = ActiveFedora::Predicates.predicate_config
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
after :each do
|
93
93
|
ActiveFedora::Predicates.predicate_config = @old_predicate_config
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it 'should allow explicit initialization of predicates' do
|
97
|
-
ActiveFedora::Predicates.find_predicate(:is_part_of).
|
97
|
+
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq(['isPartOf', 'info:fedora/fedora-system:def/relations-external#'])
|
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
|
-
ActiveFedora::Predicates.find_predicate(:has_bar).
|
105
|
-
|
104
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_bar)).to eq(['hasBAR', 'http://example.com/foo'])
|
105
|
+
expect { 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
|
-
|
109
|
+
expect { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }.to raise_error TypeError
|
110
110
|
end
|
111
111
|
|
112
|
-
it
|
112
|
+
it 'should allow adding predicates without wiping out existing predicates' do
|
113
113
|
ActiveFedora::Predicates.set_predicates({
|
114
|
-
|
115
|
-
|
116
|
-
references:
|
117
|
-
has_derivation:
|
118
|
-
}
|
114
|
+
'http://projecthydra.org/ns/relations#' => {has_profile: 'hasProfile'},
|
115
|
+
'info:fedora/fedora-system:def/relations-external#' => {
|
116
|
+
references: 'references',
|
117
|
+
has_derivation: 'cameFrom'
|
118
|
+
}
|
119
119
|
})
|
120
120
|
# New & Modified Predicates
|
121
|
-
ActiveFedora::Predicates.find_predicate(:has_profile).
|
122
|
-
ActiveFedora::Predicates.find_predicate(:references).
|
123
|
-
ActiveFedora::Predicates.find_predicate(:has_derivation).
|
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', 'info:fedora/fedora-system:def/relations-external#'])
|
123
|
+
expect(ActiveFedora::Predicates.find_predicate(:has_derivation)).to eq(['cameFrom', 'info:fedora/fedora-system:def/relations-external#'])
|
124
124
|
# Pre-Existing predicates should be unharmed
|
125
|
-
ActiveFedora::Predicates.find_predicate(:is_part_of).
|
126
|
-
ActiveFedora::Predicates.find_predicate(:is_governed_by).
|
125
|
+
expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq(['isPartOf', 'info:fedora/fedora-system:def/relations-external#'])
|
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
|
130
|
-
|
130
|
+
|
131
131
|
end
|
data/spec/unit/property_spec.rb
CHANGED
@@ -4,30 +4,22 @@ require 'active_fedora'
|
|
4
4
|
require 'active_fedora/model'
|
5
5
|
|
6
6
|
describe ActiveFedora::Property do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
@test_property = ActiveFedora::Property.new(stub("model_stub"),"file_name", :string)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should provide .new' do
|
13
|
-
ActiveFedora::Property.should respond_to(:new)
|
14
|
-
end
|
15
7
|
|
16
|
-
|
17
|
-
|
8
|
+
before :each do
|
9
|
+
mstub = double('model_stub')
|
10
|
+
@test_property = ActiveFedora::Property.new(mstub, 'file_name', :string)
|
18
11
|
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@test_property.should respond_to(:instance_variable_name)
|
13
|
+
it 'should provide .new and .name' do
|
14
|
+
expect(ActiveFedora::Property).to respond_to(:new)
|
15
|
+
expect(ActiveFedora::Property).to respond_to(:name)
|
25
16
|
end
|
26
17
|
|
27
18
|
describe '.instance_variable_name' do
|
28
19
|
it 'should return the value of the name attribute with an @ appended' do
|
29
|
-
@test_property.
|
20
|
+
expect(@test_property).to respond_to(:instance_variable_name)
|
21
|
+
expect(@test_property.instance_variable_name).to eql("@#{@test_property.name}")
|
30
22
|
end
|
31
23
|
end
|
32
|
-
|
24
|
+
|
33
25
|
end
|
@@ -5,10 +5,10 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
# Load Sample OralHistory Model
|
8
|
-
require File.join( File.dirname(__FILE__),
|
8
|
+
require File.join( File.dirname(__FILE__), '..', 'samples', 'oral_history_sample_model' )
|
9
9
|
@dc_terms = []
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
before(:each) do
|
13
13
|
@sample_xml = "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
|
14
14
|
<dcterms:type xsi:type='DCMITYPE'>sound</dcterms:type>
|
@@ -40,47 +40,47 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
40
40
|
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(@sample_xml )
|
41
41
|
|
42
42
|
end
|
43
|
-
it
|
44
|
-
@test_ds.ng_xml.
|
43
|
+
it 'from_xml should parse everything correctly' do
|
44
|
+
expect(@test_ds.ng_xml).to be_equivalent_to @sample_xml
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size.
|
47
|
+
it 'should create the right number of fields' do
|
48
|
+
expect(ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size).to eq(54)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
|
51
|
+
it 'should have unmodifiable constants' do
|
52
|
+
expect {ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS << :foo}.to raise_error((TypeError if RUBY_VERSION < '1.9.0') || RuntimeError, /can't modify frozen array/i)
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'should default dc elements to :multiple=>true' do
|
57
57
|
@test_ds.fields.values.each do |s|
|
58
|
-
s.has_key?(:multiple).
|
58
|
+
expect(s.has_key?(:multiple)).to eq(true)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
after(:each) do
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
describe '#new' do
|
66
66
|
it 'should provide #new' do
|
67
|
-
ActiveFedora::QualifiedDublinCoreDatastream.
|
67
|
+
expect(ActiveFedora::QualifiedDublinCoreDatastream).to respond_to(:new)
|
68
68
|
end
|
69
|
-
|
70
|
-
|
71
|
-
describe
|
69
|
+
|
70
|
+
|
71
|
+
describe 'model methods' do
|
72
72
|
|
73
73
|
DC_ELEMENTS.each do |el|
|
74
74
|
it "should respond to getters and setters for #{el} element" do
|
75
|
-
|
75
|
+
skip if el == :type
|
76
76
|
value = "Hey #{el}"
|
77
|
-
@test_ds.send("#{el.to_s}=", value)
|
78
|
-
@test_ds.send(el).first.
|
77
|
+
@test_ds.send("#{el.to_s}=", value)
|
78
|
+
expect(@test_ds.send(el).first).to eq(value) #Looking at first because creator has 2 nodes
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
describe '.to_xml' do
|
85
85
|
it 'should output the fields hash as Qualified Dublin Core XML' do
|
86
86
|
#@test_ds.should_receive(:new?).and_return(true).twice
|
@@ -90,12 +90,12 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
90
90
|
@test_ds.field :publisher
|
91
91
|
@test_ds.field :creator
|
92
92
|
@test_ds.field :title
|
93
|
-
|
94
|
-
@test_ds.publisher= ["publisher1"]
|
95
|
-
@test_ds.creator= ["creator1", "creator2"]
|
96
|
-
@test_ds.title= ["title1"]
|
97
93
|
|
98
|
-
@test_ds.
|
94
|
+
@test_ds.publisher = ['publisher1']
|
95
|
+
@test_ds.creator = ['creator1', 'creator2']
|
96
|
+
@test_ds.title = ['title1']
|
97
|
+
|
98
|
+
expect(@test_ds.to_xml).to be_equivalent_to('
|
99
99
|
<dc xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
100
100
|
<dcterms:publisher>publisher1</dcterms:publisher>
|
101
101
|
<dcterms:creator>creator1</dcterms:creator>
|
@@ -105,12 +105,12 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
describe
|
109
|
-
it
|
108
|
+
describe '#to_solr' do
|
109
|
+
it 'should have title' do
|
110
110
|
@test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, 'qdc' )
|
111
|
-
@test_ds.title =
|
111
|
+
@test_ds.title = 'War and Peace'
|
112
112
|
solr = @test_ds.to_solr
|
113
|
-
solr[ActiveFedora::SolrService.solr_name('title', type: :string)].
|
113
|
+
expect(solr[ActiveFedora::SolrService.solr_name('title', type: :string)]).to eq('War and Peace')
|
114
114
|
end
|
115
115
|
|
116
116
|
end
|
@@ -120,15 +120,15 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
|
|
120
120
|
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
121
|
test_ds = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(sample_xml )
|
122
122
|
test_ds.field :cust
|
123
|
-
test_ds.cust.
|
123
|
+
expect(test_ds.cust).to eq(['custom'])
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
describe
|
127
|
+
describe '#field should accept :path option' do
|
128
128
|
it "should be able to map :dc_type to the path 'type'" do
|
129
129
|
test_ds = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(@sample_xml)
|
130
|
-
test_ds.field :dc_type, :string, path:
|
131
|
-
test_ds.dc_type.
|
130
|
+
test_ds.field :dc_type, :string, path: 'type', multiple: true
|
131
|
+
expect(test_ds.dc_type).to eq(['sound'])
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
data/spec/unit/query_spec.rb
CHANGED
@@ -1,130 +1,121 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class Basic < ActiveFedora::Base
|
8
|
-
end
|
3
|
+
module SpecModel
|
4
|
+
class Basic < ActiveFedora::Base
|
5
|
+
def name
|
6
|
+
self.class
|
9
7
|
end
|
10
|
-
@model_query = "_query_:\"{!raw f=" + ActiveFedora::SolrService.solr_name("has_model", :symbol) + "}info:fedora/afmodel:SpecModel_Basic" + "\""
|
11
|
-
@sort_query = ActiveFedora::SolrService.solr_name("system_create", :stored_sortable, type: :date) + ' asc'
|
12
8
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ActiveFedora::Base do
|
12
|
+
|
13
|
+
before :all do
|
14
|
+
@model_query = "_query_:\"{!raw f=" + ActiveFedora::SolrService.solr_name('has_model', :symbol) + '}info:fedora/afmodel:SpecModel_Basic' + "\""
|
15
|
+
@sort_query = ActiveFedora::SolrService.solr_name('system_create', :stored_sortable, type: :date) + ' asc'
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe '#find_one' do
|
19
|
-
describe
|
19
|
+
describe 'when called on AF::Base' do
|
20
20
|
it 'should notify of deprecation if no cast parameter is passed' do
|
21
|
-
Deprecation.
|
22
|
-
expect {
|
23
|
-
ActiveFedora::Base.find_one('mypid:99999')
|
24
|
-
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
21
|
+
expect(Deprecation).to receive(:warn).at_least(1).times
|
22
|
+
expect { ActiveFedora::Base.find_one('mypid:99999') }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
25
23
|
end
|
26
24
|
end
|
27
|
-
describe
|
25
|
+
describe 'when called on a model extending AF::Base' do
|
28
26
|
it 'should not have a deprecation warning when no cast parameter is passed' do
|
29
|
-
Deprecation.
|
30
|
-
expect {
|
31
|
-
SpecModel::Basic.find_one('mypid:99999')
|
32
|
-
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
27
|
+
expect(Deprecation).not_to receive(:warn)
|
28
|
+
expect { SpecModel::Basic.find_one('mypid:99999') }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
37
33
|
describe '#find' do
|
38
|
-
describe
|
39
|
-
describe
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
SpecModel::Basic.
|
43
|
-
SpecModel::Basic.
|
44
|
-
mock_docs = [{
|
45
|
-
mock_docs.
|
46
|
-
ActiveFedora::SolrService.instance.conn.
|
47
|
-
SpecModel::Basic.
|
34
|
+
describe 'without :cast' do
|
35
|
+
describe '#all' do
|
36
|
+
describe 'called on a concrete class' do
|
37
|
+
it 'should query solr for all objects with :has_model_s of self.class' do
|
38
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:30', nil).and_return('Fake Object1')
|
39
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:22', nil).and_return('Fake Object2')
|
40
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
41
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
42
|
+
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})
|
43
|
+
expect(SpecModel::Basic.all).to eq(['Fake Object1', 'Fake Object2'])
|
48
44
|
end
|
49
45
|
end
|
50
|
-
describe
|
51
|
-
it
|
52
|
-
ActiveFedora::Base.
|
53
|
-
ActiveFedora::Base.
|
54
|
-
mock_docs = [{
|
55
|
-
mock_docs.
|
56
|
-
ActiveFedora::SolrService.instance.conn.
|
57
|
-
ActiveFedora::Base.
|
46
|
+
describe 'called without a specific class' do
|
47
|
+
it 'should specify a q parameter' do
|
48
|
+
expect(ActiveFedora::Base).to receive(:find_one).with('changeme:30', true).and_return('Fake Object1')
|
49
|
+
expect(ActiveFedora::Base).to receive(:find_one).with('changeme:22', true).and_return('Fake Object2')
|
50
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
51
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
52
|
+
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})
|
53
|
+
expect(ActiveFedora::Base.all).to eq(['Fake Object1', 'Fake Object2'])
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
61
|
-
describe
|
62
|
-
it
|
57
|
+
describe 'and a pid is specified' do
|
58
|
+
it 'should use SpecModel::Basic.allocate.init_with_object to instantiate an object' do
|
63
59
|
allow_any_instance_of(SpecModel::Basic).to receive(:init_with_object).and_return(SpecModel::Basic.new)
|
64
|
-
ActiveFedora::DigitalObject.
|
65
|
-
SpecModel::Basic.find(
|
60
|
+
expect(ActiveFedora::DigitalObject).to receive(:find).and_return(double('inner obj', :'new?' => false))
|
61
|
+
expect(SpecModel::Basic.find('_PID_')).to be_a SpecModel::Basic
|
66
62
|
end
|
67
|
-
it
|
63
|
+
it 'should raise an exception if it is not found' do
|
68
64
|
allow_any_instance_of(Rubydora::Fc3Service).to receive(:object).and_raise(RestClient::ResourceNotFound)
|
69
|
-
|
70
|
-
SpecModel::Basic.
|
71
|
-
lambda {SpecModel::Basic.find("_PID_")}.should raise_error ActiveFedora::ObjectNotFoundError
|
65
|
+
expect(SpecModel::Basic).to receive(:connection_for_pid).with('_PID_')
|
66
|
+
expect {SpecModel::Basic.find('_PID_')}.to raise_error ActiveFedora::ObjectNotFoundError
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
75
|
-
describe
|
76
|
-
it
|
77
|
-
allow_any_instance_of(SpecModel::Basic).to receive(:init_with_object).and_return(double(
|
78
|
-
ActiveFedora::DigitalObject.
|
79
|
-
SpecModel::Basic.find(
|
70
|
+
describe 'with :cast' do
|
71
|
+
it 'should use SpecModel::Basic.allocate.init_with_object to instantiate an object' do
|
72
|
+
allow_any_instance_of(SpecModel::Basic).to receive(:init_with_object).and_return(double('Model', :adapt_to_cmodel => SpecModel::Basic.new ))
|
73
|
+
expect(ActiveFedora::DigitalObject).to receive(:find).and_return(double('inner obj', :'new?' => false))
|
74
|
+
SpecModel::Basic.find('_PID_', :cast => true)
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
|
-
describe
|
84
|
-
it
|
85
|
-
SpecModel::Basic.
|
86
|
-
SpecModel::Basic.
|
78
|
+
describe 'with conditions' do
|
79
|
+
it 'should filter by the provided fields' do
|
80
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:30', nil).and_return('Fake Object1')
|
81
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:22', nil).and_return('Fake Object2')
|
87
82
|
|
88
|
-
mock_docs = [{
|
89
|
-
mock_docs.
|
90
|
-
ActiveFedora::SolrService.instance.conn.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
102
|
-
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
|
83
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
84
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
85
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate) { |page, rows, method, hash|
|
86
|
+
expect(page).to eq(1)
|
87
|
+
expect(rows).to eq(1000)
|
88
|
+
expect(method).to eq('select')
|
89
|
+
expect(hash[:params]).to be_a(Hash)
|
90
|
+
expect(hash[:params]).to include(:sort => [@sort_query])
|
91
|
+
expect(hash[:params]).to include(:fl => 'id')
|
92
|
+
qs = hash[:params][:q].split(' AND ')
|
93
|
+
expect(qs).to include(@model_query, "foo:\"bar\"", "baz:\"quix\"", "baz:\"quack\"")
|
94
|
+
}.and_return('response' => {'docs' => mock_docs})
|
95
|
+
expect(SpecModel::Basic.find({:foo => 'bar', :baz => ['quix', 'quack']})).to eq(['Fake Object1', 'Fake Object2'])
|
103
96
|
end
|
104
97
|
|
105
|
-
it
|
106
|
-
SpecModel::Basic.find(
|
98
|
+
it 'should correctly query for empty strings' do
|
99
|
+
expect(SpecModel::Basic.find(:active_fedora_model_ssi => '').count).to eq(0)
|
107
100
|
end
|
108
101
|
|
109
|
-
it
|
110
|
-
SpecModel::Basic.
|
111
|
-
SpecModel::Basic.
|
102
|
+
it 'should add options' do
|
103
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:30', nil).and_return('Fake Object1')
|
104
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:22', nil).and_return('Fake Object2')
|
112
105
|
|
113
|
-
mock_docs = [{
|
114
|
-
mock_docs.
|
115
|
-
ActiveFedora::SolrService.instance.conn.
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
}.and_return('response'=>{'docs'=>mock_docs})
|
127
|
-
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}, :sort=>'title_t desc').should == ["Fake Object1", "Fake Object2"]
|
106
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
107
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
108
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate) { |page, rows, method, hash|
|
109
|
+
expect(page).to eq(1)
|
110
|
+
expect(rows).to eq(1000)
|
111
|
+
expect(method).to eq('select')
|
112
|
+
expect(hash[:params]).to be_a(Hash)
|
113
|
+
expect(hash[:params]).to include(:sort => [@sort_query])
|
114
|
+
expect(hash[:params]).to include(:fl => 'id')
|
115
|
+
qs = hash[:params][:q].split(' AND ')
|
116
|
+
expect(qs).to include(@model_query, "foo:\"bar\"", "baz:\"quix\"", "baz:\"quack\"")
|
117
|
+
}.and_return('response' => {'docs' => mock_docs})
|
118
|
+
expect(SpecModel::Basic.find({:foo => 'bar', :baz => ['quix', 'quack']}, :sort => 'title_t desc')).to eq(['Fake Object1', 'Fake Object2'])
|
128
119
|
end
|
129
120
|
|
130
121
|
end
|
@@ -132,166 +123,146 @@ describe ActiveFedora::Base do
|
|
132
123
|
|
133
124
|
|
134
125
|
describe '#find_each' do
|
135
|
-
it
|
136
|
-
mock_docs = [{
|
137
|
-
mock_docs.
|
138
|
-
ActiveFedora::SolrService.instance.conn.
|
139
|
-
|
140
|
-
SpecModel::Basic.
|
141
|
-
SpecModel::Basic.
|
142
|
-
yielded = double(
|
143
|
-
yielded.
|
126
|
+
it 'should query solr for all objects with :active_fedora_model_s of self.class' do
|
127
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
128
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
129
|
+
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})
|
130
|
+
|
131
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:30', nil).and_return(SpecModel::Basic.new(:pid => 'changeme:30'))
|
132
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:22', nil).and_return(SpecModel::Basic.new(:pid => 'changeme:22'))
|
133
|
+
yielded = double('yielded method')
|
134
|
+
expect(yielded).to receive(:run) { |obj| obj.class == SpecModel::Basic }.twice
|
144
135
|
SpecModel::Basic.find_each(){|obj| yielded.run(obj) }
|
145
136
|
end
|
146
|
-
describe
|
147
|
-
it
|
148
|
-
SpecModel::Basic.
|
149
|
-
SpecModel::Basic.
|
137
|
+
describe 'with conditions' do
|
138
|
+
it 'should filter by the provided fields' do
|
139
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:30', nil).and_return(SpecModel::Basic.new(:pid => 'changeme:30'))
|
140
|
+
expect(SpecModel::Basic).to receive(:find_one).with('changeme:22', nil).and_return(SpecModel::Basic.new(:pid => 'changeme:22'))
|
150
141
|
|
151
|
-
mock_docs = [{
|
152
|
-
mock_docs.
|
153
|
-
ActiveFedora::SolrService.instance.conn.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
167
|
-
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| yielded.run(obj) }
|
142
|
+
mock_docs = [{'id' => 'changeme:30'}, {'id' => 'changeme:22'}]
|
143
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
144
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate) { |page, rows, method, hash|
|
145
|
+
expect(page).to eq(1)
|
146
|
+
expect(rows).to eq(1000)
|
147
|
+
expect(method).to eq('select')
|
148
|
+
expect(hash[:params]).to be_a(Hash)
|
149
|
+
expect(hash[:params]).to include(:sort => [@sort_query])
|
150
|
+
expect(hash[:params]).to include(:fl => 'id')
|
151
|
+
qs = hash[:params][:q].split(' AND ')
|
152
|
+
expect(qs).to include(@model_query, "foo:\"bar\"", "baz:\"quix\"", "baz:\"quack\"")
|
153
|
+
}.and_return('response' => {'docs' => mock_docs})
|
154
|
+
yielded = double('yielded method')
|
155
|
+
expect(yielded).to receive(:run) { |obj| obj.class == SpecModel::Basic }.twice
|
156
|
+
SpecModel::Basic.find_each({:foo => 'bar', :baz => ['quix', 'quack']}){|obj| yielded.run(obj) }
|
168
157
|
end
|
169
158
|
end
|
170
159
|
end
|
171
160
|
|
172
161
|
describe '#find_in_batches' do
|
173
|
-
describe
|
174
|
-
it
|
162
|
+
describe 'with conditions hash' do
|
163
|
+
it 'should filter by the provided fields' do
|
175
164
|
mock_docs = double('docs')
|
176
|
-
mock_docs.
|
177
|
-
ActiveFedora::SolrService.instance.conn.
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
yielded.should_receive(:run).with(mock_docs)
|
191
|
-
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'}){|group| yielded.run group }.should
|
165
|
+
expect(mock_docs).to receive(:has_next?).and_return(false)
|
166
|
+
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate) { |page, rows, method, hash|
|
167
|
+
expect(page).to eq(1)
|
168
|
+
expect(rows).to eq(1002)
|
169
|
+
expect(method).to eq('select')
|
170
|
+
expect(hash[:params]).to be_a(Hash)
|
171
|
+
expect(hash[:params]).to include(:sort => [@sort_query])
|
172
|
+
expect(hash[:params]).to include(:fl => 'id')
|
173
|
+
qs = hash[:params][:q].split(' AND ')
|
174
|
+
expect(qs).to include(@model_query, "foo:\"bar\"", "baz:\"quix\"", "baz:\"quack\"")
|
175
|
+
}.and_return('response' => {'docs' => mock_docs})
|
176
|
+
yielded = double('yielded method')
|
177
|
+
expect(yielded).to receive(:run).with(mock_docs)
|
178
|
+
expect(SpecModel::Basic.find_in_batches({:foo => 'bar', :baz => ['quix', 'quack']}, {:batch_size => 1002, :fl => 'id'}){|group| yielded.run group }).not_to raise_error
|
192
179
|
end
|
193
180
|
end
|
194
181
|
end
|
195
182
|
|
196
183
|
describe '#count' do
|
197
|
-
|
198
|
-
|
199
|
-
mock_result = {'response'=>{'numFound'=>7}}
|
200
|
-
ActiveFedora::SolrService.should_receive(:query).with(@model_query, :rows=>0, :raw=>true).and_return(mock_result)
|
201
|
-
SpecModel::Basic.count.should == 7
|
184
|
+
before :each do
|
185
|
+
@mock_result = {'response' => {'numFound' => 7}}
|
202
186
|
end
|
203
|
-
it
|
204
|
-
|
205
|
-
|
206
|
-
SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
|
187
|
+
it 'should return a count' do
|
188
|
+
expect(ActiveFedora::SolrService).to receive(:query).with(@model_query, :rows => 0, :raw => true).and_return(@mock_result)
|
189
|
+
expect(SpecModel::Basic.count).to eq(7)
|
207
190
|
end
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
191
|
+
it 'should allow conditions' do
|
192
|
+
expect(ActiveFedora::SolrService).to receive(:query).with("#{@model_query} AND (foo:bar)", :rows => 0, :raw => true).and_return(@mock_result)
|
193
|
+
expect(SpecModel::Basic.count(:conditions => 'foo:bar')).to eq(7)
|
194
|
+
end
|
195
|
+
it 'should count without a class specified' do
|
196
|
+
expect(ActiveFedora::SolrService).to receive(:query).with('foo:bar', :rows => 0, :raw => true).and_return(@mock_result)
|
197
|
+
expect(ActiveFedora::Base.count(:conditions => 'foo:bar')).to eq(7)
|
213
198
|
end
|
214
199
|
end
|
215
200
|
|
216
|
-
describe '#last' do
|
217
|
-
describe 'with
|
218
|
-
before(:all) do
|
219
|
-
(@a, @b, @c) = 3.times {SpecModel::Basic.create!}
|
220
|
-
end
|
221
|
-
it 'should return one object' do
|
222
|
-
SpecModel::Basic.class == SpecModel::Basic
|
223
|
-
end
|
224
|
-
it 'should return the last object sorted by pid' do
|
225
|
-
SpecModel::Basic.last == @c
|
226
|
-
SpecModel::Basic.last != @a
|
227
|
-
end
|
228
|
-
end
|
229
|
-
describe 'with one object' do
|
201
|
+
describe '#last and #last' do
|
202
|
+
describe 'with one object' do
|
230
203
|
it 'should equal the first object when there is only one' do
|
204
|
+
SpecModel::Basic.delete_all
|
231
205
|
a = SpecModel::Basic.create!
|
232
|
-
SpecModel::Basic.first
|
206
|
+
expect(SpecModel::Basic.first).to eq(SpecModel::Basic.last)
|
233
207
|
end
|
234
208
|
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe '#first' do
|
238
209
|
describe 'with multiple objects' do
|
239
|
-
before
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
end
|
245
|
-
it 'should return the last object sorted by pid' do
|
246
|
-
SpecModel::Basic.first == @a
|
247
|
-
SpecModel::Basic.first != @c
|
210
|
+
before :each do
|
211
|
+
SpecModel::Basic.delete_all
|
212
|
+
@a = SpecModel::Basic.create!
|
213
|
+
@b = SpecModel::Basic.create!
|
214
|
+
@c = SpecModel::Basic.create!
|
248
215
|
end
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
SpecModel::Basic.
|
216
|
+
it 'should return the first/last object sorted by pid' do
|
217
|
+
expect(SpecModel::Basic.last.class ).to eq(SpecModel::Basic)
|
218
|
+
expect(SpecModel::Basic.first.class).to eq(SpecModel::Basic)
|
219
|
+
expect(SpecModel::Basic.last).to eq(@c)
|
220
|
+
expect(SpecModel::Basic.last).not_to eq(@a)
|
221
|
+
expect(SpecModel::Basic.first).to eq(@a)
|
222
|
+
expect(SpecModel::Basic.first).not_to eq(@c)
|
254
223
|
end
|
255
224
|
end
|
256
225
|
end
|
257
|
-
|
226
|
+
|
258
227
|
describe '#find_with_conditions' do
|
259
|
-
|
260
|
-
mock_result = double('Result')
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
228
|
+
before :each do
|
229
|
+
@mock_result = double('Result')
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should make a query to solr and return the results' do
|
233
|
+
expect(ActiveFedora::SolrService).to receive(:query) { |args|
|
234
|
+
q = args.first if args.is_a? Array
|
235
|
+
q ||= args
|
236
|
+
qs = q.split(' AND ')
|
237
|
+
qs.include?(@model_query) &&
|
238
|
+
qs.include?("foo:\"bar\"") &&
|
239
|
+
qs.include?("baz:\"quix\"") &&
|
240
|
+
qs.include?("baz:\"quack\"")
|
241
|
+
}.and_return(@mock_result)
|
242
|
+
expect(SpecModel::Basic.find_with_conditions(:foo => 'bar', :baz => ['quix', 'quack'])).to eq(@mock_result)
|
270
243
|
end
|
271
244
|
|
272
|
-
it
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack']).
|
245
|
+
it 'should escape quotes' do
|
246
|
+
expect(ActiveFedora::SolrService).to receive(:query) { |args|
|
247
|
+
q = args.first if args.is_a? Array
|
248
|
+
q ||= args
|
249
|
+
qs = q.split(' AND ')
|
250
|
+
qs.include?(@model_query) &&
|
251
|
+
qs.include?(@model_query) &&
|
252
|
+
qs.include?('foo:"9\\" Nails"') &&
|
253
|
+
qs.include?('baz:"7\\" version"') &&
|
254
|
+
qs.include?('baz:"quack"')
|
255
|
+
}.and_return(@mock_result)
|
256
|
+
expect(SpecModel::Basic.find_with_conditions(:foo => '9" Nails', :baz => ['7" version', 'quack'])).to eq(@mock_result)
|
284
257
|
end
|
285
258
|
|
286
|
-
it "shouldn't use the class if it's called on AF:Base
|
287
|
-
|
288
|
-
ActiveFedora::
|
289
|
-
ActiveFedora::Base.find_with_conditions(:baz=>'quack').should == mock_result
|
259
|
+
it "shouldn't use the class if it's called on AF:Base" do
|
260
|
+
expect(ActiveFedora::SolrService).to receive(:query).with('baz:"quack"', {:sort => [@sort_query]}).and_return(@mock_result)
|
261
|
+
expect(ActiveFedora::Base.find_with_conditions(:baz => 'quack')).to eq(@mock_result)
|
290
262
|
end
|
291
263
|
it "should use the query string if it's provided" do
|
292
|
-
|
293
|
-
ActiveFedora::
|
294
|
-
ActiveFedora::Base.find_with_conditions('chunky:monkey').should == mock_result
|
264
|
+
expect(ActiveFedora::SolrService).to receive(:query).with('chunky:monkey', {:sort => [@sort_query]}).and_return(@mock_result)
|
265
|
+
expect(ActiveFedora::Base.find_with_conditions('chunky:monkey')).to eq(@mock_result)
|
295
266
|
end
|
296
267
|
end
|
297
268
|
end
|