active-fedora 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@ h2. Getting Started
18
18
 
19
19
  The "ActiveFedora Console Tour":https://github.com/mediashelf/active_fedora/blob/master/CONSOLE_GETTING_STARTED.textile gives you a brief tour through ActiveFedora's features on the command line.
20
20
 
21
- h2. Installation
21
+ h2. Testing
22
22
 
23
23
  In order to run the RSpec tests, you need to have a copy of the ActiveFedora source code, and then run bundle install in the source directory.
24
24
 
@@ -26,9 +26,11 @@ In order to run the RSpec tests, you need to have a copy of the ActiveFedora sou
26
26
  git clone https://github.com/mediashelf/active_fedora.git
27
27
  cd /wherever/active_fedora/is
28
28
  bundle install
29
+ git submodule init
30
+ git submodule update
29
31
  </pre>
30
32
 
31
- h2. Testing with Hudson Rake Task
33
+ h3. Testing with Hudson Rake Task
32
34
 
33
35
  The hudson rake task will spin up jetty, import the fixtures, and run the tests for you.
34
36
 
@@ -36,7 +38,7 @@ The hudson rake task will spin up jetty, import the fixtures, and run the tests
36
38
  rake hudson
37
39
  </pre>
38
40
 
39
- h2. Testing Manually
41
+ h3. Testing Manually
40
42
 
41
43
  If you want to run the tests manually, follow these instructions.
42
44
 
@@ -49,16 +51,15 @@ java -jar start.jar
49
51
  Then open a new terminal, go to your ActiveFedora source directory, and import fedora's demo objects.
50
52
 
51
53
  <pre>
54
+ export FEDORA_HOME=/path/to/hydra/jetty/fedora/default
52
55
  rake active_fedora:load_fixtures RAILS_ENV=test
53
56
  </pre>
54
57
 
55
58
  This does the equivalent of:
56
59
 
57
60
  <pre>
58
- cd /wherever/active_fedora/is
59
- export FEDORA_HOME=/path/to/hydra/jetty/fedora/default
60
- $FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http
61
- rake af:import_fixture pid=hydrangea:fixture_mods_article1 RAILS_ENV=test
61
+ $FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http
62
+ rake af:import_fixture pid=hydrangea:fixture_mods_article1 RAILS_ENV=test
62
63
  </pre>
63
64
 
64
65
  Now you're ready to run the tests. In the directory where active_fedora is installed, run
@@ -67,6 +68,18 @@ Now you're ready to run the tests. In the directory where active_fedora is inst
67
68
  rake spec
68
69
  </pre>
69
70
 
71
+ h2. Predicate Mappings
72
+
73
+ ActiveFedora versions 2.2.1 and higher provides specialized control over the predicate mappings used by SemanticNode. In order to provide your own mappings,
74
+ you must supply a predicate_mappings.yml in the same format as the config/predicate_mappings.yml file shipped with the ActiveFedora gem. Place the file in the same directory
75
+ as your fedora.yml file and use the current method of initializing ActiveFedora:
76
+
77
+ <pre>
78
+ ActiveFedora.init("/path/to/my/config/fedora.yml")
79
+ </pre>
80
+
81
+ If no predicate_mappings.yml file is found, ActiveFedora will use the default mappings.
82
+
70
83
  h2. Acknowledgements
71
84
 
