Skip to content

Commit

Permalink
Merge pull request #521 from samvera/rails6-redux
Browse files Browse the repository at this point in the history
Rails 6 support
  • Loading branch information
tpendragon authored Nov 18, 2020
2 parents 33e793c + 389570c commit 9693041
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 43 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ jobs:
workflows:
ci:
jobs:
- bundle_and_test:
name: "ruby2-7_rails6.0"
ruby_version: 2.7.0
rails_version: 6.0.3.4
- bundle_and_test:
name: "ruby2-7_rails5.2"
ruby_version: 2.7.0
Expand Down
8 changes: 7 additions & 1 deletion hydra-access-controls/lib/hydra-access-controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def configure(_ = nil)
alias :config :configure
end

class Engine < Rails::Engine; end
class Engine < Rails::Engine
config.before_configuration do
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'ACL'
end
end
end

# This error is raised when a user isn't allowed to access a given controller action.
# This usually happens within a call to AccessControlsEnforcement#enforce_access_controls but can be
Expand Down
34 changes: 34 additions & 0 deletions hydra-access-controls/spec/factories/objects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FactoryBot.define do

#
# Repository Objects
#

factory :asset, :class => ModsAsset do |o|
end

factory :admin_policy, :class => Hydra::AdminPolicy do |o|
end

factory :default_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "joe_creator", access: "edit", type: "person" }] }
end

factory :dept_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "africana-faculty", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }] }
end

factory :group_edit_asset, :parent=>:asset do |a|
permissions_attributes { [{ name:"africana-faculty", access: "edit", type: "group" }, {name: "calvin_collaborator", access: "edit", type: "person"}] }
end

factory :org_read_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "registered", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }] }
end

factory :open_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "public", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }] }
end

end

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FactoryBot.define do

# Users

# Prototype user factory
factory :user, :aliases => [:owner] do |u|
sequence :uid do |n|
Expand Down Expand Up @@ -58,36 +57,5 @@
uid { 'alice_admin' }
password { 'alice_admin' }
end

#
# Repository Objects
#

factory :asset, :class => ModsAsset do |o|
end

factory :admin_policy, :class => Hydra::AdminPolicy do |o|
end

factory :default_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "joe_creator", access: "edit", type: "person" }] }
end

factory :dept_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "africana-faculty", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }] }
end

factory :group_edit_asset, :parent=>:asset do |a|
permissions_attributes { [{ name:"africana-faculty", access: "edit", type: "group" }, {name: "calvin_collaborator", access: "edit", type: "person"}] }
end

factory :org_read_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "registered", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }] }
end

factory :open_access_asset, :parent=>:asset do |a|
permissions_attributes { [{ name: "public", access: "read", type: "group" }, { name: "joe_creator", access: "edit", type: "person" }, { name: "calvin_collaborator", access: "edit", type: "person" }] }
end

end

3 changes: 2 additions & 1 deletion hydra-access-controls/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def coverage_needed?
require "factory_bot"
require 'rspec/mocks'
require 'rspec/its'
require "factories"
require 'factories/user'
require 'factories/objects'

# HttpLogger.logger = Logger.new(STDOUT)
# HttpLogger.ignore = [/localhost:8983\/solr/]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def content_options
# Override this if you'd like a different filename
# @return [String] the filename
def file_name
params[:filename] || file.original_name || (asset.respond_to?(:label) && asset.label) || file.id
fname = params[:filename] || file.original_name || (asset.respond_to?(:label) && asset.label) || file.id
fname = URI.unescape(fname) if Rails.version >= '6.0'
fname
end


Expand Down
4 changes: 2 additions & 2 deletions hydra-core/spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
it "is able to negotiate jsonld" do
get 'show', params: { id: asset.id, format: :jsonld }

expect(response).to be_success
expect(response).to be_successful
expect(response.headers['Content-Type']).to include("application/ld+json")
graph = RDF::Reader.for(:jsonld).new(response.body)
expect(graph.statements.to_a.length).to eq 3
Expand All @@ -88,7 +88,7 @@
it "is able to negotiate ttl" do
get 'show', params: { id: asset.id, format: :ttl }

expect(response).to be_success
expect(response).to be_successful
graph = RDF::Reader.for(:ttl).new(response.body)
expect(graph.statements.to_a.length).to eq 3
end
Expand Down
13 changes: 7 additions & 6 deletions hydra-core/spec/controllers/downloads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ContentHolder < ActiveFedora::Base
get :show, params: { id: obj }
expect(response).to be_successful
expect(response.headers['Content-Type']).to start_with "image/png"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"buzz.png\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"buzz.png\""
expect(response.body).to eq 'fizz'
end

Expand All @@ -85,7 +85,7 @@ class ContentHolder < ActiveFedora::Base
get :show, params: { id: obj }
expect(response).to be_successful
expect(response.headers['Content-Type']).to start_with "image/png"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"world.png\""
expect(response.body).to eq 'foobarfoobarfoobar'
end

Expand All @@ -101,7 +101,7 @@ class ContentHolder < ActiveFedora::Base
get :show, params: { id: obj, file: "descMetadata" }
expect(response).to be_successful
expect(response.headers['Content-Type']).to start_with "text/plain"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"metadata.xml\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"metadata.xml\""
expect(response.body).to eq "It's a stream"
end
end
Expand All @@ -111,15 +111,16 @@ class ContentHolder < ActiveFedora::Base
get :show, params: { id: obj, disposition: "inline" }
expect(response).to be_successful
expect(response.headers['Content-Type']).to start_with "image/png"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"world.png\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"world.png\""
expect(response.body).to eq 'foobarfoobarfoobar'
end

it "allows you to specify filename for download" do
get :show, params: { id: obj, "filename" => "my%20dog.png" }
expect(response).to be_successful
expect(response.headers['Content-Type']).to start_with "image/png"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"my%20dog.png\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename="
expect(response.headers["Content-Disposition"]).to include "my%20dog.png"
expect(response.body).to eq 'foobarfoobarfoobar'
end
end
Expand Down Expand Up @@ -148,7 +149,7 @@ class ContentHolder < ActiveFedora::Base
expect(response.headers["Content-Length"]).to eq '16'
expect(response.headers['Accept-Ranges']).to eq 'bytes'
expect(response.headers['Content-Type']).to start_with "video/webm"
expect(response.headers["Content-Disposition"]).to eq "inline; filename=\"MyVideo.webm\""
expect(response.headers["Content-Disposition"]).to start_with "inline; filename=\"MyVideo.webm\""
expect(response.status).to eq 206
end

Expand Down
4 changes: 4 additions & 0 deletions hydra-core/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

require 'simplecov'
require 'coveralls'
require 'rails-controller-testing'

SimpleCov.root(File.expand_path('../..', __dir__))
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
Expand All @@ -29,6 +30,9 @@
require 'active_fedora/cleaner'
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.include ::Rails::Controller::Testing::TemplateAssertions, type: :controller
config.include ::Rails::Controller::Testing::TestProcess, type: :controller
config.include ::Rails::Controller::Testing::Integration, type: :controller
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!

Expand Down
2 changes: 2 additions & 0 deletions hydra-head.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Gem::Specification.new do |s|
s.add_development_dependency 'coveralls'
s.add_development_dependency 'engine_cart', '~> 2.2'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'factory_bot_rails'
s.add_development_dependency 'fcrepo_wrapper', '~> 0.6'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'solr_wrapper', '~> 2.0'
s.add_development_dependency 'rspec_junit_formatter'
s.add_development_dependency 'rails-controller-testing'
end

0 comments on commit 9693041

Please sign in to comment.