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.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -5
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +2 -32
  7. data/README.md +143 -0
  8. data/Rakefile +5 -7
  9. data/active-fedora.gemspec +9 -9
  10. data/gemfiles/rails3.gemfile +11 -0
  11. data/gemfiles/rails4.gemfile +10 -0
  12. data/lib/active_fedora.rb +31 -4
  13. data/lib/active_fedora/association_relation.rb +18 -0
  14. data/lib/active_fedora/associations.rb +38 -171
  15. data/lib/active_fedora/associations/association.rb +163 -0
  16. data/lib/active_fedora/associations/association_scope.rb +39 -0
  17. data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
  18. data/lib/active_fedora/associations/builder/association.rb +55 -0
  19. data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
  20. data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
  22. data/lib/active_fedora/associations/builder/has_many.rb +63 -0
  23. data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
  24. data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
  25. data/lib/active_fedora/associations/collection_proxy.rb +862 -0
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
  27. data/lib/active_fedora/associations/has_many_association.rb +36 -11
  28. data/lib/active_fedora/associations/singular_association.rb +62 -0
  29. data/lib/active_fedora/attributes.rb +43 -139
  30. data/lib/active_fedora/autosave_association.rb +317 -0
  31. data/lib/active_fedora/base.rb +10 -327
  32. data/lib/active_fedora/callbacks.rb +1 -3
  33. data/lib/active_fedora/content_model.rb +16 -0
  34. data/lib/active_fedora/core.rb +151 -0
  35. data/lib/active_fedora/datastream_attribute.rb +76 -0
  36. data/lib/active_fedora/datastream_hash.rb +8 -13
  37. data/lib/active_fedora/datastreams.rb +39 -26
  38. data/lib/active_fedora/digital_object.rb +2 -2
  39. data/lib/active_fedora/fedora_attributes.rb +45 -0
  40. data/lib/active_fedora/fixture_loader.rb +1 -1
  41. data/lib/active_fedora/indexing.rb +6 -1
  42. data/lib/active_fedora/model.rb +0 -17
  43. data/lib/active_fedora/nested_attributes.rb +2 -2
  44. data/lib/active_fedora/null_relation.rb +7 -0
  45. data/lib/active_fedora/om_datastream.rb +3 -4
  46. data/lib/active_fedora/persistence.rb +41 -29
  47. data/lib/active_fedora/querying.rb +2 -163
  48. data/lib/active_fedora/rdf.rb +1 -0
  49. data/lib/active_fedora/rdf/indexing.rb +67 -0
  50. data/lib/active_fedora/rdf_datastream.rb +2 -50
  51. data/lib/active_fedora/rdf_node.rb +12 -7
  52. data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
  53. data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
  54. data/lib/active_fedora/reflection.rb +163 -20
  55. data/lib/active_fedora/relation.rb +33 -130
  56. data/lib/active_fedora/relation/calculations.rb +19 -0
  57. data/lib/active_fedora/relation/delegation.rb +22 -0
  58. data/lib/active_fedora/relation/finder_methods.rb +247 -0
  59. data/lib/active_fedora/relation/merger.rb +22 -0
  60. data/lib/active_fedora/relation/query_methods.rb +58 -0
  61. data/lib/active_fedora/relation/spawn_methods.rb +46 -0
  62. data/lib/active_fedora/relationship_graph.rb +0 -2
  63. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  64. data/lib/active_fedora/rubydora_connection.rb +1 -1
  65. data/lib/active_fedora/scoping.rb +20 -0
  66. data/lib/active_fedora/scoping/default.rb +38 -0
  67. data/lib/active_fedora/scoping/named.rb +32 -0
  68. data/lib/active_fedora/semantic_node.rb +54 -106
  69. data/lib/active_fedora/serialization.rb +19 -0
  70. data/lib/active_fedora/sharding.rb +58 -0
  71. data/lib/active_fedora/solr_digital_object.rb +15 -5
  72. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  73. data/lib/active_fedora/solr_service.rb +1 -1
  74. data/lib/active_fedora/unsaved_digital_object.rb +6 -4
  75. data/lib/active_fedora/version.rb +1 -1
  76. data/lib/tasks/active_fedora.rake +3 -0
  77. data/lib/tasks/active_fedora_dev.rake +6 -5
  78. data/spec/config_helper.rb +14 -14
  79. data/spec/integration/associations_spec.rb +168 -455
  80. data/spec/integration/attributes_spec.rb +12 -11
  81. data/spec/integration/auditable_spec.rb +11 -11
  82. data/spec/integration/autosave_association_spec.rb +25 -0
  83. data/spec/integration/base_spec.rb +163 -163
  84. data/spec/integration/belongs_to_association_spec.rb +166 -0
  85. data/spec/integration/bug_spec.rb +7 -7
  86. data/spec/integration/collection_association_spec.rb +58 -0
  87. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  88. data/spec/integration/datastream_collections_spec.rb +69 -69
  89. data/spec/integration/datastream_spec.rb +43 -43
  90. data/spec/integration/datastreams_spec.rb +63 -63
  91. data/spec/integration/delete_all_spec.rb +46 -39
  92. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  93. data/spec/integration/field_to_solr_name_spec.rb +34 -0
  94. data/spec/integration/full_featured_model_spec.rb +100 -101
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
  96. data/spec/integration/has_many_associations_spec.rb +172 -24
  97. data/spec/integration/json_serialization_spec.rb +31 -0
  98. data/spec/integration/load_from_solr_spec.rb +48 -0
  99. data/spec/integration/model_spec.rb +35 -40
  100. data/spec/integration/nested_attribute_spec.rb +42 -43
  101. data/spec/integration/ntriples_datastream_spec.rb +131 -113
  102. data/spec/integration/om_datastream_spec.rb +67 -67
  103. data/spec/integration/persistence_spec.rb +7 -7
  104. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  105. data/spec/integration/relation_delegation_spec.rb +26 -25
  106. data/spec/integration/relation_spec.rb +42 -0
  107. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  108. data/spec/integration/scoped_query_spec.rb +61 -51
  109. data/spec/integration/solr_instance_loader_spec.rb +5 -5
  110. data/spec/integration/solr_service_spec.rb +46 -46
  111. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  112. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  113. data/spec/samples/marpa-dc_datastream.rb +17 -17
  114. data/spec/samples/models/audio_record.rb +16 -16
  115. data/spec/samples/models/image.rb +2 -2
  116. data/spec/samples/models/mods_article.rb +5 -5
  117. data/spec/samples/models/oral_history.rb +18 -18
  118. data/spec/samples/models/seminar.rb +24 -24
  119. data/spec/samples/models/seminar_audio_file.rb +17 -17
  120. data/spec/samples/oral_history_sample_model.rb +21 -21
  121. data/spec/samples/special_thing.rb +14 -14
  122. data/spec/spec_helper.rb +11 -7
  123. data/spec/support/an_active_model.rb +2 -8
  124. data/spec/support/freeze_mocks.rb +12 -0
  125. data/spec/support/mock_fedora.rb +17 -16
  126. data/spec/unit/active_fedora_spec.rb +58 -60
  127. data/spec/unit/attributes_spec.rb +314 -0
  128. data/spec/unit/base_active_model_spec.rb +28 -27
  129. data/spec/unit/base_cma_spec.rb +5 -5
  130. data/spec/unit/base_datastream_management_spec.rb +27 -27
  131. data/spec/unit/base_extra_spec.rb +76 -48
  132. data/spec/unit/base_spec.rb +277 -348
  133. data/spec/unit/callback_spec.rb +18 -19
  134. data/spec/unit/code_configurator_spec.rb +17 -17
  135. data/spec/unit/config_spec.rb +8 -16
  136. data/spec/unit/content_model_spec.rb +79 -60
  137. data/spec/unit/datastream_collections_spec.rb +229 -229
  138. data/spec/unit/datastream_spec.rb +51 -63
  139. data/spec/unit/datastreams_spec.rb +87 -87
  140. data/spec/unit/file_configurator_spec.rb +217 -217
  141. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
  142. data/spec/unit/has_many_collection_spec.rb +26 -8
  143. data/spec/unit/inheritance_spec.rb +13 -12
  144. data/spec/unit/model_spec.rb +39 -45
  145. data/spec/unit/nom_datastream_spec.rb +15 -15
  146. data/spec/unit/ntriples_datastream_spec.rb +123 -118
  147. data/spec/unit/om_datastream_spec.rb +227 -233
  148. data/spec/unit/persistence_spec.rb +34 -15
  149. data/spec/unit/predicates_spec.rb +73 -73
  150. data/spec/unit/property_spec.rb +17 -9
  151. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  152. data/spec/unit/query_spec.rb +222 -198
  153. data/spec/unit/rdf_datastream_spec.rb +21 -28
  154. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  155. data/spec/unit/rdf_list_spec.rb +65 -64
  156. data/spec/unit/rdf_node_spec.rb +7 -7
  157. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  158. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  159. data/spec/unit/relationship_graph_spec.rb +51 -51
  160. data/spec/unit/rels_ext_datastream_spec.rb +68 -74
  161. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  162. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  163. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  164. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  165. data/spec/unit/rubydora_connection_spec.rb +5 -5
  166. data/spec/unit/semantic_node_spec.rb +48 -107
  167. data/spec/unit/serializers_spec.rb +4 -4
  168. data/spec/unit/service_definitions_spec.rb +26 -26
  169. data/spec/unit/simple_datastream_spec.rb +17 -17
  170. data/spec/unit/solr_config_options_spec.rb +29 -28
  171. data/spec/unit/solr_digital_object_spec.rb +17 -25
  172. data/spec/unit/solr_service_spec.rb +95 -82
  173. data/spec/unit/unsaved_digital_object_spec.rb +24 -23
  174. data/spec/unit/validations_spec.rb +21 -21
  175. metadata +110 -159
  176. data/.rspec +0 -1
  177. data/.rubocop.yml +0 -1
  178. data/.rubocop_todo.yml +0 -938
  179. data/CONSOLE_GETTING_STARTED.textile +0 -1
  180. data/NOKOGIRI_DATASTREAMS.textile +0 -1
  181. data/README.textile +0 -116
  182. data/lib/active_fedora/associations/association_proxy.rb +0 -178
  183. data/lib/active_fedora/delegating.rb +0 -72
  184. data/lib/active_fedora/nokogiri_datastream.rb +0 -11
  185. data/spec/integration/delegating_spec.rb +0 -59
  186. data/spec/rails3_test_app/.gitignore +0 -4
  187. data/spec/rails3_test_app/.rspec +0 -1
  188. data/spec/rails3_test_app/Gemfile +0 -40
  189. data/spec/rails3_test_app/Rakefile +0 -7
  190. data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
  191. data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
  192. data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
  193. data/spec/rails3_test_app/config.ru +0 -4
  194. data/spec/rails3_test_app/config/application.rb +0 -42
  195. data/spec/rails3_test_app/config/boot.rb +0 -6
  196. data/spec/rails3_test_app/config/database.yml +0 -22
  197. data/spec/rails3_test_app/config/environment.rb +0 -5
  198. data/spec/rails3_test_app/config/environments/development.rb +0 -25
  199. data/spec/rails3_test_app/config/environments/production.rb +0 -49
  200. data/spec/rails3_test_app/config/environments/test.rb +0 -35
  201. data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
  202. data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
  203. data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
  204. data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
  205. data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
  206. data/spec/rails3_test_app/config/locales/en.yml +0 -5
  207. data/spec/rails3_test_app/config/routes.rb +0 -58
  208. data/spec/rails3_test_app/db/seeds.rb +0 -7
  209. data/spec/rails3_test_app/run_tests +0 -3
  210. data/spec/rails3_test_app/script/rails +0 -6
  211. data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
  212. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
  213. data/spec/unit/association_proxy_spec.rb +0 -12
  214. data/spec/unit/base_delegate_spec.rb +0 -197
  215. 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
