hydra-core 5.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +5 -0
  3. data/app/helpers/blacklight_helper.rb +4 -0
  4. data/app/helpers/facets_helper.rb +4 -0
  5. data/app/helpers/hydra/blacklight_helper_behavior.rb +36 -0
  6. data/app/helpers/hydra/facets_helper_behavior.rb +25 -0
  7. data/app/models/hydra/datastream/properties.rb +24 -0
  8. data/app/models/mods_asset.rb +25 -0
  9. data/app/views/_flash_msg.html.erb +5 -0
  10. data/app/views/catalog/_citation.html.erb +11 -0
  11. data/app/views/catalog/_constraints_element.html.erb +34 -0
  12. data/app/views/catalog/_delete_partials/_default.html.erb +22 -0
  13. data/app/views/catalog/_edit_partials/_default.html.erb +57 -0
  14. data/app/views/catalog/_edit_partials/_default_details.html.erb +13 -0
  15. data/app/views/catalog/_facets.html.erb +37 -0
  16. data/app/views/catalog/_home.html.erb +6 -0
  17. data/app/views/catalog/_home_text.html.erb +4 -0
  18. data/app/views/catalog/_index_partials/_default.html.erb +20 -0
  19. data/app/views/catalog/_index_partials/_default_details.html.erb +14 -0
  20. data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -0
  21. data/app/views/catalog/_show_partials/_default.html.erb +21 -0
  22. data/app/views/catalog/_show_partials/_default_details.html.erb +15 -0
  23. data/app/views/catalog/_show_partials/_facets.html.erb +52 -0
  24. data/app/views/catalog/_sms_form.html.erb +21 -0
  25. data/app/views/catalog/_sort_and_per_page.html.erb +23 -0
  26. data/app/views/catalog/_uva_tabs.html.erb +10 -0
  27. data/app/views/catalog/about.html.erb +0 -0
  28. data/app/views/catalog/show.html.erb +40 -0
  29. data/app/views/layouts/hydra-head.html.erb +47 -0
  30. data/config/jetty.yml +6 -0
  31. data/config/locales/hydra.en.yml +7 -0
  32. data/hydra-core.gemspec +40 -0
  33. data/lib/application_helper.rb +3 -0
  34. data/lib/generators/hydra/assets_generator.rb +50 -0
  35. data/lib/generators/hydra/cucumber_support_generator.rb +29 -0
  36. data/lib/generators/hydra/head_generator.rb +160 -0
  37. data/lib/generators/hydra/hyhead_fixtures_generator.rb +27 -0
  38. data/lib/generators/hydra/templates/catalog_controller.rb +162 -0
  39. data/lib/generators/hydra/templates/config/fedora.yml +14 -0
  40. data/lib/generators/hydra/templates/config/initializers/action_dispatch_http_upload_monkey_patch.rb +12 -0
  41. data/lib/generators/hydra/templates/config/initializers/hydra_config.rb +39 -0
  42. data/lib/generators/hydra/templates/config/role_map_cucumber.yml +10 -0
  43. data/lib/generators/hydra/templates/config/role_map_development.yml +12 -0
  44. data/lib/generators/hydra/templates/config/role_map_production.yml +2 -0
  45. data/lib/generators/hydra/templates/config/role_map_test.yml +15 -0
  46. data/lib/generators/hydra/templates/config/solr.yml +10 -0
  47. data/lib/generators/hydra/templates/config/solr_mappings.yml +22 -0
  48. data/lib/generators/hydra/templates/fedora_conf/conf/development/fedora.fcfg +946 -0
  49. data/lib/generators/hydra/templates/fedora_conf/conf/test/fedora.fcfg +946 -0
  50. data/lib/generators/hydra/templates/solr_conf/conf/schema.xml +692 -0
  51. data/lib/generators/hydra/templates/solr_conf/conf/solrconfig.xml +1887 -0
  52. data/lib/generators/hydra/templates/solr_conf/solr.xml +35 -0
  53. data/lib/hydra-core.rb +1 -0
  54. data/lib/hydra-head.rb +27 -0
  55. data/lib/hydra-head/engine.rb +14 -0
  56. data/lib/hydra-head/routes.rb +90 -0
  57. data/lib/hydra-head/version.rb +4 -0
  58. data/lib/hydra.rb +30 -0
  59. data/lib/hydra/catalog.rb +11 -0
  60. data/lib/hydra/controller.rb +25 -0
  61. data/lib/hydra/controller/controller_behavior.rb +39 -0
  62. data/lib/hydra/controller/repository_controller_behavior.rb +78 -0
  63. data/lib/hydra/controller/upload_behavior.rb +139 -0
  64. data/lib/hydra/global_configurable.rb +46 -0
  65. data/lib/hydra/model_methods.rb +109 -0
  66. data/lib/hydra/model_mixins/common_metadata.rb +25 -0
  67. data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
  68. data/lib/hydra/models/file_asset.rb +76 -0
  69. data/lib/hydra/repository_controller.rb +28 -0
  70. data/lib/hydra/solr.rb +9 -0
  71. data/lib/railties/active-fedora.rake +1 -0
  72. data/lib/railties/hydra-fixtures.rake +50 -0
  73. data/lib/railties/hydra_jetty.rake +53 -0
  74. data/spec/.gitignore +1 -0
  75. data/spec/controllers/catalog_controller_spec.rb +101 -0
  76. data/spec/controllers/catalog_valid_html_spec.rb +114 -0
  77. data/spec/factories.rb +11 -0
  78. data/spec/helpers/blacklight_helper_spec.rb +15 -0
  79. data/spec/helpers/facets_helper_spec.rb +15 -0
  80. data/spec/lib/catalog_spec.rb +16 -0
  81. data/spec/lib/global_configurable_spec.rb +98 -0
  82. data/spec/lib/model_methods_spec.rb +29 -0
  83. data/spec/lib/repository_controller_behavior_spec.rb +28 -0
  84. data/spec/models/mods_asset_spec.rb +21 -0
  85. data/spec/models/solr_document_spec.rb +17 -0
  86. data/spec/models/user_spec.rb +32 -0
  87. data/spec/rcov.opts +3 -0
  88. data/spec/spec.opts +4 -0
  89. data/spec/spec_helper.rb +26 -0
  90. data/spec/support/Gemfile +12 -0
  91. data/spec/support/app/models/generic_content.rb +23 -0
  92. data/spec/support/app/models/sample.rb +33 -0
  93. data/spec/support/app/models/solr_document.rb +5 -0
  94. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  95. data/spec/support/lib/generators/test_app_generator.rb +33 -0
  96. data/spec/support/matchers/helper_matcher.rb +14 -0
  97. data/spec/support/matchers/solr_matchers.rb +60 -0
  98. data/spec/support/spec/fixtures/hydra_test_generic_content.foxml.xml +138 -0
  99. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +234 -0
  100. data/spec/unit/hydra-head-engine_spec.rb +8 -0
  101. data/spec/unit/hydra-head_spec.rb +8 -0
  102. data/tasks/hydra-head-fixtures.rake +58 -0
  103. data/tasks/hydra_jetty.rake +53 -0
  104. data/tasks/rspec.rake +53 -0
  105. metadata +469 -0
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ # This uses nokogiri to check formedness. It's slightly less strict than the markup_validit
4
+ # currently not being used.
5
+ def well_formed(html)
6
+ begin
7
+ Nokogiri::XML(html.gsub("&", "&" )) { |config| config.strict } #Literal & in text are not allowed, but we don't care.
8
+ return "ok"
9
+ rescue Nokogiri::XML::SyntaxError => e
10
+ # Write the offensive HTML to a file in tmp/html_validity_failures with a filename based on Time.now.iso8601
11
+ html_failures_dir = File.expand_path(File.dirname(__FILE__) + '/../../tmp/html_validity_failures')
12
+ FileUtils.mkdir_p(html_failures_dir)
13
+ filename = Time.now.iso8601(3).gsub(":","")+".html"
14
+ file_path = File.join(html_failures_dir, filename)
15
+ file = File.open(file_path, "w")
16
+ file.write(html)
17
+ return "#{e.inspect} -- Line: #{e.line} -- Level: #{e.level} -- Code: #{e.code}. HTML Saved to RAILS_ROOT/tmp/html_validity_failures/#{filename}"
18
+ end
19
+ end
20
+
21
+
22
+
23
+ # This checks document for validity (if required) and well formedness
24
+ # Pass in a html string. IF you want to check for XHTML validity, do rake spec HTML_VALIDITY=true. Otherwise only document form is checked
25
+ # by nokogiri.
26
+ def document_check(html, html_validity=ENV["HTML_VALIDITY"])
27
+ if html_validity == "true" || html_validity == true
28
+ html.should be_xhtml_transitional
29
+ end
30
+ well_formed(html).should == "ok"
31
+ end
32
+
33
+
34
+ describe CatalogController do
35
+ describe "Home Page" do
36
+
37
+ it "Should have Valid HTML when not logged in" do
38
+ controller.stub(:current_user).and_return(nil)
39
+ get("index", "controller"=>"catalog")
40
+ document_check(response.body)
41
+ end
42
+
43
+ it "Should have Valid HTML when I'm logged in" do
44
+ mock_user = FactoryGirl.build(:user, :email=>"archivist1@example.com")
45
+ mock_user.stub(:can_be_superuser?).and_return(true)
46
+ mock_user.stub(:is_being_superuser?).and_return(true)
47
+
48
+ sign_in mock_user
49
+ get("index", "controller"=>"catalog")
50
+ document_check(response.body)
51
+ end
52
+ end
53
+
54
+ describe "Document Pages" do
55
+
56
+ before(:each) do
57
+ mock_user = FactoryGirl.build(:user, :email=>"archivist1@example.com")
58
+ mock_user.stub(:can_be_superuser?).and_return(true)
59
+ mock_user.stub(:is_being_superuser?).and_return(true)
60
+ sign_in mock_user
61
+ end
62
+
63
+ #Article Data Type
64
+ it "Should have valid html when in Article Edit Show" do
65
+ controller.session[:viewing_context] = "edit"
66
+ get(:show, {:id=>"hydrangea:fixture_mods_article1"}, :action=>"edit")
67
+ document_check(response.body)
68
+ end
69
+
70
+ it "Should have valid html when in Article Browse Show" do
71
+
72
+ controller.session[:viewing_context] = "browse"
73
+ get(:show, {:id=>"hydrangea:fixture_mods_article1"}, :action=>"browse")
74
+ document_check(response.body)
75
+ end
76
+
77
+ #Data Set Data Type
78
+ it "Should have valid html when in Dataset Edit Show" do
79
+ controller.session[:viewing_context] = "edit"
80
+ get(:show, {:id=>"hydrangea:fixture_mods_dataset1"}, :action=>"edit")
81
+ document_check(response.body)
82
+ end
83
+
84
+ it "Should have valid html when in Dataset Browse Show" do
85
+ controller.session[:viewing_context] = "browse"
86
+ get(:show, {:id=>"hydrangea:fixture_mods_dataset1"}, :action=>"browse")
87
+ document_check(response.body)
88
+ end
89
+
90
+ #APO datatype hydrus:admin_class1
91
+ it "Should have valid html when in Dataset Edit Show" do
92
+ controller.session[:viewing_context] = "edit"
93
+ get(:show, {:id=>"hydrus:admin_class1"}, :action=>"edit")
94
+ document_check(response.body)
95
+ end
96
+
97
+ it "Should have valid html when in Dataset Browse Show" do
98
+ controller.session[:viewing_context] = "browse"
99
+ get(:show, {:id=>"hydrus:admin_class1"}, :action=>"browse")
100
+ File.open('/tmp/out.xml', 'w') { |f| f << response.body }
101
+ document_check(response.body)
102
+
103
+ end
104
+
105
+ # The delete view should be the same for all data types
106
+ it "Should have valid html when in Dataset Delete" do
107
+ get(:show, {:id=>"hydrangea:fixture_mods_dataset1"}, :action=>"delete")
108
+ document_check(response.body)
109
+ end
110
+
111
+
112
+ end #Document pages
113
+
114
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ sequence :email do |n|
3
+ "person#{n}@example.com"
4
+ end
5
+
6
+ factory :user do
7
+ email
8
+ password 'password'
9
+ end
10
+
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe BlacklightHelper do
4
+ describe "document_partial_name" do
5
+ it "Should lop off everything before the first colin after the slash" do
6
+ @config = Blacklight::Configuration.new.configure do |config|
7
+ config.show.display_type = 'has_model_s'
8
+ end
9
+ helper.stub(:blacklight_config).and_return(@config)
10
+ helper.document_partial_name('has_model_s' => ["info:fedora/afmodel:Presentation"]).should == "presentations"
11
+ helper.document_partial_name('has_model_s' => ["info:fedora/hull-cModel:genericContent"]).should == "generic_contents"
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe FacetsHelper do
4
+
5
+ describe "render_selected_facet_value" do
6
+ it "should be html_safe and not have the remove link" do
7
+ item = stub("item", :value=>'two', :hits=>9)
8
+
9
+ ret_val = helper.render_selected_facet_value("one", item)
10
+ ret_val.should == "<span class=\"selected\">two <span class=\"count\">(9)</span></span>"
11
+ ret_val.should be_html_safe
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Hydra::Controller::ControllerBehavior do
4
+
5
+ before(:all) do
6
+ class CatalogTest < ApplicationController
7
+ include Hydra::Controller::ControllerBehavior
8
+ end
9
+ @catalog = CatalogTest.new
10
+ end
11
+
12
+ it "should extend classes with the necessary Hydra modules" do
13
+ CatalogTest.included_modules.should include(Hydra::AccessControlsEnforcement)
14
+ end
15
+
16
+ end
@@ -0,0 +1,98 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe Hydra::GlobalConfigurable do
5
+
6
+ class TestConfig
7
+ extend Hydra::GlobalConfigurable
8
+ end
9
+
10
+ before(:each) do
11
+ TestConfig.reset_configs!
12
+ end
13
+
14
+ it "should respond to configure" do
15
+ TestConfig.respond_to? :configure
16
+ end
17
+
18
+ describe "the default state" do
19
+ describe "config" do
20
+ it "should be a Hash" do
21
+ TestConfig.config.should be_a Hash
22
+ end
23
+ end
24
+ describe "configs[:shared]" do
25
+ it "should be a Hash" do
26
+ TestConfig.configs[:shared].should be_a Hash
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "configs[:shared]" do
32
+ it "should not have the values of its members altered by other environments" do
33
+ TestConfig.configure do |config|
34
+ config[:key] = ":shared value"
35
+ end
36
+ TestConfig.configure(::Rails.env) do |config|
37
+ config[:key] = ":test value"
38
+ end
39
+ TestConfig.config[:key].should == ":test value"
40
+ TestConfig.configs[:shared][:key].should == ":shared value"
41
+ TestConfig.configs[::Rails.env][:key].should == ":test value"
42
+ end
43
+ end
44
+
45
+ describe "the #configure method behavior" do
46
+ it "requires a block" do
47
+ lambda{TestConfig.configure}.should raise_error(LocalJumpError)
48
+ end
49
+ it "yields a hash" do
50
+ TestConfig.configure{|config| config.should be_a(Hash) }
51
+ end
52
+ it "should clear the configs if reset_configs! is called" do
53
+ TestConfig.configure do |config|
54
+ config[:asdf] = 'asdf'
55
+ end
56
+ TestConfig.configs[:shared][:asdf].should == 'asdf'
57
+ TestConfig.reset_configs!
58
+ TestConfig.configs[:shared][:asdf].should == nil
59
+ end
60
+
61
+ it "should merge settings from the :shared environment" do
62
+ TestConfig.configure do |config|
63
+ config[:app_id] = 'Blacklight'
64
+ config[:mode] = :shared!
65
+ end
66
+ TestConfig.configure(::Rails.env) do |config|
67
+ config[:mode] = ::Rails.env
68
+ end
69
+ TestConfig.config[:app_id].should == 'Blacklight'
70
+ TestConfig.config[:mode].should_not == :shared!
71
+ TestConfig.config[:mode].should == ::Rails.env
72
+ end
73
+ end
74
+
75
+ describe "config" do
76
+ it "should return an empty Hash if nothing was configured" do
77
+ TestConfig.config.should == {}
78
+ end
79
+
80
+ it "should return only what is in configs[:shared] if no other environment was configured" do
81
+ TestConfig.configure(:shared) do |config|
82
+ config[:foo] = 'bar'
83
+ config[:baz] = 'dang'
84
+ end
85
+ TestConfig.config.should == {:foo => 'bar', :baz => 'dang'}
86
+ TestConfig.config.should == TestConfig.configs[:shared]
87
+ end
88
+
89
+ it "should return a merge of configs[:shared] and configs[RAILS_ENV]" do
90
+ TestConfig.configure(:shared) do |config|
91
+ config[:foo] = 'bar'
92
+ config[:baz] = 'dang'
93
+ end
94
+ end
95
+ end
96
+
97
+
98
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Hydra::ModelMethods do
4
+
5
+ before :all do
6
+ class TestModel < ActiveFedora::Base
7
+ include Hydra::ModelMixins::CommonMetadata
8
+ include Hydra::ModelMethods
9
+ has_metadata :name => "properties", :type => Hydra::Datastream::Properties
10
+ end
11
+ end
12
+
13
+ describe "apply_depositor_metadata" do
14
+ subject {TestModel.new }
15
+ it "should add edit access" do
16
+ subject.apply_depositor_metadata('naomi')
17
+ subject.rightsMetadata.individuals.should == {'naomi' => 'edit'}
18
+ end
19
+ it "should not overwrite people with edit access" do
20
+ subject.rightsMetadata.permissions({:person=>"jessie"}, 'edit')
21
+ subject.apply_depositor_metadata('naomi')
22
+ subject.rightsMetadata.individuals.should == {'naomi' => 'edit', 'jessie' =>'edit'}
23
+ end
24
+ it "should set depositor" do
25
+ subject.apply_depositor_metadata('chris')
26
+ subject.properties.depositor.should == ['chris']
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Controller::RepositoryControllerBehavior do
4
+ before(:all) do
5
+ class RepositoryControllerTest < ApplicationController
6
+ include Hydra::Controller::RepositoryControllerBehavior
7
+ end
8
+ end
9
+
10
+ subject { RepositoryControllerTest.new }
11
+
12
+ describe "load_document" do
13
+ it "should load the model for the pid" do
14
+ mock_model = mock("model")
15
+ subject.stub(:params).and_return( {:id => "object id"} )
16
+ ActiveFedora::Base.should_receive(:find).with("object id", :cast=>true).and_return(mock_model)
17
+ subject.send(:load_document).should == mock_model
18
+ end
19
+ end
20
+
21
+ describe "format_pid" do
22
+ it "convert pids into XHTML safe strings" do
23
+ pid = subject.format_pid("hydra:123")
24
+ pid.should match(/hydra_123/)
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ModsAsset do
4
+
5
+ before(:each) do
6
+ @asset = ModsAsset.new nil
7
+ end
8
+
9
+ it "Should be a kind of ActiveFedora::Base" do
10
+ @asset.should be_kind_of(ActiveFedora::Base)
11
+ end
12
+
13
+ it "should set up descMetadata and rightsMetadata datastreams" do
14
+ # Mods article was moved to the mods gem. Ask cbeer about this. Jcoyne 2012-07-10
15
+ #@asset.datastreams.should have_key("descMetadata")
16
+ #@asset.datastreams["descMetadata"].should be_instance_of(Hydra::Datastream::ModsArticle)
17
+ @asset.datastreams.should have_key("rightsMetadata")
18
+ @asset.datastreams["rightsMetadata"].should be_instance_of(Hydra::Datastream::RightsMetadata)
19
+ end
20
+
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SolrDocument do
4
+ describe "#to_model" do
5
+
6
+ before do
7
+ class SolrDocumentWithHydraOverride < SolrDocument
8
+ include Hydra::Solr::Document
9
+ end
10
+ end
11
+ # this isn't a great test, but...
12
+ it "should try to cast the SolrDocument to the Fedora object" do
13
+ ActiveFedora::Base.should_receive(:load_instance_from_solr).with('asdfg', kind_of(SolrDocument))
14
+ SolrDocumentWithHydraOverride.new(:id => 'asdfg').to_model
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+
5
+ describe "user_key" do
6
+ before do
7
+ @user = User.new(:email=>"foo@example.com")
8
+ @user.stub(:username =>'foo')
9
+ end
10
+
11
+ it "should return email" do
12
+ @user.user_key.should == 'foo@example.com'
13
+ end
14
+
15
+ it "should return username" do
16
+ Devise.stub(:authentication_keys =>[:username])
17
+ @user.user_key.should == 'foo'
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ module UserTestAttributes
25
+ ['first_name','last_name','full_name','affiliation','photo'].each do |attr|
26
+ class_eval <<-EOM
27
+ def #{attr}
28
+ "test_#{attr}"
29
+ end
30
+ EOM
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ --exclude "spec/*,gems/*,features/*"
2
+ --rails
3
+ --aggregate coverage.data
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ ENV["RAILS_ENV"] ||= "test"
5
+
6
+ require File.expand_path("config/environment", ENV['RAILS_ROOT'] || File.expand_path("../internal", __FILE__))
7
+ require 'bundler/setup'
8
+ require 'rspec/rails'
9
+ require 'rspec/autorun'
10
+ require 'hydra-core'
11
+
12
+ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
13
+ require 'simplecov'
14
+ require 'simplecov-rcov'
15
+
16
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
17
+ SimpleCov.start
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.include Devise::TestHelpers, :type => :controller
22
+
23
+
24
+ end
25
+
26
+