From 6447a24f8329abc103892df8f23498643c3c399d Mon Sep 17 00:00:00 2001 From: Fred Duby Date: Wed, 13 Nov 2024 14:15:24 -0500 Subject: [PATCH 1/4] Update Rails to 7.2.2 (SWORD-112) -) Update Gemfile and run 'bundle update rails' -) Run 'bin/rails app:update' -) pass the class as a keyword argument in serialize -) Update capistrano to 3.19.2. Fixes following error: uninitialized constant Capistrano::SCM::Git::StringIO (SSHKit::Runner::ExecuteError) --- Capfile | 7 +- Gemfile | 4 +- Gemfile.lock | 203 +++++++++--------- app/models/collection.rb | 4 +- app/models/deposit.rb | 4 +- bin/rubocop | 8 + bin/setup | 6 +- config/application.rb | 2 +- config/deploy.rb | 2 +- config/environments/development.rb | 17 +- config/environments/production.rb | 13 +- config/environments/test.rb | 13 +- config/initializers/assets.rb | 2 +- .../initializers/filter_parameter_logging.rb | 2 +- .../new_framework_defaults_7_2.rb | 70 ++++++ config/puma.rb | 34 +++ public/404.html | 12 +- public/406-unsupported-browser.html | 66 ++++++ public/422.html | 12 +- public/500.html | 12 +- public/icon.png | Bin 0 -> 5599 bytes public/icon.svg | 3 + public/robots.txt | 6 +- 23 files changed, 352 insertions(+), 150 deletions(-) create mode 100755 bin/rubocop create mode 100644 config/initializers/new_framework_defaults_7_2.rb create mode 100644 config/puma.rb create mode 100644 public/406-unsupported-browser.html create mode 100644 public/icon.png create mode 100644 public/icon.svg diff --git a/Capfile b/Capfile index 2eeeb78..db5093c 100644 --- a/Capfile +++ b/Capfile @@ -1,9 +1,14 @@ # default requires require 'capistrano/setup' require 'capistrano/deploy' + +# Git SCM plugin +require 'capistrano/scm/git' +install_plugin Capistrano::SCM::Git + # additional optional modules used by clio require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' -require 'capistrano/passenger' \ No newline at end of file +require 'capistrano/passenger' diff --git a/Gemfile b/Gemfile index edf7ff8..514c9ad 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' ruby "3.2.2" -gem 'rails', '~> 7.1.2' +gem 'rails', '~> 7.2.2' gem 'mysql2' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' @@ -58,7 +58,7 @@ group :development do # Use Puma as the app server gem 'puma' # Use Capistrano for deployment - gem 'capistrano', '~> 3.17.3', require: false + gem 'capistrano', '~> 3.19.2', require: false # Rails and Bundler integrations were moved out from Capistrano 3 gem 'capistrano-rails', '~> 1.4', require: false gem 'capistrano-bundler', '~> 1.1', require: false diff --git a/Gemfile.lock b/Gemfile.lock index d185732..07f4a36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,90 +1,88 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.2) - actionpack (= 7.1.2) - activesupport (= 7.1.2) + actioncable (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.2) - actionpack (= 7.1.2) - activejob (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.2) - actionpack (= 7.1.2) - actionview (= 7.1.2) - activejob (= 7.1.2) - activesupport (= 7.1.2) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) + actionmailer (7.2.2) + actionpack (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.2) - actionview (= 7.1.2) - activesupport (= 7.1.2) + actionpack (7.2.2) + actionview (= 7.2.2) + activesupport (= 7.2.2) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.2) - actionpack (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) + useragent (~> 0.16) + actiontext (7.2.2) + actionpack (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.2) - activesupport (= 7.1.2) + actionview (7.2.2) + activesupport (= 7.2.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.2) - activesupport (= 7.1.2) + activejob (7.2.2) + activesupport (= 7.2.2) globalid (>= 0.3.6) - activemodel (7.1.2) - activesupport (= 7.1.2) - activerecord (7.1.2) - activemodel (= 7.1.2) - activesupport (= 7.1.2) + activemodel (7.2.2) + activesupport (= 7.2.2) + activerecord (7.2.2) + activemodel (= 7.2.2) + activesupport (= 7.2.2) timeout (>= 0.4.0) - activestorage (7.1.2) - actionpack (= 7.1.2) - activejob (= 7.1.2) - activerecord (= 7.1.2) - activesupport (= 7.1.2) + activestorage (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activesupport (= 7.2.2) marcel (~> 1.0) - activesupport (7.1.2) + activesupport (7.2.2) base64 + benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) - airbrussh (1.5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + airbrussh (1.5.3) sshkit (>= 1.6.1, != 1.7.0) ast (2.4.2) base64 (0.1.1) bcrypt (3.1.20) - bigdecimal (3.1.5) + benchmark (0.4.0) + bigdecimal (3.1.8) bootsnap (1.17.0) msgpack (~> 1.2) - builder (3.2.4) - capistrano (3.17.3) + builder (3.3.0) + capistrano (3.19.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -106,10 +104,10 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) - date (3.3.4) + date (3.4.0) devise (4.9.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -118,19 +116,18 @@ GEM warden (~> 1.2.3) diff-lcs (1.5.0) docile (1.4.1) - drb (2.2.0) - ruby2_keywords - erubi (1.12.0) + drb (2.2.1) + erubi (1.13.0) execjs (2.9.1) ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) hashie (5.0.0) - i18n (1.14.1) + i18n (1.14.6) concurrent-ruby (~> 1.0) - io-console (0.7.1) - irb (1.11.1) - rdoc + io-console (0.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) reline (>= 0.4.2) jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) @@ -141,7 +138,8 @@ GEM listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.22.0) + logger (1.6.1) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -149,13 +147,13 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) mini_mime (1.1.5) - minitest (5.20.0) + minitest (5.25.1) msgpack (1.7.2) mutex_m (0.2.0) mysql2 (0.5.5) - net-imap (0.4.9.1) + net-imap (0.5.1) date net-protocol net-pop (0.1.2) @@ -166,13 +164,13 @@ GEM net-ssh (>= 2.6.5, < 8.0.0) net-sftp (4.0.0) net-ssh (>= 5.0.0, < 8.0.0) - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol net-ssh (7.2.1) - nio4r (2.7.0) - nokogiri (1.16.0-arm64-darwin) + nio4r (2.7.4) + nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.0-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) omniauth (2.1.2) hashie (>= 3.4.6) @@ -186,12 +184,12 @@ GEM parser (3.3.5.0) ast (~> 2.4.1) racc - psych (5.1.2) + psych (5.2.0) stringio puma (6.4.2) nio4r (~> 2.0) - racc (1.7.3) - rack (2.2.8) + racc (1.8.1) + rack (2.2.10) rack-protection (3.2.0) base64 (>= 0.1.0) rack (~> 2.2, >= 2.2.4) @@ -199,23 +197,23 @@ GEM rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) + rackup (1.0.1) rack (< 3) webrick - rails (7.1.2) - actioncable (= 7.1.2) - actionmailbox (= 7.1.2) - actionmailer (= 7.1.2) - actionpack (= 7.1.2) - actiontext (= 7.1.2) - actionview (= 7.1.2) - activejob (= 7.1.2) - activemodel (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) + rails (7.2.2) + actioncable (= 7.2.2) + actionmailbox (= 7.2.2) + actionmailer (= 7.2.2) + actionpack (= 7.2.2) + actiontext (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activemodel (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) bundler (>= 1.15.0) - railties (= 7.1.2) + railties (= 7.2.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -223,23 +221,23 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.2) - actionpack (= 7.1.2) - activesupport (= 7.1.2) - irb + railties (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.6.2) + rdoc (6.7.0) psych (>= 4.0.0) regexp_parser (2.9.2) - reline (0.4.2) + reline (0.5.11) io-console (~> 0.5) responders (3.1.1) actionpack (>= 5.2) @@ -306,7 +304,6 @@ GEM rubocop-rails (~> 2.25) rubocop-rspec (~> 2.28) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) rubyzip (2.3.2) sass (3.7.4) sass-listen (~> 4.0.0) @@ -319,6 +316,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + securerandom (0.3.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -340,23 +338,24 @@ GEM net-scp (>= 1.1.2) net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) - stringio (3.1.0) - thor (1.3.0) + stringio (3.1.2) + thor (1.3.2) tilt (2.3.0) - timeout (0.4.1) + timeout (0.4.2) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) + useragent (0.16.10) warden (1.2.9) rack (>= 2.0.9) - webrick (1.8.1) + webrick (1.9.0) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.12) + zeitwerk (2.7.1) PLATFORMS arm64-darwin-21 @@ -366,7 +365,7 @@ DEPENDENCIES base64 (= 0.1.1) bcrypt (~> 3.1.7) bootsnap (>= 1.4.2) - capistrano (~> 3.17.3) + capistrano (~> 3.19.2) capistrano-bundler (~> 1.1) capistrano-passenger (~> 0.2) capistrano-rails (~> 1.4) @@ -380,7 +379,7 @@ DEPENDENCIES omniauth omniauth-cul (~> 0.2.0) puma - rails (~> 7.1.2) + rails (~> 7.2.2) rainbow (~> 3.0) rspec-rails rubocul (~> 4.0) diff --git a/app/models/collection.rb b/app/models/collection.rb index 530d3cb..bf62fbb 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -2,8 +2,8 @@ class Collection < ApplicationRecord validates :name, presence: true validates :atom_title, presence: true validates :slug, presence: true - serialize :mime_types, Array - serialize :sword_package_types, Array + serialize :mime_types, type: Array + serialize :sword_package_types, type: Array has_many :deposits has_many :depositor_collection_pairings, dependent: :destroy has_many :depositors, through: :depositor_collection_pairings diff --git a/app/models/deposit.rb b/app/models/deposit.rb index c88589f..42a7368 100644 --- a/app/models/deposit.rb +++ b/app/models/deposit.rb @@ -1,6 +1,6 @@ class Deposit < ApplicationRecord # belongs_to :depositor # belongs_to :collectio - serialize :deposit_errors, Array - serialize :deposit_files, Array + serialize :deposit_errors, type: Array + serialize :deposit_files, type: Array end diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup index 3cd5a9d..632ab28 100755 --- a/bin/setup +++ b/bin/setup @@ -1,8 +1,8 @@ #!/usr/bin/env ruby require "fileutils" -# path to your application root. APP_ROOT = File.expand_path("..", __dir__) +APP_NAME = "sword-foo" def system!(*args) system(*args, exception: true) @@ -30,4 +30,8 @@ FileUtils.chdir APP_ROOT do puts "\n== Restarting application server ==" system! "bin/rails restart" + + # puts "\n== Configuring puma-dev ==" + # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}" + # system "curl -Is https://#{APP_NAME}.test/up | head -n 1" end diff --git a/config/application.rb b/config/application.rb index 990f947..48424c6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,7 @@ class Application < Rails::Application # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w(assets tasks)) + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # diff --git a/config/deploy.rb b/config/deploy.rb index 4e8c072..15f49bd 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,4 +1,4 @@ -lock '3.17.3' +lock '3.19.2' set :department, 'ldpd' set :instance, fetch(:department) diff --git a/config/environments/development.rb b/config/environments/development.rb index 2e7fb48..9b67360 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,7 +14,7 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true # Enable/disable caching. By default caching is disabled. @@ -24,9 +24,7 @@ config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -39,8 +37,12 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -66,11 +68,14 @@ # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true + config.action_view.annotate_rendered_view_with_filenames = true # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end diff --git a/config/environments/production.rb b/config/environments/production.rb index 368d6e6..0da8c9f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -26,7 +26,7 @@ # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass - # Do not fallback to assets pipeline if a precompiled asset is missed. + # Do not fall back to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. @@ -51,6 +51,9 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) .tap { |logger| logger.formatter = ::Logger::Formatter.new } @@ -59,7 +62,7 @@ # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] - # Info include generic and useful information about system operation, but avoids logging too much + # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") @@ -71,6 +74,8 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "sword_foo_production" + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. @@ -87,6 +92,10 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Only use :id for inspections in production. + # config.active_record.attributes_for_inspect = :all + config.active_record.attributes_for_inspect = [ :id ] + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/environments/test.rb b/config/environments/test.rb index adbb4a6..0c616a1 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,10 +18,7 @@ config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" - } + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -37,6 +34,8 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -44,6 +43,10 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: "www.example.com" } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -59,6 +62,6 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 2eeef96..bd5bcd2 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -9,4 +9,4 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) +# Rails.application.config.assets.precompile += %w[ admin.js admin.css ] diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c2d89e2..c010b83 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -4,5 +4,5 @@ # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 0000000..b549c4a --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,70 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. +# +# Example: +# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date +# +# This query used to return a `String`. +#++ +# Rails.application.config.active_record.postgresql_adapter_decode_dates = true + +### +# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are +# deploying to a memory constrained environment you may want to set this to `false`. +#++ +# Rails.application.config.yjit = true diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..03c166f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. + +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# to prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/public/404.html b/public/404.html index b612547..2be3af2 100644 --- a/public/404.html +++ b/public/404.html @@ -4,7 +4,7 @@ The page you were looking for doesn't exist (404) - +
diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 0000000..7cf1e16 --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,66 @@ + + + + Your browser is not supported (406) + + + + + + +
+
+

