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

Test with hyrax main branch #26

Open
wants to merge 15 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
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ jobs:
ruby_version: << parameters.ruby_version >>
bundler_version: << parameters.bundler_version >>
project: hyrax-iiif_av


- samvera/rubocop

- samvera/engine_cart_generate:
cache_key: v1-internal-test-app-{{ checksum "hyrax-iiif_av.gemspec" }}-{{ checksum "spec/test_app_templates/lib/generators/test_app_generator.rb" }}-{{ checksum "lib/generators/hyrax/iiif_av/install_generator.rb" }}

- samvera/install_solr_core:
solr_config_path: .internal_test_app/solr/config
solr_config_path: .internal_test_app/solr/conf

- samvera/bundle_for_gem:
ruby_version: << parameters.ruby_version >>
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Metrics/BlockLength:
- 'lib/hyrax/iiif_av/spec/shared_specs/displays_iiif_av.rb'
- 'spec/controllers/generic_works_controller_spec.rb'
- 'spec/controllers/iiif_av_controller_spec.rb'
- 'spec/factories/users.rb'
- 'spec/helpers/iiif_av_helper_spec.rb'
- 'spec/requests/auth_controller_behavior_spec.rb'
- 'spec/support/features/session_helpers.rb'

RSpec/VerifiedDoubles:
Exclude:
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ gemspec
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# Last revision before version 0.6 was released. This can be removed once this gem is upgraded to hyrax master (3.0.0.beta2) or support for 0.6 is backported to hyrax 2.x
gem 'iiif_manifest', git: 'https://github.com/samvera-labs/iiif_manifest.git', ref: '4219eb57ae9fbcd178391f401928040ebe057529'
gem 'hyrax', github: 'samvera/hyrax'

# To use a debugger
# gem 'byebug', group: [:development, :test]
Expand Down
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ end

RSpec::Core::RakeTask.new(:spec)

task :spec_with_server do
require 'solr_wrapper' # necessary for rake_support to work
require 'fcrepo_wrapper' # necessary for rake_support to work
require 'active_fedora/rake_support'

ENV['environment'] = "test"
with_test_server do
Rake::Task['spec'].invoke
end
end

desc "CI build"
task ci: [:rubocop, "engine_cart:generate", :spec]
task ci: [:rubocop, "engine_cart:generate", :spec_with_server]
18 changes: 14 additions & 4 deletions app/controllers/concerns/hyrax/iiif_av/controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ module ControllerBehavior

included do
prepend_view_path(Hyrax::IiifAv::Engine.view_path)
self.iiif_manifest_builder = (Flipflop.cache_work_iiif_manifest? ? Hyrax::CachingIiifManifestBuilder : Hyrax::ManifestBuilderService)
end

IIIF_PRESENTATION_2_MIME = 'application/ld+json;profile="http://iiif.io/api/presentation/2/context.json"'
IIIF_PRESENTATION_3_MIME = 'application/ld+json;profile="http://iiif.io/api/presentation/3/context.json"'

def manifest
add_iiif_header
super

# super
headers['Access-Control-Allow-Origin'] = '*'

json = iiif_manifest_builder.manifest_for(presenter: presenter, iiif_manifest_factory: manifest_factory)

respond_to do |wants|
wants.json { render json: json }
wants.html { render json: json }
end
end

private
Expand All @@ -50,11 +60,11 @@ def add_iiif_header
headers['Content-Type'] = iiif_mime
end

def manifest_builder
def manifest_factory
if iiif_version_3?
::IIIFManifest::V3::ManifestFactory.new(presenter)
::IIIFManifest::V3::ManifestFactory
else
::IIIFManifest::ManifestFactory.new(presenter)
::IIIFManifest::ManifestFactory
end
end
end
Expand Down
19 changes: 13 additions & 6 deletions app/presenters/concerns/hyrax/iiif_av/displays_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ def content_supported?
end

def image_content
latest_file_id = lookup_original_file_id

return nil unless latest_file_id

url = Hyrax.config.iiif_image_url_builder.call(
solr_document.id,
latest_file_id,
request.base_url,
Hyrax.config.iiif_image_size_default
Hyrax.config.iiif_image_size_default,
format: image_format(alpha_channels)
)