72
85
  Creator: Matt Zumwalt ("MediaShelf":http://yourmediashelf.com)
@@ -101,4 +114,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
101
114
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
102
115
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
103
116
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
104
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
117
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -58,7 +58,6 @@ module ActiveFedora #:nodoc:
58
58
 
59
59
 
60
60
  logger.info("FEDORA: loading ActiveFedora config from #{File.expand_path(config_path)}")
61
-
62
61
  fedora_config = YAML::load(File.open(config_path))
63
62
  raise "The #{config_env} environment settings were not found in the fedora.yml config. If you already have a fedora.yml file defined, make sure it defines settings for the #{config_env} environment" unless fedora_config[config_env]
64
63
 
@@ -77,16 +76,7 @@ module ActiveFedora #:nodoc:
77
76
  logger.info("FEDORA: initialized Fedora as: #{Fedora::Repository.instance.inspect}")
78
77
 
79
78
  # Retrieve the valid path for the predicate mappings config file
80
- pred_config_paths = [File.dirname(config_path),File.join(File.dirname(__FILE__),"..","config")]
81
- pred_config_paths.each do |path|
82
- testfile = File.join(path,"predicate_mappings.yml")
83
- if File.exist?(testfile)
84
- @predicate_config_path = testfile
85
- break
86
- end
87
- end
88
- raise "Could not find predicate_mappings.yml in these locations: #{pred_config_paths.join("; ")}." unless @predicate_config_path
89
-
79
+ @predicate_config_path = build_predicate_config_path(File.dirname(config_path))
90
80
 
91
81
  end
92
82
 
@@ -103,17 +93,41 @@ module ActiveFedora #:nodoc:
103
93
  end
104
94
 
105
95
  def self.predicate_config
106
- @predicate_config_path
96
+ @predicate_config_path ||= build_predicate_config_path
107
97
  end
108
98
 
109
99
  def self.version
110
100
  ActiveFedora::VERSION
111
101
  end
102
+
103
+ protected
104
+
105
+ def self.build_predicate_config_path(config_path=nil)
106
+ pred_config_paths = [File.expand_path(File.join(File.dirname(__FILE__),"..","config"))]
107
+ pred_config_paths.unshift config_path if config_path
108
+ pred_config_paths.each do |path|
109
+ testfile = File.join(path,"predicate_mappings.yml")
110
+ if File.exist?(testfile) && valid_predicate_mapping?(testfile)
111
+ return testfile
112
+ end
113
+ end
114
+ raise PredicateMappingsNotFoundError #"Could not find predicate_mappings.yml in these locations: #{pred_config_paths.join("; ")}." unless @predicate_config_path
115
+ end
116
+
117
+ def self.valid_predicate_mapping?(testfile)
118
+ mapping = YAML::load(File.open(testfile))
119
+ return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
120
+ return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
121
+ true
122
+ end
123
+
124
+
112
125
  end
113
126
 
114
127
 
115
128
 
116
129
 
130
+
117
131
  # if ![].respond_to?(:count)
118
132
  # class Array
119
133
  # puts "active_fedora is Adding count method to Array"
@@ -129,5 +143,6 @@ end
129
143
  module ActiveFedora
130
144
  class ServerError < Fedora::ServerError; end # :nodoc:
131
145
  class ObjectNotFoundError < RuntimeError; end # :nodoc:
146
+ class PredicateMappingsNotFoundError < RuntimeError; end # :nodoc:
132
147
  end
133
148
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -38,6 +38,7 @@ task :hudson do
38
38
  :startup_wait=>30
39
39
  }
40
40
  error = Jettywrapper.wrap(jetty_params) do
41
+ ENV["FEDORA_HOME"]=File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
41
42
  Rake::Task["active_fedora:load_fixtures"].invoke
42
43
  Rake::Task["active_fedora:rspec"].invoke
43
44
  end
@@ -94,7 +95,7 @@ namespace :active_fedora do
94
95
  require 'solrizer'
95
96
  require 'solrizer-fedora'
96
97
  require 'spec/samples/models/hydrangea_article'
97
- ENV["FEDORA_HOME"]=File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
98
+ ENV["FEDORA_HOME"] ||= File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
98
99
  retval = `$FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http`
99
100
  puts "loaded demo objects #{retval}"
100
101
  ActiveFedora.init unless Thread.current[:repo]
@@ -12,4 +12,72 @@ describe ActiveFedora do
12
12
  # push the model definition into the cmodel's datastream (ie. dsname: oral_history.rb vs dsname: ruby)
