Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hyrax main branch (and allow rails 5.2) #144

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ source 'https://rubygems.org'
# development dependencies will be added by default to the :development group.
gemspec

gem 'hyrax', github: 'samvera/hyrax'

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/hyrax/batch_ingest/batches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def index
@batches = @batches.left_joins(:batch_items)
.group(:batch_id, :id)
.order(sanitize_order(params[:order]))
.page(params[:page])
.per(params[:per])
@batches = @batches.page(params[:page]) if params[:page].present?
@batches = @batches.per(params[:per]) if params[:per].present?
@presenters = @batches.map do |batch|
Hyrax::BatchIngest::BatchPresenter.new(batch)
end
Expand Down
18 changes: 9 additions & 9 deletions app/presenters/hyrax/batch_ingest/batch_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def status_label

def status_icon_css_class
{
initialized: 'fa-info',
enqueued: 'fa-info',
running: 'fa-refresh',
completed: repo_object_exists? ? 'fa-check-circle' : 'fa-ban',
failed: 'fa-exclamation-triangle'
initialized: 'fa-info',
enqueued: 'fa-info',
running: 'fa-refresh',
completed: repo_object_exists? ? 'fa-check-circle' : 'fa-ban',
failed: 'fa-exclamation-triangle'
}.fetch(status.to_sym, 'fa-question')
end

Expand All @@ -52,10 +52,10 @@ class << self
def status_labels
{
initialized: I18n.t('hyrax.batch_ingest.batch_items.status.initialized'),
enqueued: I18n.t('hyrax.batch_ingest.batch_items.status.enqueued'),
running: I18n.t('hyrax.batch_ingest.batch_items.status.running'),
completed: I18n.t('hyrax.batch_ingest.batch_items.status.completed'),
failed: I18n.t('hyrax.batch_ingest.batch_items.status.failed')
enqueued: I18n.t('hyrax.batch_ingest.batch_items.status.enqueued'),
running: I18n.t('hyrax.batch_ingest.batch_items.status.running'),
completed: I18n.t('hyrax.batch_ingest.batch_items.status.completed'),
failed: I18n.t('hyrax.batch_ingest.batch_items.status.failed')
}.with_indifferent_access
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/presenters/hyrax/batch_ingest/batch_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def status_labels

