hydra-core 8.2.0 → 9.0.0.beta1

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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/hydra/controller/controller_behavior.rb +5 -6
  3. data/app/controllers/concerns/hydra/controller/download_behavior.rb +37 -39
  4. data/app/models/concerns/hydra/model_methods.rb +22 -22
  5. data/hydra-core.gemspec +3 -3
  6. data/lib/generators/hydra/head_generator.rb +0 -2
  7. data/lib/generators/hydra/templates/catalog_controller.rb +1 -2
  8. data/lib/generators/hydra/templates/config/initializers/hydra_config.rb +8 -8
  9. data/lib/hydra-core.rb +4 -0
  10. data/lib/hydra-head/version.rb +1 -2
  11. data/spec/controllers/catalog_controller_spec.rb +6 -8
  12. data/spec/controllers/downloads_controller_spec.rb +40 -47
  13. data/spec/lib/catalog_spec.rb +15 -0
  14. data/spec/lib/model_methods_spec.rb +19 -9
  15. data/spec/spec_helper.rb +9 -5
  16. data/spec/support/lib/generators/test_app_generator.rb +1 -8
  17. data/spec/support/lib/tasks/rspec.rake +2 -1
  18. data/tasks/rspec.rake +1 -7
  19. metadata +25 -31
  20. data/app/search_builders/hydra/search_builder.rb +0 -5
  21. data/lib/generators/hydra/hyhead_fixtures_generator.rb +0 -27
  22. data/lib/generators/hydra/templates/config/blacklight.yml +0 -9
  23. data/lib/railties/hydra-fixtures.rake +0 -49
  24. data/spec/models/mods_asset_spec.rb +0 -16
  25. data/spec/search_builders/search_builder_spec.rb +0 -22
  26. data/spec/support/app/models/generic_content.rb +0 -21
  27. data/spec/support/spec/fixtures/hydra_test_generic_content.foxml.xml +0 -138
  28. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +0 -234
  29. data/tasks/hydra-head-fixtures.rake +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9149fd7d024bdce7772151bc109c99c4b5d32108
4
- data.tar.gz: f00f9eacaf3fe941bbb5a136cb73c6496ab25109
3
+ metadata.gz: e233f2087f4d4d190c24ffe41bfd5915ac668bf7
4
+ data.tar.gz: 0d257fe1e9583e99e60df8d863bb30e9eba9f7c2
5
5
  SHA512:
6
- metadata.gz: 27c8e9be8cca17069ff6770d885ae4bd93879cd8a8cff3c5d57d677101edffa52ff8d5fc1e76d5cb95293a3261ca6fdac26a4c4e643f8935ad21e44e9dfadea2
7
- data.tar.gz: 15c49fd63d8820d7bce149d261c891e1bc6e16db2e1a1d8b49a5b1421fa14f009a5d5da19391837ea10324c929e97a511172626507653f0cb1381ccda602e13a
6
+ metadata.gz: 0a0843e0f816379e1da9da3e6af2c07855cbddf7310c42d63fdf45fc1f06940e8585f1a349287b974591249503a1aa5389782f8a850d6b32898a05f838c3a707
7
+ data.tar.gz: 39f081771adf23e600202ad12c4550a08ea0d7df4d8da6cc50e779bcdec2e4d7806261938258b02f0a4602402b6019105131df4d1953bab2affbb77a6e410b67
@@ -12,6 +12,9 @@ module Hydra::Controller::ControllerBehavior
12
12
  extend ActiveSupport::Concern
13
13
 
14
14
  included do
15
+ # Other modules to auto-include
16
+ include Hydra::AccessControlsEnforcement
17
+
15
18
  # Catch permission errors
16
19
  rescue_from CanCan::AccessDenied do |exception|
17
20
  if (exception.action == :edit)
@@ -24,11 +27,7 @@ module Hydra::Controller::ControllerBehavior
24
27
  end
25
28
  end
26
29
  end
27
-
28
- # Override blacklight to produce a search_builder that has the current collection in context
29
- def search_builder processor_chain = search_params_logic
30
- super.tap { |builder| builder.current_ability = current_ability }
31
- end
30
+
32
31
 
33
32
  # get the currently configured user identifier. Can be overridden to return whatever (ie. login, email, etc)
34
33
  # defaults to using whatever you have set as the Devise authentication_key
