active-fedora 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ class ActiveFedoraConfigurationException < Exception
2
+ end
@@ -89,6 +89,20 @@ module ActiveFedora
89
89
  @ds_specs[args[:name]]= [args[:type], args.fetch(:label,""), block]
90
90
  end
91
91
 
92
+ def method_missing(name, *args)
93
+ if datastreams.has_key? name.to_s
94
+ ### Create and invoke a proxy method
95
+ self.class.class_eval <<-end_eval
96
+ def #{name}()
97
+ datastreams["#{name.to_s}"]
98
+ end
99
+ end_eval
100
+ self.send(name)
101
+ else
102
+ super
103
+ end
104
+ end
105
+
92
106
  #Saves a Base object, and any dirty datastreams, then updates
93
107
  #the Solr index for this object.
94
108
  def save
@@ -149,7 +163,6 @@ module ActiveFedora
149
163
  @datastreams = datastreams_in_memory
150
164
  else
151
165
  @datastreams = (@datastreams == {}) ? datastreams_in_fedora : datastreams_in_memory
152
- #@datastreams = datastreams_in_fedora.merge(datastreams_in_memory)
153
166
  end
154
167
 
155
168
  end
@@ -713,8 +726,8 @@ module ActiveFedora
713
726
  # Add a Rels-Ext relationship to the Object.
714
727
  # @param predicate
715
728
  # @param object Either a string URI or an object that responds to .pid
716
- def add_relationship(predicate, obj)
717
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
729
+ def add_relationship(predicate, obj, literal=false)
730
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj, :is_literal=>literal)
718
731
  unless relationship_exists?(r.subject, r.predicate, r.object)
719
732
  rels_ext.add_relationship(r)
720
733
  #need to call here to indicate update of named_relationships
@@ -728,8 +741,8 @@ module ActiveFedora
728
741
  # Remove a Rels-Ext relationship from the Object.
729
742
  # @param predicate
730
743
  # @param object Either a string URI or an object that responds to .pid
731
- def remove_relationship(predicate, obj)
732
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
744
+ def remove_relationship(predicate, obj, literal=false)
745
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj, :is_literal=>literal)
733
746
  rels_ext.remove_relationship(r)
734
747
  #need to call here to indicate update of named_relationships
735
748
  @relationships_are_dirty = true
@@ -9,7 +9,6 @@ module ActiveFedora
9
9
  module Model
10
10
  extend ActiveFedora::FedoraObject
11
11
 
12
- attr_accessor :properties
13
12
 
14
13
  def self.included(klass) # :nodoc:
15
14
  klass.extend(ClassMethods)
@@ -221,7 +220,6 @@ module ActiveFedora
221
220
 
222
221
  #wrapper around instance_variable_get, returns current value of @name
223
222
  def attribute_get(name)
224
- #instance_variable_get(properties[":#{name}"].instance_variable_name)
225
223
  instance_variable_get("@#{name}")
226
224
  end
227
225
 
@@ -309,7 +309,6 @@ class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream
309
309
  result = {}
310
310
  unless current_params.empty?
311
311
  result = update_values( current_params )
312
- self.dirty = true
313
312
  end
314
313
 
315
314
  return result
@@ -329,7 +328,9 @@ class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream
329
328
  if @internal_solr_doc
330
329
  raise "No update performed, this object was initialized via Solr instead of Fedora and is therefore read-only. Please utilize ActiveFedora::Base.load_instance to first load object via Fedora instead."
331
330
  else
332
- om_update_values(params)
331
+ result = om_update_values(params)
332
+ self.dirty= true
333
+ return result
333
334
  end
334
335
  end
335
336
 
@@ -1,14 +1,15 @@
1
+ require 'uri'
1
2
  module ActiveFedora
2
3
 
3
4
  class Relationship
4
5
 
5
6
  attr_accessor :subject, :predicate, :object, :is_literal, :data_type
6
7
  def initialize(attr={})
7
- attr.merge!({:is_literal => false})
8
+ attr = {:is_literal => false}.merge(attr)
9
+ @is_literal = attr[:is_literal] # must happen first
8
10
  self.subject = attr[:subject]
9
11
  @predicate = attr[:predicate]
10
12
  self.object = attr[:object]
11
- @is_literal = attr[:is_literal]
12
13
  @data_type = attr[:data_type]
