active-fedora 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/active-fedora.gemspec +1 -2
- data/lib/active_fedora/datastreams.rb +14 -14
- data/lib/active_fedora/file_management.rb +5 -3
- data/lib/active_fedora/metadata_datastream_helper.rb +5 -1
- data/lib/active_fedora/nokogiri_datastream.rb +17 -4
- data/lib/active_fedora/rdf_datastream.rb +59 -36
- data/lib/active_fedora/relationships.rb +28 -11
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +3 -3
- data/spec/integration/base_spec.rb +15 -3
- data/spec/integration/bug_spec.rb +0 -3
- data/spec/integration/datastream_collections_spec.rb +9 -9
- data/spec/integration/datastream_spec.rb +1 -1
- data/spec/integration/full_featured_model_spec.rb +3 -4
- data/spec/integration/ntriples_datastream_spec.rb +0 -1
- data/spec/integration/rels_ext_datastream_spec.rb +12 -1
- data/spec/integration/semantic_node_spec.rb +10 -0
- data/spec/integration/solr_service_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -7
- data/spec/support/mock_fedora.rb +10 -10
- data/spec/unit/active_fedora_spec.rb +8 -8
- data/spec/unit/association_proxy_spec.rb +2 -1
- data/spec/unit/base_cma_spec.rb +2 -2
- data/spec/unit/base_datastream_management_spec.rb +9 -9
- data/spec/unit/base_extra_spec.rb +25 -25
- data/spec/unit/base_file_management_spec.rb +32 -23
- data/spec/unit/base_spec.rb +94 -151
- data/spec/unit/callback_spec.rb +16 -11
- data/spec/unit/code_configurator_spec.rb +4 -4
- data/spec/unit/content_model_spec.rb +8 -8
- data/spec/unit/datastream_collections_spec.rb +23 -23
- data/spec/unit/datastream_spec.rb +7 -7
- data/spec/unit/datastreams_spec.rb +189 -304
- data/spec/unit/file_configurator_spec.rb +56 -56
- data/spec/unit/has_many_collection_spec.rb +1 -1
- data/spec/unit/model_spec.rb +51 -56
- data/spec/unit/nokogiri_datastream_spec.rb +24 -25
- data/spec/unit/ntriples_datastream_spec.rb +18 -27
- data/spec/unit/property_spec.rb +0 -2
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -2
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +1 -1
- data/spec/unit/relationship_graph_spec.rb +1 -1
- data/spec/unit/relationships_spec.rb +64 -52
- data/spec/unit/rels_ext_datastream_spec.rb +7 -7
- data/spec/unit/semantic_node_spec.rb +5 -5
- data/spec/unit/service_definitions_spec.rb +18 -16
- data/spec/unit/solr_config_options_spec.rb +6 -6
- data/spec/unit/solr_service_spec.rb +16 -16
- metadata +5 -21
@@ -13,7 +13,7 @@ describe ActiveFedora::FileConfigurator do
|
|
13
13
|
|
14
14
|
describe "#initialize" do
|
15
15
|
it "should trigger configuration reset (to empty defaults)" do
|
16
|
-
ActiveFedora::FileConfigurator.any_instance.
|
16
|
+
ActiveFedora::FileConfigurator.any_instance.should_receive(:reset!)
|
17
17
|
ActiveFedora::FileConfigurator.new
|
18
18
|
end
|
19
19
|
end
|
@@ -32,7 +32,7 @@ describe ActiveFedora::FileConfigurator do
|
|
32
32
|
subject.reset!
|
33
33
|
end
|
34
34
|
it "should trigger configuration to load" do
|
35
|
-
subject.
|
35
|
+
subject.should_receive(:load_fedora_config)
|
36
36
|
subject.fedora_config
|
37
37
|
end
|
38
38
|
end
|
@@ -41,7 +41,7 @@ describe ActiveFedora::FileConfigurator do
|
|
41
41
|
subject.reset!
|
42
42
|
end
|
43
43
|
it "should trigger configuration to load" do
|
44
|
-
subject.
|
44
|
+
subject.should_receive(:load_solr_config)
|
45
45
|
subject.solr_config
|
46
46
|
end
|
47
47
|
end
|
@@ -63,55 +63,55 @@ describe ActiveFedora::FileConfigurator do
|
|
63
63
|
|
64
64
|
describe "get_config_path(:fedora)" do
|
65
65
|
it "should use the config_options[:config_path] if it exists" do
|
66
|
-
subject.
|
67
|
-
File.
|
66
|
+
subject.should_receive(:config_options).and_return({:fedora_config_path => "/path/to/fedora.yml"})
|
67
|
+
File.should_receive(:file?).with("/path/to/fedora.yml").and_return(true)
|
68
68
|
subject.get_config_path(:fedora).should eql("/path/to/fedora.yml")
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should look in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
|
72
|
-
subject.
|
72
|
+
subject.should_receive(:config_options).and_return({})
|
73
73
|
stub_rails(:root => "/rails/root")
|
74
|
-
File.
|
74
|
+
File.should_receive(:file?).with("/rails/root/config/fedora.yml").and_return(true)
|
75
75
|
subject.get_config_path(:fedora).should eql("/rails/root/config/fedora.yml")
|
76
76
|
unstub_rails
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should look in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
|
80
|
-
subject.
|
81
|
-
Dir.
|
82
|
-
File.
|
80
|
+
subject.should_receive(:config_options).and_return({})
|
81
|
+
Dir.stub(:getwd => "/current/working/directory")
|
82
|
+
File.should_receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(true)
|
83
83
|
subject.get_config_path(:fedora).should eql("/current/working/directory/config/fedora.yml")
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should return default fedora.yml that ships with active-fedora if none of the above" do
|
87
|
-
subject.
|
88
|
-
Dir.
|
89
|
-
File.
|
90
|
-
File.
|
91
|
-
logger.
|
87
|
+
subject.should_receive(:config_options).and_return({})
|
88
|
+
Dir.should_receive(:getwd).and_return("/current/working/directory")
|
89
|
+
File.should_receive(:file?).with("/current/working/directory/config/fedora.yml").and_return(false)
|
90
|
+
File.should_receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml'))).and_return(true)
|
91
|
+
logger.should_receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.")
|
92
92
|
subject.get_config_path(:fedora).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml')))
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe "get_config_path(:solr)" do
|
97
97
|
it "should return the solr_config_path if set in config_options hash" do
|
98
|
-
subject.
|
99
|
-
File.
|
98
|
+
subject.stub(:config_options => {:solr_config_path => "/path/to/solr.yml"})
|
99
|
+
File.should_receive(:file?).with("/path/to/solr.yml").and_return(true)
|
100
100
|
subject.get_config_path(:solr).should eql("/path/to/solr.yml")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should return the solr.yml file in the same directory as the fedora.yml if it exists" do
|
104
|
-
subject.
|
105
|
-
File.
|
104
|
+
subject.should_receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
105
|
+
File.should_receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(true)
|
106
106
|
subject.get_config_path(:solr).should eql("/path/to/fedora/config/solr.yml")
|
107
107
|
end
|
108
108
|
|
109
109
|
context "no solr.yml in same directory as fedora.yml and fedora.yml does not contain solr url" do
|
110
110
|
|
111
111
|
before :each do
|
112
|
-
subject.
|
113
|
-
subject.
|
114
|
-
File.
|
112
|
+
subject.stub(:config_options => {})
|
113
|
+
subject.should_receive(:path).and_return("/path/to/fedora/config/fedora.yml")
|
114
|
+
File.should_receive(:file?).with("/path/to/fedora/config/solr.yml").and_return(false)
|
115
115
|
end
|
116
116
|
after :each do
|
117
117
|
unstub_rails
|
@@ -119,21 +119,21 @@ describe ActiveFedora::FileConfigurator do
|
|
119
119
|
|
120
120
|
it "should not raise an error if there is not a solr.yml in the same directory as the fedora.yml and the fedora.yml has a solr url defined and look in rails.root" do
|
121
121
|
stub_rails(:root=>"/rails/root")
|
122
|
-
File.
|
122
|
+
File.should_receive(:file?).with("/rails/root/config/solr.yml").and_return(true)
|
123
123
|
subject.get_config_path(:solr).should eql("/rails/root/config/solr.yml")
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should look in ./config/solr.yml if no rails root" do
|
127
|
-
Dir.
|
128
|
-
File.
|
127
|
+
Dir.stub(:getwd => "/current/working/directory")
|
128
|
+
File.should_receive(:file?).with("/current/working/directory/config/solr.yml").and_return(true)
|
129
129
|
subject.get_config_path(:solr).should eql("/current/working/directory/config/solr.yml")
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should return the default solr.yml file that ships with active-fedora if no other option is set" do
|
133
|
-
Dir.
|
134
|
-
File.
|
135
|
-
File.
|
136
|
-
logger.
|
133
|
+
Dir.stub(:getwd => "/current/working/directory")
|
134
|
+
File.should_receive(:file?).with("/current/working/directory/config/solr.yml").and_return(false)
|
135
|
+
File.should_receive(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml'))).and_return(true)
|
136
|
+
logger.should_receive(:warn).with("Using the default solr.yml that comes with active-fedora. If you want to override this, pass the path to solr.yml to ActiveFedora - ie. ActiveFedora.init(:solr_config_path => '/path/to/solr.yml') - or set Rails.root and put solr.yml into \#{Rails.root}/config.")
|
137
137
|
subject.get_config_path(:solr).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml')))
|
138
138
|
end
|
139
139
|
end
|
@@ -145,25 +145,25 @@ describe ActiveFedora::FileConfigurator do
|
|
145
145
|
subject.reset!
|
146
146
|
end
|
147
147
|
it "should load the file specified in fedora_config_path" do
|
148
|
-
subject.
|
149
|
-
subject.
|
150
|
-
IO.
|
148
|
+
subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
149
|
+
subject.should_receive(:load_solr_config)
|
150
|
+
IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n url: http://myfedora:8080")
|
151
151
|
subject.load_fedora_config.should == {:url=>"http://myfedora:8080"}
|
152
152
|
subject.fedora_config.should == {:url=>"http://myfedora:8080"}
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should allow sharding" do
|
156
|
-
subject.
|
157
|
-
subject.
|
158
|
-
IO.
|
156
|
+
subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
157
|
+
subject.should_receive(:load_solr_config)
|
158
|
+
IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:8983\ntest:\n- url: http://myfedora:8080\n- url: http://myfedora:8081")
|
159
159
|
subject.load_fedora_config.should == [{:url=>"http://myfedora:8080"}, {:url=>"http://myfedora:8081"}]
|
160
160
|
subject.fedora_config.should == [{:url=>"http://myfedora:8080"}, {:url=>"http://myfedora:8081"}]
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should parse the file using ERb" do
|
164
|
-
subject.
|
165
|
-
subject.
|
166
|
-
IO.
|
164
|
+
subject.should_receive(:get_config_path).with(:fedora).and_return("/path/to/fedora.yml")
|
165
|
+
subject.should_receive(:load_solr_config)
|
166
|
+
IO.should_receive(:read).with("/path/to/fedora.yml").and_return("development:\n url: http://devfedora:<%= 8983 %>\ntest:\n url: http://myfedora:<%= 8081 %>")
|
167
167
|
subject.load_fedora_config.should == {:url=>"http://myfedora:8081"}
|
168
168
|
subject.fedora_config.should == {:url=>"http://myfedora:8081"}
|
169
169
|
end
|
@@ -174,17 +174,17 @@ describe ActiveFedora::FileConfigurator do
|
|
174
174
|
subject.reset!
|
175
175
|
end
|
176
176
|
it "should load the file specified in solr_config_path" do
|
177
|
-
subject.
|
178
|
-
subject.
|
179
|
-
IO.
|
177
|
+
subject.should_receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
|
178
|
+
subject.should_receive(:load_fedora_config)
|
179
|
+
IO.should_receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
|
180
180
|
subject.load_solr_config.should == {:url=>"http://mysolr:8080"}
|
181
181
|
subject.solr_config.should == {:url=>"http://mysolr:8080"}
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should parse the file using ERb" do
|
185
|
-
subject.
|
186
|
-
subject.
|
187
|
-
IO.
|
185
|
+
subject.should_receive(:get_config_path).with(:solr).and_return("/path/to/solr.yml")
|
186
|
+
subject.should_receive(:load_fedora_config)
|
187
|
+
IO.should_receive(:read).with("/path/to/solr.yml").and_return("development:\n default:\n url: http://devsolr:<%= 8983 %>\ntest:\n default:\n url: http://mysolr:<%= 8081 %>")
|
188
188
|
subject.load_solr_config.should == {:url=>"http://mysolr:8081"}
|
189
189
|
subject.solr_config.should == {:url=>"http://mysolr:8081"}
|
190
190
|
end
|
@@ -206,7 +206,7 @@ describe ActiveFedora::FileConfigurator do
|
|
206
206
|
subject.instance_variable_set :@config_loaded, true
|
207
207
|
end
|
208
208
|
it "should load the fedora and solr configs" do
|
209
|
-
subject.
|
209
|
+
subject.should_receive(:load_config).never
|
210
210
|
subject.config_loaded?.should be_true
|
211
211
|
subject.load_configs
|
212
212
|
subject.config_loaded?.should be_true
|
@@ -216,13 +216,13 @@ describe ActiveFedora::FileConfigurator do
|
|
216
216
|
|
217
217
|
describe "check_fedora_path_for_solr" do
|
218
218
|
it "should find the solr.yml file and return it if it exists" do
|
219
|
-
subject.
|
220
|
-
File.
|
219
|
+
subject.should_receive(:path).and_return("/path/to/fedora/fedora.yml")
|
220
|
+
File.should_receive(:file?).with("/path/to/fedora/solr.yml").and_return(true)
|
221
221
|
subject.check_fedora_path_for_solr.should == "/path/to/fedora/solr.yml"
|
222
222
|
end
|
223
223
|
it "should return nil if the solr.yml file is not there" do
|
224
|
-
subject.
|
225
|
-
File.
|
224
|
+
subject.should_receive(:path).and_return("/path/to/fedora/fedora.yml")
|
225
|
+
File.should_receive(:file?).with("/path/to/fedora/solr.yml").and_return(false)
|
226
226
|
subject.check_fedora_path_for_solr.should be_nil
|
227
227
|
end
|
228
228
|
end
|
@@ -246,14 +246,14 @@ describe ActiveFedora::FileConfigurator do
|
|
246
246
|
subject.should respond_to(:solr_config_path)
|
247
247
|
end
|
248
248
|
it "loads a config from the current working directory as a second choice" do
|
249
|
-
Dir.
|
249
|
+
Dir.stub(:getwd).and_return(@fake_rails_root)
|
250
250
|
subject.init
|
251
251
|
subject.get_config_path(:fedora).should eql("#{@fake_rails_root}/config/fedora.yml")
|
252
252
|
subject.solr_config_path.should eql("#{@fake_rails_root}/config/solr.yml")
|
253
253
|
end
|
254
254
|
it "loads the config that ships with this gem as a last choice" do
|
255
|
-
Dir.
|
256
|
-
logger.
|
255
|
+
Dir.stub(:getwd).and_return("/fake/path")
|
256
|
+
logger.should_receive(:warn).with("Using the default fedora.yml that comes with active-fedora. If you want to override this, pass the path to fedora.yml to ActiveFedora - ie. ActiveFedora.init(:fedora_config_path => '/path/to/fedora.yml') - or set Rails.root and put fedora.yml into \#{Rails.root}/config.").exactly(3).times
|
257
257
|
subject.init
|
258
258
|
expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
|
259
259
|
subject.get_config_path(:fedora).should eql(expected_config+'/fedora.yml')
|
@@ -298,14 +298,14 @@ describe ActiveFedora::FileConfigurator do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
it "should return the path to the default config/predicate_mappings.yml if specified config file not found" do
|
301
|
-
File.
|
302
|
-
File.
|
301
|
+
File.should_receive(:exist?).with("/path/to/predicate_mappings.yml").and_return(false)
|
302
|
+
File.should_receive(:exist?).with(default_predicate_mapping_file).and_return(true)
|
303
303
|
subject.send(:build_predicate_config_path,"/path/to").should == default_predicate_mapping_file
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should return the path to the specified config_path if it exists" do
|
307
|
-
File.
|
308
|
-
subject.
|
307
|
+
File.should_receive(:exist?).with("/path/to/predicate_mappings.yml").and_return(true)
|
308
|
+
subject.should_receive(:valid_predicate_mapping?).and_return(true)
|
309
309
|
subject.send(:build_predicate_config_path,"/path/to").should == "/path/to/predicate_mappings.yml"
|
310
310
|
end
|
311
311
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Associations::HasManyAssociation do
|
4
4
|
it "should be able to replace the collection" do
|
5
5
|
@owner = stub(:new_record? => false, :to_ary => nil, :internal_uri => 'info:fedora/changeme:99')
|
6
|
-
@reflection = stub(:klass =>
|
6
|
+
@reflection = stub(:klass => mock.class, :options=>{:property=>'predicate'})
|
7
7
|
#ac = ActiveFedora::Associations::AssociationCollection.new(@owner, @reflection)
|
8
8
|
ac = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
|
9
9
|
@target = [stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true)]
|
data/spec/unit/model_spec.rb
CHANGED
@@ -36,57 +36,54 @@ describe ActiveFedora::Model do
|
|
36
36
|
describe ":all" do
|
37
37
|
describe "called on a concrete class" do
|
38
38
|
it "should query solr for all objects with :has_model_s of self.class" do
|
39
|
-
SpecModel::Basic.
|
40
|
-
SpecModel::Basic.
|
41
|
-
mock_docs =
|
42
|
-
mock_docs.
|
43
|
-
|
44
|
-
ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
|
39
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:30", nil).and_return("Fake Object1")
|
40
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:22", nil).and_return("Fake Object2")
|
41
|
+
mock_docs = [{"id" => "changeme:30"}, {"id" => "changeme:22"}]
|
42
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
43
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
45
44
|
SpecModel::Basic.find(:all).should == ["Fake Object1", "Fake Object2"]
|
46
45
|
end
|
47
46
|
end
|
48
47
|
describe "called without a specific class" do
|
49
48
|
it "should specify a q parameter" do
|
50
|
-
ActiveFedora::Base.
|
51
|
-
ActiveFedora::Base.
|
52
|
-
mock_docs =
|
53
|
-
mock_docs.
|
54
|
-
|
55
|
-
ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>'*:*', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
|
49
|
+
ActiveFedora::Base.should_receive(:find_one).with("changeme:30", nil).and_return("Fake Object1")
|
50
|
+
ActiveFedora::Base.should_receive(:find_one).with("changeme:22", nil).and_return("Fake Object2")
|
51
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
52
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
53
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>'*:*', :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
56
54
|
ActiveFedora::Base.find(:all).should == ["Fake Object1", "Fake Object2"]
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
60
58
|
describe "and a pid is specified" do
|
61
59
|
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
62
|
-
SpecModel::Basic.any_instance.
|
63
|
-
ActiveFedora::DigitalObject.
|
60
|
+
SpecModel::Basic.any_instance.should_receive(:init_with).and_return(SpecModel::Basic.new)
|
61
|
+
ActiveFedora::DigitalObject.should_receive(:find).and_return(stub("inner obj", :'new?'=>false))
|
64
62
|
SpecModel::Basic.find("_PID_").should be_a SpecModel::Basic
|
65
63
|
end
|
66
64
|
it "should raise an exception if it is not found" do
|
67
|
-
Rubydora::Repository.any_instance.
|
68
|
-
SpecModel::Basic.
|
65
|
+
Rubydora::Repository.any_instance.should_receive(:object).and_raise(RestClient::ResourceNotFound)
|
66
|
+
SpecModel::Basic.should_receive(:connection_for_pid).with("_PID_")
|
69
67
|
lambda {SpecModel::Basic.find("_PID_")}.should raise_error ActiveFedora::ObjectNotFoundError
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
73
71
|
describe "with :cast" do
|
74
72
|
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
75
|
-
SpecModel::Basic.any_instance.
|
76
|
-
ActiveFedora::DigitalObject.
|
73
|
+
SpecModel::Basic.any_instance.should_receive(:init_with).and_return(mock("Model", :adapt_to_cmodel=>SpecModel::Basic.new ))
|
74
|
+
ActiveFedora::DigitalObject.should_receive(:find).and_return(stub("inner obj", :'new?'=>false))
|
77
75
|
SpecModel::Basic.find("_PID_", :cast=>true)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
describe "with conditions" do
|
82
80
|
it "should filter by the provided fields" do
|
83
|
-
SpecModel::Basic.
|
84
|
-
SpecModel::Basic.
|
81
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:30", nil).and_return("Fake Object1")
|
82
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:22", nil).and_return("Fake Object2")
|
85
83
|
|
86
|
-
mock_docs =
|
87
|
-
mock_docs.
|
88
|
-
|
89
|
-
ActiveFedora::SolrService.instance.conn.expects(:paginate).with() { |page, rows, method, hash|
|
84
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
85
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
86
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
90
87
|
page == 1 &&
|
91
88
|
rows == 1000 &&
|
92
89
|
method == 'select' &&
|
@@ -97,7 +94,7 @@ describe ActiveFedora::Model do
|
|
97
94
|
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
98
95
|
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
99
96
|
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
100
|
-
}.
|
97
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
101
98
|
SpecModel::Basic.find({:foo=>'bar', :baz=>['quix','quack']}).should == ["Fake Object1", "Fake Object2"]
|
102
99
|
end
|
103
100
|
end
|
@@ -105,33 +102,31 @@ describe ActiveFedora::Model do
|
|
105
102
|
|
106
103
|
describe '#all' do
|
107
104
|
it "should pass everything through to .find" do
|
108
|
-
SpecModel::Basic.
|
105
|
+
SpecModel::Basic.should_receive(:find).with(:all, {})
|
109
106
|
SpecModel::Basic.all
|
110
107
|
end
|
111
108
|
end
|
112
109
|
|
113
110
|
describe '#find_each' do
|
114
111
|
it "should query solr for all objects with :active_fedora_model_s of self.class" do
|
115
|
-
mock_docs =
|
116
|
-
mock_docs.
|
117
|
-
|
118
|
-
ActiveFedora::SolrService.instance.conn.expects(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).returns('response'=>{'docs'=>mock_docs})
|
112
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
113
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
114
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with(1, 1000, 'select', :params=>{:q=>@model_query, :qt => 'standard', :sort => ['system_create_dt asc'], :fl=> 'id', }).and_return('response'=>{'docs'=>mock_docs})
|
119
115
|
|
120
|
-
SpecModel::Basic.
|
121
|
-
SpecModel::Basic.
|
116
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:30", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:30'))
|
117
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:22", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:22'))
|
122
118
|
yielded = mock("yielded method")
|
123
|
-
yielded.
|
119
|
+
yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
124
120
|
SpecModel::Basic.find_each(){|obj| yielded.run(obj) }
|
125
121
|
end
|
126
122
|
describe "with conditions" do
|
127
123
|
it "should filter by the provided fields" do
|
128
|
-
SpecModel::Basic.
|
129
|
-
SpecModel::Basic.
|
124
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:30", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:30'))
|
125
|
+
SpecModel::Basic.should_receive(:find_one).with("changeme:22", nil).and_return(SpecModel::Basic.new(:pid=>'changeme:22'))
|
130
126
|
|
131
|
-
mock_docs =
|
132
|
-
mock_docs.
|
133
|
-
|
134
|
-
ActiveFedora::SolrService.instance.conn.expects(:paginate).with() { |page, rows, method, hash|
|
127
|
+
mock_docs = [{"id" => "changeme:30"},{"id" => "changeme:22"}]
|
128
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
129
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
135
130
|
page == 1 &&
|
136
131
|
rows == 1000 &&
|
137
132
|
method == 'select' &&
|
@@ -142,9 +137,9 @@ describe ActiveFedora::Model do
|
|
142
137
|
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
143
138
|
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
144
139
|
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
145
|
-
}.
|
140
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
146
141
|
yielded = mock("yielded method")
|
147
|
-
yielded.
|
142
|
+
yielded.should_receive(:run).with { |obj| obj.class == SpecModel::Basic}.twice
|
148
143
|
SpecModel::Basic.find_each({:foo=>'bar', :baz=>['quix','quack']}){|obj| yielded.run(obj) }
|
149
144
|
end
|
150
145
|
end
|
@@ -154,8 +149,8 @@ describe ActiveFedora::Model do
|
|
154
149
|
describe "with conditions hash" do
|
155
150
|
it "should filter by the provided fields" do
|
156
151
|
mock_docs = mock('docs')
|
157
|
-
mock_docs.
|
158
|
-
ActiveFedora::SolrService.instance.conn.
|
152
|
+
mock_docs.should_receive(:has_next?).and_return(false)
|
153
|
+
ActiveFedora::SolrService.instance.conn.should_receive(:paginate).with() { |page, rows, method, hash|
|
159
154
|
page == 1 &&
|
160
155
|
rows == 1002 &&
|
161
156
|
method == 'select' &&
|
@@ -166,9 +161,9 @@ describe ActiveFedora::Model do
|
|
166
161
|
hash[:params][:q].split(" AND ").include?("foo:\"bar\"") &&
|
167
162
|
hash[:params][:q].split(" AND ").include?("baz:\"quix\"") &&
|
168
163
|
hash[:params][:q].split(" AND ").include?("baz:\"quack\"")
|
169
|
-
}.
|
164
|
+
}.and_return('response'=>{'docs'=>mock_docs})
|
170
165
|
yielded = mock("yielded method")
|
171
|
-
yielded.
|
166
|
+
yielded.should_receive(:run).with(mock_docs)
|
172
167
|
SpecModel::Basic.find_in_batches({:foo=>'bar', :baz=>['quix','quack']}, {:batch_size=>1002, :fl=>'id'}){|group| yielded.run group }.should
|
173
168
|
end
|
174
169
|
end
|
@@ -178,18 +173,18 @@ describe ActiveFedora::Model do
|
|
178
173
|
|
179
174
|
it "should return a count" do
|
180
175
|
mock_result = {'response'=>{'numFound'=>7}}
|
181
|
-
ActiveFedora::SolrService.
|
176
|
+
ActiveFedora::SolrService.should_receive(:query).with(@model_query, :rows=>0, :raw=>true).and_return(mock_result)
|
182
177
|
SpecModel::Basic.count.should == 7
|
183
178
|
end
|
184
179
|
it "should allow conditions" do
|
185
180
|
mock_result = {'response'=>{'numFound'=>7}}
|
186
|
-
ActiveFedora::SolrService.
|
181
|
+
ActiveFedora::SolrService.should_receive(:query).with("#{@model_query} AND foo:bar", :rows=>0, :raw=>true).and_return(mock_result)
|
187
182
|
SpecModel::Basic.count(:conditions=>'foo:bar').should == 7
|
188
183
|
end
|
189
184
|
|
190
185
|
it "should count without a class specified" do
|
191
186
|
mock_result = {'response'=>{'numFound'=>7}}
|
192
|
-
ActiveFedora::SolrService.
|
187
|
+
ActiveFedora::SolrService.should_receive(:query).with("foo:bar", :rows=>0, :raw=>true).and_return(mock_result)
|
193
188
|
ActiveFedora::Base.count(:conditions=>'foo:bar').should == 7
|
194
189
|
end
|
195
190
|
end
|
@@ -197,20 +192,20 @@ describe ActiveFedora::Model do
|
|
197
192
|
describe '#find_with_conditions' do
|
198
193
|
it "should make a query to solr and return the results" do
|
199
194
|
mock_result = stub('Result')
|
200
|
-
ActiveFedora::SolrService.
|
195
|
+
ActiveFedora::SolrService.should_receive(:query).with() { |args|
|
201
196
|
q = args.first if args.is_a? Array
|
202
197
|
q ||= args
|
203
198
|
q.split(" AND ").include?(@model_query) &&
|
204
199
|
q.split(" AND ").include?("foo:\"bar\"") &&
|
205
200
|
q.split(" AND ").include?("baz:\"quix\"") &&
|
206
201
|
q.split(" AND ").include?("baz:\"quack\"")
|
207
|
-
}.
|
202
|
+
}.and_return(mock_result)
|
208
203
|
SpecModel::Basic.find_with_conditions(:foo=>'bar', :baz=>['quix','quack']).should == mock_result
|
209
204
|
end
|
210
205
|
|
211
206
|
it "should escape quotes" do
|
212
207
|
mock_result = stub('Result')
|
213
|
-
ActiveFedora::SolrService.
|
208
|
+
ActiveFedora::SolrService.should_receive(:query).with() { |args|
|
214
209
|
q = args.first if args.is_a? Array
|
215
210
|
q ||= args
|
216
211
|
q.split(" AND ").include?(@model_query) &&
|
@@ -218,18 +213,18 @@ describe ActiveFedora::Model do
|
|
218
213
|
q.split(" AND ").include?('foo:"9\\" Nails"') &&
|
219
214
|
q.split(" AND ").include?('baz:"7\\" version"') &&
|
220
215
|
q.split(" AND ").include?('baz:"quack"')
|
221
|
-
}.
|
216
|
+
}.and_return(mock_result)
|
222
217
|
SpecModel::Basic.find_with_conditions(:foo=>'9" Nails', :baz=>['7" version','quack']).should == mock_result
|
223
218
|
end
|
224
219
|
|
225
220
|
it "shouldn't use the class if it's called on AF:Base " do
|
226
221
|
mock_result = stub('Result')
|
227
|
-
ActiveFedora::SolrService.
|
222
|
+
ActiveFedora::SolrService.should_receive(:query).with('baz:"quack"', {:sort => ['system_create_dt asc']}).and_return(mock_result)
|
228
223
|
ActiveFedora::Base.find_with_conditions(:baz=>'quack').should == mock_result
|
229
224
|
end
|
230
225
|
it "should use the query string if it's provided" do
|
231
226
|
mock_result = stub('Result')
|
232
|
-
ActiveFedora::SolrService.
|
227
|
+
ActiveFedora::SolrService.should_receive(:query).with('chunky:monkey', {:sort => ['system_create_dt asc']}).and_return(mock_result)
|
233
228
|
ActiveFedora::Base.find_with_conditions('chunky:monkey').should == mock_result
|
234
229
|
end
|
235
230
|
end
|
@@ -253,13 +248,13 @@ describe ActiveFedora::Model do
|
|
253
248
|
|
254
249
|
context "with the namespace declared in the model" do
|
255
250
|
before do
|
256
|
-
subject.
|
251
|
+
subject.stub(:pid_namespace).and_return("test-cModel")
|
257
252
|
end
|
258
253
|
its(:to_class_uri) {should == 'info:fedora/test-cModel:SpecModel_CamelCased' }
|
259
254
|
end
|
260
255
|
context "with the suffix declared in the model" do
|
261
256
|
before do
|
262
|
-
subject.
|
257
|
+
subject.stub(:pid_suffix).and_return("-TEST-SUFFIX")
|
263
258
|
end
|
264
259
|
its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
|
265
260
|
end
|