- before :all do
5
- class SpecNode
6
- include ActiveFedora::Persistence
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
- subject { SpecNode.new }
14
+ subject { SpecNode.new }
14
15
 
15
- describe '#create_needs_index?' do
16
- it 'should be true' do
17
- expect(subject.send(:create_needs_index?)).to be_truthy
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
- describe '#update_needs_index?' do
22
- it 'should be true' do
23
- expect(subject.send(:update_needs_index?)).to be_truthy
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 '#short_predicate' do
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(:oai_item_id)
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
- 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')
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 'should find predicates regardless of order loaded or shared namespace prefixes' do
18
+ it "should find predicates regardless of order loaded or shared namespace prefixes" do
19
19
  ActiveFedora::Predicates.predicate_config[:predicate_mapping] = {
20
- 'http://example.org/' => {:ceo => 'Manager'},
21
- 'http://example.org/zoo/wolves/' => {:alpha => 'Manager'},
22
- 'http://example.org/zoo/' => {:keeper => 'Manager'}
20
+ "http://example.org/"=>{:ceo => 'Manager'},
21
+ "http://example.org/zoo/wolves/"=>{:alpha => 'Manager'},
22
+ "http://example.org/zoo/"=>{:keeper => 'Manager'}
23
23
  }
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)
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
- expect(ActiveFedora::Predicates.default_predicate_namespace).to eq('info:fedora/fedora-system:def/relations-external#')
31
+ ActiveFedora::Predicates.default_predicate_namespace.should == 'info:fedora/fedora-system:def/relations-external#'
32
32
  end
