active-fedora 4.0.0.rc10 → 4.0.0.rc11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/History.txt +1 -1
- data/lib/active_fedora/file_configurator.rb +17 -5
- data/lib/active_fedora/version.rb +1 -1
- data/spec/unit/file_configurator_spec.rb +99 -66
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/History.txt
CHANGED
@@ -44,23 +44,33 @@ module ActiveFedora
|
|
44
44
|
# url: http://127.0.0.1:8983/fedora2
|
45
45
|
#
|
46
46
|
|
47
|
-
attr_accessor :solr_config, :
|
47
|
+
attr_accessor :solr_config, :config_env
|
48
48
|
attr_reader :config_options, :fedora_config_path, :solr_config_path
|
49
49
|
|
50
50
|
# The configuration hash that gets used by RSolr.connect
|
51
|
-
@solr_config ||= {}
|
52
|
-
@fedora_config ||= {}
|
53
|
-
@config_options ||= {}
|
51
|
+
# @solr_config ||= {}
|
52
|
+
# @fedora_config ||= {}
|
53
|
+
# @config_options ||= {}
|
54
|
+
def initialize
|
55
|
+
reset!
|
56
|
+
end
|
54
57
|
|
55
58
|
def init options = {}
|
56
59
|
if options.is_a?(String)
|
57
60
|
raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})"
|
58
61
|
end
|
62
|
+
reset!
|
59
63
|
@config_options = options
|
60
|
-
|
64
|
+
load_configs
|
65
|
+
end
|
66
|
+
|
67
|
+
def fedora_config
|
68
|
+
load_configs
|
69
|
+
@fedora_config
|
61
70
|
end
|
62
71
|
|
63
72
|
def config_reload!
|
73
|
+
ActiveSupport::Deprecation.warn("config_reload! is not supported")
|
64
74
|
reset!
|
65
75
|
load_configs
|
66
76
|
end
|
@@ -71,6 +81,8 @@ module ActiveFedora
|
|
71
81
|
|
72
82
|
def reset!
|
73
83
|
@config_loaded = false #Force reload of configs
|
84
|
+
@fedora_config = {}
|
85
|
+
@config_options = {}
|
74
86
|
@predicate_config_path = nil
|
75
87
|
end
|
76
88
|
|
@@ -3,9 +3,7 @@ require 'config_helper'
|
|
3
3
|
|
4
4
|
describe ActiveFedora::FileConfigurator do
|
5
5
|
|
6
|
-
|
7
|
-
@configurator = ActiveFedora.configurator
|
8
|
-
end
|
6
|
+
subject {ActiveFedora.configurator }
|
9
7
|
|
10
8
|
after :all do
|
11
9
|
unstub_rails
|
@@ -13,58 +11,93 @@ describe ActiveFedora::FileConfigurator do
|
|
13
11
|
restore_spec_configuration
|
14
12
|
end
|
15
13
|
|
14
|
+
describe "#initialize" do
|
15
|
+
it "should trigger configuration reset (to empty defaults)" do
|
16
|
+
ActiveFedora::FileConfigurator.any_instance.expects(:reset!)
|
17
|
+
ActiveFedora::FileConfigurator.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#config_options" do
|
22
|
+
before do
|
23
|
+
subject.reset!
|
24
|
+
end
|
25
|
+
it "should be an empty hash" do
|
26
|
+
subject.config_options.should == {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#fedora_config" do
|
31
|
+
before do
|
32
|
+
subject.reset!
|
33
|
+
end
|
34
|
+
it "should trigger configuration to load" do
|
35
|
+
subject.fedora_config.should == {"url"=>"http://127.0.0.1:8983/fedora-test", "password"=>"fedoraAdmin", "user"=>"fedoraAdmin"}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#reset!" do
|
40
|
+
before { subject.reset! }
|
41
|
+
it "should clear @fedora_config" do
|
42
|
+
subject.instance_variable_get(:@fedora_config).should == {}
|
43
|
+
end
|
44
|
+
it "should clear @config_options" do
|
45
|
+
subject.instance_variable_get(:@config_options).should == {}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
16
49
|
describe "initialization methods" do
|
17
50
|
|
18
51
|
describe "get_config_path(:fedora)" do
|
19
52
|
it "should use the config_options[:config_path] if it exists" do
|
20
|
-
|
53
|
+
subject.expects(:config_options).at_least_once.returns({:fedora_config_path => "/path/to/fedora.yml"})
|
21
54
|
File.expects(:file?).with("/path/to/fedora.yml").returns(true)
|
22
|
-
|
55
|
+
subject.get_config_path(:fedora).should eql("/path/to/fedora.yml")
|
23
56
|
end
|
24
57
|
|
25
58
|
it "should look in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
|
26
|
-
|
59
|
+
subject.expects(:config_options).at_least_once.returns({})
|
27
60
|
stub_rails(:root => "/rails/root")
|
28
61
|
File.expects(:file?).with("/rails/root/config/fedora.yml").returns(true)
|
29
|
-
|
62
|
+
subject.get_config_path(:fedora).should eql("/rails/root/config/fedora.yml")
|
30
63
|
unstub_rails
|
31
64
|
end
|
32
65
|
|
33
66
|
it "should look in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
|
34
|
-
|
67
|
+
subject.expects(:config_options).at_least_once.returns({})
|
35
68
|
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
36
69
|
File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(true)
|
37
|
-
|
70
|
+
subject.get_config_path(:fedora).should eql("/current/working/directory/config/fedora.yml")
|
38
71
|
end
|
39
72
|
|
40
73
|
it "should return default fedora.yml that ships with active-fedora if none of the above" do
|
41
|
-
|
74
|
+
subject.expects(:config_options).at_least_once.returns({})
|
42
75
|
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
43
76
|
File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(false)
|
44
77
|
File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml'))).returns(true)
|
45
78
|
logger.expects(: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.")
|
46
|
-
|
79
|
+
subject.get_config_path(:fedora).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml')))
|
47
80
|
end
|
48
81
|
end
|
49
82
|
|
50
83
|
describe "get_config_path(:solr)" do
|
51
84
|
it "should return the solr_config_path if set in config_options hash" do
|
52
|
-
|
85
|
+
subject.expects(:config_options).at_least_once.returns({:solr_config_path => "/path/to/solr.yml"})
|
53
86
|
File.expects(:file?).with("/path/to/solr.yml").returns(true)
|
54
|
-
|
87
|
+
subject.get_config_path(:solr).should eql("/path/to/solr.yml")
|
55
88
|
end
|
56
89
|
|
57
90
|
it "should return the solr.yml file in the same directory as the fedora.yml if it exists" do
|
58
|
-
|
91
|
+
subject.expects(:path).returns("/path/to/fedora/config/fedora.yml")
|
59
92
|
File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(true)
|
60
|
-
|
93
|
+
subject.get_config_path(:solr).should eql("/path/to/fedora/config/solr.yml")
|
61
94
|
end
|
62
95
|
|
63
96
|
context "no solr.yml in same directory as fedora.yml and fedora.yml does not contain solr url" do
|
64
97
|
|
65
98
|
before :each do
|
66
|
-
|
67
|
-
|
99
|
+
subject.expects(:config_options).at_least_once.returns({})
|
100
|
+
subject.expects(:path).returns("/path/to/fedora/config/fedora.yml")
|
68
101
|
File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(false)
|
69
102
|
end
|
70
103
|
after :each do
|
@@ -74,13 +107,13 @@ describe ActiveFedora::FileConfigurator do
|
|
74
107
|
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
|
75
108
|
stub_rails(:root=>"/rails/root")
|
76
109
|
File.expects(:file?).with("/rails/root/config/solr.yml").returns(true)
|
77
|
-
|
110
|
+
subject.get_config_path(:solr).should eql("/rails/root/config/solr.yml")
|
78
111
|
end
|
79
112
|
|
80
113
|
it "should look in ./config/solr.yml if no rails root" do
|
81
114
|
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
82
115
|
File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(true)
|
83
|
-
|
116
|
+
subject.get_config_path(:solr).should eql("/current/working/directory/config/solr.yml")
|
84
117
|
end
|
85
118
|
|
86
119
|
it "should return the default solr.yml file that ships with active-fedora if no other option is set" do
|
@@ -88,7 +121,7 @@ describe ActiveFedora::FileConfigurator do
|
|
88
121
|
File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(false)
|
89
122
|
File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml'))).returns(true)
|
90
123
|
logger.expects(: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.")
|
91
|
-
|
124
|
+
subject.get_config_path(:solr).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml')))
|
92
125
|
end
|
93
126
|
end
|
94
127
|
|
@@ -97,61 +130,61 @@ describe ActiveFedora::FileConfigurator do
|
|
97
130
|
describe "#determine url" do
|
98
131
|
it "should support config['environment']['url'] if config_type is fedora" do
|
99
132
|
config = {:test=> {:url=>"http://fedoraAdmin:fedorAdmin@localhost:8983/fedora"}}
|
100
|
-
|
133
|
+
subject.determine_url("fedora",config).should eql("http://localhost:8983/fedora")
|
101
134
|
end
|
102
135
|
|
103
136
|
it "should call #get_solr_url to determine the solr url if config_type is solr" do
|
104
137
|
config = {:test=>{:default => "http://default.solr:8983"}}
|
105
|
-
|
106
|
-
|
138
|
+
subject.expects(:get_solr_url).with(config[:test]).returns("http://default.solr:8983")
|
139
|
+
subject.determine_url("solr",config).should eql("http://default.solr:8983")
|
107
140
|
end
|
108
141
|
end
|
109
142
|
|
110
143
|
describe "load_config" do
|
111
144
|
it "should load the file specified in solr_config_path" do
|
112
|
-
|
145
|
+
subject.expects(:solr_config_path).returns("/path/to/solr.yml")
|
113
146
|
File.expects(:open).with("/path/to/solr.yml").returns("development:\n default:\n url: http://devsolr:8983\ntest:\n default:\n url: http://mysolr:8080")
|
114
|
-
|
115
|
-
|
147
|
+
subject.load_config(:solr).should eql({:url=>"http://mysolr:8080",:development=>{"default"=>{"url"=>"http://devsolr:8983"}}, :test=>{:default=>{"url"=>"http://mysolr:8080"}}})
|
148
|
+
subject.solr_config.should eql({:url=>"http://mysolr:8080",:development=>{"default"=>{"url"=>"http://devsolr:8983"}}, :test=>{:default=>{"url"=>"http://mysolr:8080"}}})
|
116
149
|
end
|
117
150
|
end
|
118
151
|
|
119
152
|
describe "load_configs" do
|
120
153
|
describe "when config is not loaded" do
|
121
154
|
before do
|
122
|
-
|
155
|
+
subject.instance_variable_set :@config_loaded, nil
|
123
156
|
end
|
124
157
|
it "should load the fedora and solr configs" do
|
125
158
|
#ActiveFedora.expects(:load_config).with(:fedora)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
159
|
+
subject.expects(:load_config).with(:solr)
|
160
|
+
subject.config_loaded?.should be_false
|
161
|
+
subject.load_configs
|
162
|
+
subject.config_loaded?.should be_true
|
130
163
|
end
|
131
164
|
end
|
132
165
|
describe "when config is loaded" do
|
133
166
|
before do
|
134
|
-
|
167
|
+
subject.instance_variable_set :@config_loaded, true
|
135
168
|
end
|
136
169
|
it "should load the fedora and solr configs" do
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
170
|
+
subject.expects(:load_config).never
|
171
|
+
subject.config_loaded?.should be_true
|
172
|
+
subject.load_configs
|
173
|
+
subject.config_loaded?.should be_true
|
141
174
|
end
|
142
175
|
end
|
143
176
|
end
|
144
177
|
|
145
178
|
describe "check_fedora_path_for_solr" do
|
146
179
|
it "should find the solr.yml file and return it if it exists" do
|
147
|
-
|
180
|
+
subject.expects(:path).returns("/path/to/fedora/fedora.yml")
|
148
181
|
File.expects(:file?).with("/path/to/fedora/solr.yml").returns(true)
|
149
|
-
|
182
|
+
subject.check_fedora_path_for_solr.should == "/path/to/fedora/solr.yml"
|
150
183
|
end
|
151
184
|
it "should return nil if the solr.yml file is not there" do
|
152
|
-
|
185
|
+
subject.expects(:path).returns("/path/to/fedora/fedora.yml")
|
153
186
|
File.expects(:file?).with("/path/to/fedora/solr.yml").returns(false)
|
154
|
-
|
187
|
+
subject.check_fedora_path_for_solr.should be_nil
|
155
188
|
end
|
156
189
|
end
|
157
190
|
end
|
@@ -170,28 +203,28 @@ describe ActiveFedora::FileConfigurator do
|
|
170
203
|
end
|
171
204
|
|
172
205
|
it "can tell its config paths" do
|
173
|
-
|
174
|
-
|
206
|
+
subject.init
|
207
|
+
subject.should respond_to(:solr_config_path)
|
175
208
|
end
|
176
209
|
it "loads a config from the current working directory as a second choice" do
|
177
210
|
Dir.stubs(:getwd).returns(@fake_rails_root)
|
178
|
-
|
179
|
-
|
180
|
-
|
211
|
+
subject.init
|
212
|
+
subject.get_config_path(:fedora).should eql("#{@fake_rails_root}/config/fedora.yml")
|
213
|
+
subject.solr_config_path.should eql("#{@fake_rails_root}/config/solr.yml")
|
181
214
|
end
|
182
215
|
it "loads the config that ships with this gem as a last choice" do
|
183
216
|
Dir.stubs(:getwd).returns("/fake/path")
|
184
217
|
logger.expects(: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.").times(3)
|
185
|
-
|
218
|
+
subject.init
|
186
219
|
expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
|
187
|
-
|
188
|
-
|
220
|
+
subject.get_config_path(:fedora).should eql(expected_config+'/fedora.yml')
|
221
|
+
subject.solr_config_path.should eql(expected_config+'/solr.yml')
|
189
222
|
end
|
190
223
|
it "raises an error if you pass in a string" do
|
191
|
-
lambda{
|
224
|
+
lambda{ subject.init("#{@fake_rails_root}/config/fake_fedora.yml") }.should raise_exception(ArgumentError)
|
192
225
|
end
|
193
226
|
it "raises an error if you pass in a non-existant config file" do
|
194
|
-
lambda{
|
227
|
+
lambda{ subject.init(:fedora_config_path=>"really_fake_fedora.yml") }.should raise_exception(ActiveFedora::ConfigurationError)
|
195
228
|
end
|
196
229
|
|
197
230
|
describe "within Rails" do
|
@@ -204,14 +237,14 @@ describe ActiveFedora::FileConfigurator do
|
|
204
237
|
end
|
205
238
|
|
206
239
|
it "loads a config from Rails.root as a first choice" do
|
207
|
-
|
208
|
-
|
209
|
-
|
240
|
+
subject.init
|
241
|
+
subject.get_config_path(:fedora).should eql("#{Rails.root}/config/fedora.yml")
|
242
|
+
subject.solr_config_path.should eql("#{Rails.root}/config/solr.yml")
|
210
243
|
end
|
211
244
|
|
212
245
|
it "can tell what environment it is set to run in" do
|
213
246
|
stub_rails(:env=>"development")
|
214
|
-
|
247
|
+
subject.init
|
215
248
|
ActiveFedora.environment.should eql("development")
|
216
249
|
end
|
217
250
|
|
@@ -222,52 +255,52 @@ describe ActiveFedora::FileConfigurator do
|
|
222
255
|
|
223
256
|
describe ".build_predicate_config_path" do
|
224
257
|
it "should return the path to the default config/predicate_mappings.yml if no valid path is given" do
|
225
|
-
|
258
|
+
subject.send(:build_predicate_config_path, nil).should == default_predicate_mapping_file
|
226
259
|
end
|
227
260
|
|
228
261
|
it "should return the path to the default config/predicate_mappings.yml if specified config file not found" do
|
229
262
|
File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(false)
|
230
263
|
File.expects(:exist?).with(default_predicate_mapping_file).returns(true)
|
231
|
-
|
264
|
+
subject.send(:build_predicate_config_path,"/path/to").should == default_predicate_mapping_file
|
232
265
|
end
|
233
266
|
|
234
267
|
it "should return the path to the specified config_path if it exists" do
|
235
268
|
File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(true)
|
236
|
-
|
237
|
-
|
269
|
+
subject.expects(:valid_predicate_mapping?).returns(true)
|
270
|
+
subject.send(:build_predicate_config_path,"/path/to").should == "/path/to/predicate_mappings.yml"
|
238
271
|
end
|
239
272
|
end
|
240
273
|
|
241
274
|
describe ".predicate_config" do
|
242
275
|
before do
|
243
|
-
|
276
|
+
subject.instance_variable_set :@config_loaded, nil
|
244
277
|
end
|
245
278
|
it "should return the default mapping if it has not been initialized" do
|
246
|
-
|
279
|
+
subject.predicate_config().should == YAML.load(File.read(default_predicate_mapping_file))
|
247
280
|
end
|
248
281
|
end
|
249
282
|
|
250
283
|
describe ".valid_predicate_mapping" do
|
251
284
|
it "should return true if the predicate mapping has the appropriate keys and value types" do
|
252
|
-
|
285
|
+
subject.send(:valid_predicate_mapping?,default_predicate_mapping_file).should be_true
|
253
286
|
end
|
254
287
|
it "should return false if the mapping is missing the :default_namespace" do
|
255
288
|
mock_yaml({:default_namespace0=>"my_namespace",:predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
256
|
-
|
289
|
+
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
257
290
|
end
|
258
291
|
it "should return false if the :default_namespace is not a string" do
|
259
292
|
mock_yaml({:default_namespace=>{:foo=>"bar"}, :predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
260
|
-
|
293
|
+
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
261
294
|
end
|
262
295
|
it "should return false if the :predicate_mappings key is missing" do
|
263
296
|
mock_yaml({:default_namespace=>"a string"},"/path/to/predicate_mappings.yml")
|
264
|
-
|
297
|
+
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
265
298
|
end
|
266
299
|
it "should return false if the :predicate_mappings key is not a hash" do
|
267
300
|
mock_yaml({:default_namespace=>"a string",:predicate_mapping=>"another string"},"/path/to/predicate_mappings.yml")
|
268
|
-
|
301
|
+
subject.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
269
302
|
end
|
270
303
|
|
271
304
|
end
|
272
305
|
|
273
|
-
end
|
306
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424131
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 4
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 4.0.0.
|
11
|
+
- 11
|
12
|
+
version: 4.0.0.rc11
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Matt Zumwalt
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2012-03-
|
22
|
+
date: 2012-03-13 00:00:00 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
prerelease: false
|