active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- 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/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- 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 +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- 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 +68 -74
- 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 +48 -107
- 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 +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -1,28 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Persistence do
|
4
|
-
|
5
|
-
|
6
|
-
|
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)
|
7
12
|
end
|
8
|
-
end
|
9
|
-
after :all do
|
10
|
-
Object.send(:remove_const, :SpecNode)
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
+
subject { SpecNode.new }
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
describe "#create_needs_index?" do
|
17
|
+
it "should be true" do
|
18
|
+
subject.send(:create_needs_index?).should be_true
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
it
|
23
|
-
|
22
|
+
describe "#update_needs_index?" do
|
23
|
+
it "should be true" do
|
24
|
+
subject.send(:update_needs_index?).should be_true
|
24
25
|
end
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
29
|
+
describe "an unsaved object" do
|
30
|
+
subject { ActiveFedora::Base.new }
|
31
|
+
it "should be deleteable (nop) and return the object" do
|
32
|
+
expect(subject.delete).to eq subject
|
33
|
+
end
|
34
|
+
end
|
27
35
|
|
36
|
+
describe "a saved object" do
|
37
|
+
subject { ActiveFedora::Base.create! }
|
38
|
+
describe "that is deleted" do
|
39
|
+
before do
|
40
|
+
subject.delete
|
41
|
+
end
|
42
|
+
it "should be frozen" do
|
43
|
+
expect(subject).to be_frozen
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
28
47
|
end
|
@@ -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
|
-
|
6
|
+
ActiveFedora::Predicates.short_predicate('http://www.openarchives.org/OAI/2.0/itemID').should == :oai_item_id
|
7
7
|
end
|
8
8
|
it 'should parse uris' do
|
9
|
-
|
10
|
-
|
9
|
+
ActiveFedora::Predicates.short_predicate(RDF::DC.creator).should == 'dc_terms_creator'
|
10
|
+
ActiveFedora::Predicates.short_predicate(RDF::SKOS.hasTopConcept).should == '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
|
-
|
25
|
-
|
26
|
-
|
24
|
+
ActiveFedora::Predicates.short_predicate("http://example.org/zoo/Manager").should == :keeper
|
25
|
+
ActiveFedora::Predicates.short_predicate("http://example.org/zoo/wolves/Manager").should == :alpha
|
26
|
+
ActiveFedora::Predicates.short_predicate("http://example.org/Manager").should == :ceo
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it 'should provide .default_predicate_namespace' do
|
31
|
-
|
31
|
+
ActiveFedora::Predicates.default_predicate_namespace.should == '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
|
-
|
37
|
+
ActiveFedora::Predicates.predicate_mappings.should be_kind_of Hash
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
|
42
|
-
|
40
|
+
it "should provide mappings to the fedora ontology via the info:fedora/fedora-system:def/relations-external default namespace mapping" do
|
41
|
+
ActiveFedora::Predicates.predicate_mappings.keys.include?(ActiveFedora::Predicates.default_predicate_namespace).should be_true
|
42
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].should 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,
|
70
|
-
|
71
|
-
|
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
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].should have_key(k)
|
71
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace][k].should == 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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
ActiveFedora::Predicates.should respond_to(:predicate_lookup)
|
78
|
+
ActiveFedora::Predicates.predicate_lookup(:is_part_of).should == "isPartOf"
|
79
|
+
ActiveFedora::Predicates.predicate_lookup(:is_member_of).should == "isMemberOf"
|
80
|
+
ActiveFedora::Predicates.predicate_lookup("isPartOfCollection").should == "isPartOfCollection"
|
81
|
+
ActiveFedora::Predicates.predicate_config[:predicate_mapping].merge!({"some_namespace"=>{:has_foo=>"hasFOO"}})
|
82
|
+
ActiveFedora::Predicates.find_predicate(:has_foo).should == ["hasFOO","some_namespace"]
|
83
|
+
ActiveFedora::Predicates.predicate_lookup(:has_foo,"some_namespace").should == "hasFOO"
|
84
|
+
lambda { ActiveFedora::Predicates.predicate_lookup(:has_foo) }.should 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
|
-
|
97
|
+
ActiveFedora::Predicates.find_predicate(:is_part_of).should == ["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
|
-
|
105
|
-
|
104
|
+
ActiveFedora::Predicates.find_predicate(:has_bar).should == ["hasBAR", "http://example.com/foo"]
|
105
|
+
lambda { ActiveFedora::Predicates.find_predicate(:is_part_of) }.should raise_error ActiveFedora::UnregisteredPredicateError
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
it 'should ensure that the configuration has the correct keys' do
|
109
|
-
|
109
|
+
lambda { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }.should 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
|
-
|
122
|
-
|
123
|
-
|
121
|
+
ActiveFedora::Predicates.find_predicate(:has_profile).should == ["hasProfile", "http://projecthydra.org/ns/relations#"]
|
122
|
+
ActiveFedora::Predicates.find_predicate(:references).should == ["references", "info:fedora/fedora-system:def/relations-external#"]
|
123
|
+
ActiveFedora::Predicates.find_predicate(:has_derivation).should == ["cameFrom", "info:fedora/fedora-system:def/relations-external#"]
|
124
124
|
# Pre-Existing predicates should be unharmed
|
125
|
-
|
126
|
-
|
125
|
+
ActiveFedora::Predicates.find_predicate(:is_part_of).should == ["isPartOf", "info:fedora/fedora-system:def/relations-external#"]
|
126
|
+
ActiveFedora::Predicates.find_predicate(:is_governed_by).should == ["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,22 +4,30 @@ 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
|
7
15
|
|
8
|
-
|
9
|
-
|
10
|
-
@test_property = ActiveFedora::Property.new(mstub, 'file_name', :string)
|
16
|
+
it 'should provide .name' do
|
17
|
+
ActiveFedora::Property.should respond_to(:name)
|
11
18
|
end
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
|
21
|
+
it 'should provide .instance_variable_name' do
|
22
|
+
#ActiveFedora::Property.should respond_to(:instance_variable_name)
|
23
|
+
|
24
|
+
@test_property.should respond_to(:instance_variable_name)
|
16
25
|
end
|
17
26
|
|
18
27
|
describe '.instance_variable_name' do
|
19
28
|
it 'should return the value of the name attribute with an @ appended' do
|
20
|
-
|
21
|
-
expect(@test_property.instance_variable_name).to eql("@#{@test_property.name}")
|
29
|
+
@test_property.instance_variable_name.should eql("@#{@test_property.name}")
|
22
30
|
end
|
23
31
|
end
|
24
|
-
|
32
|
+
|
25
33
|
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
|
-
|
43
|
+
it "from_xml should parse everything correctly" do
|
44
|
+
@test_ds.ng_xml.should be_equivalent_to @sample_xml
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
|
47
|
+
it "should create the right number of fields" do
|
48
|
+
ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size.should == 54
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
|
51
|
+
it "should have unmodifiable constants" do
|
52
|
+
proc {ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS<<:foo}.should 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
|
-
|
58
|
+
s.has_key?(:multiple).should == 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
|
-
|
67
|
+
ActiveFedora::QualifiedDublinCoreDatastream.should 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
|
+
pending if el == :type
|
76
76
|
value = "Hey #{el}"
|
77
|
-
@test_ds.send("#{el.to_s}=", value)
|
78
|
-
|
77
|
+
@test_ds.send("#{el.to_s}=", value)
|
78
|
+
@test_ds.send(el).first.should == 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"]
|
93
97
|
|
94
|
-
@test_ds.
|
95
|
-
@test_ds.creator = ['creator1', 'creator2']
|
96
|
-
@test_ds.title = ['title1']
|
97
|
-
|
98
|
-
expect(@test_ds.to_xml).to be_equivalent_to('
|
98
|
+
@test_ds.to_xml.should 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
|
-
|
113
|
+
solr[ActiveFedora::SolrService.solr_name('title', type: :string)].should == "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
|
-
|
123
|
+
test_ds.cust.should == ['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
|
-
|
130
|
+
test_ds.field :dc_type, :string, path: "type", multiple: true
|
131
|
+
test_ds.dc_type.should == ['sound']
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
data/spec/unit/query_spec.rb
CHANGED
@@ -1,121 +1,123 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
module SpecModel
|
7
|
+
class Basic < ActiveFedora::Base
|
8
|
+
end
|
7
9
|
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'
|
8
12
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
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'
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
Object.send(:remove_const, :SpecModel)
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
describe ":all" do
|
19
|
+
before { ActiveFedora::Base.stub(:relation => relation) }
|
20
|
+
describe "called on a concrete class" do
|
21
|
+
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
22
|
+
it "should query solr for all objects with :has_model_s of self.class" do
|
23
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
24
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
25
|
+
mock_docs = [{"id" => "changeme:30"}, {"id" => "changeme:22"}]
|
26
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
27
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
28
|
+
SpecModel::Basic.all.should == ["Fake Object1", "Fake Object2"]
|
23
29
|
end
|
24
30
|
end
|
25
|
-
describe
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
describe "called without a specific class" do
|
32
|
+
let(:relation) { ActiveFedora::Relation.new(ActiveFedora::Base) }
|
33
|
+
it "should specify a q parameter" do
|
34
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", true).and_return("Fake Object1")
|
35
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", true).and_return("Fake Object2")
|
36
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
37
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
38
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>'*:*', :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
39
|
+
ActiveFedora::Base.all.should == ["Fake Object1", "Fake Object2"]
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
describe '#find' do
|
34
|
-
describe
|
35
|
-
describe
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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'])
|
44
|
-
end
|
45
|
-
end
|
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'])
|
54
|
-
end
|
45
|
+
describe "with :cast false" do
|
46
|
+
describe "and a pid is specified" do
|
47
|
+
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
48
|
+
SpecModel::Basic.any_instance.should_receive(:init_with).and_return(SpecModel::Basic.new )
|
49
|
+
ActiveFedora::DigitalObject.should_receive(:find).and_return(double("inner obj", :'new?'=>false))
|
50
|
+
SpecModel::Basic.find("_PID_", cast: false).should be_a SpecModel::Basic
|
55
51
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
62
|
-
end
|
63
|
-
it 'should raise an exception if it is not found' do
|
64
|
-
allow_any_instance_of(Rubydora::Fc3Service).to receive(:object).and_raise(RestClient::ResourceNotFound)
|
65
|
-
expect(SpecModel::Basic).to receive(:connection_for_pid).with('_PID_')
|
66
|
-
expect {SpecModel::Basic.find('_PID_')}.to raise_error ActiveFedora::ObjectNotFoundError
|
52
|
+
it "should raise an exception if it is not found" do
|
53
|
+
Rubydora::Fc3Service.any_instance.should_receive(:object).and_raise(RestClient::ResourceNotFound)
|
54
|
+
SpecModel::Basic.should_receive(:connection_for_pid).with("_PID_")
|
55
|
+
lambda {SpecModel::Basic.find("_PID_")}.should raise_error ActiveFedora::ObjectNotFoundError
|
67
56
|
end
|
68
57
|
end
|
69
58
|
end
|
70
|
-
describe
|
71
|
-
it
|
72
|
-
|
73
|
-
|
74
|
-
SpecModel::Basic.find(
|
59
|
+
describe "with default :cast of true" do
|
60
|
+
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
61
|
+
SpecModel::Basic.any_instance.should_receive(:init_with).and_return(double("Model", :adapt_to_cmodel=>SpecModel::Basic.new ))
|
62
|
+
ActiveFedora::DigitalObject.should_receive(:find).and_return(double("inner obj", :'new?'=>false))
|
63
|
+
SpecModel::Basic.find("_PID_")
|
75
64
|
end
|
76
65
|
end
|
77
66
|
|
78
|
-
describe
|
79
|
-
|
80
|
-
|
81
|
-
|
67
|
+
describe "with conditions" do
|
68
|
+
before do
|
69
|
+
ActiveFedora::Base.stub(:relation => relation)
|
70
|
+
relation.stub(clone: relation)
|
71
|
+
end
|
72
|
+
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
73
|
+
it "should filter by the provided fields" do
|
74
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
75
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
76
|
+
|
77
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
78
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
79
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
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
|
+
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
|
92
|
+
end
|
82
93
|
|
83
|
-
|
84
|
-
|
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'])
|
94
|
+
it "should correctly query for empty strings" do
|
95
|
+
SpecModel::Basic.find( :active_fedora_model_ssi => '').count.should == 0
|
96
96
|
end
|
97
97
|
|
98
|
-
it 'should correctly query for empty
|
99
|
-
|
98
|
+
it 'should correctly query for empty arrays' do
|
99
|
+
SpecModel::Basic.find( :active_fedora_model_ssi => []).count.should == 0
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
|
104
|
-
|
102
|
+
it "should add options" do
|
103
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", nil).and_return("Fake Object1")
|
104
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", nil).and_return("Fake Object2")
|
105
105
|
|
106
|
-
mock_docs = [{
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
106
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
107
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
108
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
109
|
+
page == 1 &&
|
110
|
+
rows == 1000 &&
|
111
|
+
method == 'select' &&
|
112
|
+
hash[:params] &&
|
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
|
+
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}, :sort=>'title_t desc').should == ["Fake Object1", "Fake Object2"]
|
119
121
|
end
|
120
122
|
|
121
123
|
end
|
@@ -123,146 +125,168 @@ describe ActiveFedora::Base do
|
|
123
125
|
|
124
126
|
|
125
127
|
describe '#find_each' do
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
before { ActiveFedora::Base.stub(:relation => relation) }
|
129
|
+
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
130
|
+
it "should query solr for all objects with :active_fedora_model_s of self.class" do
|
131
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
132
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
133
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => [@sort_query], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
134
|
+
|
135
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:30'))
|
136
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:22'))
|
137
|
+
yielded = double("yielded method")
|
138
|
+
yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
135
139
|
SpecModel::Basic.find_each(){|obj| yielded.run(obj) }
|
136
140
|
end
|
137
|
-
describe
|
138
|
-
it
|
139
|
-
|
140
|
-
|
141
|
+
describe "with conditions" do
|
142
|
+
it "should filter by the provided fields" do
|
143
|
+
relation.should_receive(:load_from_fedora).with("changeme:30", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:30'))
|
144
|
+
relation.should_receive(:load_from_fedora).with("changeme:22", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:22'))
|
141
145
|
|
142
|
-
mock_docs = [{
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
146
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
147
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
148
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
149
|
+
page == 1 &&
|
150
|
+
rows == 1000 &&
|
151
|
+
method == 'select' &&
|
152
|
+
hash[:params] &&
|
153
|
+
hash[:params][:sort] == [@sort_query] &&
|
154
|
+
hash[:params][:fl] == 'id' &&
|
155
|
+
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
156
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
157
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
158
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
159
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
160
|
+
yielded = double("yielded method")
|
161
|
+
yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
162
|
+
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| yielded.run(obj) }
|
157
163
|
end
|
158
164
|
end
|
159
165
|
end
|
160
166
|
|
161
167
|
describe '#find_in_batches' do
|
162
|
-
describe
|
163
|
-
it
|
168
|
+
describe "with conditions hash" do
|
169
|
+
it "should filter by the provided fields" do
|
164
170
|
mock_docs = double('docs')
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
171
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
172
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
173
|
+
page == 1 &&
|
174
|
+
rows == 1002 &&
|
175
|
+
method == 'select' &&
|
176
|
+
hash[:params] &&
|
177
|
+
hash[:params][:sort] == [@sort_query] &&
|
178
|
+
hash[:params][:fl] == 'id' &&
|
179
|
+
hash[:params][:q].split(" AND ").include?(@model_query) &&
|
180
|
+
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
181
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
182
|
+
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
183
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
184
|
+
yielded = double("yielded method")
|
185
|
+
yielded.should_receive(:run).with(mock_docs)
|
186
|
+
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'}){|group| yielded.run group }.should
|
179
187
|
end
|
180
188
|
end
|
181
189
|
end
|
182
190
|
|
183
191
|
describe '#count' do
|
184
|
-
|
185
|
-
|
192
|
+
|
193
|
+
it "should return a count" do
|
194
|
+
mock_result = {'response'=>{'numFound'=>7}}
|
195
|
+
ActiveFedora::SolrService.should_receive(:query).with(@model_query, :rows=>0, :raw=>true).and_return(mock_result)
|
196
|
+
SpecModel::Basic.count.should == 7
|
186
197
|
end
|
187
|
-
it
|
188
|
-
|
189
|
-
|
198
|
+
it "should allow conditions" do
|
199
|
+
mock_result = {'response'=>{'numFound'=>7}}
|
200
|
+
ActiveFedora::SolrService.should_receive(:query).with("#{@model_query} AND (foo:bar)", :rows=>0, :raw=>true).and_return(mock_result)
|
201
|
+
SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
|
190
202
|
end
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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)
|
203
|
+
|
204
|
+
it "should count without a class specified" do
|
205
|
+
mock_result = {'response'=>{'numFound'=>7}}
|
206
|
+
ActiveFedora::SolrService.should_receive(:query).with("foo:bar", :rows=>0, :raw=>true).and_return(mock_result)
|
207
|
+
ActiveFedora::Base.count(:conditions=>'foo:bar').should == 7
|
198
208
|
end
|
199
209
|
end
|
200
210
|
|
201
|
-
describe '#last
|
202
|
-
describe 'with
|
211
|
+
describe '#last' do
|
212
|
+
describe 'with multiple objects' do
|
213
|
+
before(:all) do
|
214
|
+
(@a, @b, @c) = 3.times {SpecModel::Basic.create!}
|
215
|
+
end
|
216
|
+
it 'should return one object' do
|
217
|
+
SpecModel::Basic.class == SpecModel::Basic
|
218
|
+
end
|
219
|
+
it 'should return the last object sorted by pid' do
|
220
|
+
SpecModel::Basic.last == @c
|
221
|
+
SpecModel::Basic.last != @a
|
222
|
+
end
|
223
|
+
end
|
224
|
+
describe 'with one object' do
|
203
225
|
it 'should equal the first object when there is only one' do
|
204
|
-
SpecModel::Basic.delete_all
|
205
226
|
a = SpecModel::Basic.create!
|
206
|
-
|
227
|
+
SpecModel::Basic.first == SpecModel::Basic.last
|
207
228
|
end
|
208
229
|
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#first' do
|
209
233
|
describe 'with multiple objects' do
|
210
|
-
before
|
211
|
-
SpecModel::Basic.
|
212
|
-
|
213
|
-
|
214
|
-
|
234
|
+
before(:all) do
|
235
|
+
(@a, @b, @c) = 3.times {SpecModel::Basic.create!}
|
236
|
+
end
|
237
|
+
it 'should return one object' do
|
238
|
+
SpecModel::Basic.class == SpecModel::Basic
|
215
239
|
end
|
216
|
-
it 'should return the
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
240
|
+
it 'should return the last object sorted by pid' do
|
241
|
+
SpecModel::Basic.first == @a
|
242
|
+
SpecModel::Basic.first != @c
|
243
|
+
end
|
244
|
+
end
|
245
|
+
describe 'with one object' do
|
246
|
+
it 'should equal the first object when there is only one' do
|
247
|
+
a = SpecModel::Basic.create!
|
248
|
+
SpecModel::Basic.first == SpecModel::Basic.last
|
223
249
|
end
|
224
250
|
end
|
225
251
|
end
|
226
|
-
|
252
|
+
|
227
253
|
describe '#find_with_conditions' do
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
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)
|
254
|
+
it "should make a query to solr and return the results" do
|
255
|
+
mock_result = double('Result')
|
256
|
+
ActiveFedora::SolrService.should_receive(:query).with() { |args|
|
257
|
+
q = args.first if args.is_a? Array
|
258
|
+
q ||= args
|
259
|
+
q.split(" AND ").include?(@model_query) &&
|
260
|
+
q.split(" AND ").include?("foo:\"bar\"") &&
|
261
|
+
q.split(" AND ").include?("baz:\"quix\"") &&
|
262
|
+
q.split(" AND ").include?("baz:\"quack\"")
|
263
|
+
}.and_return(mock_result)
|
264
|
+
SpecModel::Basic.find_with_conditions(:foo=>'bar', :baz=>['quix','quack']).should == mock_result
|
243
265
|
end
|
244
266
|
|
245
|
-
it
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
267
|
+
it "should escape quotes" do
|
268
|
+
mock_result = double('Result')
|
269
|
+
ActiveFedora::SolrService.should_receive(:query).with() { |args|
|
270
|
+
q = args.first if args.is_a? Array
|
271
|
+
q ||= args
|
272
|
+
q.split(" AND ").include?(@model_query) &&
|
273
|
+
q.split(" AND ").include?(@model_query) &&
|
274
|
+
q.split(" AND ").include?('foo:"9\\" Nails"') &&
|
275
|
+
q.split(" AND ").include?('baz:"7\\" version"') &&
|
276
|
+
q.split(" AND ").include?('baz:"quack"')
|
277
|
+
}.and_return(mock_result)
|
278
|
+
SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack']).should == mock_result
|
257
279
|
end
|
258
280
|
|
259
|
-
it "shouldn't use the class if it's called on AF:Base" do
|
260
|
-
|
261
|
-
|
281
|
+
it "shouldn't use the class if it's called on AF:Base " do
|
282
|
+
mock_result = double('Result')
|
283
|
+
ActiveFedora::SolrService.should_receive(:query).with('baz:"quack"', {:sort => [@sort_query]}).and_return(mock_result)
|
284
|
+
ActiveFedora::Base.find_with_conditions(:baz=>'quack').should == mock_result
|
262
285
|
end
|
263
286
|
it "should use the query string if it's provided" do
|
264
|
-
|
265
|
-
|
287
|
+
mock_result = double('Result')
|
288
|
+
ActiveFedora::SolrService.should_receive(:query).with('chunky:monkey', {:sort => [@sort_query]}).and_return(mock_result)
|
289
|
+
ActiveFedora::Base.find_with_conditions('chunky:monkey').should == mock_result
|
266
290
|
end
|
267
291
|
end
|
268
292
|
end
|