active-fedora 6.7.8 → 6.8.0

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