def status_css_classes
{
'received' => 'fa fa-info',
'accepted' => 'fa fa-info',
'enqueued' => 'fa fa-info',
'running' => 'fa fa-refresh fa-sync',
'completed' => 'fa fa-check-circle',
'failed' => 'fa fa-exclamation-triangle'
'received' => 'fa fa-info',
'accepted' => 'fa fa-info',
'enqueued' => 'fa fa-info',
'running' => 'fa fa-refresh fa-sync',
'completed' => 'fa fa-check-circle',
'failed' => 'fa fa-exclamation-triangle'
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions hyrax-batch_ingest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

s.add_dependency 'rails', '~> 5.1.6'
s.add_dependency 'hyrax', '~> 2.2'
s.add_dependency 'rails', '~> 5.2', '>= 5.2.4.3'
s.add_dependency 'hyrax', '< 4'
s.add_dependency 'roo', '~> 2.7.0'

s.add_development_dependency 'bixby'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true
RSpec.shared_examples "a Hyrax::BatchIngest::BatchItemIngester" do
subject { ingester }
before do
raise 'ingester class must be set with `let(:ingester_class)`' unless defined? ingester_class
raise 'batch item must be set with `let(:batch_item)`' unless defined? batch_item
end

subject { ingester }

let(:ingester) { ingester_class.new(batch_item) }

it { is_expected.to respond_to :ingest }
Expand Down
3 changes: 1 addition & 2 deletions lib/hyrax/batch_ingest/spec/shared_specs/batch_reader.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# frozen_string_literal: true
RSpec.shared_examples "a Hyrax::BatchIngest::BatchReader" do
subject { reader }
before do
raise 'reader class must be set with `let(:reader_class)`' unless defined? reader_class
raise 'source location must be set with `let(:source_location)`' unless defined? source_location
raise 'invalid source location must be set with `let(:invalid_source_location)`' unless defined? invalid_source_location
end

subject { reader }

let(:reader) { reader_class.new(source_location) }
let(:invalid_reader) { reader_class.new(invalid_source_location) }

Expand Down
2 changes: 1 addition & 1 deletion lib/hyrax/batch_ingest/spec/shared_specs/batch_scanner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true
RSpec.shared_examples "a Hyrax::BatchIngest::BatchScanner" do
subject { scanner }
before do
raise 'scanner class must be set with `let(:scanner_class)`' unless defined? scanner_class
raise 'admin_set must be set with `let(:admin_set)`' unless defined? admin_set
raise 'manifests must be set with `let(:manifests)`' unless defined? manifests
end

subject { scanner }
let(:scanner) { scanner_class.new(admin_set) }

it { is_expected.to respond_to :admin_set }
Expand Down
32 changes: 32 additions & 0 deletions spec/factories/admin_sets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true
FactoryBot.define do
factory :admin_set do
sequence(:title) { |n| ["Title #{n}"] }

# Given the relationship between permission template and admin set, when
# an admin set is created via a factory, I believe it is appropriate to go ahead and
# create the corresponding permission template
#
# This way, we can go ahead
after(:create) do |admin_set, evaluator|
if evaluator.with_permission_template
attributes = { source_id: admin_set.id }
attributes = evaluator.with_permission_template.merge(attributes) if evaluator.with_permission_template.respond_to?(:merge)
# There is a unique constraint on permission_templates.source_id; I don't want to
# create a permission template if one already exists for this admin_set
create(:permission_template, attributes) unless Hyrax::PermissionTemplate.find_by(source_id: admin_set.id)
end
end

transient do
# false, true, or Hash with keys for permission_template
with_permission_template { false }
end

factory :complete_admin_set do
alternative_title { ['alternative admin set title'] }
creator { ['moomin', 'snufkin'] }
description { ['Before a revolution happens', 'it is perceived as impossible'] }
end
end
end
21 changes: 0 additions & 21 deletions spec/factories/hyrax_factories.rb

This file was deleted.

17 changes: 17 additions & 0 deletions spec/factories/permission_template_accesses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true
FactoryBot.define do
factory :permission_template_access, class: Hyrax::PermissionTemplateAccess do
permission_template
trait :manage do
access { 'manage' }
end

trait :deposit do
access { 'deposit' }
end

trait :view do
access { 'view' }
end
end
end
80 changes: 80 additions & 0 deletions spec/factories/permission_templates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true
FactoryBot.define do
factory :permission_template, class: Hyrax::PermissionTemplate do
# Given that there is a one to one strong relation between permission_template and admin_set,
# with a unique index on the source_id, I don't want to have duplication in source_id
sequence(:source_id) { |n| format("%010d", n) }

before(:create) do |permission_template, evaluator|
if evaluator.with_admin_set
source_id = permission_template.source_id
admin_set =
if source_id.present?
begin
AdminSet.find(source_id)
rescue ActiveFedora::ObjectNotFoundError
create(:admin_set, id: source_id)
end
else
create(:admin_set)
end
permission_template.source_id = admin_set.id
elsif evaluator.with_collection
source_id = permission_template.source_id
collection =
if source_id.present?
begin
Collection.find(source_id)
rescue ActiveFedora::ObjectNotFoundError
create(:collection, id: source_id)
end
else
create(:collection)
end
permission_template.source_id = collection.id
end
end

after(:create) do |permission_template, evaluator|
if evaluator.with_workflows
Hyrax::Workflow::WorkflowImporter.load_workflow_for(permission_template: permission_template)
Sipity::Workflow.activate!(permission_template: permission_template, workflow_id: permission_template.available_workflows.pluck(:id).first)
end
if evaluator.with_active_workflow
workflow = create(:workflow, active: true, permission_template: permission_template)
create(:workflow_action, workflow: workflow) # Need to create a single action that can be taken
end
AccessHelper.create_access(permission_template, 'user', :manage, evaluator.manage_users) if evaluator.manage_users.present?
AccessHelper.create_access(permission_template, 'group', :manage, evaluator.manage_groups) if evaluator.manage_groups.present?
AccessHelper.create_access(permission_template, 'user', :deposit, evaluator.deposit_users) if evaluator.deposit_users.present?
AccessHelper.create_access(permission_template, 'group', :deposit, evaluator.deposit_groups) if evaluator.deposit_groups.present?
AccessHelper.create_access(permission_template, 'user', :view, evaluator.view_users) if evaluator.view_users.present?
AccessHelper.create_access(permission_template, 'group', :view, evaluator.view_groups) if evaluator.view_groups.present?
end

transient do
with_admin_set { false }
with_collection { false }
with_workflows { false }
with_active_workflow { false }
manage_users { nil }
manage_groups { nil }
deposit_users { nil }
deposit_groups { nil }
view_users { nil }
view_groups { nil }
end
end

class AccessHelper
def self.create_access(permission_template_id, agent_type, access, agent_ids)
agent_ids.each do |agent_id|
FactoryBot.create(:permission_template_access,
access,
permission_template: permission_template_id,
agent_type: agent_type,
agent_id: agent_id)
end
end
end
end
60 changes: 60 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user do
sequence(:email) { |n| "user#{n}@example.com" }
password { 'password' }

transient do
# Allow for custom groups when a user is instantiated.
# @example create(:user, groups: 'avacado')
groups { [] }
end

# TODO: Register the groups for the given user key such that we can remove the following from other specs:
# `allow(::User.group_service).to receive(:byname).and_return(user.user_key => ['admin'])``
after(:build) do |user, evaluator|
# In case we have the instance but it has not been persisted
::RSpec::Mocks.allow_message(user, :groups).and_return(Array.wrap(evaluator.groups))
# Given that we are stubbing the class, we need to allow for the original to be called
::RSpec::Mocks.allow_message(user.class.group_service, :fetch_groups).and_call_original
# We need to ensure that each instantiation of the admin user behaves as expected.
# This resolves the issue of both the created object being used as well as re-finding the created object.
::RSpec::Mocks.allow_message(user.class.group_service, :fetch_groups).with(user: user).and_return(Array.wrap(evaluator.groups))
end

factory :admin do
groups { ['admin'] }
end

factory :user_with_mail do
after(:create) do |user|
# Create examples of single file successes and failures
(1..10).each do |number|
file = MockFile.new(number.to_s, "Single File #{number}")
User.batch_user.send_message(user, 'File 1 could not be updated. You do not have sufficient privileges to edit it.', file.to_s, false)
User.batch_user.send_message(user, 'File 1 has been saved', file.to_s, false)
end

# Create examples of mulitple file successes and failures
files = []
(1..50).each do |number|
files << MockFile.new(number.to_s, "File #{number}")
end
User.batch_user.send_message(user, 'These files could not be updated. You do not have sufficient privileges to edit them.', 'Batch upload permission denied', false)
User.batch_user.send_message(user, 'These files have been saved', 'Batch upload complete', false)
end
end
end

trait :guest do
guest { true }
end
end

class MockFile
attr_accessor :to_s, :id
def initialize(id, string)
self.id = id
self.to_s = string
end
end
6 changes: 3 additions & 3 deletions spec/views/hyrax/dashboard/batch_sidebar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
end

context 'as any logged in user' do
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }
subject { rendered }
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }

it 'has the Collection link' do
is_expected.to have_link t('hyrax.admin.sidebar.collections')
Expand All @@ -26,17 +26,17 @@
end

context 'as a user who can view Batch info' do
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }
subject { rendered }
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }
let(:can_view_batches) { true }
it 'has the Batches link' do
is_expected.to have_link 'Batches'
end
end

context 'as a user who cannot view Batch info' do
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }
subject { rendered }
before { render 'hyrax/dashboard/sidebar/repository_content', menu: menu }
let(:can_view_batches) { false }
it 'does not have the Batches link' do
is_expected.not_to have_link 'Batches'
Expand Down