33
-
34
- describe '#predicate_mappings' do
33
+
34
+ describe "#predicate_mappings" do
35
35
 
36
36
  it 'should return a hash' do
37
- expect(ActiveFedora::Predicates.predicate_mappings).to be_kind_of Hash
37
+ ActiveFedora::Predicates.predicate_mappings.should be_kind_of Hash
38
38
  end
39
39
 
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
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 => '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)
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
- 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
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
- expect(ActiveFedora::Predicates.find_predicate(:is_part_of)).to eq(['isPartOf', 'info:fedora/fedora-system:def/relations-external#'])
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
- 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
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
- expect { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }.to raise_error TypeError
109
+ lambda { ActiveFedora::Predicates.predicate_config = { :foo => 'invalid!' } }.should raise_error TypeError
110
110
  end
111
111
 
112
- it 'should allow adding predicates without wiping out existing predicates' do
112
+ it "should allow adding predicates without wiping out existing predicates" do
113
113
  ActiveFedora::Predicates.set_predicates({
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
- }
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
- 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#'])
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
- 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#'])
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
@@ -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
- before :each do
9
- mstub = double('model_stub')
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
- it 'should provide .new and .name' do
14
- expect(ActiveFedora::Property).to respond_to(:new)
15
- expect(ActiveFedora::Property).to respond_to(:name)
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
- expect(@test_property).to respond_to(:instance_variable_name)
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__), '..', 'samples', 'oral_history_sample_model' )
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 'from_xml should parse everything correctly' do
44
- expect(@test_ds.ng_xml).to be_equivalent_to @sample_xml
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 'should create the right number of fields' do
48
- expect(ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size).to eq(54)
47
+ it "should create the right number of fields" do
48
+ ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size.should == 54
49
49
  end