@@ -39,7 +38,7 @@ module Hydra::Controller::ControllerBehavior
39
38
  module ClassMethods
40
39
  # get the solr name for a field with this name and using the given solrizer descriptor
41
40
  def solr_name(name, *opts)
42
- ActiveFedora::SolrService.solr_name(name, *opts)
41
+ ActiveFedora::SolrQueryBuilder.solr_name(name, *opts)
43
42
  end
44
43
  end
45
44
  end
@@ -5,14 +5,12 @@ module Hydra
5
5
 
6
6
  included do
7
7
  include Hydra::Controller::ControllerBehavior
8
- before_filter :load_asset
9
- before_filter :load_datastream
10
8
  before_filter :authorize_download!
11
9
  end
12
-
10
+
13
11
  # Responds to http requests to show the datastream
14
12
  def show
15
- if datastream.new?
13
+ if datastream.new_record?
16
14
  render_404
17
15
  else
18
16
  send_content
@@ -34,41 +32,34 @@ module Hydra
34
32
  :id
35
33
  end
36
34
 
37
- def load_asset
38
- @asset = ActiveFedora::Base.load_instance_from_solr(params[asset_param_key])
39
- end
40
-
41
- def load_datastream
42
- @ds = datastream_to_show
43
- end
44
-
45
35
  # Customize the :download ability in your Ability class, or override this method
46
36
  def authorize_download!
47
37
  authorize! :download, datastream
48
38
  end
49
39
 
50
40
  def asset
51
- @asset
41
+ @asset ||= ActiveFedora::Base.find(params[asset_param_key])
52
42
  end
53
43
 
54
44
  def datastream
55
- @ds
45
+ @ds ||= datastream_to_show
56
46
  end
57
47
 
58
48
  # Override this method to change which datastream is shown.
59
- # Loads the datastream specified by the HTTP parameter `:datastream_id`.
49
+ # Loads the file specified by the HTTP parameter `:datastream_id`.
60
50
  # If this object does not have a datastream by that name, return the default datastream
61
51
  # as returned by {#default_content_ds}
62
- # @return [ActiveFedora::Datastream] the datastream
52
+ # @return [ActiveFedora::File] the file
63
53
  def datastream_to_show
64
- ds = asset.datastreams[params[:datastream_id]] if params.has_key?(:datastream_id)
65
- ds = default_content_ds if ds.nil?
54
+ ds = asset.attached_files[params[:datastream_id]] if params.has_key?(:datastream_id)
55
+ ds ||= default_content_ds
66
56
  raise "Unable to find a datastream for #{asset}" if ds.nil?
67
57
  ds
68
58
  end
69
-
59
+
70
60
  # Handle the HTTP show request
71
61
  def send_content
62
+
72
63
  response.headers['Accept-Ranges'] = 'bytes'
73
64
 
74
65
  if request.head?
@@ -82,60 +73,67 @@ module Hydra
82
73
 
83
74
  # Create some headers for the datastream
84
75
  def content_options
85
- {disposition: 'inline', type: datastream.mimeType, filename: datastream_name}
76
+ {disposition: 'inline', type: datastream.mime_type, filename: datastream_name}
86
77
  end
87
78
 
88
79
  # Override this if you'd like a different filename
89
80
  # @return [String] the filename
90
81
  def datastream_name
91
- params[:filename] || asset.label
82
+ params[:filename] || datastream.original_name || (asset.respond_to?(:label) && asset.label) || datastream.id
92
83
  end
93
84
 
94
85
 
95
86
  # render an HTTP HEAD response
96
87
  def content_head
97
- response.headers['Content-Length'] = datastream.dsSize
98
- response.headers['Content-Type'] = datastream.mimeType
88
+ response.headers['Content-Length'] = datastream.size
89
+ response.headers['Content-Type'] = datastream.mime_type
99
90
  head :ok
100
91
  end
101
-
92
+
102
93
 
103
94
  # render an HTTP Range response
104
95
  def send_range
105
96
  _, range = request.headers['HTTP_RANGE'].split('bytes=')
106
97
  from, to = range.split('-').map(&:to_i)
107
- to = datastream.dsSize - 1 unless to
98
+ to = datastream.size - 1 unless to
108
99
  length = to - from + 1
109
- response.headers['Content-Range'] = "bytes #{from}-#{to}/#{datastream.dsSize}"
100
+ response.headers['Content-Range'] = "bytes #{from}-#{to}/#{datastream.size}"
110
101
  response.headers['Content-Length'] = "#{length}"
