diff --git a/Gemfile b/Gemfile index ac7a6c378..db4d06a08 100644 --- a/Gemfile +++ b/Gemfile @@ -38,3 +38,7 @@ else end end # END ENGINE_CART BLOCK + +if !ENV['RAILS_VERSION'] || ENV['RAILS_VERSION'] =~ /^5.0/ + gem 'rails-controller-testing' +end diff --git a/Rakefile b/Rakefile index cbc5c38cf..df6ca3b84 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,9 @@ require 'rake/testtask' -require 'bundler' +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end Bundler::GemHelper.install_tasks APP_ROOT= File.dirname(__FILE__) diff --git a/hydra-core/app/controllers/concerns/hydra/controller/download_behavior.rb b/hydra-core/app/controllers/concerns/hydra/controller/download_behavior.rb index 2ba8980fe..d601acb44 100644 --- a/hydra-core/app/controllers/concerns/hydra/controller/download_behavior.rb +++ b/hydra-core/app/controllers/concerns/hydra/controller/download_behavior.rb @@ -87,8 +87,7 @@ def file_name # render an HTTP HEAD response def content_head response.headers['Content-Length'] = file.size - response.headers['Content-Type'] = file.mime_type - head :ok + head :ok, content_type: file.mime_type end # render an HTTP Range response diff --git a/hydra-core/hydra-core.gemspec b/hydra-core/hydra-core.gemspec index 9e57518b3..d82d1f330 100644 --- a/hydra-core/hydra-core.gemspec +++ b/hydra-core/hydra-core.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 1.9.3' - gem.add_dependency "rails", '~> 4.0' + gem.add_dependency "railties", '>= 4.0.0', '< 6' gem.add_dependency 'hydra-access-controls', version gem.add_development_dependency 'sqlite3', '~> 1.3' diff --git a/hydra-core/spec/controllers/downloads_controller_spec.rb b/hydra-core/spec/controllers/downloads_controller_spec.rb index 2bfca7c7d..40c259c87 100644 --- a/hydra-core/spec/controllers/downloads_controller_spec.rb +++ b/hydra-core/spec/controllers/downloads_controller_spec.rb @@ -74,7 +74,7 @@ class ContentHolder < ActiveFedora::Base allow(ContentHolder).to receive(:default_file_path).and_return('buzz') get :show, id: obj expect(response).to be_successful - expect(response.headers['Content-Type']).to eq "image/png" + expect(response.headers['Content-Type']).to start_with "image/png" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"buzz.png\"" expect(response.body).to eq 'fizz' end @@ -83,7 +83,7 @@ class ContentHolder < ActiveFedora::Base expect(DownloadsController.default_file_path).to eq "content" get :show, id: obj expect(response).to be_successful - expect(response.headers['Content-Type']).to eq "image/png" + expect(response.headers['Content-Type']).to start_with "image/png" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\"" expect(response.body).to eq 'foobarfoobarfoobar' end @@ -99,7 +99,7 @@ class ContentHolder < ActiveFedora::Base it "should return it" do get :show, id: obj, file: "descMetadata" expect(response).to be_successful - expect(response.headers['Content-Type']).to eq "text/plain" + expect(response.headers['Content-Type']).to start_with "text/plain" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"metadata.xml\"" expect(response.body).to eq "It's a stream" end @@ -108,14 +108,14 @@ class ContentHolder < ActiveFedora::Base it "should support setting disposition to inline" do get :show, id: obj, :disposition => "inline" expect(response).to be_successful - expect(response.headers['Content-Type']).to eq "image/png" + expect(response.headers['Content-Type']).to start_with "image/png" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\"" expect(response.body).to eq 'foobarfoobarfoobar' end it "should allow you to specify filename for download" do get :show, id: obj, "filename" => "my%20dog.png" expect(response).to be_successful - expect(response.headers['Content-Type']).to eq "image/png" + expect(response.headers['Content-Type']).to start_with "image/png" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"my%20dog.png\"" expect(response.body).to eq 'foobarfoobarfoobar' end @@ -128,37 +128,42 @@ class ContentHolder < ActiveFedora::Base parent.save! expect(controller).to receive(:authorize!).with(:download, instance_of(ActiveFedora::File)).and_return(true) end + it "head request" do request.env["HTTP_RANGE"] = 'bytes=0-15' head :show, id: parent, file: 'webm' expect(response.headers['Content-Length']).to eq 16 expect(response.headers['Accept-Ranges']).to eq 'bytes' - expect(response.headers['Content-Type']).to eq 'video/webm' + expect(response.headers['Content-Type']).to start_with 'video/webm' end - it "should send the whole thing" do + + it "sends the whole thing" do request.env["HTTP_RANGE"] = 'bytes=0-15' get :show, id: '1234', file: 'webm' expect(response.body).to eq 'one1two2threfour' expect(response.headers["Content-Range"]).to eq 'bytes 0-15/16' expect(response.headers["Content-Length"]).to eq '16' expect(response.headers['Accept-Ranges']).to eq 'bytes' - expect(response.headers['Content-Type']).to eq "video/webm" + expect(response.headers['Content-Type']).to start_with "video/webm" expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"MyVideo.webm\"" expect(response.status).to eq 206 end - it "should send the whole thing when the range is open ended" do + + it "sends the whole thing when the range is open ended" do request.env["HTTP_RANGE"] = 'bytes=0-' get :show, id: '1234', file: 'webm' expect(response.body).to eq 'one1two2threfour' end - it "should get a range not starting at the beginning" do + + it "gets a range not starting at the beginning" do request.env["HTTP_RANGE"] = 'bytes=3-15' get :show, id: '1234', file: 'webm' expect(response.body).to eq '1two2threfour' expect(response.headers["Content-Range"]).to eq 'bytes 3-15/16' expect(response.headers["Content-Length"]).to eq '13' end - it "should get a range not ending at the end" do + + it "gets a range not ending at the end" do request.env["HTTP_RANGE"] = 'bytes=4-11' get :show, id: '1234', file: 'webm' expect(response.body).to eq 'two2thre' diff --git a/hydra-core/spec/test_app_templates/Gemfile.extra b/hydra-core/spec/test_app_templates/Gemfile.extra deleted file mode 100644 index b4436628a..000000000 --- a/hydra-core/spec/test_app_templates/Gemfile.extra +++ /dev/null @@ -1,6 +0,0 @@ -gem 'rspec-rails', '~> 3.1', group: :test -gem 'rspec-its' -gem 'byebug' unless ENV['CI'] - -gem 'rails', ENV.fetch('RAILS_VERSION', '4.2.6') -gem 'blacklight', ENV.fetch('BLACKLIGHT_VERSION', '6.0.0') diff --git a/hydra-head.gemspec b/hydra-head.gemspec index bb414d6ff..b8555d5ff 100644 --- a/hydra-head.gemspec +++ b/hydra-head.gemspec @@ -16,14 +16,14 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 1.9.3' - s.add_dependency('rails', '>= 3.2.6') - s.add_dependency('hydra-access-controls', version) - s.add_dependency('hydra-core', version) + s.add_dependency 'rails', '>= 3.2.6' + s.add_dependency 'hydra-access-controls', version + s.add_dependency 'hydra-core', version s.add_development_dependency 'solr_wrapper', '~> 0.5' s.add_development_dependency 'fcrepo_wrapper', '~> 0.2' s.add_development_dependency 'engine_cart', '~> 0.10' - s.add_development_dependency "yard" + s.add_development_dependency 'yard' s.add_development_dependency 'rspec-rails' s.add_development_dependency 'factory_girl_rails' end diff --git a/spec/test_app_templates/Gemfile.extra b/spec/test_app_templates/Gemfile.extra new file mode 100644 index 000000000..c2e0b5135 --- /dev/null +++ b/spec/test_app_templates/Gemfile.extra @@ -0,0 +1 @@ +gem 'byebug' unless ENV['CI']