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,46 @@
1
+ module Hydra::GlobalConfigurable
2
+
3
+ # The config environment name used by the #config method
4
+ #
5
+ # Example:
6
+ # class MyThing
7
+ # extend Hydra::GlobalConfigurable
8
+ # end
9
+ #
10
+ # Now MyThing.config will be the result of:
11
+ # MyThing.configure(:production) {|config|}
12
+ #
13
+ # You set shared attributes by leaving the first argument blank or passing the :shared value:
14
+ # MyThing.configure {|config|}
15
+ # or
16
+ # MyThing.configure(:shared) {|config|}
17
+
18
+ # sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil
19
+ def reset_configs!
20
+ @config = nil
21
+ @configs = {:shared=>{}}
22
+ end
23
+
24
+ # A hash of all environment configs
25
+ # The key is the environment name, the value a Hash
26
+ def configs
27
+ @configs ? @configs : (reset_configs! and @configs)
28
+ end
29
+
30
+ # The main config accessor. It merges the current configs[::Rails.env]
31
+ # with configs[:shared] and lazy-loads @config to the result.
32
+ def config
33
+ @config ||= configs[:shared].merge(configs[::Rails.env] ||= {})
34
+ end
35
+ alias_method :blacklight_config, :config
36
+
37
+ # Accepts a value for the environment to configure and a block
38
+ # A hash is yielded to the block
39
+ # If the "env" != :shared,
40
+ # the hash is created by deep cloning the :shared environment config.
41
+ # This makes it possible to create defaults in the :shared config
42
+ def configure(env = :shared, &blk)
43
+ configs[env] = {}
44
+ yield configs[env]
45
+ end
46
+ end
@@ -0,0 +1,109 @@
1
+ # will move to lib/hydra/model/model_behavior.rb (with appropriate namespace changes) in release 5.x
2
+ module Hydra::ModelMethods
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ unless self.class == Module
7
+ self.has_many :parts, :class_name=>'ActiveFedora::Base', :property=>:is_part_of
8
+ end
9
+ end
10
+
11
+ #
12
+ # Adds metadata about the depositor to the asset
13
+ # Most important behavior: if the asset has a rightsMetadata datastream, this method will add +depositor_id+ to its individual edit permissions.
14
+ #
15
+ def apply_depositor_metadata(depositor_id)
16
+ prop_ds = self.datastreams["properties"]
17
+ rights_ds = self.datastreams["rightsMetadata"]
18
+
19
+ if prop_ds
20
+ prop_ds.depositor = depositor_id unless prop_ds.nil?
21
+ end
22
+ rights_ds.permissions({:person=>depositor_id}, 'edit') unless rights_ds.nil?
23
+ return true
24
+ end
25
+
26
+ #
27
+ # Set the collection type (e.g. hydrangea_article) for the asset
28
+ #
29
+ def set_collection_type(collection)
30
+ prop_ds = self.datastreams["properties"]
31
+ if !prop_ds.nil? && prop_ds.respond_to?(:collection_values)
32
+ prop_ds.collection_values = collection
33
+ end
34
+ end
35
+
36
+ # Set the title and label on the current object
37
+ #
38
+ # @param [String] new_title
39
+ # @param [Hash] opts (optional) hash of configuration options
40
+ #
41
+ # @example Use :only_if_blank option to only update the values when the label is empty
42
+ # obj.set_title_and_label("My Title", :only_if_blank=> true)
43
+ def set_title_and_label(new_title, opts={})
44
+ if opts[:only_if_blank]
45
+ if self.label.nil? || self.label.empty?
46
+ self.label = new_title
47
+ self.set_title( new_title )
48
+ end
49
+ else
50
+ self.label = new_title
51
+ set_title( new_title )
52
+ end
53
+ end
54
+
55
+ # Set the title and label on the current object
56
+ #
57
+ # @param [String] new_title
58
+ # @param [Hash] opts (optional) hash of configuration options
59
+ def set_title(new_title, opts={})
60
+ if self.datastreams.has_key?("descMetadata")
61
+ desc_metadata_ds = self.datastreams["descMetadata"]
62
+ if desc_metadata_ds.respond_to?(:title_values)
63
+ desc_metadata_ds.title_values = new_title
64
+ else
65
+ desc_metadata_ds.title = new_title
66
+ end
67
+ end
68
+ end
69
+
70
+ # Call insert_contributor on the descMetadata datastream
71
+ def insert_contributor(type, opts={})
72
+ ds = self.datastreams["descMetadata"]
73
+ node, index = ds.insert_contributor(type,opts)
74
+ return node, index
75
+ end
76
+
77
+ # Call remove_contributor on the descMetadata datastream
78
+ def remove_contributor(type, index)
79
+ ds = self.datastreams["descMetadata"]
80
+ result = ds.remove_contributor(type,index)
81
+ return result
82
+ end
83
+
84
+ # Call to remove file objects
85
+ def destroy_child_assets
86
+ destroyable_child_assets.each.inject([]) do |destroyed,fo|
87
+ destroyed << fo.pid
88
+ fo.delete
89
+ destroyed
90
+ end
91
+
92
+ end
93
+
94
+ def destroyable_child_assets
95
+ return [] unless self.parts
96
+ self.parts.each.inject([]) do |file_assets, fo|
97
+ parents = fo.ids_for_outbound(:is_part_of)
98
+ if parents.length == 1 && parents.first.match(/#{self.pid}$/)
99
+ file_assets << fo
100
+ end
101
+ file_assets
102
+ end
103
+ end
104
+
105
+ def file_asset_count
106
+ ### TODO switch to AF::Base.count
107
+ parts.length
108
+ end
109
+ end
@@ -0,0 +1,25 @@
1
+ # Include this into models that you want to conform to the Hydra commonMetadata cModel
2
+ # See https://wiki.duraspace.org/display/hydra/Hydra+objects%2C+content+models+%28cModels%29+and+disseminators#Hydraobjects%2Ccontentmodels%28cModels%29anddisseminators-models
3
+ #
4
+ # Explicitly declares:
5
+ # rightsMetadata datastream using Hydra::RightsMetadata Terminology
6
+ #
7
+ # Does not explicitly declare:
8
+ # descMetadata datastream -- should be declared by a more specific mixin like Hydra::ModelMixins::ModsObject
9
+ # DC datastream -- Handled by ActiveFedora::Base
10
+ # RELS-EXT datastream -- Handled by ActiveFedora::Base & ActiveFedora::RelsExtDatastream
11
+ # optional datastreams (contentMetadata, technicalMetadata, provenanceMetadata, sourceMetadata)
12
+ #
13
+ # will move to lib/hydra/model/common_metadata_behavior in release 5.x
14
+ module Hydra::ModelMixins
15
+ module CommonMetadata
16
+
17
+ def self.included(klazz)
18
+ # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
19
+ klazz.has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
20
+
21
+ # Ensure that objects assert the commonMetadata cModel
22
+ # klazz.relationships << :has_model => "info:fedora/hydra-cModel:commonMetadata"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Hydra::ModelMixins
2
+ module SolrDocumentExtension
3
+ def document_type display_type = CatalogController.blacklight_config.show.display_type
4
+ type = self.fetch(:medium_t, nil)
5
+
6
+ type ||= self.fetch(display_type, nil) if display_type
7
+
8
+ type.first.to_s.gsub("info:fedora/afmodel:","").gsub("Hydrangea","").gsub(/^Generic/,"")
9
+ end
10
+
11
+ def get_person_from_role(role, opts={})
12
+ i = 0
13
+ while i < 10
14
+ persons_roles = self["person_#{i}_role_t"].map{|w|w.strip.downcase} unless self["person_#{i}_role_t"].nil?
15
+ if persons_roles and persons_roles.include?(role.downcase)
16
+ return {:first=>self["person_#{i}_first_name_t"], :last=>self["person_#{i}_last_name_t"]}
17
+ end
18
+ i += 1
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ SolrDocument.use_extension Hydra::ModelMixins::SolrDocumentExtension
@@ -0,0 +1,76 @@
1
+ # will move to lib/hydra/model/file_asset_behavior in release 5.x
2
+ module Hydra
3
+ module Models
4
+ # Defines Behaviors for a FileAsset Model
5
+ # Conforms to the Hydra genericContent cModel -- the "content" is in a datastream called content
6
+ # TODO: Could we just move this behavior into app/models/file_asset.rb?
7
+ module FileAsset
8
+ extend ActiveSupport::Concern
9
+ included do
10
+ include Hydra::ModelMethods
11
+
12
+ belongs_to :container, :class_name=>'ActiveFedora::Base', :property=>:is_part_of
13
+ has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
14
+ end
15
+ end
16
+
17
+
18
+ # Returns a human readable filesize appropriate for the given number of bytes (ie. automatically chooses 'bytes','KB','MB','GB','TB')
19
+ # Based on a bit of python code posted here: http://blogmag.net/blog/read/38/Print_human_readable_file_size
20
+ # @param [Numeric] num file size in bits
21
+ def bits_to_human_readable(num)
22
+ ['bytes','KB','MB','GB','TB'].each do |x|
23
+ if num < 1024.0
24
+ return "#{num.to_i} #{x}"
25
+ else
26
+ num = num/1024.0
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ def label
33
+ descMetadata.title.first
34
+ end
35
+
36
+ def label=(label)
37
+ super
38
+ descMetadata.title = label
39
+ end
40
+
41
+ # augments add_file_datastream to also put file size (in bytes/KB/MB/GB/TB) in dc:extent
42
+ def add_file_datastream(file, opts={})
43
+ super
44
+ if file.respond_to?(:size)
45
+ size = bits_to_human_readable(file.size)
46
+ elsif file.kind_of?(File)
47
+ size = bits_to_human_readable(File.size(file))
48
+ else
49
+ size = ""
50
+ end
51
+ datastreams["descMetadata"].extent = size
52
+ end
53
+
54
+ # Override ActiveFedora::Base.to_solr to...
55
+ # Check if we are dealing with a child of FileAsset and if so when calling to_solr from Solrizer indexer we want to skip loading parent metadata again
56
+ #
57
+ # if known models greater than one (without ActiveFedora::Base) and
58
+ # known models contains a child of FileAsset and
59
+ # opts[:model_only] == true and
60
+ # current object class is FileAsset
61
+ # that means that the child already has had to_solr called which included metadata from FileAsset
62
+ # if any of the above is false then call to_solr as normal
63
+ def to_solr(solr_doc=Hash.new, opts={})
64
+
65
+ active_fedora_model_s = solr_doc["active_fedora_model_s"] if solr_doc["active_fedora_model_s"]
66
+ actual_class = active_fedora_model_s.constantize if active_fedora_model_s
67
+ if actual_class && actual_class != self.class && actual_class.superclass == ::FileAsset
68
+ solr_doc
69
+ else
70
+ super(solr_doc,opts)
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ # Hydra-repository Contoller is a controller layer mixin. It is in the controller scope: request params, session etc.
2
+ #
3
+ # will move to lib/hydra/controller/repository_controller_behavior in release 5.x
4
+ #
5
+ # NOTE: Be careful when creating variables here as they may be overriding something that already exists.
6
+ # The ActionController docs: http://api.rubyonrails.org/classes/ActionController/Base.html
7
+ #
8
+ # Override these methods in your own controller for customizations:
9
+ #
10
+ # class HomeController < ActionController::Base
11
+ #
12
+ # include Stanford::SolrHelper
13
+ #
14
+ # def solr_search_params
15
+ # super.merge :per_page=>10
16
+ # end
17
+ #
18
+ # end
19
+ #
20
+ module Hydra::RepositoryController
21
+ extend ActiveSupport::Concern
22
+
23
+ included do
24
+ ActiveSupport::Deprecation.warn "Hydra::RepositoryController has moved to Hydra::Controller::RepositoryControllerBehavior"
25
+ include Hydra::Controller::RepositoryControllerBehavior
26
+ end
27
+
28
+ end
@@ -0,0 +1,9 @@
1
+ module Hydra
2
+ module Solr
3
+ module Document
4
+ def to_model
5
+ ActiveFedora::Base.load_instance_from_solr(id, self)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require "active-fedora" # This causes active-fedora's rake tasks to be loaded
@@ -0,0 +1,50 @@
1
+ namespace :hydra do
2
+
3
+ desc "Init Hydra configuration"
4
+ task :init => [:environment] do
5
+ # We need to just start rails so that all the models are loaded
6
+ end
7
+
8
+ desc "Load hydra-head models"
9
+ task :load_models do
10
+ require "hydra"
11
+ Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), "..",'app','models', '*.rb')).each do |model|
12
+ load model
13
+ end
14
+ end
15
+
16
+ namespace :fixtures do
17
+ task :load do
18
+ ENV["dir"] ||= File.join("spec", "fixtures")
19
+ loader = ActiveFedora::FixtureLoader.new(ENV['dir'])
20
+ Dir.glob("#{ENV['dir']}/*.foxml.xml").each do |fixture_path|
21
+ pid = File.basename(fixture_path, ".foxml.xml").sub("_",":")
22
+ begin
23
+ foo = loader.reload(pid)
24
+ puts "Updated #{pid}"
25
+ rescue Errno::ECONNREFUSED => e
26
+ puts "Can't connect to Fedora! Are you sure jetty is running? (#{ActiveFedora::Base.connection_for_pid(pid).inspect})"
27
+ rescue Exception => e
28
+ puts("Received a Fedora error while loading #{pid}\n#{e}")
29
+ logger.error("Received a Fedora error while loading #{pid}\n#{e}")
30
+ end
31
+ end
32
+ end
33
+
34
+ desc "Remove default Hydra fixtures"
35
+ task :delete do
36
+ ENV["dir"] ||= File.join("spec", "fixtures")
37
+ loader = ActiveFedora::FixtureLoader.new(ENV['dir'])
38
+ Dir.glob("#{ENV['dir']}/*.foxml.xml").each do |fixture_path|
39
+ ENV["pid"] = File.basename(fixture_path, ".foxml.xml").sub("_",":")
40
+ Rake::Task["repo:delete"].reenable
41
+ Rake::Task["repo:delete"].invoke
42
+ end
43
+ end
44
+
45
+ desc "Refresh default Hydra fixtures"
46
+ task :refresh => [:delete, :load]
47
+
48
+ end
49
+ end
50
+
@@ -0,0 +1,53 @@
1
+ namespace :jetty do
2
+ desc "Apply all configs to Testing Server (relies on hydra:jetty:config tasks unless you override it)"
3
+ task :config do
4
+ Rake::Task["hydra:jetty:config"].invoke
5
+ end
6
+ end
7
+
8
+ namespace :hydra do
9
+ namespace :jetty do
10
+ desc "Copies the default Solr & Fedora configs into the bundled Hydra Testing Server"
11
+ task :config do
12
+ Rake::Task["hydra:jetty:config_fedora"].invoke
13
+ Rake::Task["hydra:jetty:config_solr"].invoke
14
+ end
15
+
16
+ desc "Copies the contents of solr_conf into the Solr development-core and test-core of Testing Server"
17
+ task :config_solr do
18
+ FileList['solr_conf/conf/*'].each do |f|
19
+ cp("#{f}", 'jetty/solr/development-core/conf/', :verbose => true)
20
+ cp("#{f}", 'jetty/solr/test-core/conf/', :verbose => true)
21
+ end
22
+ end
23
+
24
+ desc "Copies a custom fedora config for the bundled Hydra Testing Server"
25
+ task :config_fedora do
26
+ # load a custom fedora.fcfg -
27
+ if defined?(Rails.root)
28
+ app_root = Rails.root
29
+ else
30
+ app_root = File.join(File.dirname(__FILE__),"..")
31
+ end
32
+
33
+ fcfg = File.join(app_root,"fedora_conf","conf","development","fedora.fcfg")
34
+ if File.exists?(fcfg)
35
+ puts "copying over development/fedora.fcfg"
36
+ cp("#{fcfg}", 'jetty/fedora/default/server/config/', :verbose => true)
37
+ else
38
+ puts "#{fcfg} file not found -- skipping fedora config"
39
+ end
40
+ fcfg = File.join(app_root,"fedora_conf","conf","test","fedora.fcfg")
41
+ if File.exists?(fcfg)
42
+ puts "copying over test/fedora.fcfg"
43
+ cp("#{fcfg}", 'jetty/fedora/test/server/config/', :verbose => true)
44
+ else
45
+ puts "#{fcfg} file not found -- skipping fedora config"
46
+ end
47
+ end
48
+
49
+ desc "Copies the default SOLR config files and starts up the fedora instance."
50
+ task :load => [:config, 'jetty:start']
51
+
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ internal
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ # See cucumber tests (ie. /features/edit_document.feature) for more tests, including ones that test the edit method & view
4
+ # You can run the cucumber tests with
5
+ #
6
+ # cucumber --tags @edit
7
+ # or
8
+ # rake cucumber
9
+
10
+ describe CatalogController do
11
+
12
+ before do
13
+ session[:user]='bob'
14
+ end
15
+
16
+ it "should use CatalogController" do
17
+ controller.should be_an_instance_of(CatalogController)
18
+ end
19
+
20
+
21
+ describe "Paths Generated by Custom Routes:" do
22
+ # paths generated by custom routes
23
+ it "should map {:controller=>'catalog', :action=>'index'} to GET /catalog" do
24
+ { :get => "/catalog" }.should route_to(:controller => 'catalog', :action => 'index')
25
+ end
26
+ it "should map {:controller=>'catalog', :action=>'show', :id=>'test:3'} to GET /catalog/test:3" do
27
+ { :get => "/catalog/test:3" }.should route_to(:controller => 'catalog', :action => 'show', :id=>'test:3')
28
+ end
29
+ it "should map {:controller=>'catalog', :action=>'edit', :id=>'test:3'} to GET /catalog/test:3" do
30
+ { :get => "/catalog/test:3/edit" }.should route_to(:controller => 'catalog', :action => 'edit', :id=>'test:3')
31
+ end
32
+
33
+ it "should map catalog_path" do
34
+ # catalog_path.should == '/catalog'
35
+ catalog_path("test:3").should == '/catalog/test:3'
36
+ end
37
+ end
38
+
39
+ it "should not choke on objects with periods in ids (ie Fedora system objects)" do
40
+ pending "Need to override blacklight routes"
41
+
42
+ ## We could do something like this to remove the catalog/show route and replace it with a route that allows dots (e.g. resources :catalog, :id=> /.+/)
43
+ # def add_route
44
+ # new_route = ActionController::Routing::Routes.builder.build(name, route_options)
45
+ # ActionController::Routing::Routes.routes.insert(0, new_route)
46
+ # end
47
+
48
+ # def remove_route
49
+ # ActionController::Routing::Routes.routes.reject! { |r| r.instance_variable_get(:@requirements)[:slug_id] == id }
50
+ # end
51
+
52
+ catalog_path("fedora-system:FedoraObject-3.0").should == '/catalog/fedora-system:FedoraObject-3.0'
53
+ { :get => "/catalog/fedora-system:FedoraObject-3.0" }.should route_to(:controller => 'catalog', :action => 'show', :id=>'fedora-system:FedoraObject-3.0')
54
+ end
55
+
56
+ describe "index" do
57
+
58
+ describe "access controls" do
59
+ before(:all) do
60
+ @public_only_results = Blacklight.solr.find Hash[:fq=>"access_t:public"]
61
+ # @public_only_results = Blacklight.solr.find Hash[:phrases=>{:access_t=>"public"}]
62
+ # @private_only_results = Blacklight.solr.find Hash[:phrases=>{:access_t=>"private"}]
63
+ @private_only_results = Blacklight.solr.find Hash[:fq=>"access_t:private"]
64
+ end
65
+
66
+ it "should only return public documents if role does not have permissions" do
67
+ controller.stub(:current_user).and_return(nil)
68
+ get :index
69
+ assigns(:document_list).count.should == @public_only_results.docs.count
70
+ end
71
+ it "should return all documents if role does have permissions" do
72
+ pending "Need to put documents into solr"
73
+ mock_user = FactoryGirl.build(:user, :email=>"BigWig@example.com")
74
+ mock_user.stub(:is_being_superuser?).and_return(true)
75
+ controller.stub(:current_user).and_return(mock_user)
76
+ get :index
77
+ ### This fails when there are more than 10 public documents in the solr index
78
+ ### TODO: instead, expect a certain query(especially the :fq component) to solr
79
+ assigns(:document_list).count.should > @public_only_results.docs.count
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "filters" do
85
+ describe "index" do
86
+ it "should trigger enforce_index_permissions" do
87
+ controller.should_receive(:add_access_controls_to_solr_params)
88
+ controller.should_receive(:enforce_index_permissions)
89
+ get :index
90
+ end
91
+ end
92
+ describe "show" do
93
+ it "should trigger enforce_show_permissions" do
94
+ controller.stub(:current_user).and_return(nil)
95
+ controller.should_receive(:enforce_show_permissions)
96
+ get :show, :id=>'test:3'
97
+ end
98
+ end
99
+ end
100
+
101
+ end