111
102
  self.status = 206
112
103
  prepare_file_headers
113
- self.response_body = datastream.stream(from, length)
104
+ datastream.stream(request.headers['HTTP_RANGE']) do |block|
105
+ response.stream.write block
106
+ end
107
+ ensure
108
+ response.stream.close
114
109
  end
115
110
 
116
111
  def send_file_contents
117
112
  self.status = 200
118
113
  prepare_file_headers
119
- self.response_body = datastream.stream
114
+ datastream.stream do |block|
115
+ response.stream.write block
116
+ end
117
+ ensure
118
+ response.stream.close
120
119
  end
121
-
120
+
122
121
  def prepare_file_headers
123
122
  send_file_headers! content_options
124
- response.headers['Content-Type'] = datastream.mimeType
125
- self.content_type = datastream.mimeType
123
+ response.headers['Content-Type'] = datastream.mime_type
124
+ self.content_type = datastream.mime_type
126
125
  end
127
126
 
128
- private
129
-
127
+ private
128
+
130
129
  def default_content_ds
131
- ActiveFedora::ContentModel.known_models_for(asset).each do |model_class|
132
- return asset.datastreams[model_class.default_content_ds] if model_class.respond_to?(:default_content_ds)
133
- end
134
- if asset.datastreams.keys.include?(DownloadsController.default_content_dsid)
135
- return asset.datastreams[DownloadsController.default_content_dsid]
130
+ if asset.class.respond_to?(:default_content_ds)
131
+ asset.attached_files[asset.class.default_content_ds]
132
+ elsif asset.attached_files.key?(DownloadsController.default_content_dsid)
133
+ asset.attached_files[DownloadsController.default_content_dsid]
136
134
  end
137
135
  end
138
-
136
+
139
137
  module ClassMethods
140
138
  def default_content_dsid
141
139
  "content"
@@ -1,39 +1,40 @@
1
+ require 'mime/types'
2
+
1
3
  module Hydra::ModelMethods
2
-
3
- #
4
+
4
5
  # Adds metadata about the depositor to the asset
5
6
  # Most important behavior: if the asset has a rightsMetadata datastream, this method will add +depositor_id+ to its individual edit permissions.
6
7
  # @param [String, #user_key] depositor
7
8
  #
8
9
  def apply_depositor_metadata(depositor)
9
- prop_ds = self.datastreams["properties"]
10
- rights_ds = self.datastreams["rightsMetadata"]
11
-
12
10
  depositor_id = depositor.respond_to?(:user_key) ? depositor.user_key : depositor
13
-
14
- if prop_ds
15
- prop_ds.depositor = depositor_id unless prop_ds.nil?
11
+
12
+ if respond_to? :depositor
13
+ self.depositor = depositor_id
16
14
  end
17
- rights_ds.permissions({:person=>depositor_id}, 'edit') unless rights_ds.nil?
15
+ self.edit_users += [depositor_id]
18
16
  return true
19
17
  end
20
18
 
21
- # Puts the contents of file (posted blob) into a datastream and sets the title and label
19
+ # Puts the contents of file (posted blob) into a datastream and sets the title and label
22
20
  # Sets asset label and title to filename if they're empty
23
21
  #
24
22
  # @param [#read] file the IO object that is the blob
25
23
  # @param [String] file the IO object that is the blob
26
- def add_file(file, dsid, file_name)
27
- mime_types = MIME::Types.of(file_name)
28
- mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
29
- options = {:label=>file_name, :mimeType=>mime_type}
24
+ def add_file(file, dsid, file_name, mime_type=nil)
25
+ mime_type ||= best_mime_for_filename(file_name)
26
+ options = {label: file_name, mime_type: mime_type, original_name: file_name}
30
27
  options[:dsid] = dsid if dsid
31
28
  add_file_datastream(file, options)
32
- set_title_and_label( file_name, :only_if_blank=>true )
29
+ set_title_and_label( file_name, only_if_blank: true )
30
+ end
31
+
32
+ def best_mime_for_filename(file_name)
33
+ mime_types = MIME::Types.of(file_name)
34
+ mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
33
35
  end
34
36
 
35
37
 
36
-
37
38
  # Set the title and label on the current object
38
39
  #