# Look at the request and target prezi 2 or 3 for images
Expand All @@ -60,17 +65,19 @@ def image_content
def image_content_v3(url)
# @see https://github.com/samvera-labs/iiif_manifest
IIIFManifest::V3::DisplayContent.new(url,
width: 640,
height: 480,
format: image_format(alpha_channels),
width: width,
height: height,
type: 'Image',
iiif_endpoint: iiif_endpoint(solr_document.id))
end

def image_content_v2(url)
# @see https://github.com/samvera-labs/iiif_manifest
IIIFManifest::DisplayImage.new(url,
width: 640,
height: 480,
format: image_format(alpha_channels),
width: width,
height: height,
iiif_endpoint: iiif_endpoint(solr_document.id))
end

Expand Down
8 changes: 5 additions & 3 deletions hyrax-iiif_av.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ Gem::Specification.new do |s|
f.match(%r{^(test|spec|features)/})
end

s.add_dependency "rails", "~>5.1"
s.add_dependency "rails", "~>5.2"
s.add_dependency "blacklight"
s.add_dependency "hyrax", "~> 2.4"
s.add_dependency "iiif_manifest", "~> 0.5"
s.add_dependency "hyrax", "< 4"
s.add_dependency "iiif_manifest", "~> 1.0"

s.add_development_dependency 'bixby'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'engine_cart', '~> 2.2'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'fcrepo_wrapper'
s.add_development_dependency 'rails-controller-testing'
s.add_development_dependency 'rspec-rails', '~> 3.8'
s.add_development_dependency 'rspec_junit_formatter'
s.add_development_dependency 'solr_wrapper'
end
4 changes: 3 additions & 1 deletion lib/hyrax/iiif_av/spec/shared_specs/displays_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
let(:parent_presenter) { double("Hyrax::GenericWorkPresenter", iiif_version: 2) }
let(:first_title) { 'File Set Title' }
let(:title) { [first_title] }
let(:versioned_file_id) { id }

before do
allow(ability).to receive(:can?).with(:read, solr_document.id).and_return(read_permission)
allow(presenter).to receive(:parent).and_return(parent_presenter)
allow(presenter).to receive(:title).and_return(title)
allow(presenter).to receive(:original_file_id).and_return(versioned_file_id)
end

describe '#display_content' do
Expand Down Expand Up @@ -130,7 +132,7 @@

context 'with custom image url builder' do
let(:custom_builder) do
->(file_id, base_url, _size) { "#{base_url}/downloads/#{file_id.split('/').first}" }
->(file_id, base_url, _size, _format) { "#{base_url}/downloads/#{file_id.split('/').first}" }
end

around do |example|
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/generic_works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class IiifAvWorkPresenter < Hyrax::GenericWorkPresenter
allow(presenter).to receive(:list_of_item_ids_to_display).and_return([])
allow(presenter).to receive(:member_presenters_for).and_return([])
allow(controller).to receive(:can?).and_return(false)
allow(ability).to receive(:can?).and_return(false)
end

context "when the work presenter doesn't define #iiif_viewer", skip: true do
Expand Down
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
5 changes: 2 additions & 3 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require 'hyrax'
require 'devise'
require 'factory_bot'
require File.expand_path('spec/support/features/session_helpers', Hyrax::Engine.root)

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand All @@ -29,7 +28,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand All @@ -40,7 +39,7 @@
exit 1
end

FactoryBot.definition_file_paths = [File.expand_path("spec/factories", Hyrax::Engine.root)]
FactoryBot.definition_file_paths = [File.expand_path("spec/factories", Hyrax::IiifAv::Engine.root)]
FactoryBot.find_definitions

RSpec.configure do |config|
Expand Down
15 changes: 15 additions & 0 deletions spec/support/features/session_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true
# spec/support/features/session_helpers.rb
module Features
module SessionHelpers
def sign_in(who = :user)
logout
user = who.is_a?(User) ? who : build(:user).tap(&:save!)
visit new_user_session_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Log in'
expect(page).not_to have_text 'Invalid email or password.'
end
end
end
2 changes: 1 addition & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gem 'hyrax'
gem 'hyrax', github: 'samvera/hyrax'
gem 'rails-controller-testing'