Your browser is not supported.

+

Please upgrade your browser to continue.

+
+
+ + diff --git a/public/422.html b/public/422.html index a21f82b..c08eac0 100644 --- a/public/422.html +++ b/public/422.html @@ -4,7 +4,7 @@ The change you wanted was rejected (422) - +
diff --git a/public/500.html b/public/500.html index 061abc5..78a030a 100644 --- a/public/500.html +++ b/public/500.html @@ -4,7 +4,7 @@ We're sorry, but something went wrong (500) - +
diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f3b5abcbde91cf6d7a6a26e514eb7e30f476f950 GIT binary patch literal 5599 zcmeHL-D}fO6hCR_taXJlzs3}~RuB=Iujyo=i*=1|1FN%E=zNfMTjru|Q<6v{J{U!C zBEE}?j6I3sz>fzN!6}L_BKjcuASk~1;Dg|U_@d{g?V8mM`~#9U+>>*Ezw>c(PjYWA z4(;!cgge6k5E&d$G5`S-0}!Ik>CV(0Y#1}s-v_gAHhja2=W1?nBAte9D2HG<(+)uj z!5=W4u*{VKMw#{V@^NNs4TClr!FAA%ID-*gc{R%CFKEzG<6gm*9s_uy)oMGW*=nJf zw{(Mau|2FHfXIv6C0@Wk5k)F=3jo1srV-C{pl&k&)4_&JjYrnbJiul}d0^NCSh(#7h=F;3{|>EU>h z6U8_p;^wK6mAB(1b92>5-HxJ~V}@3?G`&Qq-TbJ2(&~-HsH6F#8mFaAG(45eT3VPO zM|(Jd<+;UZs;w>0Qw}0>D%{~r{uo_Fl5_Bo3ABWi zWo^j^_T3dxG6J6fH8X)$a^%TJ#PU!=LxF=#Fd9EvKx_x>q<(KY%+y-08?kN9dXjXK z**Q=yt-FTU*13ouhCdqq-0&;Ke{T3sQU9IdzhV9LhQIpq*P{N)+}|Mh+a-VV=x?R} c>%+pvTcMWshj-umO}|qP?%A)*_KlqT3uEqhU;qFB literal 0 HcmV?d00001 diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..78307cc --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/robots.txt b/public/robots.txt index 3c9c7c0..c19f78a 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1 @@ -# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file From 34c06004117ac6905e0275c7dda290e5cab4a1b4 Mon Sep 17 00:00:00 2001 From: Fred Duby Date: Fri, 15 Nov 2024 11:58:31 -0500 Subject: [PATCH 2/4] Add encrypted credentials (SWORD-111) --- .gitignore | 2 ++ config/credentials.yml.enc | 1 + config/deploy.rb | 1 + 3 files changed, 4 insertions(+) create mode 100644 config/credentials.yml.enc diff --git a/.gitignore b/.gitignore index 597e4b5..fe089f0 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ # Ignore simplecov coverage report /coverage + +/config/master.key diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..43f9b98 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +v06g4L5370ws2l84uAwwWjVzFth5pYEZ/EJjI3/q71d9zYkq1JrHuCAAZh1fNzvbEd3m13n08m/CK+whQNBFSntoMKtTQ4gI6l4K3xWPLULR2UKZnIR7kQ0rTkO7PHtoMHvIS4GkEwkelbofvYoSwMuJElrKwZvtDB1c3GZotal5RYpMrvcaAd9/zCp7/6YvG5w/JDONe5sfhC8b3TWEaoAOagDOOxFv4kyn33uGKBJ5mqRB39nbp2SE8tkp9U2pORFFmlqGv96QyIh7dT0uzxCsY6K7AuZU6cmZ9wEuRmt7B0ejoL2iW6lk4hYAaP14mwif7VI0R+MM7MtnBZxOcALpwqvTaSuX1fmTbLxC2V79KCRbPY+ws3e8s6nW7FdHRR6HrRvBFrlttHhxLrCDRmVLwlN4--yc+eua1j1+T3zHL3--00tSaNKnHicurdZXqRzuRQ== \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index 15f49bd..39081e6 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -38,6 +38,7 @@ set :passenger_restart_with_touch, true set :linked_files, fetch(:linked_files, []).push( + 'config/master.key', 'config/collections.yml', 'config/database.yml', 'config/depositors.yml', From 033ab7b120a164726d44fccd385918a33e0433e1 Mon Sep 17 00:00:00 2001 From: Fred Duby Date: Thu, 21 Nov 2024 17:45:34 -0500 Subject: [PATCH 3/4] Ingest confirmation; re-submit; database changes (SWORD-113, SWORD-97) -) Save and display asset PIDs -) Compare expected and retrieved (from Hyacinth) asset PIDs -) Save and display ingest confirmation result -) Save and display path to deposit content -) deposit re-ingest --- Gemfile | 2 + Gemfile.lock | 6 +++ app/controllers/deposits_controller.rb | 52 +++++++++++++++++++ app/controllers/sword_controller.rb | 3 ++ app/models/deposit.rb | 1 + app/views/deposits/show.html.erb | 16 ++++++ config/routes.rb | 5 +- ...241121213246_add_asset_pids_to_deposits.rb | 5 ++ ...163611_add_ingest_confirmed_to_deposits.rb | 5 ++ ...1122185253_add_content_path_to_deposits.rb | 5 ++ db/schema.rb | 5 +- lib/sword/adapters/hyacinth_adapter.rb | 28 +++++++++- .../endpoints/mets_to_hyacinth_endpoint.rb | 12 +++++ spec/controllers/deposits_controller_spec.rb | 35 +++++++++++++ spec/factories/deposit.rb | 8 +++ spec/rails_helper.rb | 2 + spec/sword/adapters/hyacinth_adapter_spec.rb | 20 +++++++ .../mets_to_hyacinth_endpoint_spec.rb | 19 +++++++ 18 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20241121213246_add_asset_pids_to_deposits.rb create mode 100644 db/migrate/20241122163611_add_ingest_confirmed_to_deposits.rb create mode 100644 db/migrate/20241122185253_add_content_path_to_deposits.rb create mode 100644 spec/controllers/deposits_controller_spec.rb create mode 100644 spec/factories/deposit.rb diff --git a/Gemfile b/Gemfile index 514c9ad..82ca61a 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,8 @@ group :development, :test do # simplecov for test coverage gem 'simplecov', '~> 0.22', require: false + + gem 'factory_bot_rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 07f4a36..fc85dcb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -119,6 +119,11 @@ GEM drb (2.2.1) erubi (1.13.0) execjs (2.9.1) + factory_bot (6.5.0) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.4) + factory_bot (~> 6.5) + railties (>= 5.0.0) ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) @@ -372,6 +377,7 @@ DEPENDENCIES capistrano-rvm (~> 0.1) coffee-rails (~> 4.2) devise + factory_bot_rails jquery-rails listen mysql2 diff --git a/app/controllers/deposits_controller.rb b/app/controllers/deposits_controller.rb index 9c7850d..38eb310 100644 --- a/app/controllers/deposits_controller.rb +++ b/app/controllers/deposits_controller.rb @@ -63,6 +63,58 @@ def destroy end end + def get_endpoint(collection_slug, + depositor_user_id) + case COLLECTIONS[:slug][collection_slug][:parser] + when "academic-commons" + Sword::Endpoints::AcademicCommonsEndpoint.new(collection_slug, depositor_user_id) + when "proquest" + Sword::Endpoints::ProquestEndpoint.new(collection_slug, depositor_user_id) + when "eprints" + Sword::Endpoints::EprintsEndpoint.new(collection_slug, depositor_user_id) + else + # raise an exception here + end + end + + def resubmit + original_deposit = Deposit.find(params[:id]) + endpoint = get_endpoint(original_deposit.collection_slug, + original_deposit.depositor_user_id) + + path_to_deposit_contents = original_deposit.content_path + + # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. + Rails.logger.warn("About to resubmit deposit for deposit id: #{original_deposit.id}:" \ + "Collection slug: #{original_deposit.collection_slug}, " \ + "Username: #{original_deposit.depositor_user_id}, " \ + "Path to contents: #{path_to_deposit_contents}" + ) + + endpoint.handle_deposit(path_to_deposit_contents) + + # log basic essential info. Keep it terse! Gonna use :warn level, though not a warning. + Rails.logger.warn("Following is a re-deposit:" \ + "Title: #{endpoint.deposit_title.truncate_words(10)}, " \ + "Files: #{endpoint.documents_to_deposit}, " \ + "Hyacinth item pid: #{endpoint.adapter_item_identifier}, " \ + "Hyacinth asset pids: #{endpoint.asset_pids}, " \ + "Path to SWORD contents: #{path_to_deposit_contents}" + ) + + # create Deposit instance to store deposit info in database + resubmit_deposit = Deposit.new + resubmit_deposit.depositor_user_id = @depositor_user_id + resubmit_deposit.collection_slug = @collection_slug + resubmit_deposit.deposit_files = endpoint.documents_to_deposit + resubmit_deposit.title = "(RE-DEPOSIT) " + original_deposit.title + resubmit_deposit.item_in_hyacinth = endpoint.adapter_item_identifier + resubmit_deposit.asset_pids = endpoint.asset_pids + resubmit_deposit.ingest_confirmed = endpoint.confirm_ingest + resubmit_deposit.content_path = path_to_deposit_contents + resubmit_deposit.save + end + private # Use callbacks to share common setup or constraints between actions. def set_deposit diff --git a/app/controllers/sword_controller.rb b/app/controllers/sword_controller.rb index 9ba0efc..9e95360 100644 --- a/app/controllers/sword_controller.rb +++ b/app/controllers/sword_controller.rb @@ -47,6 +47,9 @@ def deposit @deposit.title = @endpoint.deposit_title.truncate_words(20).truncate(200, omission: '') @deposit.item_in_hyacinth = @endpoint.adapter_item_identifier + @deposit.asset_pids = @endpoint.asset_pids + @deposit.ingest_confirmed = @endpoint.confirm_ingest + @deposit.content_path = @path_to_deposit_contents @deposit.save # @depositor.deposits << @deposit # @collection.deposits << @deposit diff --git a/app/models/deposit.rb b/app/models/deposit.rb index 42a7368..4b03bfb 100644 --- a/app/models/deposit.rb +++ b/app/models/deposit.rb @@ -1,6 +1,7 @@ class Deposit < ApplicationRecord # belongs_to :depositor # belongs_to :collectio + serialize :asset_pids, type: Array serialize :deposit_errors, type: Array serialize :deposit_files, type: Array end diff --git a/app/views/deposits/show.html.erb b/app/views/deposits/show.html.erb index ad6fe89..41e52fb 100644 --- a/app/views/deposits/show.html.erb +++ b/app/views/deposits/show.html.erb @@ -5,6 +5,11 @@ <%= @deposit.title %>

+

+ Path to deposit contents: + <%= @deposit.content_path %> +

+

Files in deposit: <%= @deposit.deposit_files %> @@ -18,6 +23,16 @@ target: '_blank') %>