39
40
  # @param [String] new_title
@@ -52,18 +53,17 @@ module Hydra::ModelMethods
52
53
  set_title( new_title )
53
54
  end
54
55
  end
55
-
56
+
56
57
  # Set the title and label on the current object
57
58
  #
58
59
  # @param [String] new_title
59
60
  # @param [Hash] opts (optional) hash of configuration options
60
61
  def set_title(new_title, opts={})
61
- if self.datastreams.has_key?("descMetadata")
62
- desc_metadata_ds = self.datastreams["descMetadata"]
63
- if desc_metadata_ds.respond_to?(:title_values)
64
- desc_metadata_ds.title_values = new_title
62
+ if attached_files.has_key?("descMetadata")
63
+ if descMetadata.respond_to?(:title_values)
64
+ descMetadata.title_values = new_title
65
65
  else
66
- desc_metadata_ds.title = new_title
66
+ descMetadata.title = new_title
67
67
  end
68
68
  end
69
69
  end
data/hydra-core.gemspec CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |gem|
17
17
  gem.version = version
18
18
  gem.license = "APACHE2"
19
19
 
20
- gem.required_ruby_version = '>= 2.0.0'
20
+ gem.required_ruby_version = '>= 1.9.3'
21
21
 
22
22
 
23
- gem.add_dependency "rails", '~> 4.0'
23
+ gem.add_dependency "rails", '>= 3.2.3', '< 5'
24
24
  gem.add_dependency 'block_helpers'
25
25
  gem.add_dependency 'hydra-access-controls', version
26
- gem.add_dependency 'jettywrapper', "~> 1.5"
26
+ gem.add_dependency 'jettywrapper', ">=1.4.1"
27
27
 
28
28
  gem.add_development_dependency 'sqlite3'
29
29
  gem.add_development_dependency 'yard'
@@ -62,8 +62,6 @@ module Hydra
62
62
 
63
63
  # Fedora & Solr YAML files
64
64
  invoke('active_fedora:config')
65
-
66
- copy_file 'config/blacklight.yml', force: true
67
65
  end
68
66
 
69
67
  # Add Hydra behaviors to the user model
@@ -8,11 +8,10 @@ class CatalogController < ApplicationController
8
8
  # These before_filters apply the hydra access controls
9
9
  before_filter :enforce_show_permissions, :only=>:show
10
10
  # This applies appropriate access controls to all solr queries
11
- CatalogController.search_params_logic += [:add_access_controls_to_solr_params]
11
+ CatalogController.solr_search_params_logic += [:add_access_controls_to_solr_params]
12
12
 
13
13
 
14
14
  configure_blacklight do |config|