13
14
  end
14
15
 
@@ -21,7 +22,7 @@ module ActiveFedora
21
22
  end
22
23
 
23
24
  def object=(object)
24
- @object = generate_uri(object)
25
+ @object = (is_literal)? object : generate_uri(object)
25
26
  end
26
27
 
27
28
  def object_pid=(pid)
@@ -31,6 +32,8 @@ module ActiveFedora
31
32
  def generate_uri(input)
32
33
  if input.class == Symbol || input == nil
33
34
  return input
35
+ elsif input.is_a? URI::Generic
36
+ return input.to_s
34
37
  elsif input.respond_to?(:pid)
35
38
  return "info:fedora/#{input.pid}"
36
39
  else
@@ -40,4 +43,4 @@ module ActiveFedora
40
43
 
41
44
  end
42
45
 
43
- end
46
+ end
@@ -1,4 +1,5 @@
1
1
  require 'solrizer/field_name_mapper'
2
+ require 'uri'
2
3
 
3
4
  module ActiveFedora
4
5
  class RelsExtDatastream < Datastream
@@ -44,8 +45,9 @@ module ActiveFedora
44
45
  logger.warn "You have a predicate without a namespace #{f.name}. Verify your rels-ext is correct."
45
46
  predicate = "#{f.name}"
46
47
  end
47
- object = f["resource"] ? f["resource"] : f.inner_text
48
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>object)
48
+ is_obj = f["resource"]
49
+ object = is_obj ? f["resource"] : f.inner_text
50
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>object, :is_literal=>!is_obj)
49
51
  tmpl.add_relationship(r)
50
52
  end
51
53
  tmpl.send(:dirty=, false)
@@ -84,11 +86,15 @@ module ActiveFedora
84
86
  unless value.nil?
85
87
  if value.is_a? Array
86
88
  value.each do |obj|
87
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
89
+ o_uri = URI.parse(obj)
90
+ literal = o_uri.scheme.nil?
91
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj, :is_literal=>literal)
88
92
  add_relationship(r)
89
93
  end
90
94
  else
91
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>value)
95
+ o_uri = URI.parse(value)
96
+ literal = o_uri.scheme.nil?
97
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>value, :is_literal=>literal)
92
98
  add_relationship(r)
93
99
  end
94
100
  end
@@ -95,6 +95,7 @@ module ActiveFedora
95
95
  objects.each do |object|
96
96
  if (response_format == :uri)
97
97
  #create a Relationship object so that it generates the appropriate uri
98
+ #inbound relationships are always object properties
98
99
  r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>object)
99
100
  items.push(r.object)
100
101
  else
@@ -437,7 +438,12 @@ module ActiveFedora
437
438
  rel_predicate, xmlns = self.class.find_predicate(predicate)
438
439
  end
439
440
  # puts ". #{predicate} #{target} #{xmlns}"
440
- xml.root.elements["rdf:Description"].add_element(rel_predicate, {"xmlns" => "#{xmlns}", "rdf:resource"=>target})
441
+ literal = URI.parse(target).scheme.nil?
442
+ if literal
443
+ xml.root.elements["rdf:Description"].add_element(rel_predicate, {"xmlns" => "#{xmlns}"}).add_text(target)
444
+ else
445
+ xml.root.elements["rdf:Description"].add_element(rel_predicate, {"xmlns" => "#{xmlns}", "rdf:resource"=>target})
446
+ end
441
447
  end
442
448
  end
443
449
  xml.to_s
@@ -787,7 +793,6 @@ module ActiveFedora
787
793
  return predicates[predicate], namespace
788
794
  end
789
795
  end
790
- debugger
791
796
  raise ActiveFedora::UnregisteredPredicateError
792
797
  end
793
798
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "2.3.3"
2
+ VERSION = "2.3.4"
3
3
  end
@@ -15,6 +15,17 @@ EOS
15
15
  end
16
16
 
17
17
  $: << 'lib'
18
+ def jetty_params
19
+ project_root = File.expand_path("#{File.dirname(__FILE__)}/../../")
20
+ {
21
+ :quiet => false,
22
+ :jetty_home => File.join(project_root,'jetty'),
23
+ :jetty_port => 8983,
24
+ :solr_home => File.expand_path(File.join(project_root,'jetty','solr')),
25
+ :fedora_home => File.expand_path(File.join(project_root,'jetty','fedora','default')),
26
+ :startup_wait=>30
27
+ }
28
+ end
18
29
 