13
13
  end
14
14
  end
15
- end
15
+
16
+ describe ".build_predicate_config_path" do
17
+ it "should return the path to the default config/predicate_mappings.yml if no valid path is given" do
18
+ ActiveFedora.send(:build_predicate_config_path, nil).should == default_predicate_mapping_file
19
+ end
20
+
21
+ it "should return the path to the default config/predicate_mappings.yml if specified config file not found" do
22
+ File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(false)
23
+ File.expects(:exist?).with(default_predicate_mapping_file).returns(true)
24
+ ActiveFedora.send(:build_predicate_config_path,"/path/to").should == default_predicate_mapping_file
25
+ end
26
+
27
+ it "should return the path to the specified config_path if it exists" do
28
+ File.expects(:exist?).with("/path/to/predicate_mappings.yml").returns(true)
29
+ ActiveFedora.expects(:valid_predicate_mapping?).returns(true)
30
+ ActiveFedora.send(:build_predicate_config_path,"/path/to").should == "/path/to/predicate_mappings.yml"
31
+ end
32
+ end
33
+
34
+ describe ".predicate_config" do
35
+ it "should return the default mapping if it has not been initialized" do
36
+ ActiveFedora.instance_variable_set("@predicate_config_path",nil)
37
+ ActiveFedora.predicate_config().should == default_predicate_mapping_file
38
+ end
39
+ it "should return the path that was set at initialization" do
40
+ pending()
41
+ File.expects(:exist?).with("/path/to/my/files/predicate_mappings.yml").returns(true)
42
+ mock_file = mock("fedora.yml")
43
+ File.expects(:open).returns(mock_file)
44
+ YAML.expects(:load).returns({"test"=>{"solr"=>{"url"=>"http://127.0.0.1:8983/solr/development"}, "fedora"=>{"url"=>"http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"}}})
45
+ ActiveFedora.init("/path/to/my/files/fedora.yml")
46
+ ActiveFedora.predicate_config.should == "/path/to/my/files/predicate_mappings.yml"
47
+ end
48
+ end
49
+
50
+ describe ".valid_predicate_mapping" do
51
+ it "should return true if the predicate mapping has the appropriate keys and value types" do
52
+ ActiveFedora.send(:valid_predicate_mapping?,default_predicate_mapping_file).should be_true
53
+ end
54
+ it "should return false if the mapping is missing the :default_namespace" do
55
+ mock_yaml({:default_namespace0=>"my_namespace",:predicate_mapping=>{:key0=>"value0", :key1=>"value1"}})
56
+ ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
57
+ end
58
+ it "should return false if the :default_namespace is not a string" do
59
+ mock_yaml({:default_namespace=>{:foo=>"bar"}, :predicate_mapping=>{:key0=>"value0", :key1=>"value1"}})
60
+ ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
61
+ end
62
+ it "should return false if the :predicate_mappings key is missing" do
63
+ mock_yaml({:default_namespace=>"a string"})
64
+ ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
65
+ end
66
+ it "should return false if the :predicate_mappings key is not a hash" do
67
+ mock_yaml({:default_namespace=>"a string",:predicate_mapping=>"another string"})
68
+ ActiveFedora.send(:valid_predicate_mapping?,"/path/to/predicate_mappings.yml").should be_false
69
+ end
70
+
71
+ end
72
+ end
73
+
74
+
75
+ def mock_yaml(hash)
76
+ mock_file = mock("predicate_mappings.yml")
77
+ File.expects(:open).with("/path/to/predicate_mappings.yml").returns(mock_file)
78
+ YAML.expects(:load).returns(hash)
79
+ end
80
+
81
+ def default_predicate_mapping_file
82
+ File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","predicate_mappings.yml"))
83
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 1
10
- version: 2.2.1
9
+ - 2
10
+ version: 2.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-31 00:00:00 Z
19
+ date: 2011-06-05 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: solr-ruby