15
- config.search_builder_class = Hydra::SearchBuilder
16
15
  config.default_solr_params = {
17
16
  :qt => 'search',
18
17
  :rows => 10
@@ -6,15 +6,15 @@ Hydra.configure do |config|
6
6
  # You only need to change these values if you've indexed permissions by some means other than the Hydra's built-in tooling.
7
7
  # If you change these, you must also update the permissions request handler in your solrconfig.xml to return those values
8
8
  #
9
- # config.permissions.discover.group = ActiveFedora::SolrService.solr_name("discover_access_group", :symbol)
10
- # config.permissions.discover.individual = ActiveFedora::SolrService.solr_name("discover_access_person", :symbol)
11
- # config.permissions.read.group = ActiveFedora::SolrService.solr_name("read_access_group", :symbol)
12
- # config.permissions.read.individual = ActiveFedora::SolrService.solr_name("read_access_person", :symbol)
13
- # config.permissions.edit.group = ActiveFedora::SolrService.solr_name("edit_access_group", :symbol)
14
- # config.permissions.edit.individual = ActiveFedora::SolrService.solr_name("edit_access_person", :symbol)
9
+ # config.permissions.discover.group = ActiveFedora::SolrQueryBuilder.solr_name("discover_access_group", :symbol)
10
+ # config.permissions.discover.individual = ActiveFedora::SolrQueryBuilder.solr_name("discover_access_person", :symbol)
11
+ # config.permissions.read.group = ActiveFedora::SolrQueryBuilder.solr_name("read_access_group", :symbol)
12
+ # config.permissions.read.individual = ActiveFedora::SolrQueryBuilder.solr_name("read_access_person", :symbol)
13
+ # config.permissions.edit.group = ActiveFedora::SolrQueryBuilder.solr_name("edit_access_group", :symbol)
14
+ # config.permissions.edit.individual = ActiveFedora::SolrQueryBuilder.solr_name("edit_access_person", :symbol)
15
15
  #
16
- # config.permissions.embargo.release_date = ActiveFedora::SolrService.solr_name("embargo_release_date", :stored_sortable, type: :date)
17
- # config.permissions.lease.expiration_date = ActiveFedora::SolrService.solr_name("lease_expiration_date", :stored_sortable, type: :date)
16
+ # config.permissions.embargo.release_date = ActiveFedora::SolrQueryBuilder.solr_name("embargo_release_date", :stored_sortable, type: :date)
17
+ # config.permissions.lease.expiration_date = ActiveFedora::SolrQueryBuilder.solr_name("lease_expiration_date", :stored_sortable, type: :date)
18
18
  #
19
19
  #
20
20
  # specify the user model
data/lib/hydra-core.rb CHANGED
@@ -2,6 +2,10 @@ require 'hydra-access-controls'
2
2
  require 'deprecation'
3
3
 
4
4
  module HydraHead
5
+ extend Deprecation
5
6
  require 'hydra-head/engine' if defined?(Rails)
7
+ def self.add_routes(router, options = {})
8
+ Deprecation.warn HydraHead, "add_routes has been removed." # remove this warning in hydra-head 8
9
+ end
6
10
  end
7
11
 
@@ -1,4 +1,3 @@
1
1
  module HydraHead
2
- VERSION = "8.2.0"
2
+ VERSION = "9.0.0.beta1"
3
3
  end
4
-
@@ -10,14 +10,6 @@ describe CatalogController do
10
10
  expect(controller).to be_an_instance_of CatalogController
11
11
  end
12
12
 
13
- describe "configuration" do
14
- let(:config) { CatalogController.blacklight_config }
15
- describe "search_builder_class" do
16
- subject {config.search_builder_class }
17
- it { is_expected.to eq Hydra::SearchBuilder }
18
- end
19
- end
20
-
21
13
  describe "Paths Generated by Custom Routes:" do
22
14
  # paths generated by custom routes
23
15
  it "should map {:controller=>'catalog', :action=>'index'} to GET /catalog" do
@@ -56,6 +48,12 @@ describe CatalogController do
56
48
  end
57
49
 
58
50
  describe "filters" do
51
+ describe "index" do
52
+ it "should trigger enforce_index_permissions" do
53
+ expect(controller).to receive(:add_access_controls_to_solr_params)
54
+ get :index
55
+ end
56
+ end
59
57
  describe "show" do
60
58
  it "should trigger enforce_show_permissions" do
61
59
  allow(controller).to receive(:current_user).and_return(nil)
@@ -18,26 +18,30 @@ describe DownloadsController do
18
18
  describe "with a file" do
19
19
  before do
20
20
  class ContentHolder < ActiveFedora::Base
21
+ include Hydra::ModelMethods
21
22
  include Hydra::AccessControls::Permissions
22
- has_file_datastream 'thumbnail'
23
+ contains 'thumbnail'
23
24
  end
24
25
  @user = User.new.tap {|u| u.email = 'email@example.com'; u.password = 'password'; u.save}
25
- @obj = ContentHolder.new
26
- @obj.label = "world.png"
27
- @obj.add_file_datastream('fizz', :dsid=>'buzz', :mimeType => 'image/png')
28
- @obj.add_file_datastream('foobarfoobarfoobar', :dsid=>'content', :mimeType => 'image/png')
29
- @obj.add_file_datastream("It's a stream", :dsid=>'descMetadata', :mimeType => 'text/plain')
30
- @obj.read_users = [@user.user_key]
31
- @obj.save!
32
26
  end
27
+ let(:obj) do
28
+ ContentHolder.new.tap do |obj|
29
+ obj.add_file_datastream('fizz', dsid: 'buzz', mime_type: 'image/png', original_name: 'buzz.png')
30
+ obj.add_file_datastream('foobarfoobarfoobar', dsid: 'content', mime_type: 'image/png', original_name: 'world.png')
31
+ obj.add_file_datastream("It's a stream", dsid: 'descMetadata', mime_type: 'text/plain', original_name: 'metadata.xml')
32
+ obj.read_users = [@user.user_key]
33
+ obj.save!
34
+ end
35
+ end
36
+
33
37
  after do
34
- @obj.destroy
38
+ obj.destroy
35
39
  Object.send(:remove_const, :ContentHolder)
36
40
  end
37
41
  context "when not logged in" do
38
42
  context "when a specific datastream is requested" do
39
43
  it "should redirect to the root path and display an error" do
40
- get "show", id: @obj.pid, datastream_id: "descMetadata"
44
+ get :show, id: obj, datastream_id: "descMetadata"
41
45
  expect(response).to redirect_to new_user_session_path
42
46
  expect(flash[:alert]).to eq "You are not authorized to access this page."
43
47
  end
@@ -50,7 +54,7 @@ describe DownloadsController do
50
54
  end
51
55
  context "when a specific datastream is requested" do
52
56
  it "should redirect to the root path and display an error" do
53
- get "show", id: @obj.pid, datastream_id: "descMetadata"
57
+ get :show, id: obj, datastream_id: "descMetadata"
54
58
  expect(response).to redirect_to root_path
55
59
  expect(flash[:alert]).to eq "You are not authorized to access this page."
56
60
  end
@@ -65,16 +69,16 @@ describe DownloadsController do
65
69
  describe "#show" do
66
70
  it "should default to returning default download configured by object" do
67
71
  allow(ContentHolder).to receive(:default_content_ds).and_return('buzz')
68
- get "show", :id => @obj.pid
69
- expect(response).to be_success
72
+ get :show, id: obj
73
+ expect(response).to be_successful
70
74
  expect(response.headers['Content-Type']).to eq "image/png"
71
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
75
+ expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"buzz.png\""
72
76
  expect(response.body).to eq 'fizz'
73
77
  end
74
78
  it "should default to returning default download configured by controller" do
75
79
  expect(DownloadsController.default_content_dsid).to eq "content"
76
- get "show", :id => @obj.pid
77
- expect(response).to be_success
80
+ get :show, id: obj
81
+ expect(response).to be_successful
78
82
  expect(response.headers['Content-Type']).to eq "image/png"
79
83
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
80
84
  expect(response.body).to eq 'foobarfoobarfoobar'
@@ -83,63 +87,53 @@ describe DownloadsController do
83
87
  context "when a specific datastream is requested" do
84
88
  context "and it doesn't exist" do
85
89
  it "should return :not_found when the datastream doesn't exist" do
86
- get "show", :id => @obj.pid, :datastream_id => "thumbnail"
90
+ get :show, id: obj, datastream_id: "thumbnail"
87
91
  expect(response).to be_not_found
88
92
  end
89
93
  end
90
94
  context "and it exists" do
91
95
  it "should return it" do
92
- get "show", :id => @obj.pid, :datastream_id => "descMetadata"
93
- expect(response).to be_success
96
+ get :show, id: obj, datastream_id: "descMetadata"
97
+ expect(response).to be_successful
94
98
  expect(response.headers['Content-Type']).to eq "text/plain"
95
- expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
99
+ expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"metadata.xml\""
96
100
  expect(response.body).to eq "It's a stream"
97
101
  end
98
102
  end
99
103
  end
100
104
  it "should support setting disposition to inline" do
101
- get "show", :id => @obj.pid, :disposition => "inline"
102
- expect(response).to be_success
105
+ get :show, id: obj, :disposition => "inline"
106
+ expect(response).to be_successful
103
107
  expect(response.headers['Content-Type']).to eq "image/png"
104
108
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
105
109
  expect(response.body).to eq 'foobarfoobarfoobar'
106
110
  end
107
111
  it "should allow you to specify filename for download" do
108
- get "show", :id => @obj.pid, "filename" => "my%20dog.png"
109
- expect(response).to be_success
112
+ get :show, id: obj, "filename" => "my%20dog.png"
113
+ expect(response).to be_successful
110
114
  expect(response.headers['Content-Type']).to eq "image/png"
111
115
  expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"my%20dog.png\""
112
116
  expect(response.body).to eq 'foobarfoobarfoobar'
113
117
  end
114
118
  end
115
119
  describe "stream" do
120
+ let(:parent) { ActiveFedora::Base.new(id: '1234') }
121
+
116
122
  before do
117
- stub_response = double
118
- allow(stub_response).to receive(:read_body).and_yield("one1").and_yield('two2').and_yield('thre').and_yield('four')
119
- stub_repo = double
120
- allow(stub_repo).to receive(:datastream_dissemination).and_yield(stub_response)
121
- stub_ds = ActiveFedora::Datastream.new
122
- allow(stub_ds).to receive(:repository).and_return(stub_repo)
123
- allow(stub_ds).to receive(:mimeType).and_return('video/webm')
124
- allow(stub_ds).to receive(:dsSize).and_return(16)
125
- allow(stub_ds).to receive(:dsid).and_return('webm')
126
- allow(stub_ds).to receive(:new?).and_return(false)
127
- allow(stub_ds).to receive(:pid).and_return('changeme:test')
128
- stub_file = double('stub object', datastreams: {'webm' => stub_ds}, pid:'changeme:test', label: "MyVideo.webm")
129
- expect(ActiveFedora::Base).to receive(:load_instance_from_solr).with('changeme:test').and_return(stub_file)
130
- allow(controller).to receive(:authorize!).with(:download, stub_ds).and_return(true)
131
- allow(controller).to receive(:log_download)
123
+ parent.add_file_datastream('one1two2threfour', dsid: 'webm', mime_type: 'video/webm', original_name: 'MyVideo.webm')
124
+ parent.save!
125
+ expect(controller).to receive(:authorize!).with(:download, instance_of(ActiveFedora::File)).and_return(true)
132
126
  end
133
127
  it "head request" do
134
128
  request.env["HTTP_RANGE"] = 'bytes=0-15'
135
- head :show, id: 'changeme:test', datastream_id: 'webm'
129
+ head :show, id: parent, datastream_id: 'webm'
136
130
  expect(response.headers['Content-Length']).to eq 16
137
131
  expect(response.headers['Accept-Ranges']).to eq 'bytes'
138
132
  expect(response.headers['Content-Type']).to eq 'video/webm'
139
133
  end
140
134
  it "should send the whole thing" do
141
135
  request.env["HTTP_RANGE"] = 'bytes=0-15'
142
- get :show, id: 'changeme:test', datastream_id: 'webm'
136
+ get :show, id: '1234', datastream_id: 'webm'
143
137
  expect(response.body).to eq 'one1two2threfour'
144
138
  expect(response.headers["Content-Range"]).to eq 'bytes 0-15/16'
145
139
  expect(response.headers["Content-Length"]).to eq '16'
@@ -149,20 +143,20 @@ describe DownloadsController do
149
143
  expect(response.status).to eq 206
150
144
  end
151
145
  it "should send the whole thing when the range is open ended" do
152
- request.env["Range"] = 'bytes=0-'
153
- get :show, id: 'changeme:test', datastream_id: 'webm'
146
+ request.env["HTTP_RANGE"] = 'bytes=0-'
147
+ get :show, id: '1234', datastream_id: 'webm'
154
148
  expect(response.body).to eq 'one1two2threfour'
155
149
  end
156
150
  it "should get a range not starting at the beginning" do
157
151
  request.env["HTTP_RANGE"] = 'bytes=3-15'
158
- get :show, id: 'changeme:test', datastream_id: 'webm'
152
+ get :show, id: '1234', datastream_id: 'webm'
159
153
  expect(response.body).to eq '1two2threfour'
160
154
  expect(response.headers["Content-Range"]).to eq 'bytes 3-15/16'
161
155
  expect(response.headers["Content-Length"]).to eq '13'
162
156
  end
163
157
  it "should get a range not ending at the end" do
164
158
  request.env["HTTP_RANGE"] = 'bytes=4-11'
165
- get :show, id: 'changeme:test', datastream_id: 'webm'
159
+ get :show, id: '1234', datastream_id: 'webm'
166
160
  expect(response.body).to eq 'two2thre'
167
161
  expect(response.headers["Content-Range"]).to eq 'bytes 4-11/16'
168
162
  expect(response.headers["Content-Length"]).to eq '8'
@@ -181,10 +175,9 @@ describe DownloadsController do
181
175
  end
182
176
  it "should use the custom param value to retrieve the asset" do
183
177
  allow(controller).to receive(:asset_param_key).and_return(:object_id)
184
- get "show", :object_id => @obj.pid
178
+ get :show, object_id: obj
185
179
  expect(response).to be_successful
186
180
  end
187
181
  end
188
-
189
182
  end
190
183
  end