19
30
  desc "Run active-fedora rspec tests"
20
31
  task :spec do
@@ -24,19 +35,10 @@ end
24
35
  desc "Hudson build"
25
36
  task :hudson do
26
37
  require 'jettywrapper'
27
- project_root = File.expand_path("#{File.dirname(__FILE__)}/../../")
28
38
 
29
39
  if (ENV['environment'] == "test")
30
40
  Rake::Task["active_fedora:doc"].invoke
31
41
  Rake::Task["active_fedora:configure_jetty"].invoke
32
- jetty_params = {
33
- :quiet => false,
34
- :jetty_home => File.join(project_root,'jetty'),
35
- :jetty_port => 8983,
36
- :solr_home => File.expand_path(File.join(project_root,'jetty','solr')),
37
- :fedora_home => File.expand_path(File.join(project_root,'jetty','fedora','default')),
38
- :startup_wait=>30
39
- }
40
42
  error = Jettywrapper.wrap(jetty_params) do
41
43
  ENV["FEDORA_HOME"]=File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
42
44
  Rake::Task["active_fedora:load_fixtures"].invoke
@@ -114,6 +116,19 @@ namespace :active_fedora do
114
116
  end
115
117
  end
116
118
 
119
+ namespace :jetty do
120
+ desc "start jetty"
121
+ task :start do
122
+ require 'jettywrapper'
123
+ Jettywrapper.start(jetty_params)
124
+ end
125
+ desc "stop jetty"
126
+ task :stop do
127
+ require 'jettywrapper'
128
+ Jettywrapper.stop(jetty_params)
129
+ end
130
+ end
131
+
117
132
  end
118
133
 
119
134
  # Provides an :environment task for use while working within a working copy of active-fedora
@@ -0,0 +1,7 @@
1
+ development:
2
+ url: http://development.com/fedora
3
+ test:
4
+ url: http://test.com/fedora
5
+ production:
6
+ url: http://production.com/fedora
7
+
@@ -0,0 +1,15 @@
1
+ development:
2
+ default:
3
+ url: http://localhost:8983/solr/development
4
+ full_text:
5
+ url: http://localhost:8983/solr/development
6
+ test:
7
+ default:
8
+ url: http://localhost:8983/solr/test
9
+ full_text:
10
+ url: http://localhost:8983/solr/test
11
+ production:
12
+ default:
13
+ url: http://localhost:8080/solr/production
14
+ full_text:
15
+ url: http://localhost:8080/solr/production
@@ -134,6 +134,15 @@ describe ActiveFedora::Base do
134
134
 
135
135
  end
136
136
 
137
+ it "should create proxies to all the datastreams" do
138
+ properties_ds = @test_history.datastreams["properties"]
139
+ dublin_core_ds = @test_history.datastreams["dublin_core"]
140
+ @test_history.should_not respond_to(:properties)
141
+ @test_history.properties.should be properties_ds
142
+ @test_history.should respond_to(:properties)
143
+ OralHistory.new.should respond_to(:properties)
144
+ end
145
+
137
146
  it "t1" do# should load all of the metadata fields from fedora xml" do
138
147
  pending
139
148
  properties_ds = @test_history.datastreams["properties"]
@@ -1,9 +1,269 @@
1
1
  require File.join( File.dirname(__FILE__), "../spec_helper" )
2
+ require 'equivalent-xml'
2
3
 
3
4
  # For testing Module-level methods like ActiveFedora.init
4
5
 
5
6
  describe ActiveFedora do
6
7
 