+

+ Asset PIDs: + <%= @deposit.asset_pids %> +

+ +

+ Ingest Confirmed? + <%= @deposit.ingest_confirmed %> +

+

Depositor User ID: <%= @deposit.depositor_user_id %> @@ -34,3 +49,4 @@

<%= link_to 'Delete', @deposit, method: :delete, data: { confirm: 'Are you sure?' } %> +<%= link_to 'Resubmit', resubmit_deposit_path %> diff --git a/config/routes.rb b/config/routes.rb index 60957d6..ab6de28 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,10 @@ post 'add_permission', action: 'add_permission', as: 'add_permission' end end - resources :deposits + resources :deposits do + get 'resubmit', on: :member + end + resources :packages # Example resource route with options: diff --git a/db/migrate/20241121213246_add_asset_pids_to_deposits.rb b/db/migrate/20241121213246_add_asset_pids_to_deposits.rb new file mode 100644 index 0000000..936ee37 --- /dev/null +++ b/db/migrate/20241121213246_add_asset_pids_to_deposits.rb @@ -0,0 +1,5 @@ +class AddAssetPidsToDeposits < ActiveRecord::Migration[7.2] + def change + add_column :deposits, :asset_pids, :text + end +end diff --git a/db/migrate/20241122163611_add_ingest_confirmed_to_deposits.rb b/db/migrate/20241122163611_add_ingest_confirmed_to_deposits.rb new file mode 100644 index 0000000..3ba9a49 --- /dev/null +++ b/db/migrate/20241122163611_add_ingest_confirmed_to_deposits.rb @@ -0,0 +1,5 @@ +class AddIngestConfirmedToDeposits < ActiveRecord::Migration[7.2] + def change + add_column :deposits, :ingest_confirmed, :boolean + end +end diff --git a/db/migrate/20241122185253_add_content_path_to_deposits.rb b/db/migrate/20241122185253_add_content_path_to_deposits.rb new file mode 100644 index 0000000..17cbd49 --- /dev/null +++ b/db/migrate/20241122185253_add_content_path_to_deposits.rb @@ -0,0 +1,5 @@ +class AddContentPathToDeposits < ActiveRecord::Migration[7.2] + def change + add_column :deposits, :content_path, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 644a6ca..a8f6bb4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_10_30_175752) do +ActiveRecord::Schema[7.2].define(version: 2024_11_22_185253) do create_table "collections", force: :cascade do |t| t.string "name", null: false t.string "atom_title", null: false @@ -58,6 +58,9 @@ t.datetime "updated_at", precision: nil, null: false t.string "depositor_user_id" t.string "collection_slug" + t.text "asset_pids" + t.boolean "ingest_confirmed" + t.string "content_path" t.index ["collection_id"], name: "index_deposits_on_collection_id" t.index ["collection_slug"], name: "index_deposits_on_collection_slug" t.index ["depositor_id"], name: "index_deposits_on_depositor_id" diff --git a/lib/sword/adapters/hyacinth_adapter.rb b/lib/sword/adapters/hyacinth_adapter.rb index 4ff2ab5..8737ecc 100644 --- a/lib/sword/adapters/hyacinth_adapter.rb +++ b/lib/sword/adapters/hyacinth_adapter.rb @@ -3,7 +3,8 @@ module Sword module Adapters class HyacinthAdapter - attr_reader :digital_object_data, + attr_reader :asset_pids, + :digital_object_data, :dynamic_field_data, :hyacinth_server_response, :item_pid @@ -37,6 +38,7 @@ class HyacinthAdapter :use_and_reproduction_uri def initialize + @asset_pids = [] @corporate_names = [] @dynamic_field_data = {} @notes = [] @@ -133,9 +135,33 @@ def ingest_asset(parent_pid, Rails.logger.warn("ingest_asset: Completed ingest request to Hyacinth") if HYACINTH_CONFIG[:log_ingest] end # puts @hyacinth_response.inspect + @asset_pids << pid_last_ingest @hyacinth_server_response end + def expected_and_retrieved_asset_pids_match? + # retrieve item info from Hyacinth + uri = URI("#{HYACINTH_CONFIG[:url]}/#{@item_pid}.json") + get_req = Net::HTTP::Get.new(uri) + get_req.basic_auth(HYACINTH_CONFIG[:username], + HYACINTH_CONFIG[:password]) + server_response = + Net::HTTP.start(uri.hostname, + uri.port, + use_ssl: HYACINTH_CONFIG[:use_ssl]) { |http| http.request(get_req) } + unless server_response.is_a? Net::HTTPSuccess + Rails.logger.warn("Item GET failure (Item PID: #{@item_pid}, HTTP code: #{server_response.code})") + return false + end + retrieved_pids = + JSON.parse(server_response.body)['ordered_child_digital_objects'].each.map { |pid_hash| pid_hash['pid'] } + pids_match = Set.new(@asset_pids) == Set.new(retrieved_pids) + unless pids_match + Rails.logger.warn("Asset pids mismatch (expected: #{@asset_pids}, retrieved from Hyacinth Item: #{retrieved_pids}") + end + pids_match + end + def last_ingest_successful? unless @hyacinth_server_response.nil? @hyacinth_server_response.body['success'] diff --git a/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb b/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb index 14c277c..95627b9 100644 --- a/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb +++ b/lib/sword/endpoints/mets_to_hyacinth_endpoint.rb @@ -9,6 +9,7 @@ class MetsToHyacinthEndpoint < Endpoint # Some of these can be removed if no need for external access, # though in that case specs may need to be updated to access # instance var directly instead of through attr_reader + attr_reader :asset_pids attr_reader :content_dir attr_reader :mets_xml_file attr_reader :mets_parser @@ -66,6 +67,7 @@ def ingest_into_hyacinth @adapter_item_identifier = ingest_item_into_hyacinth ingest_documents_into_hyacinth ingest_mets_xml_file_into_hyacinth + @asset_pids = @hyacinth_adapter.asset_pids else Rails.logger.warn "Bypassing ingest into Hyacinth, set bogus PID" # bogus item identifier. Instead, could use string 'NotApplicable' @@ -73,6 +75,16 @@ def ingest_into_hyacinth end end + def confirm_ingest + if @hyacinth_adapter.expected_and_retrieved_asset_pids_match? + Rails.logger.warn("MetsToHyacinthEndpoint: Ingest confirmed") + true + else + Rails.logger.warn("MetsToHyacinthEndpoint: INGEST NOT CONFIRMED!!!") + false + end + end + def handle_deposit(path_to_contents) @content_dir = path_to_contents #check existence of mets.xml file diff --git a/spec/controllers/deposits_controller_spec.rb b/spec/controllers/deposits_controller_spec.rb new file mode 100644 index 0000000..c8d9ef1 --- /dev/null +++ b/spec/controllers/deposits_controller_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe DepositsController do + describe 'get_endpoints' do + it 'returns a ProquestEndpoint for given args' do + endpoint = controller.get_endpoint('test-pq', 'firsttestdepositor') + expect(endpoint).to be_a(Sword::Endpoints::ProquestEndpoint) + end + end + + describe 'resubmit' do + before(:example) do + the_endpoint = double("the_endpoint") + allow(the_endpoint).to receive(:deposit_title) { "This is the title" } + allow(the_endpoint).to receive(:handle_deposit) {['a.txt', 'b.txt'] } + allow(the_endpoint).to receive(:documents_to_deposit) {['a.txt', 'b.txt'] } + allow(the_endpoint).to receive(:adapter_item_identifier) { 'ac:12345678' } + allow(the_endpoint).to receive(:asset_pids) { ['ac:10000000', 'ac:987654321'] } + allow(the_endpoint).to receive(:confirm_ingest) { true } + allow(controller).to receive(:get_endpoint) { the_endpoint } + allow_any_instance_of(Sword::Endpoints::ProquestEndpoint).to receive(:handle_deposit).and_return(the_endpoint) + end + + it 'creates new Deposit after re-ingest into Hyacinth' do + deposit = create(:deposit) + id = deposit.id + allow(controller).to receive(:params).and_return( { id: 1 } ) + expect(Deposit.count).to eq(1) + subject.resubmit + expect(Deposit.count).to eq(2) + end + end +end diff --git a/spec/factories/deposit.rb b/spec/factories/deposit.rb new file mode 100644 index 0000000..7e5314e --- /dev/null +++ b/spec/factories/deposit.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :deposit do + title { "This is a factory title" } + item_in_hyacinth { "ac:123456789" } + collection_slug { "test-pq" } + depositor_user_id { "depositor_user_id" } + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4b1ada3..d71ccb2 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -56,4 +56,6 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + config.include FactoryBot::Syntax::Methods end diff --git a/spec/sword/adapters/hyacinth_adapter_spec.rb b/spec/sword/adapters/hyacinth_adapter_spec.rb index 14b021a..99a793e 100644 --- a/spec/sword/adapters/hyacinth_adapter_spec.rb +++ b/spec/sword/adapters/hyacinth_adapter_spec.rb @@ -882,4 +882,24 @@ end end end + + describe 'expected_and_retrieved_asset_pids_match?' do + before(:example) do + http_success = double("http_success") + allow(http_success).to receive(:is_a?) { true } + allow(http_success).to receive(:body) { JSON.generate({'ordered_child_digital_objects' => [ { 'pid' => 'ac:12344321'} ] } ) } + allow_any_instance_of(Net::HTTP).to receive(:start).and_return(http_success) + end + it "returns true if pids match" do + subject.instance_variable_set(:@asset_pids, ['ac:12344321']) + res = subject.expected_and_retrieved_asset_pids_match? + expect(res).to be(true) + end + + it "returns false if pids don't match" do + subject.instance_variable_set(:@asset_pids, ['ac:123456789']) + res = subject.expected_and_retrieved_asset_pids_match? + expect(res).to be(false) + end + end end diff --git a/spec/sword/endpoints/mets_to_hyacinth_endpoint_spec.rb b/spec/sword/endpoints/mets_to_hyacinth_endpoint_spec.rb index 066fb2f..e619a79 100644 --- a/spec/sword/endpoints/mets_to_hyacinth_endpoint_spec.rb +++ b/spec/sword/endpoints/mets_to_hyacinth_endpoint_spec.rb @@ -30,4 +30,23 @@ # add check here about calling @mets_parser.parse end end + + describe 'confirm_ingest' do + before(:example) do + @mets_endpoint = Sword::Endpoints::MetsToHyacinthEndpoint.new('sample_collection_slug', + 'sample_depositor_user_id') + @hyacinth_adapter = double("hyacinth_adapter") + @mets_endpoint.instance_variable_set(:@hyacinth_adapter, @hyacinth_adapter) + end + + it 'returns false if expected_and_retrieved_asset_pids_match? returns false' do + allow(@hyacinth_adapter).to receive(:expected_and_retrieved_asset_pids_match?) { false } + expect(@mets_endpoint.confirm_ingest).to be(false) + end + + it 'returns true if expected_and_retrieved_asset_pids_match? return true' do + allow(@hyacinth_adapter).to receive(:expected_and_retrieved_asset_pids_match?) { true } + expect(@mets_endpoint.confirm_ingest).to be(true) + end + end end From cad3112afc1f9a5ec44690503987da5c9ecfe008 Mon Sep 17 00:00:00 2001 From: Fred Duby Date: Fri, 22 Nov 2024 15:21:23 -0500 Subject: [PATCH 4/4] Log asset PIDs (SWORD-117) --- app/controllers/sword_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/sword_controller.rb b/app/controllers/sword_controller.rb index 9e95360..00fdc2e 100644 --- a/app/controllers/sword_controller.rb +++ b/app/controllers/sword_controller.rb @@ -32,6 +32,7 @@ def deposit Rails.logger.warn("Title: #{@endpoint.deposit_title.truncate_words(10)}, " \ "Files: #{@endpoint.documents_to_deposit}, " \ "Hyacinth item pid: #{@endpoint.adapter_item_identifier}, " \ + "Hyacinth asset pids: #{@endpoint.asset_pids}, " \ "Path to SWORD contents: #{@path_to_deposit_contents}" )