50
50
 
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)
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 'should default dc elements to :multiple=>true' do
56
+ it "should default dc elements to :multiple=>true" do
57
57
  @test_ds.fields.values.each do |s|
58
- expect(s.has_key?(:multiple)).to eq(true)
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
- expect(ActiveFedora::QualifiedDublinCoreDatastream).to respond_to(:new)
67
+ ActiveFedora::QualifiedDublinCoreDatastream.should respond_to(:new)
68
68
  end
69
-
70
-
71
- describe 'model methods' do
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
- skip if el == :type
75
+ pending if el == :type
76
76
  value = "Hey #{el}"
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
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.publisher = ['publisher1']
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 '#to_solr' do
109
- it 'should have title' do
108
+ describe "#to_solr" do
109
+ it "should have title" do
110
110
  @test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, 'qdc' )
111
- @test_ds.title = 'War and Peace'
111
+ @test_ds.title = "War and Peace"
112
112
  solr = @test_ds.to_solr
113
- expect(solr[ActiveFedora::SolrService.solr_name('title', type: :string)]).to eq('War and Peace')
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
- expect(test_ds.cust).to eq(['custom'])
123
+ test_ds.cust.should == ['custom']
124
124
  end
125
125
  end
126
126
 
127
- describe '#field should accept :path option' do
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: 'type', multiple: true
131
- expect(test_ds.dc_type).to eq(['sound'])
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
 
@@ -1,121 +1,123 @@
1
1
  require 'spec_helper'
2
2
 
3
- module SpecModel
4
- class Basic < ActiveFedora::Base
5
- def name
6
- self.class
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
- 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'
13
+
14
+ after(:all) do
15
+ Object.send(:remove_const, :SpecModel)
16
16
  end
17
17
 
18
- describe '#find_one' do
19
- describe 'when called on AF::Base' do
20
- it 'should notify of deprecation if no cast parameter is passed' do
21
- expect(Deprecation).to receive(:warn).at_least(1).times
22
- expect { ActiveFedora::Base.find_one('mypid:99999') }.to raise_error(ActiveFedora::ObjectNotFoundError)
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 'when called on a model extending AF::Base' do
26
- it 'should not have a deprecation warning when no cast parameter is passed' do
27
- expect(Deprecation).not_to receive(:warn)
28
- expect { SpecModel::Basic.find_one('mypid:99999') }.to raise_error(ActiveFedora::ObjectNotFoundError)
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 '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'])
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
- end
57
- describe 'and a pid is specified' do
58
- it 'should use SpecModel::Basic.allocate.init_with_object to instantiate an object' do
59
- allow_any_instance_of(SpecModel::Basic).to receive(:init_with_object).and_return(SpecModel::Basic.new)
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 '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)
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 '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')
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
- 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'])
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 strings' do
99
- expect(SpecModel::Basic.find(:active_fedora_model_ssi => '').count).to eq(0)
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 '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')
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 = [{'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'])
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
- 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
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 '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'))
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 = [{'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) }
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 'with conditions hash' do
163
- it 'should filter by the provided fields' do
168
+ describe "with conditions hash" do
169
+ it "should filter by the provided fields" do
164
170
  mock_docs = double('docs')
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
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
- before :each do
185
- @mock_result = {'response' => {'numFound' => 7}}
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 '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)
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
- 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)
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 and #last' do
202
- describe 'with one object' do
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
- expect(SpecModel::Basic.first).to eq(SpecModel::Basic.last)
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 :each do
211
- SpecModel::Basic.delete_all
212
- @a = SpecModel::Basic.create!
213
- @b = SpecModel::Basic.create!
214
- @c = SpecModel::Basic.create!
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 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)
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
- 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)
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 '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)
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
- 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)
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
- 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)
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