active-fedora 4.0.0.rc8 → 4.0.0.rc9
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 +3 -2
- data/lib/active_fedora.rb +25 -207
- data/lib/active_fedora/config.rb +4 -6
- data/lib/active_fedora/datastream.rb +0 -4
- data/lib/active_fedora/file_configurator.rb +217 -0
- data/lib/active_fedora/predicates.rb +2 -2
- data/lib/active_fedora/rdf_datastream.rb +11 -6
- data/lib/active_fedora/solr_service.rb +5 -1
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +26 -0
- data/spec/integration/ntriples_datastream_spec.rb +52 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/unit/active_fedora_spec.rb +5 -308
- data/spec/unit/code_configurator_spec.rb +51 -0
- data/spec/unit/config_spec.rb +4 -4
- data/spec/unit/file_configurator_spec.rb +273 -0
- data/spec/unit/solr_service_spec.rb +0 -1
- metadata +11 -6
- data/spec/unit/datastream_concurrency_spec.rb +0 -59
@@ -51,14 +51,14 @@ module ActiveFedora
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.predicate_config= value
|
54
|
-
unless value.is_a?(Hash) and [:predicate_mapping,:default_namespace].all? { |key| value.has_key? key }
|
54
|
+
unless value.nil? or (value.is_a?(Hash) and [:predicate_mapping,:default_namespace].all? { |key| value.has_key? key })
|
55
55
|
raise TypeError, "predicate_config must specify :predicate_mapping and :default_namespace"
|
56
56
|
end
|
57
57
|
@@predicate_config = value
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.predicate_config
|
61
|
-
@@predicate_config ||=
|
61
|
+
@@predicate_config ||= ActiveFedora.predicate_config
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.predicate_namespaces
|
@@ -18,7 +18,7 @@ module ActiveFedora
|
|
18
18
|
raise "not an RDF vocabulary: #{v}"
|
19
19
|
end
|
20
20
|
end
|
21
|
-
ActiveFedora::Predicates.vocabularies(vocabularies)
|
21
|
+
ActiveFedora::Predicates.vocabularies(@vocabularies)
|
22
22
|
@vocabularies
|
23
23
|
end
|
24
24
|
def map_predicates(&block)
|
@@ -56,6 +56,7 @@ module ActiveFedora
|
|
56
56
|
class TermProxy
|
57
57
|
# @param [Symbol, RDF::URI] predicate the predicate to insert into the graph
|
58
58
|
# @param [ActiveFedora::RelationshipGraph] graph the graph
|
59
|
+
# @param [Array] values an array of object values
|
59
60
|
include Enumerable
|
60
61
|
def initialize(graph, predicate, values=[])
|
61
62
|
@graph = graph
|
@@ -63,7 +64,7 @@ module ActiveFedora
|
|
63
64
|
@values = values
|
64
65
|
end
|
65
66
|
def each(&block)
|
66
|
-
@values.each { |value| block.call(value)}
|
67
|
+
@values.each { |value| block.call(value) }
|
67
68
|
end
|
68
69
|
def <<(*values)
|
69
70
|
@values.concat(values)
|
@@ -72,16 +73,20 @@ module ActiveFedora
|
|
72
73
|
@values
|
73
74
|
end
|
74
75
|
def ==(other)
|
75
|
-
other
|
76
|
+
other == @values
|
76
77
|
end
|
77
78
|
def delete(*values)
|
78
79
|
values.each do |value|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
unless @values.delete(value).nil?
|
81
|
+
@graph.delete(@predicate, value)
|
82
|
+
@graph.dirty = true
|
83
|
+
end
|
82
84
|
end
|
83
85
|
@values
|
84
86
|
end
|
87
|
+
def empty?
|
88
|
+
@values.empty?
|
89
|
+
end
|
85
90
|
end
|
86
91
|
|
87
92
|
include ModelMethods
|
@@ -13,8 +13,12 @@ module ActiveFedora
|
|
13
13
|
|
14
14
|
def self.register(host=nil, args={})
|
15
15
|
Thread.current[:solr_service]=self.new(host, args)
|
16
|
+
end
|
16
17
|
|
18
|
+
def self.reset!
|
19
|
+
Thread.current[:solr_service] = nil
|
17
20
|
end
|
21
|
+
|
18
22
|
def initialize(host, args)
|
19
23
|
host = 'http://localhost:8080/solr' unless host
|
20
24
|
args = args.dup
|
@@ -27,9 +31,9 @@ module ActiveFedora
|
|
27
31
|
# Register Solr
|
28
32
|
|
29
33
|
unless Thread.current[:solr_service]
|
30
|
-
ActiveFedora.load_configs
|
31
34
|
register(ActiveFedora.solr_config[:url])
|
32
35
|
end
|
36
|
+
|
33
37
|
raise SolrNotInitialized unless Thread.current[:solr_service]
|
34
38
|
Thread.current[:solr_service]
|
35
39
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
def mock_yaml(hash, path)
|
2
|
+
mock_file = mock(path.split("/")[-1])
|
3
|
+
File.stubs(:exist?).with(path).returns(true)
|
4
|
+
File.expects(:open).with(path).returns(mock_file)
|
5
|
+
YAML.expects(:load).returns(hash)
|
6
|
+
end
|
7
|
+
|
8
|
+
def default_predicate_mapping_file
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__),"..","config","predicate_mappings.yml"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_rails(opts={})
|
13
|
+
Object.const_set("Rails",Class)
|
14
|
+
Rails.send(:undef_method,:env) if Rails.respond_to?(:env)
|
15
|
+
Rails.send(:undef_method,:root) if Rails.respond_to?(:root)
|
16
|
+
opts.each { |k,v| Rails.send(:define_method,k){ return v } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def unstub_rails
|
20
|
+
Object.send(:remove_const,:Rails) if defined?(Rails)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_pretest_env
|
24
|
+
ENV['RAILS_ENV']='test'
|
25
|
+
ENV['environment']='test'
|
26
|
+
end
|
@@ -78,4 +78,56 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
78
78
|
@subject.title.should be_nil
|
79
79
|
@subject.related_url.should == ["http://psu.edu/"]
|
80
80
|
end
|
81
|
+
it "should delete multiple values at once" do
|
82
|
+
@subject.part = "MacBeth"
|
83
|
+
@subject.part << "Hamlet"
|
84
|
+
@subject.part << "Romeo & Juliet"
|
85
|
+
@subject.part.first.should == "MacBeth"
|
86
|
+
@subject.part.delete("MacBeth", "Romeo & Juliet")
|
87
|
+
@subject.part.should == ["Hamlet"]
|
88
|
+
@subject.part.first.should == "Hamlet"
|
89
|
+
end
|
90
|
+
it "should ignore values to be deleted that do not exist" do
|
91
|
+
@subject.part = ["title1", "title2", "title3"]
|
92
|
+
@subject.part.delete("title2", "title4", "title6")
|
93
|
+
@subject.part.should == ["title1", "title3"]
|
94
|
+
end
|
95
|
+
describe "term proxy methods" do
|
96
|
+
before(:each) do
|
97
|
+
class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
|
98
|
+
register_vocabularies RDF::DC
|
99
|
+
map_predicates { |map| map.title(:in => RDF::DC) }
|
100
|
+
end
|
101
|
+
class Foobar < ActiveFedora::Base
|
102
|
+
has_metadata :name=>'rdf', :type=>TitleDatastream
|
103
|
+
delegate :title, :to=>'rdf'
|
104
|
+
end
|
105
|
+
@subject = Foobar.new
|
106
|
+
@subject.title = ["title1", "title2", "title3"]
|
107
|
+
end
|
108
|
+
|
109
|
+
after(:each) do
|
110
|
+
Object.send(:remove_const, :Foobar)
|
111
|
+
Object.send(:remove_const, :TitleDatastream)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should support the count method to determine # of values" do
|
115
|
+
@subject.title.count.should == 3
|
116
|
+
end
|
117
|
+
it "should iterate over multiple values" do
|
118
|
+
@subject.title.should respond_to(:each)
|
119
|
+
end
|
120
|
+
it "should get the first value" do
|
121
|
+
@subject.title.first.should == "title1"
|
122
|
+
end
|
123
|
+
it "should evaluate equality predictably" do
|
124
|
+
@subject.title.should == ["title1", "title2", "title3"]
|
125
|
+
end
|
126
|
+
it "should support the empty? method" do
|
127
|
+
@subject.title.should respond_to(:empty?)
|
128
|
+
@subject.title.empty?.should be_false
|
129
|
+
@subject.title.delete("title1", "title2", "title3")
|
130
|
+
@subject.title.empty?.should be_true
|
131
|
+
end
|
132
|
+
end
|
81
133
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,10 @@ $VERBOSE=nil
|
|
13
13
|
|
14
14
|
# This loads the Fedora and Solr config info from /config/fedora.yml
|
15
15
|
# You can load it from a different location by passing a file path as an argument.
|
16
|
-
|
16
|
+
def restore_spec_configuration
|
17
|
+
ActiveFedora.init(:fedora_config_path=>File.join(File.dirname(__FILE__), "..", "config", "fedora.yml"))
|
18
|
+
end
|
19
|
+
restore_spec_configuration
|
17
20
|
|
18
21
|
RSpec.configure do |config|
|
19
22
|
config.mock_with :mocha
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'config_helper'
|
2
3
|
|
3
4
|
# For testing Module-level methods like ActiveFedora.init
|
4
5
|
|
@@ -7,13 +8,10 @@ describe ActiveFedora do
|
|
7
8
|
after :all do
|
8
9
|
unstub_rails
|
9
10
|
# Restore to default fedora configs
|
10
|
-
|
11
|
-
ActiveFedora.init(:environment=>"test", :fedora_config_path=>fedora_config_path)
|
11
|
+
restore_spec_configuration
|
12
12
|
end
|
13
|
-
|
14
|
-
|
13
|
+
|
15
14
|
describe "initialization methods" do
|
16
|
-
|
17
15
|
describe "environment" do
|
18
16
|
it "should use config_options[:environment] if set" do
|
19
17
|
ActiveFedora.expects(:config_options).at_least_once.returns(:environment=>"ballyhoo")
|
@@ -51,279 +49,8 @@ describe ActiveFedora do
|
|
51
49
|
ENV['environment']="test"
|
52
50
|
end
|
53
51
|
end
|
54
|
-
|
55
|
-
describe "get_config_path(:fedora)" do
|
56
|
-
it "should use the config_options[:config_path] if it exists" do
|
57
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({:fedora_config_path => "/path/to/fedora.yml"})
|
58
|
-
File.expects(:file?).with("/path/to/fedora.yml").returns(true)
|
59
|
-
ActiveFedora.get_config_path(:fedora).should eql("/path/to/fedora.yml")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should look in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
|
63
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({})
|
64
|
-
stub_rails(:root => "/rails/root")
|
65
|
-
File.expects(:file?).with("/rails/root/config/fedora.yml").returns(true)
|
66
|
-
ActiveFedora.get_config_path(:fedora).should eql("/rails/root/config/fedora.yml")
|
67
|
-
unstub_rails
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should look in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
|
71
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({})
|
72
|
-
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
73
|
-
File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(true)
|
74
|
-
ActiveFedora.get_config_path(:fedora).should eql("/current/working/directory/config/fedora.yml")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should return default fedora.yml that ships with active-fedora if none of the above" do
|
78
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({})
|
79
|
-
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
80
|
-
File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(false)
|
81
|
-
File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml'))).returns(true)
|
82
|
-
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.")
|
83
|
-
ActiveFedora.get_config_path(:fedora).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml')))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "get_config_path(:solr)" do
|
88
|
-
it "should return the solr_config_path if set in config_options hash" do
|
89
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({:solr_config_path => "/path/to/solr.yml"})
|
90
|
-
File.expects(:file?).with("/path/to/solr.yml").returns(true)
|
91
|
-
ActiveFedora.get_config_path(:solr).should eql("/path/to/solr.yml")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should return the solr.yml file in the same directory as the fedora.yml if it exists" do
|
95
|
-
ActiveFedora::Config.any_instance.expects(:path).returns("/path/to/fedora/config/fedora.yml")
|
96
|
-
File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(true)
|
97
|
-
ActiveFedora.get_config_path(:solr).should eql("/path/to/fedora/config/solr.yml")
|
98
|
-
end
|
99
|
-
|
100
|
-
context "no solr.yml in same directory as fedora.yml and fedora.yml does not contain solr url" do
|
101
|
-
|
102
|
-
before :each do
|
103
|
-
ActiveFedora.expects(:config_options).at_least_once.returns({})
|
104
|
-
ActiveFedora::Config.any_instance.expects(:path).returns("/path/to/fedora/config/fedora.yml")
|
105
|
-
File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(false)
|
106
|
-
end
|
107
|
-
after :each do
|
108
|
-
unstub_rails
|
109
|
-
end
|
110
|
-
|
111
|
-
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
|
112
|
-
stub_rails(:root=>"/rails/root")
|
113
|
-
File.expects(:file?).with("/rails/root/config/solr.yml").returns(true)
|
114
|
-
ActiveFedora.get_config_path(:solr).should eql("/rails/root/config/solr.yml")
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should look in ./config/solr.yml if no rails root" do
|
118
|
-
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
119
|
-
File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(true)
|
120
|
-
ActiveFedora.get_config_path(:solr).should eql("/current/working/directory/config/solr.yml")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should return the default solr.yml file that ships with active-fedora if no other option is set" do
|
124
|
-
Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
|
125
|
-
File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(false)
|
126
|
-
File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml'))).returns(true)
|
127
|
-
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.")
|
128
|
-
ActiveFedora.get_config_path(:solr).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml')))
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
describe "#determine url" do
|
136
|
-
it "should support config['environment']['url'] if config_type is fedora" do
|
137
|
-
config = {:test=> {:url=>"http://fedoraAdmin:fedorAdmin@localhost:8983/fedora"}}
|
138
|
-
ActiveFedora.determine_url("fedora",config).should eql("http://localhost:8983/fedora")
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should call #get_solr_url to determine the solr url if config_type is solr" do
|
142
|
-
config = {:test=>{:default => "http://default.solr:8983"}}
|
143
|
-
ActiveFedora.expects(:get_solr_url).with(config[:test]).returns("http://default.solr:8983")
|
144
|
-
ActiveFedora.determine_url("solr",config).should eql("http://default.solr:8983")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "load_config" do
|
149
|
-
it "should load the file specified in solr_config_path" do
|
150
|
-
ActiveFedora.expects(:solr_config_path).returns("/path/to/solr.yml")
|
151
|
-
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")
|
152
|
-
ActiveFedora.load_config(:solr).should eql({:url=>"http://mysolr:8080",:development=>{"default"=>{"url"=>"http://devsolr:8983"}}, :test=>{:default=>{"url"=>"http://mysolr:8080"}}})
|
153
|
-
ActiveFedora.solr_config.should eql({:url=>"http://mysolr:8080",:development=>{"default"=>{"url"=>"http://devsolr:8983"}}, :test=>{:default=>{"url"=>"http://mysolr:8080"}}})
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "load_configs" do
|
158
|
-
describe "when config is not loaded" do
|
159
|
-
before do
|
160
|
-
ActiveFedora.instance_variable_set :@config_loaded, nil
|
161
|
-
end
|
162
|
-
it "should load the fedora and solr configs" do
|
163
|
-
#ActiveFedora.expects(:load_config).with(:fedora)
|
164
|
-
ActiveFedora.expects(:load_config).with(:solr)
|
165
|
-
ActiveFedora.config_loaded?.should be_false
|
166
|
-
ActiveFedora.load_configs
|
167
|
-
ActiveFedora.config_loaded?.should be_true
|
168
|
-
end
|
169
|
-
end
|
170
|
-
describe "when config is loaded" do
|
171
|
-
before do
|
172
|
-
ActiveFedora.instance_variable_set :@config_loaded, true
|
173
|
-
end
|
174
|
-
it "should load the fedora and solr configs" do
|
175
|
-
ActiveFedora.expects(:load_config).never
|
176
|
-
ActiveFedora.config_loaded?.should be_true
|
177
|
-
ActiveFedora.load_configs
|
178
|
-
ActiveFedora.config_loaded?.should be_true
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "check_fedora_path_for_solr" do
|
184
|
-
it "should find the solr.yml file and return it if it exists" do
|
185
|
-
ActiveFedora::Config.any_instance.expects(:path).returns("/path/to/fedora/fedora.yml")
|
186
|
-
File.expects(:file?).with("/path/to/fedora/solr.yml").returns(true)
|
187
|
-
ActiveFedora.check_fedora_path_for_solr.should == "/path/to/fedora/solr.yml"
|
188
|
-
end
|
189
|
-
it "should return nil if the solr.yml file is not there" do
|
190
|
-
ActiveFedora::Config.any_instance.expects(:path).returns("/path/to/fedora/fedora.yml")
|
191
|
-
File.expects(:file?).with("/path/to/fedora/solr.yml").returns(false)
|
192
|
-
ActiveFedora.check_fedora_path_for_solr.should be_nil
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
###########################
|
200
|
-
|
201
|
-
describe "setting the environment and loading configuration" do
|
202
|
-
|
203
|
-
before(:all) do
|
204
|
-
@fake_rails_root = File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails_root')
|
205
|
-
end
|
206
|
-
|
207
|
-
|
208
|
-
after(:all) do
|
209
|
-
config_file = File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml")
|
210
|
-
environment = "test"
|
211
|
-
ActiveFedora.init(:environment=>environment, :fedora_config_path=>config_file)
|
212
|
-
end
|
213
|
-
|
214
|
-
it "can tell its config paths" do
|
215
|
-
ActiveFedora.init
|
216
|
-
ActiveFedora.should respond_to(:solr_config_path)
|
217
|
-
end
|
218
|
-
it "loads a config from the current working directory as a second choice" do
|
219
|
-
Dir.stubs(:getwd).returns(@fake_rails_root)
|
220
|
-
ActiveFedora.init
|
221
|
-
ActiveFedora.get_config_path(:fedora).should eql("#{@fake_rails_root}/config/fedora.yml")
|
222
|
-
ActiveFedora.solr_config_path.should eql("#{@fake_rails_root}/config/solr.yml")
|
223
|
-
end
|
224
|
-
it "loads the config that ships with this gem as a last choice" do
|
225
|
-
Dir.stubs(:getwd).returns("/fake/path")
|
226
|
-
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.").twice
|
227
|
-
ActiveFedora.init
|
228
|
-
expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
|
229
|
-
ActiveFedora.get_config_path(:fedora).should eql(expected_config+'/fedora.yml')
|
230
|
-
ActiveFedora.solr_config_path.should eql(expected_config+'/solr.yml')
|
231
|
-
end
|
232
|
-
it "raises an error if you pass in a string" do
|
233
|
-
lambda{ ActiveFedora.init("#{@fake_rails_root}/config/fake_fedora.yml") }.should raise_exception(ArgumentError)
|
234
|
-
end
|
235
|
-
it "raises an error if you pass in a non-existant config file" do
|
236
|
-
lambda{ ActiveFedora.init(:fedora_config_path=>"really_fake_fedora.yml") }.should raise_exception(ActiveFedora::ConfigurationError)
|
237
|
-
end
|
238
|
-
|
239
|
-
describe "within Rails" do
|
240
|
-
before(:all) do
|
241
|
-
stub_rails(:root=>File.dirname(__FILE__) + '/../fixtures/rails_root')
|
242
|
-
end
|
243
|
-
|
244
|
-
after(:all) do
|
245
|
-
unstub_rails
|
246
|
-
end
|
247
|
-
|
248
|
-
it "loads a config from Rails.root as a first choice" do
|
249
|
-
ActiveFedora.init
|
250
|
-
ActiveFedora.get_config_path(:fedora).should eql("#{Rails.root}/config/fedora.yml")
|
251
|
-
ActiveFedora.solr_config_path.should eql("#{Rails.root}/config/solr.yml")
|
252
|
-
end
|
253
|
-
|
254
|
-
it "can tell what environment it is set to run in" do
|
255
|
-
stub_rails(:env=>"development")
|
256
|
-
ActiveFedora.init
|
257
|
-
ActiveFedora.environment.should eql("development")
|
258
|
-
end
|
259
|
-
|
260
|
-
end
|
261
52
|
end
|
262
53
|
|
263
|
-
##########################
|
264
|
-
|
265
|
-
describe ".build_predicate_config_path" do
|
266
|
-
it "should return the path to the default config/predicate_mappings.yml if no valid path is given" do
|
267
|
-
ActiveFedora.send(:build_predicate_config_path, nil).should == default_predicate_mapping_file
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should return the path to the default config/predicate_mappings.yml if specified config file not found" do
|
271
|
-
File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(false)
|
272
|
-
File.expects(:exist?).with(default_predicate_mapping_file).returns(true)
|
273
|
-
ActiveFedora.send(:build_predicate_config_path,"/path/to").should == default_predicate_mapping_file
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should return the path to the specified config_path if it exists" do
|
277
|
-
File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(true)
|
278
|
-
ActiveFedora.expects(:valid_predicate_mapping?).returns(true)
|
279
|
-
ActiveFedora.send(:build_predicate_config_path,"/path/to").should == "/path/to/predicate_mappings.yml"
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
describe ".predicate_config" do
|
284
|
-
before do
|
285
|
-
ActiveFedora.instance_variable_set :@config_loaded, nil
|
286
|
-
end
|
287
|
-
it "should return the default mapping if it has not been initialized" do
|
288
|
-
ActiveFedora.predicate_config().should == default_predicate_mapping_file
|
289
|
-
end
|
290
|
-
describe "when the path has been set" do
|
291
|
-
before do
|
292
|
-
|
293
|
-
ActiveFedora.instance_variable_set :@predicate_config_path, nil
|
294
|
-
ActiveFedora::Config.any_instance.expects(:path).returns("/path/to/my/files/fedora.yml")
|
295
|
-
end
|
296
|
-
it "should return the path that was set at initialization" do
|
297
|
-
File.expects(:exist?).with("/path/to/my/files/predicate_mappings.yml").returns(true)
|
298
|
-
ActiveFedora.expects(:valid_predicate_mapping?).with("/path/to/my/files/predicate_mappings.yml").returns(true)
|
299
|
-
ActiveFedora.predicate_config.should == "/path/to/my/files/predicate_mappings.yml"
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe ".valid_predicate_mapping" do
|
305
|
-
it "should return true if the predicate mapping has the appropriate keys and value types" do
|
306
|
-
ActiveFedora.send(:valid_predicate_mapping?,default_predicate_mapping_file).should be_true
|
307
|
-
end
|
308
|
-
it "should return false if the mapping is missing the :default_namespace" do
|
309
|
-
mock_yaml({:default_namespace0=>"my_namespace",:predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
310
|
-
ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
311
|
-
end
|
312
|
-
it "should return false if the :default_namespace is not a string" do
|
313
|
-
mock_yaml({:default_namespace=>{:foo=>"bar"}, :predicate_mapping=>{:key0=>"value0", :key1=>"value1"}},"/path/to/predicate_mappings.yml")
|
314
|
-
ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
315
|
-
end
|
316
|
-
it "should return false if the :predicate_mappings key is missing" do
|
317
|
-
mock_yaml({:default_namespace=>"a string"},"/path/to/predicate_mappings.yml")
|
318
|
-
ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
319
|
-
end
|
320
|
-
it "should return false if the :predicate_mappings key is not a hash" do
|
321
|
-
mock_yaml({:default_namespace=>"a string",:predicate_mapping=>"another string"},"/path/to/predicate_mappings.yml")
|
322
|
-
ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
54
|
describe ".init" do
|
328
55
|
|
329
56
|
after(:all) do
|
@@ -337,7 +64,7 @@ describe ActiveFedora do
|
|
337
64
|
ActiveFedora.config.credentials.should == {:url=> "http://127.0.0.1:8983/fedora-test", :user=>'fedoraAdmin', :password=>'fedoraAdmin'}
|
338
65
|
end
|
339
66
|
it "should load the passed config if explicit config passed in as a string" do
|
340
|
-
ActiveFedora.init(:fedora_config_path=>'./spec/fixtures/rails_root/config/fedora.yml')
|
67
|
+
ActiveFedora.init(:fedora_config_path=>'./spec/fixtures/rails_root/config/fedora.yml', :environment => 'test')
|
341
68
|
ActiveFedora.config.credentials.should == {:url=> "http://testhost.com:8983/fedora", :user=>'fedoraAdmin', :password=>'fedoraAdmin'}
|
342
69
|
end
|
343
70
|
end
|
@@ -362,7 +89,7 @@ describe ActiveFedora do
|
|
362
89
|
File.stubs(:open).with(solr_config_path).returns(solr_config)
|
363
90
|
|
364
91
|
|
365
|
-
ActiveSupport::Deprecation.expects(:warn).with("
|
92
|
+
# ActiveSupport::Deprecation.expects(:warn).with("Configuring fedora with \":url\" without :user and :password is no longer supported.")
|
366
93
|
ActiveFedora.init(:fedora_config_path=>fedora_config_path,:solr_config_path=>solr_config_path)
|
367
94
|
ActiveFedora.solr.class.should == ActiveFedora::SolrService
|
368
95
|
end
|
@@ -384,33 +111,3 @@ describe ActiveFedora do
|
|
384
111
|
end
|
385
112
|
end
|
386
113
|
end
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
def mock_yaml(hash, path)
|
391
|
-
mock_file = mock(path.split("/")[-1])
|
392
|
-
File.stubs(:exist?).with(path).returns(true)
|
393
|
-
File.expects(:open).with(path).returns(mock_file)
|
394
|
-
YAML.expects(:load).returns(hash)
|
395
|
-
end
|
396
|
-
|
397
|
-
def default_predicate_mapping_file
|
398
|
-
File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","predicate_mappings.yml"))
|
399
|
-
end
|
400
|
-
|
401
|
-
def stub_rails(opts={})
|
402
|
-
Object.const_set("Rails",Class)
|
403
|
-
Rails.send(:undef_method,:env) if Rails.respond_to?(:env)
|
404
|
-
Rails.send(:undef_method,:root) if Rails.respond_to?(:root)
|
405
|
-
opts.each { |k,v| Rails.send(:define_method,k){ return v } }
|
406
|
-
end
|
407
|
-
|
408
|
-
def unstub_rails
|
409
|
-
Object.send(:remove_const,:Rails) if defined?(Rails)
|
410
|
-
end
|
411
|
-
|
412
|
-
|
413
|
-
def setup_pretest_env
|
414
|
-
ENV['RAILS_ENV']='test'
|
415
|
-
ENV['environment']='test'
|
416
|
-
end
|