8
+ describe "initialization methods" do
9
+
10
+ describe "environment" do
11
+ it "should use config_options[:environment] if set" do
12
+ ActiveFedora.expects(:config_options).at_least_once.returns(:environment=>"ballyhoo")
13
+ ActiveFedora.environment.should eql("ballyhoo")
14
+ end
15
+
16
+ it "should use Rails.env if no config_options and Rails.env is set" do
17
+ stub_rails(:env => "bedbugs")
18
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
19
+ ActiveFedora.environment.should eql("bedbugs")
20
+ unstub_rails
21
+ end
22
+
23
+ it "should use ENV['environment'] if neither config_options nor Rails.env are set" do
24
+ ENV['environment'] = "wichita"
25
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
26
+ ActiveFedora.environment.should eql("wichita")
27
+ end
28
+
29
+ it "should use ENV['RAILS_ENV'] and log a warning if none of the above are set" do
30
+ ENV['environment']=nil
31
+ ENV['RAILS_ENV'] = "rails_env"
32
+ logger.expects(:warn)
33
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
34
+ ActiveFedora.environment.should eql("rails_env")
35
+ ENV['environment']='test'
36
+ end
37
+
38
+ it "should raise an exception if none of the above are present" do
39
+ ENV['environment']=nil
40
+ ENV['RAILS_ENV'] = nil
41
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
42
+ lambda { ActiveFedora.environment }.should raise_exception
43
+ ENV['environment']="test"
44
+ end
45
+ end
46
+
47
+ describe "get_config_path(:fedora)" do
48
+ it "should use the config_options[:config_path] if it exists" do
49
+ ActiveFedora.expects(:config_options).at_least_once.returns({:fedora_config_path => "/path/to/fedora.yml"})
50
+ File.expects(:file?).with("/path/to/fedora.yml").returns(true)
51
+ ActiveFedora.get_config_path(:fedora).should eql("/path/to/fedora.yml")
52
+ end
53
+
54
+ it "should look in Rails.root/config/fedora.yml if it exists and no fedora_config_path passed in" do
55
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
56
+ stub_rails(:root => "/rails/root")
57
+ File.expects(:file?).with("/rails/root/config/fedora.yml").returns(true)
58
+ ActiveFedora.get_config_path(:fedora).should eql("/rails/root/config/fedora.yml")
59
+ unstub_rails
60
+ end
61
+
62
+ it "should look in ./config/fedora.yml if neither rails.root nor :fedora_config_path are set" do
63
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
64
+ Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
65
+ File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(true)
66
+ ActiveFedora.get_config_path(:fedora).should eql("/current/working/directory/config/fedora.yml")
67
+ end
68
+
69
+ it "should return default fedora.yml that ships with active-fedora if none of the above" do
70
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
71
+ Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
72
+ File.expects(:file?).with("/current/working/directory/config/fedora.yml").returns(false)
73
+ File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml'))).returns(true)
74
+ ActiveFedora.get_config_path(:fedora).should eql(File.expand_path(File.join(File.dirname("__FILE__"),'config','fedora.yml')))
75
+ end
76
+ end
77
+
78
+ describe "get_config_path(:solr)" do
79
+ it "should return the solr_config_path if set in config_options hash" do
80
+ ActiveFedora.expects(:config_options).at_least_once.returns({:solr_config_path => "/path/to/solr.yml"})
81
+ File.expects(:file?).with("/path/to/solr.yml").returns(true)
82
+ ActiveFedora.get_config_path(:solr).should eql("/path/to/solr.yml")
83
+ end
84
+
85
+ it "should return the solr.yml file in the same directory as the fedora.yml if it exists" do
86
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
87
+ ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora/config/fedora.yml")
88
+ File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(true)
89
+ ActiveFedora.get_config_path(:solr).should eql("/path/to/fedora/config/solr.yml")
90
+ end
91
+
92
+ it "should 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" do
93
+ ActiveFedora.expects(:config_options).at_least_once.returns({})
94
+ ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora/config/fedora.yml")
95
+ File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(false)
96
+ ActiveFedora.expects(:fedora_config).returns({"test"=>{"solr"=>{"url"=>"http://some_url"}}})
97
+ lambda { ActiveFedora.get_config_path(:solr) }.should raise_exception
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.expects(:fedora_config_path).returns("/path/to/fedora/config/fedora.yml")
105
+ File.expects(:file?).with("/path/to/fedora/config/solr.yml").returns(false)
106
+ ActiveFedora.expects(:fedora_config).returns({"test"=>{"url"=>"http://some_url"}})
107
+ end
108
+ after :each do
109
+ unstub_rails
110
+ end
111
+
112
+ 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
113
+ stub_rails(:root=>"/rails/root")
114
+ File.expects(:file?).with("/rails/root/config/solr.yml").returns(true)
115
+ ActiveFedora.get_config_path(:solr).should eql("/rails/root/config/solr.yml")
116
+ end
117
+
118
+ it "should look in ./config/solr.yml if no rails root" do
119
+ Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
120
+ File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(true)
121
+ ActiveFedora.get_config_path(:solr).should eql("/current/working/directory/config/solr.yml")
122
+ end
123
+
124
+ it "should return the default solr.yml file that ships with active-fedora if no other option is set" do
125
+ Dir.expects(:getwd).at_least_once.returns("/current/working/directory")
126
+ File.expects(:file?).with("/current/working/directory/config/solr.yml").returns(false)
127
+ File.expects(:file?).with(File.expand_path(File.join(File.dirname("__FILE__"),'config','solr.yml'))).returns(true)
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']['fedora']['url'] if config_type is fedora" do
137
+ config = {"test"=> {"fedora"=>{"url"=>"http://fedoraAdmin:fedorAdmin@oldstyle_url:8983/fedora"}}}
138
+ ActiveFedora.determine_url("fedora",config).should eql("http://fedoraAdmin:fedorAdmin@oldstyle_url:8983/fedora")
139
+ end
140
+
141
+ it "should support config['environment']['url'] if config_type is fedora" do
142
+ config = {"test"=> {"url"=>"http://fedoraAdmin:fedorAdmin@oldstyle_url:8983/fedora"}}
143
+ ActiveFedora.determine_url("fedora",config).should eql("http://fedoraAdmin:fedorAdmin@oldstyle_url:8983/fedora")
144
+ end
145
+
146
+ it "should call #get_solr_url to determine the solr url if config_type is solr" do
147
+ config = {"test"=>{"default" => "http://default.solr:8983"}}
148
+ ActiveFedora.expects(:get_solr_url).with(config["test"]).returns("http://default.solr:8983")
149
+ ActiveFedora.determine_url("solr",config).should eql("http://default.solr:8983")
150
+ end
151
+ end
152
+
153
+ describe "load_config" do
154
+ it "should load the file specified in fedora_config_path" do
155
+ ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora.yml")
156
+ File.expects(:open).with("/path/to/fedora.yml").returns("test:\n url: http://myfedora:8080")
157
+ ActiveFedora.load_config(:fedora).should eql({:url=>"http://myfedora:8080","test"=>{"url"=>"http://myfedora:8080"}})
158
+ ActiveFedora.fedora_config.should eql({:url=>"http://myfedora:8080","test"=>{"url"=>"http://myfedora:8080"}})
159
+ end
160
+ it "should load the file specified in solr_config_path" do
161
+ ActiveFedora.expects(:solr_config_path).returns("/path/to/solr.yml")
162
+ 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")
163
+ ActiveFedora.load_config(:solr).should eql({:url=>"http://mysolr:8080","development"=>{"default"=>{"url"=>"http://devsolr:8983"}}, "test"=>{"default"=>{"url"=>"http://mysolr:8080"}}})
164
+ ActiveFedora.solr_config.should eql({:url=>"http://mysolr:8080","development"=>{"default"=>{"url"=>"http://devsolr:8983"}}, "test"=>{"default"=>{"url"=>"http://mysolr:8080"}}})
165
+ end
166
+ end
167
+
168
+ describe "load_configs" do
169
+ it "should load the fedora and solr configs" do
170
+ ActiveFedora.expects(:load_config).with(:fedora)
171
+ ActiveFedora.expects(:load_config).with(:solr)
172
+ ActiveFedora.load_configs
173
+ end
174
+ end
175
+
176
+ describe "register_solr_and_fedora" do
177
+ it "should regiser instances with the appropriate urls" do
178
+ ActiveFedora.expects(:solr_config).at_least_once.returns({:url=>"http://megasolr:8983"})
179
+ ActiveFedora.expects(:fedora_config).at_least_once.returns({:url=>"http://megafedora:8983"})
180
+ ActiveFedora.register_fedora_and_solr
181
+ ActiveFedora.solr.conn.url.to_s.should eql("http://megasolr:8983")
182
+ ActiveFedora.fedora.fedora_url.to_s.should eql("http://megafedora:8983")
183
+ end
184
+ end
185
+
186
+ describe "check_fedora_path_for_solr" do
187
+ it "should find the solr.yml file and return it if it exists" do
188
+ ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora/fedora.yml")
189
+ File.expects(:file?).with("/path/to/fedora/solr.yml").returns(true)
190
+ ActiveFedora.check_fedora_path_for_solr.should == "/path/to/fedora/solr.yml"
191
+ end
192
+ it "should return nil if the solr.yml file is not there" do
193
+ ActiveFedora.expects(:fedora_config_path).returns("/path/to/fedora/fedora.yml")
194
+ File.expects(:file?).with("/path/to/fedora/solr.yml").returns(false)
195
+ ActiveFedora.check_fedora_path_for_solr.should be_nil
196
+ end
197
+ end
198
+ end
199
+
200
+
201
+
202
+ ###########################
203
+
204
+ describe "setting the environment and loading configuration" do
205
+
206
+ before(:all) do
207
+ @fake_rails_root = File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails_root')
208
+ end
209
+
210
+ after(:all) do
211
+ ActiveFedora.init(File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml"))
212
+ end
213
+
214
+ it "can tell its config paths" do
215
+ ActiveFedora.init
216
+ ActiveFedora.should respond_to(:fedora_config_path)
217
+ ActiveFedora.should respond_to(:solr_config_path)
218
+ end
219
+ it "loads a config from the current working directory as a second choice" do
220
+ Dir.stubs(:getwd).returns(@fake_rails_root)
221
+ ActiveFedora.init
222
+ ActiveFedora.fedora_config_path.should eql("#{@fake_rails_root}/config/fedora.yml")
223
+ ActiveFedora.solr_config_path.should eql("#{@fake_rails_root}/config/solr.yml")
224
+ end
225
+ it "loads the config that ships with this gem as a last choice" do
226
+ Dir.stubs(:getwd).returns("/fake/path")
227
+ ActiveFedora.init
228
+ expected_config = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
229
+ ActiveFedora.fedora_config_path.should eql(expected_config+'/fedora.yml')
230
+ ActiveFedora.solr_config_path.should eql(expected_config+'/solr.yml')
231
+ end
232
+ it "overrides any other config file when a file is passed in explicitly" do
233
+ ActiveFedora.init("#{@fake_rails_root}/config/fake_fedora.yml")
234
+ ActiveFedora.fedora_config_path.should eql("#{@fake_rails_root}/config/fake_fedora.yml")
235
+ #ActiveFedora.config_path.should eql("#{@fake_rails_root}/config/fake_fedora.yml")
236
+ end
237
+ it "raises an error if you pass in a non-existant config file" do
238
+ lambda{ ActiveFedora.init("really_fake_fedora.yml") }.should raise_exception(ActiveFedoraConfigurationException)
239
+ end
240
+
241
+ describe "within Rails" do
242
+ before(:all) do
243
+ stub_rails(:root=>File.dirname(__FILE__) + '/../fixtures/rails_root')
244
+ end
245
+
246
+ after(:all) do
247
+ unstub_rails
248
+ end
249
+
250
+ it "loads a config from Rails.root as a first choice" do
251
+ ActiveFedora.init
252
+ ActiveFedora.fedora_config_path.should eql("#{Rails.root}/config/fedora.yml")
253
+ ActiveFedora.solr_config_path.should eql("#{Rails.root}/config/solr.yml")
254
+ end
255
+
256
+ it "can tell what environment it is set to run in" do
257
+ stub_rails(:env=>"development")
258
+ ActiveFedora.init
259
+ ActiveFedora.environment.should eql("development")
260
+ end
261
+
262
+ end
263
+ end
264
+
265
+ ##########################
266
+
7
267
  describe ".push_models_to_fedora" do
8
268
  it "should push the model definition for each of the ActiveFedora models into Fedora CModel objects" do
9
269
  pending
@@ -74,7 +334,8 @@ describe ActiveFedora do
74
334
 
75
335
  after(:all) do
76
336
  # Restore to default fedora configs
77
- ActiveFedora.init()
337
+ ActiveFedora.init(File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml"))
338
+
78
339
  end
79
340
 
80
341
  describe "outside of rails" do
@@ -90,25 +351,26 @@ describe ActiveFedora do
90
351
 
91
352
  describe "within rails" do
92
353
 
93
- before(:all) do
94
- Object.const_set("Rails",String)
95
- end
96
-
97
354
  after(:all) do
98
- if Rails == String
99
- Object.send(:remove_const,:Rails)
100
- end
355
+ unstub_rails
101
356
  end
102
357
 
103
358
  describe "versions prior to 3.0" do
104
359
  describe "with explicit config path passed in" do
105
360
  it "should load the specified config path" do
106
- config_hash={"test"=>{"fedora"=>{"url"=>"http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"},"solr"=>{"url"=>"http://127.0.0.1:8983/solr/test/"}}}
107
- config_path = File.expand_path(File.join(File.dirname(__FILE__),"config"))
108
- mock_yaml(config_hash,File.join(config_path,"fedora.yml"))
109
- File.expects(:exist?).with(File.join(config_path,"predicate_mappings.yml")).returns(true)
110
- ActiveFedora.expects(:valid_predicate_mapping?).returns(true)
111
- ActiveFedora.init(File.join(config_path,"fedora.yml"))
361
+ fedora_config="test:\n fedora:\n url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"
362
+ solr_config = "test:\n default:\n url: http://foosolr:8983"
363
+
364
+ fedora_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/fedora.yml"))
365
+ solr_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/solr.yml"))
366
+ pred_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/predicate_mappings.yml"))
367
+
368
+ File.stubs(:open).with(fedora_config_path).returns(fedora_config)
369
+ File.stubs(:open).with(solr_config_path).returns(solr_config)
370
+
371
+ ActiveFedora.expects(:build_predicate_config_path)
372
+
373
+ ActiveFedora.init(:fedora_config_path=>fedora_config_path,:solr_config_path=>solr_config_path)
112
374
  ActiveFedora.solr.class.should == ActiveFedora::SolrService
113
375
  ActiveFedora.fedora.class.should == Fedora::Repository
114
376
  end
@@ -116,14 +378,14 @@ describe ActiveFedora do
116
378
 
117
379
  describe "with no explicit config path" do
118
380
  it "should look for the file in the path defined at Rails.root" do
119
- Rails.expects(:root).returns(File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
381
+ stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
120
382
  ActiveFedora.init()
121
383
  ActiveFedora.solr.class.should == ActiveFedora::SolrService
122
384
  ActiveFedora.fedora.class.should == Fedora::Repository
123
385
  ActiveFedora.fedora.fedora_url.to_s.should == "http://fedoraAdmin:fedoraAdmin@testhost.com:8983/fedora"
124
386
  end
125
387
  it "should load the default file if no config is found at Rails.root" do
126
- Rails.expects(:root).returns(File.join(File.dirname(__FILE__),"../fixtures/bad/path/to/rails_root"))
388
+ stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/bad/path/to/rails_root"))
127
389
  ActiveFedora.init()
128
390
  ActiveFedora.solr.class.should == ActiveFedora::SolrService
129
391
  ActiveFedora.fedora.class.should == Fedora::Repository
@@ -145,3 +407,33 @@ end
145
407
  def default_predicate_mapping_file
146
408
  File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","predicate_mappings.yml"))
147
409
  end
410
+
411
+ def stub_rails(opts={})
412
+ Object.const_set("Rails",Class)
413
+ Rails.send(:undef_method,:env) if Rails.respond_to?(:env)
414
+ Rails.send(:undef_method,:root) if Rails.respond_to?(:root)
415
+ opts.each { |k,v| Rails.send(:define_method,k){ return v } }
416
+ end
417
+
418
+ def unstub_rails
419
+ Object.send(:remove_const,:Rails) if defined?(Rails)
420
+ end
421
+
422
+ def stub_blacklight(opts={})
423
+ Object.const_set("Blacklight",Class)
424
+ Blacklight.send(:undef_method,:solr_config) if Blacklight.respond_to?(:solr_config)
425
+ if opts[:solr_config]
426
+ Blacklight.send(:define_method,:solr_config) do
427
+ opts[:solr_config]
428
+ end
429
+ end
430
+ end
431
+
432
+ def unstub_blacklight
433
+ Object.send(:remove_const,:Blacklight) if defined?(Blacklight)
434
+ end
435
+
436
+ def setup_pretest_env
437
+ ENV['RAILS_ENV']='test'
438
+ ENV['environment']='test'
439
+ end