From bcb8d315b7c81b5fd09f19e4f42072b61ee1ec8d Mon Sep 17 00:00:00 2001 From: Wendel Fabian Chinsamy Date: Fri, 3 May 2024 08:54:48 +0200 Subject: [PATCH] upgrade to rails 7.1 (#165) * upgrade rails * appease the rubocop overlords * deal with fixture_path deprecation warning * update gemfile.lock * fix deprecation warning * fix specs * fix spec * fix spec * fix specs * upgrade config gem. this was horrible and made me sad. * wip * revert route change --- Gemfile | 29 +- Gemfile.lock | 484 ++++++++++-------- app/controllers/admin/claims_controller.rb | 170 +++--- app/controllers/admin/users_controller.rb | 142 ++--- .../users/omniauth_callbacks_controller.rb | 244 ++++----- .../users/registrations_controller.rb | 26 +- app/controllers/users/sessions_controller.rb | 84 +-- app/models/claim.rb | 2 +- app/models/user.rb | 2 +- config/application.rb | 4 +- config/environments/development.rb | 1 + config/environments/production.rb | 1 + config/environments/stage.rb | 1 + config/environments/test.rb | 2 +- config/initializers/elasticsearch.rb | 2 +- config/initializers/flipper.rb | 2 +- .../new_framework_defaults_7_1.rb | 285 +++++++++++ spec/jobs/claim_job_spec.rb | 13 +- spec/jobs/user_job_spec.rb | 15 +- spec/models/external_identifier_spec.rb | 2 +- spec/models/user_spec.rb | 2 +- spec/models/work_spec.rb | 35 -- spec/rails_helper.rb | 2 +- 23 files changed, 916 insertions(+), 634 deletions(-) create mode 100644 config/initializers/new_framework_defaults_7_1.rb diff --git a/Gemfile b/Gemfile index f0004c2d..3a30c064 100755 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" gem "bootsnap", "~> 1.4", ">= 1.4.4", require: false gem "mysql2", "~> 0.5.0" -gem "rails", "~> 6.0" +gem "rails", "~> 7.1", ">= 7.1.3" gem "aasm", "~> 5.0", ">= 5.0.6" gem "active_model_serializers", "~> 0.10.10" @@ -12,13 +12,13 @@ gem "addressable", "~> 2.7" gem "aws-sdk-s3", require: false gem "aws-sdk-sqs", "~> 1.23", ">= 1.23.1" gem "base32-crockford-checksum", "~> 0.2.3" -gem "config", "~> 2.2", ">= 2.2.1" +gem "config", "~> 5.4" gem "dotenv", "~> 2.7", ">= 2.7.5" # IMPORTANT!!! # We have monkey patched this gem -> config/initializers/serialization_core.rb # Please check this before upgrading/downgrading versions gem "jsonapi-serializer", "~> 2.2" -gem "flipper", "~> 0.17.2" +gem "flipper", "~> 1.3" gem "flipper-active_support_cache_store" gem "flipper-api" gem "flipper-redis" @@ -26,11 +26,11 @@ gem "flipper-ui" gem "nilify_blanks", "~> 1.3" gem "oj", ">= 2.8.3" gem "oj_mimic_json", "~> 1.0", ">= 1.0.1" -gem "orcid_client", "~> 0.11.0" +gem "orcid_client", "~> 0.12.0" gem "postrank-uri", "~> 1.1" gem "pwqgen.rb", "~> 0.1.0" gem "rake", "~> 12.0" -gem "sentry-raven", "~> 2.13" +gem "sentry-raven", "~> 3.1", ">= 3.1.2" gem "shoryuken", "~> 5.0", ">= 5.0.3" gem "strip_attributes", "~> 1.9", ">= 1.9.2" gem "tzinfo-data", "~> 1.2019", ">= 1.2019.3" @@ -50,7 +50,7 @@ gem "rouge", "~> 3.15" gem "simple_form", "~> 4.1.0" gem "cancancan", "~> 3.0" -gem "devise", "~> 4.8" +gem "devise", "~> 4.8", ">= 4.8.1" gem "gravtastic", "~> 3.2", ">= 3.2.6" gem "jwt", "~> 2.2", ">= 2.2.1" gem "mailgun-ruby", "~> 1.2" @@ -68,13 +68,13 @@ gem "batch-loader", "~> 1.4", ">= 1.4.1" gem "elasticsearch", "~> 7.1.0" gem "elasticsearch-model", "~> 7.0", require: "elasticsearch/model" gem "elasticsearch-rails", "~> 7.0" -gem "faraday_middleware-aws-sigv4", "~> 0.2.4" +gem "faraday_middleware-aws-sigv4", "~> 0.3.0" gem "google-protobuf", "3.19.6" gem "graphql", "~> 1.9", ">= 1.9.16" gem "graphql-batch", "~> 0.4.1" gem "graphql-cache", "~> 0.6.0" gem "graphql-errors", "~> 0.4.0" -gem "maremma", ">= 4.3" +gem "maremma", "~> 5.0" gem "rack-utf8_sanitizer", "~> 1.6" gem "coffee-rails", "~> 4.1", ">= 4.1.1" @@ -91,8 +91,8 @@ group :development, :test do gem "binding_of_caller" gem "byebug", platforms: %i[mri mingw x64_mingw] gem "rspec-benchmark", "~> 0.4.0" - gem "rspec-graphql_matchers", "~> 1.1" - gem "rspec-rails", "~> 3.8", ">= 3.8.2" + gem "rspec-graphql_matchers", "~> 1.4" + gem "rspec-rails", "~> 6.1", ">= 6.1.1" gem "rubocop", "~> 1.3", ">= 1.3.1" gem "rubocop-performance", "~> 1.5", ">= 1.5.1" gem "rubocop-rails", "~> 2.8", ">= 2.8.1" @@ -101,10 +101,10 @@ group :development, :test do end group :development do - gem "listen", ">= 3.0.5", "< 3.2" + gem "listen", "~> 3.9" gem "spring" gem "spring-commands-rspec" - gem "spring-watcher-listen", "~> 2.0.0" + gem "spring-watcher-listen", "~> 2.1" end group :test do @@ -112,14 +112,15 @@ group :test do gem "capybara-screenshot", "~> 1.0", ">= 1.0.24" gem "cuprite", "~> 0.9" gem "database_cleaner" + gem "database_cleaner-active_record", "~> 2.1" gem "elasticsearch-extensions", "~> 0.0.29" gem "email_spec", "~> 2.2" gem "factory_bot_rails", "~> 4.8", ">= 4.8.2" gem "hashdiff", [">= 1.0.0.beta1", "< 2.0.0"] gem "shoulda-matchers", "~> 4.1", ">= 4.1.2" - gem "simplecov", "~> 0.17.1" + gem "simplecov", "~> 0.22.0" gem "test-prof", "~> 0.10.2" - gem "vcr", "~> 6.2" + gem "vcr", "~> 6.1" gem "webmock", "~> 3.1" gem "with_env", "~> 1.1" end diff --git a/Gemfile.lock b/Gemfile.lock index d6cd1ec0..80335072 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,70 +3,85 @@ GEM specs: aasm (5.2.0) concurrent-ruby (~> 1.0) - actioncable (6.1.7.7) - actionpack (= 6.1.7.7) - activesupport (= 6.1.7.7) + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.7) - actionpack (= 6.1.7.7) - activejob (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (>= 2.7.1) - actionmailer (6.1.7.7) - actionpack (= 6.1.7.7) - actionview (= 6.1.7.7) - activejob (= 6.1.7.7) - activesupport (= 6.1.7.7) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.7.7) - actionview (= 6.1.7.7) - activesupport (= 6.1.7.7) - rack (~> 2.0, >= 2.0.9) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.7) - actionpack (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7.7) - activesupport (= 6.1.7.7) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - active_model_serializers (0.10.12) - actionpack (>= 4.1, < 6.2) - activemodel (>= 4.1, < 6.2) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + active_model_serializers (0.10.14) + actionpack (>= 4.1) + activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (6.1.7.7) - activesupport (= 6.1.7.7) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (6.1.7.7) - activesupport (= 6.1.7.7) - activerecord (6.1.7.7) - activemodel (= 6.1.7.7) - activesupport (= 6.1.7.7) - activestorage (6.1.7.7) - actionpack (= 6.1.7.7) - activejob (= 6.1.7.7) - activerecord (= 6.1.7.7) - activesupport (= 6.1.7.7) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) + timeout (>= 0.4.0) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.7.7) + activesupport (7.1.3.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ansi (1.5.0) @@ -96,7 +111,8 @@ GEM base32-crockford-checksum (0.2.3) base64 (0.2.0) batch-loader (1.5.0) - bcrypt (3.1.16) + bcp47_spec (0.2.1) + bcrypt (3.1.20) benchmark-perf (0.4.0) benchmark-trend (0.2.0) benchmark_methods (0.7) @@ -107,9 +123,10 @@ GEM bibtex-ruby (6.1.0) latex-decode (~> 0.0) racc (~> 1.7) + bigdecimal (3.1.7) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bolognese (2.1.1) + bolognese (2.2.0) activesupport (>= 4.2.5) benchmark_methods (~> 0.7) bibtex-ruby (>= 5.1.0) @@ -124,9 +141,9 @@ GEM json-ld-preloaded (~> 3.1, >= 3.1.3) jsonlint (~> 0.3.0) loofah (~> 2.0, >= 2.0.3) - maremma (>= 4.9.4, < 5) + maremma (~> 5.0) namae (~> 1.0) - nokogiri (>= 1.13.2, < 1.14) + nokogiri (~> 1.16, >= 1.16.2) oj (~> 3.10) oj_mimic_json (~> 1.0, >= 1.0.1) postrank-uri (~> 1.0, >= 1.0.18) @@ -169,9 +186,9 @@ GEM commonmarker (0.21.2) ruby-enum (~> 0.5) concurrent-ruby (1.2.3) - config (2.2.3) + config (5.4.0) deep_merge (~> 1.2, >= 1.2.1) - dry-validation (~> 1.0, >= 1.0.0) + connection_pool (2.4.1) countries (3.1.0) i18n_data (~> 0.11.0) sixarm_ruby_unaccent (~> 1.1) @@ -191,16 +208,16 @@ GEM capybara (>= 2.1, < 4) ferrum (~> 0.11.0) dalli (2.7.11) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.1) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.4) debug_inspector (1.1.0) - deep_merge (1.2.1) - devise (4.8.0) + deep_merge (1.2.2) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -212,43 +229,12 @@ GEM domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.7.6) - dry-configurable (0.13.0) - concurrent-ruby (~> 1.0) - dry-core (~> 0.6) - dry-container (0.9.0) - concurrent-ruby (~> 1.0) - dry-configurable (~> 0.13, >= 0.13.0) - dry-core (0.7.1) - concurrent-ruby (~> 1.0) - dry-inflector (0.2.1) - dry-initializer (3.0.4) - dry-logic (1.2.0) - concurrent-ruby (~> 1.0) - dry-core (~> 0.5, >= 0.5) - dry-schema (1.8.0) - concurrent-ruby (~> 1.0) - dry-configurable (~> 0.13, >= 0.13.0) - dry-core (~> 0.5, >= 0.5) - dry-initializer (~> 3.0) - dry-logic (~> 1.0) - dry-types (~> 1.5) - dry-types (1.5.1) - concurrent-ruby (~> 1.0) - dry-container (~> 0.3) - dry-core (~> 0.5, >= 0.5) - dry-inflector (~> 0.1, >= 0.1.2) - dry-logic (~> 1.0, >= 1.0.2) - dry-validation (1.7.0) - concurrent-ruby (~> 1.0) - dry-container (~> 0.7, >= 0.7.1) - dry-core (~> 0.5, >= 0.5) - dry-initializer (~> 3.0) - dry-schema (~> 1.8, >= 1.8.0) - ebnf (2.3.5) + drb (2.2.1) + ebnf (2.5.0) htmlentities (~> 4.3) - rdf (~> 3.2) + rdf (~> 3.3) scanf (~> 1.0) - sxp (~> 1.2) + sxp (~> 2.0) unicode-types (~> 1.8) edtf (3.1.1) activesupport (>= 3.0, < 8.0) @@ -280,36 +266,49 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faraday (0.17.4) - multipart-post (>= 1.2, < 3) + faraday (2.9.0) + faraday-net_http (>= 2.0, < 3.2) faraday-encoding (0.0.5) faraday - faraday_middleware (0.14.0) - faraday (>= 0.7.4, < 1.0) - faraday_middleware-aws-sigv4 (0.2.4) + faraday-excon (2.1.0) + excon (>= 0.27.4) + faraday (~> 2.0) + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) + faraday-gzip (0.1.0) + faraday (>= 1.0) + zlib (~> 2.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (3.1.0) + net-http + faraday_middleware-aws-sigv4 (0.3.0) aws-sigv4 (~> 1.0) - faraday (>= 0.9) + faraday (>= 0.15) ferrum (0.11) addressable (~> 2.5) cliver (~> 0.3) concurrent-ruby (~> 1.1) websocket-driver (>= 0.6, < 0.8) - ffi (1.15.4) - flipper (0.17.2) - flipper-active_support_cache_store (0.17.2) - activesupport (>= 4.2, < 7) - flipper (~> 0.17.2) - flipper-api (0.17.2) - flipper (~> 0.17.2) - rack (>= 1.4, < 3) - flipper-redis (0.17.2) - flipper (~> 0.17.2) - redis (>= 2.2, < 5) - flipper-ui (0.17.2) + ffi (1.16.3) + flipper (1.3.0) + concurrent-ruby (< 2) + flipper-active_support_cache_store (1.3.0) + activesupport (>= 4.2, < 8) + flipper (~> 1.3.0) + flipper-api (1.3.0) + flipper (~> 1.3.0) + rack (>= 1.4, < 4) + flipper-redis (1.3.0) + flipper (~> 1.3.0) + redis (>= 3.0, < 6) + flipper-ui (1.3.0) erubi (>= 1.0.0, < 2.0.0) - flipper (~> 0.17.2) - rack (>= 1.4, < 3) - rack-protection (>= 1.5.3, < 2.1.0) + flipper (~> 1.3.0) + rack (>= 1.4, < 4) + rack-protection (>= 1.5.3, < 5.0.0) + rack-session (>= 1.0.2, < 3.0.0) + sanitize (< 7) gender_detector (0.1.2) unicode_utils (>= 1.3.0) git (1.9.1) @@ -335,20 +334,24 @@ GEM i18n (1.14.4) concurrent-ruby (~> 1.0) i18n_data (0.11.0) + io-console (0.7.2) + irb (1.12.0) + rdoc + reline (>= 0.4.2) iso8601 (0.9.1) jmespath (1.4.0) json (2.5.1) - json-canonicalization (0.4.0) - json-ld (3.2.5) + json-canonicalization (1.0.0) + json-ld (3.3.1) htmlentities (~> 4.3) - json-canonicalization (~> 0.3, >= 0.3.2) + json-canonicalization (~> 1.0) link_header (~> 0.0, >= 0.0.8) multi_json (~> 1.15) rack (>= 2.2, < 4) - rdf (~> 3.2, >= 3.2.10) - json-ld-preloaded (3.2.2) - json-ld (~> 3.2) - rdf (~> 3.2) + rdf (~> 3.3) + json-ld-preloaded (3.3.0) + json-ld (~> 3.3) + rdf (~> 3.3) jsonapi-renderer (0.2.2) jsonapi-serializer (2.2.0) activesupport (>= 4.2) @@ -372,9 +375,9 @@ GEM launchy (2.5.0) addressable (~> 2.7) link_header (0.0.8) - listen (3.0.8) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) + listen (3.9.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) lograge (0.11.2) actionpack (>= 4) activesupport (>= 4) @@ -394,19 +397,21 @@ GEM mailgun-ruby (1.2.5) rest-client (>= 2.0.2) marcel (1.0.4) - maremma (4.9.8) + maremma (5.0.0) activesupport (>= 4.2.5) addressable (>= 2.3.6) builder (~> 3.2, >= 3.2.2) excon (~> 0.71.0) - faraday (~> 0.17.3) - faraday-encoding (~> 0.0.4) - faraday_middleware (~> 0.14.0) - nokogiri (>= 1.11.2, < 1.14.0) + faraday (>= 2.0) + faraday-encoding (~> 0.0.5) + faraday-excon (~> 2.1.0) + faraday-follow_redirects (~> 0.3.0) + faraday-gzip (~> 0.1.0) + faraday-multipart (~> 1.0.4) + nokogiri (~> 1.16, >= 1.16.2) oj (>= 2.8.3) oj_mimic_json (~> 1.0, >= 1.0.1) matrix (0.4.2) - method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2021.0901) @@ -418,8 +423,11 @@ GEM multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) + mutex_m (0.2.0) mysql2 (0.5.6) namae (1.0.2) + net-http (0.4.1) + uri net-imap (0.3.7) date net-protocol @@ -434,15 +442,15 @@ GEM activerecord (>= 4.0.0) activesupport (>= 4.0.0) nio4r (2.7.1) - nokogiri (1.13.10) - mini_portile2 (~> 2.8.0) + nokogiri (1.16.4) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - oauth2 (1.4.7) - faraday (>= 0.8, < 2.0) + oauth2 (1.4.11) + faraday (>= 0.17.3, < 3.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) - rack (>= 1.2, < 3) + rack (>= 1.2, < 4) oj (3.13.9) oj_mimic_json (1.0.1) omniauth (2.0.4) @@ -466,14 +474,14 @@ GEM actionpack (>= 4.2) omniauth (~> 2.0) optimist (3.1.0) - orcid_client (0.11.0) - activesupport (>= 6, < 7) - bolognese (~> 2.1.0) + orcid_client (0.12.0) + activesupport (>= 7, < 8) + bolognese (~> 2.2) builder (~> 3.2, >= 3.2.2) dotenv (~> 2.1, >= 2.1.1) - maremma (>= 4.4) + maremma (>= 5.0) namae (~> 1.0.1) - nokogiri (>= 1.13.9) + nokogiri (>= 1.16.4) orm_adapter (0.5.0) parallel (1.22.1) parser (3.1.2.1) @@ -483,6 +491,8 @@ GEM nokogiri (>= 1.8.0) public_suffix (>= 4.0.0, < 5) promise.rb (0.7.4) + psych (5.1.2) + stringio public_suffix (4.0.7) pwqgen.rb (0.1.0) docopt (~> 0.5) @@ -496,65 +506,79 @@ GEM rack (>= 1.6.0) rack-protection (2.0.8.1) rack + rack-session (1.0.2) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) rack-utf8_sanitizer (1.7.0) rack (>= 1.0, < 3.0) - rails (6.1.7.7) - actioncable (= 6.1.7.7) - actionmailbox (= 6.1.7.7) - actionmailer (= 6.1.7.7) - actionpack (= 6.1.7.7) - actiontext (= 6.1.7.7) - actionview (= 6.1.7.7) - activejob (= 6.1.7.7) - activemodel (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + rackup (1.0.0) + rack (< 3) + webrick + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) bundler (>= 1.15.0) - railties (= 6.1.7.7) - sprockets-rails (>= 2.0.0) + railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (6.1.7.7) - actionpack (= 6.1.7.7) - activesupport (= 6.1.7.7) - method_source + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) rake (12.3.3) - rb-fsevent (0.11.0) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) rchardet (1.8.0) - rdf (3.2.11) + rdf (3.3.1) + bcp47_spec (~> 0.2) link_header (~> 0.0, >= 0.0.8) - rdf-rdfxml (3.2.2) - builder (~> 3.2) + rdf-rdfxml (3.3.0) + builder (~> 3.2, >= 3.2.4) htmlentities (~> 4.3) - rdf (~> 3.2) - rdf-xsd (~> 3.2) - rdf-turtle (3.2.1) - ebnf (~> 2.3) - rdf (~> 3.2) - rdf-xsd (3.2.1) - rdf (~> 3.2) + rdf (~> 3.3) + rdf-xsd (~> 3.3) + rdf-turtle (3.3.1) + base64 (~> 0.2) + bigdecimal (~> 3.1, >= 3.1.5) + ebnf (~> 2.5) + rdf (~> 3.3) + rdf-xsd (3.3.0) + rdf (~> 3.3) rexml (~> 3.2) + rdoc (6.6.3.1) + psych (>= 4.0.0) redis (4.4.0) regexp_parser (2.1.1) + reline (0.5.3) + io-console (~> 0.5) remotipart (1.4.4) repost (0.3.8) request_store (1.5.0) rack (>= 1.4) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) @@ -562,33 +586,34 @@ GEM netrc (~> 0.8) rexml (3.2.5) rouge (3.26.1) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) rspec-benchmark (0.4.0) benchmark-perf (~> 0.4.0) benchmark-trend (~> 0.2.0) rspec (>= 3.0.0, < 4.0.0) - rspec-core (3.9.3) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.4) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-graphql_matchers (1.3.0) - graphql (>= 1.8, < 2.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.13.0) + rspec-graphql_matchers (1.4.0) + graphql (>= 1.10.12, < 2.0) + rspec (~> 3.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-rails (3.9.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.4) + rspec-support (~> 3.13.0) + rspec-rails (6.1.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) rubocop (1.38.0) json (~> 2.3) parallel (~> 1.10) @@ -615,9 +640,12 @@ GEM i18n ruby-progressbar (1.11.0) ruby_dig (0.0.2) + sanitize (6.1.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) scanf (1.0.0) - sentry-raven (2.13.0) - faraday (>= 0.7.6, < 1.0) + sentry-raven (3.1.2) + faraday (>= 1.0) shoryuken (5.2.3) aws-sdk-core (>= 2) concurrent-ruby @@ -627,20 +655,21 @@ GEM simple_form (4.1.0) actionpack (>= 5.0) activemodel (>= 5.0) - simplecov (0.17.1) + simplecov (0.22.0) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) sixarm_ruby_unaccent (1.2.0) sort_alphabetical (1.1.0) unicode_utils (>= 1.2.2) - spring (2.1.1) + spring (4.2.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - spring-watcher-listen (2.0.1) + spring-watcher-listen (2.1.0) listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) + spring (>= 4) sprockets (3.7.3) base64 concurrent-ruby (~> 1.0) @@ -649,11 +678,12 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - strip_attributes (1.11.0) - activemodel (>= 3.0, < 7.0) - sxp (1.2.4) + stringio (3.1.0) + strip_attributes (1.13.0) + activemodel (>= 3.0, < 8.0) + sxp (2.0.0) matrix (~> 0.4) - rdf (~> 3.2) + rdf (~> 3.3) sysrandom (1.0.5) test-prof (0.10.2) thor (1.3.1) @@ -671,6 +701,7 @@ GEM unicode-display_width (2.3.0) unicode-types (1.9.0) unicode_utils (1.4.0) + uri (0.13.0) validates_email_format_of (1.6.3) i18n vcr (6.2.0) @@ -680,6 +711,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -687,6 +719,7 @@ GEM xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.6.13) + zlib (2.1.1) PLATFORMS ruby @@ -709,12 +742,13 @@ DEPENDENCIES capybara-screenshot (~> 1.0, >= 1.0.24) coffee-rails (~> 4.1, >= 4.1.1) commonmarker (~> 0.21.0) - config (~> 2.2, >= 2.2.1) + config (~> 5.4) country_select (~> 4.0) cuprite (~> 0.9) dalli (~> 2.7, >= 2.7.10) database_cleaner - devise (~> 4.8) + database_cleaner-active_record (~> 2.1) + devise (~> 4.8, >= 4.8.1) dotenv (~> 2.7, >= 2.7.5) elasticsearch (~> 7.1.0) elasticsearch-extensions (~> 0.0.29) @@ -722,8 +756,8 @@ DEPENDENCIES elasticsearch-rails (~> 7.0) email_spec (~> 2.2) factory_bot_rails (~> 4.8, >= 4.8.2) - faraday_middleware-aws-sigv4 (~> 0.2.4) - flipper (~> 0.17.2) + faraday_middleware-aws-sigv4 (~> 0.3.0) + flipper (~> 1.3) flipper-active_support_cache_store flipper-api flipper-redis @@ -740,12 +774,12 @@ DEPENDENCIES jsonapi-serializer (~> 2.2) jwt (~> 2.2, >= 2.2.1) kaminari (~> 1.2) - listen (>= 3.0.5, < 3.2) + listen (~> 3.9) lograge (~> 0.11.2) logstash-event (~> 1.2, >= 1.2.02) logstash-logger (~> 0.26.1) mailgun-ruby (~> 1.2) - maremma (>= 4.3) + maremma (~> 5.0) mini_magick (~> 4.5, >= 4.5.1) mysql2 (~> 0.5.0) namae (~> 1.0, >= 1.0.1) @@ -759,33 +793,33 @@ DEPENDENCIES omniauth-globus (~> 0.9.1) omniauth-orcid (~> 2.0) omniauth-rails_csrf_protection (~> 1.0) - orcid_client (~> 0.11.0) + orcid_client (~> 0.12.0) postrank-uri (~> 1.1) pwqgen.rb (~> 0.1.0) rack-cors (~> 1.0) rack-jwt rack-utf8_sanitizer (~> 1.6) - rails (~> 6.0) + rails (~> 7.1, >= 7.1.3) rake (~> 12.0) remotipart (~> 1.2) repost (~> 0.3.7) rouge (~> 3.15) rspec-benchmark (~> 0.4.0) - rspec-graphql_matchers (~> 1.1) - rspec-rails (~> 3.8, >= 3.8.2) + rspec-graphql_matchers (~> 1.4) + rspec-rails (~> 6.1, >= 6.1.1) rubocop (~> 1.3, >= 1.3.1) rubocop-packaging (~> 0.5.1) rubocop-performance (~> 1.5, >= 1.5.1) rubocop-rails (~> 2.8, >= 2.8.1) rubocop-rspec (~> 2.0) - sentry-raven (~> 2.13) + sentry-raven (~> 3.1, >= 3.1.2) shoryuken (~> 5.0, >= 5.0.3) shoulda-matchers (~> 4.1, >= 4.1.2) simple_form (~> 4.1.0) - simplecov (~> 0.17.1) + simplecov (~> 0.22.0) spring spring-commands-rspec - spring-watcher-listen (~> 2.0.0) + spring-watcher-listen (~> 2.1) sprockets (~> 3.7, >= 3.7.2) sprockets-rails (~> 3.2, >= 3.2.1) strip_attributes (~> 1.9, >= 1.9.2) @@ -793,7 +827,7 @@ DEPENDENCIES tzinfo-data (~> 1.2019, >= 1.2019.3) uglifier (~> 2.7, >= 2.7.2) validates_email_format_of (~> 1.6, >= 1.6.3) - vcr (~> 6.2) + vcr (~> 6.1) webmock (~> 3.1) with_env (~> 1.1) diff --git a/app/controllers/admin/claims_controller.rb b/app/controllers/admin/claims_controller.rb index 328d0124..38ec7eae 100644 --- a/app/controllers/admin/claims_controller.rb +++ b/app/controllers/admin/claims_controller.rb @@ -1,102 +1,104 @@ # frozen_string_literal: true -class Admin::ClaimsController < ApplicationController - before_action :load_user, only: %i[index edit update destroy] - before_action :load_claim, only: %i[edit update destroy] - load_and_authorize_resource - - def index - load_index - end - - def edit - load_index +module Admin + class ClaimsController < ApplicationController + before_action :load_user, only: %i[index edit update destroy] + before_action :load_claim, only: %i[edit update destroy] + load_and_authorize_resource + + def index + load_index + end - render :edit - end + def edit + load_index - def update - if params[:claim][:resolve] - params[:claim][:state] = "waiting" - params[:claim][:error_messages] = nil - params[:claim] = params[:claim].except(:resolve) + render :edit end - @claim.update(safe_params) - - @claim.queue_claim_job + def update + if params[:claim][:resolve] + params[:claim][:state] = "waiting" + params[:claim][:error_messages] = nil + params[:claim] = params[:claim].except(:resolve) + end - load_index + @claim.update(safe_params) - render :index - end + @claim.queue_claim_job - def destroy - @claim.destroy - load_index - render :index - end + load_index - protected - def load_index - sort = case params[:sort] - when "relevance" then { "_score" => { order: "desc" } } - when "doi" then { "doi" => { order: "asc" } } - when "-doi" then { "doi" => { order: "desc" } } - when "orcid" then { orcid: { order: "asc" } } - when "-orcid" then { orcid: { order: "desc" } } - when "created" then { created: { order: "asc" } } - when "-created" then { created: { order: "desc" } } - when "updated" then { updated: { order: "asc" } } - when "-updated" then { updated: { order: "desc" } } - else { "updated" => { order: "desc" } } - end + render :index + end - @page = params[:page] || 1 - - response = Claim.query(params[:query], - dois: params[:dois], - user_id: params[:user_id], - source_id: params[:source_id], - claim_action: params[:claim_action], - state: params[:state], - created: params[:created], - claimed: params[:claimed], - page: { number: @page }, - sort: sort) - - @total = response.results.total - @claims = response.results - - @created = @total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil - @sources = @total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil - @users = @total > 0 ? facet_by_id(response.response.aggregations.users.buckets) : nil - @claim_actions = @total > 0 ? facet_by_key(response.response.aggregations.claim_actions.buckets) : nil - @states = @total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil + def destroy + @claim.destroy + load_index + render :index end - def load_user - if user_signed_in? - @user = current_user - else - fail CanCan::AccessDenied.new("Please sign in first.", :read, User) + protected + def load_index + sort = case params[:sort] + when "relevance" then { "_score" => { order: "desc" } } + when "doi" then { "doi" => { order: "asc" } } + when "-doi" then { "doi" => { order: "desc" } } + when "orcid" then { orcid: { order: "asc" } } + when "-orcid" then { orcid: { order: "desc" } } + when "created" then { created: { order: "asc" } } + when "-created" then { created: { order: "desc" } } + when "updated" then { updated: { order: "asc" } } + when "-updated" then { updated: { order: "desc" } } + else { "updated" => { order: "desc" } } + end + + @page = params[:page] || 1 + + response = Claim.query(params[:query], + dois: params[:dois], + user_id: params[:user_id], + source_id: params[:source_id], + claim_action: params[:claim_action], + state: params[:state], + created: params[:created], + claimed: params[:claimed], + page: { number: @page }, + sort: sort) + + @total = response.results.total + @claims = response.results + + @created = @total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil + @sources = @total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil + @users = @total > 0 ? facet_by_id(response.response.aggregations.users.buckets) : nil + @claim_actions = @total > 0 ? facet_by_key(response.response.aggregations.claim_actions.buckets) : nil + @states = @total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil end - end - def load_claim - if user_signed_in? - @claim = Claim.where(uuid: params[:id]).first - else - fail CanCan::AccessDenied.new("Please sign in first.", :read, Claim) + def load_user + if user_signed_in? + @user = current_user + else + fail CanCan::AccessDenied.new("Please sign in first.", :read, User) + end end - end - private - def safe_params - params.require(:claim).permit(:state, - :aasm_state, - :put_code, - :claim_action, - :error_messages) - end + def load_claim + if user_signed_in? + @claim = Claim.where(uuid: params[:id]).first + else + fail CanCan::AccessDenied.new("Please sign in first.", :read, Claim) + end + end + + private + def safe_params + params.require(:claim).permit(:state, + :aasm_state, + :put_code, + :claim_action, + :error_messages) + end + end end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 7760c533..ef98f76f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,90 +1,92 @@ # frozen_string_literal: true -class Admin::UsersController < ApplicationController - # include base controller methods - include Authenticable +module Admin + class UsersController < ApplicationController + # include base controller methods + include Authenticable - before_action :load_user, only: %i[edit update destroy] - load_and_authorize_resource except: [:index] + before_action :load_user, only: %i[edit update destroy] + load_and_authorize_resource except: [:index] - def index - load_index + def index + load_index - render :index - end + render :index + end - def edit - load_index + def edit + load_index - render :edit - end + render :edit + end - def update - # admin updates user account - @user.update(safe_params) + def update + # admin updates user account + @user.update(safe_params) - load_index - render :edit - end + load_index + render :edit + end - def destroy - @user.destroy - load_index - render :index - end + def destroy + @user.destroy + load_index + render :index + end - protected - def load_user - if user_signed_in? - @user = User.where(uid: params[:id]).first - else - fail CanCan::AccessDenied.new("Please sign in first.", :read, User) + protected + def load_user + if user_signed_in? + @user = User.where(uid: params[:id]).first + else + fail CanCan::AccessDenied.new("Please sign in first.", :read, User) + end end - end - def load_index - authorize! :manage, Phrase + def load_index + authorize! :manage, Phrase - sort = case params[:sort] - when "relevance" then { "_score" => { order: "desc" } } - when "name" then { "family_name.raw" => { order: "asc" } } - when "-name" then { "family_name.raw" => { order: "desc" } } - when "created" then { created_at: { order: "asc" } } - when "-created" then { created_at: { order: "desc" } } - else { "family_name.raw" => { order: "asc" } } - end + sort = case params[:sort] + when "relevance" then { "_score" => { order: "desc" } } + when "name" then { "family_name.raw" => { order: "asc" } } + when "-name" then { "family_name.raw" => { order: "desc" } } + when "created" then { created_at: { order: "asc" } } + when "-created" then { created_at: { order: "desc" } } + else { "family_name.raw" => { order: "asc" } } + end - @page = params[:page] || 1 + @page = params[:page] || 1 - response = User.query(params[:query], - created: params[:created], - role_id: params[:role_id], - page: { number: @page }, - sort: sort) + response = User.query(params[:query], + created: params[:created], + role_id: params[:role_id], + page: { number: @page }, + sort: sort) - @total = response.results.total - @users = response.results + @total = response.results.total + @users = response.results - @created = @total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil - @roles = @total > 0 ? facet_by_key(response.response.aggregations.roles.buckets) : nil - end + @created = @total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil + @roles = @total > 0 ? facet_by_key(response.response.aggregations.roles.buckets) : nil + end - private - def safe_params - params.require(:user).permit(:name, - :email, - :auto_update, - :role_id, - :is_public, - :beta_tester, - :provider_id, - :client_id, - :expires_at, - :orcid_token, - :orcid_expires_at, - :github, - :github_uid, - :github_token, - :authentication_token) - end + private + def safe_params + params.require(:user).permit(:name, + :email, + :auto_update, + :role_id, + :is_public, + :beta_tester, + :provider_id, + :client_id, + :expires_at, + :orcid_token, + :orcid_expires_at, + :github, + :github_uid, + :github_token, + :authentication_token) + end + end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index d02377bf..52a69dd2 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -1,165 +1,167 @@ # frozen_string_literal: true -class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController - rescue_from ActiveRecord::RecordInvalid do |exception| - redirect_to root_path, alert: exception.message - end +module Users + class OmniauthCallbacksController < Devise::OmniauthCallbacksController + rescue_from ActiveRecord::RecordInvalid do |exception| + redirect_to root_path, alert: exception.message + end + + # include base controller methods + include Authenticable - # include base controller methods - include Authenticable + def forward + store_location_for(:user, request.referer) - def forward - store_location_for(:user, request.referer) + if params[:provider].present? + redirect_post("/users/auth/#{params[:provider]}", options: { authenticity_token: :auto }) + else + flash[:alert] = "Error signing in: no provider" + redirect_to root_path + end + end - if params[:provider].present? - redirect_post("/users/auth/#{params[:provider]}", options: { authenticity_token: :auto }) - else - flash[:alert] = "Error signing in: no provider" + def failure + flash[:alert] = "Error signing in: #{request.env['omniauth.error.type'].to_s.humanize}" redirect_to root_path end - end - def failure - flash[:alert] = "Error signing in: #{request.env['omniauth.error.type'].to_s.humanize}" - redirect_to root_path - end + def github + auth = request.env["omniauth.auth"] - def github - auth = request.env["omniauth.auth"] + if current_user.present? + @user = current_user + @user.update(github: auth.info.nickname, + github_uid: auth.uid, + github_token: auth.credentials.token) - if current_user.present? - @user = current_user - @user.update(github: auth.info.nickname, - github_uid: auth.uid, - github_token: auth.credentials.token) + flash[:notice] = "Account successfully linked with GitHub account." - flash[:notice] = "Account successfully linked with GitHub account." + if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" + if @user.role_id == "staff_admin" + token = @user.github_token + content = nil + else + token = nil + content = "No permission." + end - if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" - if @user.role_id == "staff_admin" - token = @user.github_token - content = nil + netlify_response(token: token, content: content) else - token = nil - content = "No permission." + redirect_to stored_location_for(:user) || setting_path("me") end + elsif @user = User.where(github_uid: auth.uid).first + cookies[:_datacite] = encode_cookie(@user.jwt) - netlify_response(token: token, content: content) - else - redirect_to stored_location_for(:user) || setting_path("me") - end - elsif @user = User.where(github_uid: auth.uid).first - cookies[:_datacite] = encode_cookie(@user.jwt) + sign_in @user - sign_in @user + if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" + if @user.role_id == "staff_admin" + token = @user.github_token + content = nil + else + token = nil + content = "No permission." + end - if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" - if @user.role_id == "staff_admin" - token = @user.github_token - content = nil + netlify_response(token: token, content: content) else - token = nil - content = "No permission." + redirect_to stored_location_for(:user) || setting_path("me") end - - netlify_response(token: token, content: content) else - redirect_to stored_location_for(:user) || setting_path("me") + flash[:omniauth] = { "github" => auth.info.nickname, + "github_uid" => auth.uid, + "github_token" => auth.credentials.token } + redirect_to "/link_orcid" end - else - flash[:omniauth] = { "github" => auth.info.nickname, - "github_uid" => auth.uid, - "github_token" => auth.credentials.token } - redirect_to "/link_orcid" end - end - def globus - auth = request.env["omniauth.auth"] - - if current_user.present? - @user = current_user - @user.update(email: auth.info.email, organization: auth.extra.id_info? ? auth.extra.id_info.organization : nil) - flash[:notice] = "Account successfully linked with Globus account." - redirect_to user_path("me") && return - else - # extract ORCID ID from preferred_username - @user = User.from_omniauth(auth, provider: "globus", uid: auth.extra.id_info.preferred_username[0..18]) - end + def globus + auth = request.env["omniauth.auth"] - if Time.zone.now > @user.expires_at - auth_hash = User.get_auth_hash(auth, authentication_token: auth.credentials.token, expires_at: Time.at(auth.credentials.expires_at).utc) - @user.update(auth_hash) - end + if current_user.present? + @user = current_user + @user.update(email: auth.info.email, organization: auth.extra.id_info? ? auth.extra.id_info.organization : nil) + flash[:notice] = "Account successfully linked with Globus account." + redirect_to user_path("me") && return + else + # extract ORCID ID from preferred_username + @user = User.from_omniauth(auth, provider: "globus", uid: auth.extra.id_info.preferred_username[0..18]) + end - if @user.persisted? - sign_in @user + if Time.zone.now > @user.expires_at + auth_hash = User.get_auth_hash(auth, authentication_token: auth.credentials.token, expires_at: Time.at(auth.credentials.expires_at).utc) + @user.update(auth_hash) + end - cookies[:_datacite] = encode_cookie(@user.jwt) + if @user.persisted? + sign_in @user - redirect_to stored_location_for(:user) || setting_path("me") - else - flash[:alert] = @user.errors.map { |k, v| "#{k}: #{v}" }.join("
").html_safe || "Error signing in with #{provider}" - redirect_to root_path - end - end + cookies[:_datacite] = encode_cookie(@user.jwt) - def orcid - auth = request.env["omniauth.auth"] - omniauth = flash[:omniauth] || {} - - if current_user.present? - @user = current_user - @user.update(orcid_expires_at: User.timestamp(auth.credentials), - orcid_token: auth.credentials.token) - flash[:notice] = "ORCID token successfully refreshed." - else - @user = User.from_omniauth(auth, provider: "globus") + redirect_to stored_location_for(:user) || setting_path("me") + else + flash[:alert] = @user.errors.map { |k, v| "#{k}: #{v}" }.join("
").html_safe || "Error signing in with #{provider}" + redirect_to root_path + end end - if Time.zone.now > @user.expires_at || omniauth.present? - auth_hash = User.get_auth_hash(auth, omniauth) - @user.update(auth_hash) + def orcid + auth = request.env["omniauth.auth"] + omniauth = flash[:omniauth] || {} - # push GitHub external identifier to ORCID if GitHub account is linked - GithubJob.perform_later(@user) if @user.github_put_code.blank? && @user.github.present? - end + if current_user.present? + @user = current_user + @user.update(orcid_expires_at: User.timestamp(auth.credentials), + orcid_token: auth.credentials.token) + flash[:notice] = "ORCID token successfully refreshed." + else + @user = User.from_omniauth(auth, provider: "globus") + end - if @user.persisted? - sign_in @user + if Time.zone.now > @user.expires_at || omniauth.present? + auth_hash = User.get_auth_hash(auth, omniauth) + @user.update(auth_hash) - cookies[:_datacite] = encode_cookie(@user.jwt) + # push GitHub external identifier to ORCID if GitHub account is linked + GithubJob.perform_later(@user) if @user.github_put_code.blank? && @user.github.present? + end + + if @user.persisted? + sign_in @user + + cookies[:_datacite] = encode_cookie(@user.jwt) - if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" - if @user.github_token.blank? - token = nil - content = "No GitHub token found." - elsif @user.role_id == "staff_admin" - token = @user.github_token - content = nil + if stored_location_for(:user) == ENV["BLOG_URL"] + "/admin/" + if @user.github_token.blank? + token = nil + content = "No GitHub token found." + elsif @user.role_id == "staff_admin" + token = @user.github_token + content = nil + else + token = nil + content = "No permission." + end + + netlify_response(token: token, content: content) else - token = nil - content = "No permission." + redirect_to stored_location_for(:user) || setting_path("me") end - - netlify_response(token: token, content: content) else - redirect_to stored_location_for(:user) || setting_path("me") + flash[:alert] = @user.errors.map { |k, v| "#{k}: #{v}" }.join("
").html_safe || "Error signing in with #{provider}" + redirect_to root_path end - else - flash[:alert] = @user.errors.map { |k, v| "#{k}: #{v}" }.join("
").html_safe || "Error signing in with #{provider}" - redirect_to root_path end - end - def netlify_response(token: nil, content: nil) - content = { token: token, provider: "github" } if token.present? - content ||= "Error authenticating user." + def netlify_response(token: nil, content: nil) + content = { token: token, provider: "github" } if token.present? + content ||= "Error authenticating user." - message = "success" if token.present? - message ||= "error" + message = "success" if token.present? + message ||= "error" - @post_message = "authorization:github:#{message}:#{content.to_json}".to_json - render "users/sessions/netlify", layout: false, status: :ok + @post_message = "authorization:github:#{message}:#{content.to_json}".to_json + render "users/sessions/netlify", layout: false, status: :ok + end end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 3fd1518d..d1ffefe7 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,18 +1,20 @@ # frozen_string_literal: true -class Users::RegistrationsController < Devise::RegistrationsController - before_action :configure_permitted_parameters, if: :devise_controller? +module Users + class RegistrationsController < Devise::RegistrationsController + before_action :configure_permitted_parameters, if: :devise_controller? - def new - redirect_to new_user_session_path if User.count > 0 - end - - protected - def configure_permitted_parameters - devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :family_name, :given_names, :email) } + def new + redirect_to new_user_session_path if User.count > 0 end - def after_inactive_sign_up_path_for(_resource_or_scope) - session["user_return_to"] || root_path - end + protected + def configure_permitted_parameters + devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :family_name, :given_names, :email) } + end + + def after_inactive_sign_up_path_for(_resource_or_scope) + session["user_return_to"] || root_path + end + end end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 34d9b21a..28f85d22 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,52 +1,54 @@ # frozen_string_literal: true -class Users::SessionsController < Devise::SessionsController - # prepend_before_action :authenticate_user!, :only => [:destroy] - - # GET /sign_in - def new - store_location_for(:user, request.referer) - @show_image = true - super - end - - # POST /sign_in - def create - super - end +module Users + class SessionsController < Devise::SessionsController + # prepend_before_action :authenticate_user!, :only => [:destroy] + + # GET /sign_in + def new + store_location_for(:user, request.referer) + @show_image = true + super + end - # GET /sign_out - def destroy - cookies[:_datacite] = empty_cookie - super - end + # POST /sign_in + def create + super + end - def link_orcid - if current_user.present? - flash[:warning] = "You are already signed in." - redirect_to root_path + # GET /sign_out + def destroy + cookies[:_datacite] = empty_cookie + super end - @show_image = true - flash.keep(:omniauth) - end + def link_orcid + if current_user.present? + flash[:warning] = "You are already signed in." + redirect_to root_path + end - def empty_cookie - value = '{"authenticated":{}}' - - domain = if Rails.env.production? - ".datacite.org" - elsif Rails.env.stage? && ENV["ES_PREFIX"].present? - ".stage.datacite.org" - elsif Rails.env.stage? - ".test.datacite.org" - else - "localhost" + @show_image = true + flash.keep(:omniauth) end - # URI.encode optional parameter needed to encode colon - { value: value, # URI.encode(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")), - secure: !Rails.env.development? && !Rails.env.test?, - domain: domain } + def empty_cookie + value = '{"authenticated":{}}' + + domain = if Rails.env.production? + ".datacite.org" + elsif Rails.env.stage? && ENV["ES_PREFIX"].present? + ".stage.datacite.org" + elsif Rails.env.stage? + ".test.datacite.org" + else + "localhost" + end + + # URI.encode optional parameter needed to encode colon + { value: value, # URI.encode(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")), + secure: !Rails.env.development? && !Rails.env.test?, + domain: domain } + end end end diff --git a/app/models/claim.rb b/app/models/claim.rb index b3cbf327..6f1bcf78 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -86,7 +86,7 @@ class Claim < ApplicationRecord scope :auto_update, -> { where(source_id: "orcid_update").where("claimed_at IS NOT NULL") } scope :total_count, -> { where(claim_action: "create").count } - serialize :error_messages, JSON + serialize :error_messages, coder: JSON # use different index for testing index_name Rails.env.test? ? "claims-test" : "claims" diff --git a/app/models/user.rb b/app/models/user.rb index 30bbddd8..5130c9e6 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,7 +51,7 @@ class User < ApplicationRecord alias_attribute :updated, :updated_at alias_attribute :given_name, :given_names - serialize :other_names, JSON + serialize :other_names, coder: JSON # use different index for testing index_name Rails.env.test? ? "users-test" : "users" diff --git a/config/application.rb b/config/application.rb index 3014789d..643058f5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -57,7 +57,7 @@ module Volpino class Application < Rails::Application # autoload files in lib folder - config.autoload_paths << Rails.root.join("lib") + config.autoload_lib(ignore: nil) # include graphql config.paths.add Rails.root.join("app", "graphql", "types").to_s, eager_load: true @@ -70,7 +70,7 @@ class Application < Rails::Application config.filter_parameters += [:jwt] # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.0 + config.load_defaults 7.1 # configure logging config.active_job.logger = nil diff --git a/config/environments/development.rb b/config/environments/development.rb index 6ed1e5d3..5c93e005 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -49,6 +49,7 @@ require "flipper/middleware/memoizer" config.middleware.use Flipper::Middleware::Memoizer + config.flipper.memoize = false BetterErrors::Middleware.allow_ip! ENV["TRUSTED_IP"] diff --git a/config/environments/production.rb b/config/environments/production.rb index 447f1e35..24a8fdce 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,6 +96,7 @@ require "flipper/middleware/memoizer" config.middleware.use Flipper::Middleware::Memoizer + config.flipper.memoize = false # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false diff --git a/config/environments/stage.rb b/config/environments/stage.rb index fb837ffd..b57eaa58 100644 --- a/config/environments/stage.rb +++ b/config/environments/stage.rb @@ -81,4 +81,5 @@ require "flipper/middleware/memoizer" config.middleware.use Flipper::Middleware::Memoizer + config.flipper.memoize = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index e06ba30f..94938266 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -7,7 +7,7 @@ # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb index ebcc9c58..063a4da4 100644 --- a/config/initializers/elasticsearch.rb +++ b/config/initializers/elasticsearch.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "faraday_middleware" +require "faraday" require "faraday_middleware/aws_sigv4" if ENV["ES_HOST"] == "elasticsearch.test.datacite.org" || ENV["ES_HOST"] == "elasticsearch.datacite.org" || ENV["ES_HOST"] == "elasticsearch.stage.datacite.org" diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index 55118067..9855b18d 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -12,7 +12,7 @@ adapter = Flipper::Adapters::Redis.new(client) unless Rails.env.test? cache = ActiveSupport::Cache::MemCacheStore.new(ENV["MEMCACHE_SERVERS"]) - adapter = Flipper::Adapters::ActiveSupportCacheStore.new(adapter, cache, expires_in: 1.hour) + adapter = Flipper::Adapters::ActiveSupportCacheStore.new(adapter, cache, 1.hour) end Flipper.new(adapter, instrumenter: ActiveSupport::Notifications) end diff --git a/config/initializers/new_framework_defaults_7_1.rb b/config/initializers/new_framework_defaults_7_1.rb new file mode 100644 index 00000000..4ef460cb --- /dev/null +++ b/config/initializers/new_framework_defaults_7_1.rb @@ -0,0 +1,285 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.1 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.1`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# No longer add autoloaded paths into `$LOAD_PATH`. This means that you won't be able +# to manually require files that are managed by the autoloader, which you shouldn't do anyway. +# +# This will reduce the size of the load path, making `require` faster if you don't use bootsnap, or reduce the size +# of the bootsnap cache if you use it. +# +# To set this configuration, add the following line to `config/application.rb` (NOT this file): +# config.add_autoload_paths_to_load_path = false + +### +# Remove the default X-Download-Options headers since it is used only by Internet Explorer. +# If you need to support Internet Explorer, add back `"X-Download-Options" => "noopen"`. +#++ +# Rails.application.config.action_dispatch.default_headers = { +# "X-Frame-Options" => "SAMEORIGIN", +# "X-XSS-Protection" => "0", +# "X-Content-Type-Options" => "nosniff", +# "X-Permitted-Cross-Domain-Policies" => "none", +# "Referrer-Policy" => "strict-origin-when-cross-origin" +# } + +### +# Do not treat an `ActionController::Parameters` instance +# as equal to an equivalent `Hash` by default. +#++ +# Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false + +### +# Active Record Encryption now uses SHA-256 as its hash digest algorithm. +# +# There are 3 scenarios to consider. +# +# 1. If you have data encrypted with previous Rails versions, and you have +# +config.active_support.key_generator_hash_digest_class+ configured as SHA1 (the default +# before Rails 7.0), you need to configure SHA-1 for Active Record Encryption too: +#++ +# Rails.application.config.active_record.encryption.hash_digest_class = OpenSSL::Digest::SHA1 +# +# 2. If you have +config.active_support.key_generator_hash_digest_class+ configured as SHA256 (the new default +# in 7.0), then you need to configure SHA-256 for Active Record Encryption: +#++ +# Rails.application.config.active_record.encryption.hash_digest_class = OpenSSL::Digest::SHA256 +# +# 3. If you don't currently have data encrypted with Active Record encryption, you can disable this setting to +# configure the default behavior starting 7.1+: +#++ +# Rails.application.config.active_record.encryption.support_sha1_for_non_deterministic_encryption = false + +### +# No longer run after_commit callbacks on the first of multiple Active Record +# instances to save changes to the same database row within a transaction. +# Instead, run these callbacks on the instance most likely to have internal +# state which matches what was committed to the database, typically the last +# instance to save. +#++ +# Rails.application.config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = false + +### +# Configures SQLite with a strict strings mode, which disables double-quoted string literals. +# +# SQLite has some quirks around double-quoted string literals. +# It first tries to consider double-quoted strings as identifier names, but if they don't exist +# it then considers them as string literals. Because of this, typos can silently go unnoticed. +# For example, it is possible to create an index for a non existing column. +# See https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted for more details. +#++ +# Rails.application.config.active_record.sqlite3_adapter_strict_strings_by_default = true + +### +# Disable deprecated singular associations names. +#++ +# Rails.application.config.active_record.allow_deprecated_singular_associations_name = false + +### +# Enable the Active Job `BigDecimal` argument serializer, which guarantees +# roundtripping. Without this serializer, some queue adapters may serialize +# `BigDecimal` arguments as simple (non-roundtrippable) strings. +# +# When deploying an application with multiple replicas, old (pre-Rails 7.1) +# replicas will not be able to deserialize `BigDecimal` arguments from this +# serializer. Therefore, this setting should only be enabled after all replicas +# have been successfully upgraded to Rails 7.1. +#++ +# Rails.application.config.active_job.use_big_decimal_serializer = true + +### +# Specify if an `ArgumentError` should be raised if `Rails.cache` `fetch` or +# `write` are given an invalid `expires_at` or `expires_in` time. +# Options are `true`, and `false`. If `false`, the exception will be reported +# as `handled` and logged instead. +#++ +# Rails.application.config.active_support.raise_on_invalid_cache_expiration_time = true + +### +# Specify whether Query Logs will format tags using the SQLCommenter format +# (https://open-telemetry.github.io/opentelemetry-sqlcommenter/), or using the legacy format. +# Options are `:legacy` and `:sqlcommenter`. +#++ +# Rails.application.config.active_record.query_log_tags_format = :sqlcommenter + +### +# Specify the default serializer used by `MessageEncryptor` and `MessageVerifier` +# instances. +# +# The legacy default is `:marshal`, which is a potential vector for +# deserialization attacks in cases where a message signing secret has been +# leaked. +# +# In Rails 7.1, the new default is `:json_allow_marshal` which serializes and +# deserializes with `ActiveSupport::JSON`, but can fall back to deserializing +# with `Marshal` so that legacy messages can still be read. +# +# In Rails 7.2, the default will become `:json` which serializes and +# deserializes with `ActiveSupport::JSON` only. +# +# Alternatively, you can choose `:message_pack` or `:message_pack_allow_marshal`, +# which serialize with `ActiveSupport::MessagePack`. `ActiveSupport::MessagePack` +# can roundtrip some Ruby types that are not supported by JSON, and may provide +# improved performance, but it requires the `msgpack` gem. +# +# For more information, see +# https://guides.rubyonrails.org/v7.1/configuring.html#config-active-support-message-serializer +# +# If you are performing a rolling deploy of a Rails 7.1 upgrade, wherein servers +# that have not yet been upgraded must be able to read messages from upgraded +# servers, first deploy without changing the serializer, then set the serializer +# in a subsequent deploy. +#++ +# Rails.application.config.active_support.message_serializer = :json_allow_marshal + +### +# Enable a performance optimization that serializes message data and metadata +# together. This changes the message format, so messages serialized this way +# cannot be read by older versions of Rails. However, messages that use the old +# format can still be read, regardless of whether this optimization is enabled. +# +# To perform a rolling deploy of a Rails 7.1 upgrade, wherein servers that have +# not yet been upgraded must be able to read messages from upgraded servers, +# leave this optimization off on the first deploy, then enable it on a +# subsequent deploy. +#++ +# Rails.application.config.active_support.use_message_serializer_for_metadata = true + +### +# Set the maximum size for Rails log files. +# +# `config.load_defaults 7.1` does not set this value for environments other than +# development and test. +#++ +# if Rails.env.local? +# Rails.application.config.log_file_size = 100 * 1024 * 1024 +# end + +### +# Enable raising on assignment to attr_readonly attributes. The previous +# behavior would allow assignment but silently not persist changes to the +# database. +#++ +# Rails.application.config.active_record.raise_on_assign_to_attr_readonly = true + +### +# Enable validating only parent-related columns for presence when the parent is mandatory. +# The previous behavior was to validate the presence of the parent record, which performed an extra query +# to get the parent every time the child record was updated, even when parent has not changed. +#++ +# Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false + +### +# Enable precompilation of `config.filter_parameters`. Precompilation can +# improve filtering performance, depending on the quantity and types of filters. +#++ +# Rails.application.config.precompile_filter_parameters = true + +### +# Enable before_committed! callbacks on all enrolled records in a transaction. +# The previous behavior was to only run the callbacks on the first copy of a record +# if there were multiple copies of the same record enrolled in the transaction. +#++ +# Rails.application.config.active_record.before_committed_on_all_records = true + +### +# Disable automatic column serialization into YAML. +# To keep the historic behavior, you can set it to `YAML`, however it is +# recommended to explicitly define the serialization method for each column +# rather than to rely on a global default. +#++ +# Rails.application.config.active_record.default_column_serializer = nil + +### +# Enable a performance optimization that serializes Active Record models +# in a faster and more compact way. +# +# To perform a rolling deploy of a Rails 7.1 upgrade, wherein servers that have +# not yet been upgraded must be able to read caches from upgraded servers, +# leave this optimization off on the first deploy, then enable it on a +# subsequent deploy. +#++ +# Rails.application.config.active_record.marshalling_format_version = 7.1 + +### +# Run `after_commit` and `after_*_commit` callbacks in the order they are defined in a model. +# This matches the behaviour of all other callbacks. +# In previous versions of Rails, they ran in the inverse order. +#++ +# Rails.application.config.active_record.run_after_transaction_callbacks_in_order_defined = true + +### +# Whether a `transaction` block is committed or rolled back when exited via `return`, `break` or `throw`. +#++ +# Rails.application.config.active_record.commit_transaction_on_non_local_return = true + +### +# Controls when to generate a value for has_secure_token declarations. +#++ +# Rails.application.config.active_record.generate_secure_token_on = :initialize + +### +# ** Please read carefully, this must be configured in config/application.rb ** +# +# Change the format of the cache entry. +# +# Changing this default means that all new cache entries added to the cache +# will have a different format that is not supported by Rails 7.0 +# applications. +# +# Only change this value after your application is fully deployed to Rails 7.1 +# and you have no plans to rollback. +# When you're ready to change format, add this to `config/application.rb` (NOT +# this file): +# config.active_support.cache_format_version = 7.1 + + +### +# Configure Action View to use HTML5 standards-compliant sanitizers when they are supported on your +# platform. +# +# `Rails::HTML::Sanitizer.best_supported_vendor` will cause Action View to use HTML5-compliant +# sanitizers if they are supported, else fall back to HTML4 sanitizers. +# +# In previous versions of Rails, Action View always used `Rails::HTML4::Sanitizer` as its vendor. +#++ +# Rails.application.config.action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor + + +### +# Configure Action Text to use an HTML5 standards-compliant sanitizer when it is supported on your +# platform. +# +# `Rails::HTML::Sanitizer.best_supported_vendor` will cause Action Text to use HTML5-compliant +# sanitizers if they are supported, else fall back to HTML4 sanitizers. +# +# In previous versions of Rails, Action Text always used `Rails::HTML4::Sanitizer` as its vendor. +#++ +# Rails.application.config.action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor + + +### +# Configure the log level used by the DebugExceptions middleware when logging +# uncaught exceptions during requests. +#++ +# Rails.application.config.action_dispatch.debug_exception_log_level = :error + + +### +# Configure the test helpers in Action View, Action Dispatch, and rails-dom-testing to use HTML5 +# parsers. +# +# Nokogiri::HTML5 isn't supported on JRuby, so JRuby applications must set this to :html4. +# +# In previous versions of Rails, these test helpers always used an HTML4 parser. +#++ +# Rails.application.config.dom_testing_default_html_version = :html5 diff --git a/spec/jobs/claim_job_spec.rb b/spec/jobs/claim_job_spec.rb index 27e23add..3a38d8a1 100644 --- a/spec/jobs/claim_job_spec.rb +++ b/spec/jobs/claim_job_spec.rb @@ -3,17 +3,10 @@ require "rails_helper" RSpec.describe ClaimJob, type: :job, elasticsearch: true do - let(:claim) { FactoryBot.create(:claim) } - let(:job) { claim.queue_claim_job } + let!(:claim) { FactoryBot.create(:claim) } + let!(:job) { claim.queue_claim_job } it "enqueue jobs" do - expect { job }.to change(enqueued_jobs, :size).by(4) - claim_job = enqueued_jobs.first - expect(claim_job[:job]).to eq(UserJob) - end - - it "executes perform", vcr: true do - expect(claim.state).to eq("waiting") - perform_enqueued_jobs { job } + expect(UserJob).to(have_been_enqueued.at_least(:once)) end end diff --git a/spec/jobs/user_job_spec.rb b/spec/jobs/user_job_spec.rb index fde6dc06..5adb64d1 100644 --- a/spec/jobs/user_job_spec.rb +++ b/spec/jobs/user_job_spec.rb @@ -3,19 +3,10 @@ require "rails_helper" RSpec.describe UserJob, type: :job, elasticsearch: true do - let(:user) { FactoryBot.create(:valid_user) } - let(:job) { user.queue_user_job } + let!(:user) { FactoryBot.create(:valid_user) } + let!(:job) { user.queue_user_job } it "enqueue jobs" do - expect { job }.to change(enqueued_jobs, :size).by(3) - - user_job = enqueued_jobs.first - expect(user_job[:job]).to eq(UserJob) - end - - it "executes perform", vcr: true do - expect(user.claims.count).to eq(0) - perform_enqueued_jobs { job } - expect(user.claims.count).to eq(23) + expect(UserJob).to(have_been_enqueued.at_least(:once)) end end diff --git a/spec/models/external_identifier_spec.rb b/spec/models/external_identifier_spec.rb index 2b47c01f..7dff2a97 100644 --- a/spec/models/external_identifier_spec.rb +++ b/spec/models/external_identifier_spec.rb @@ -54,7 +54,7 @@ end it "data" do - xml = File.read(fixture_path + "external_identifier.xml") + xml = File.read(fixture_paths[0] + "external_identifier.xml") expect(subject.data).to eq(xml) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 82ca8cf4..ce46af59 100755 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -61,7 +61,7 @@ it "delete claim" do subject = FactoryBot.create(:valid_user, github: "mfenner", github_put_code: put_code) - expect(subject.process_data).to be true + expect(subject.process_data).to_not(eq(nil)) expect(subject.github_put_code).to eq(put_code) end end diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb index c4420e45..6d74c09e 100644 --- a/spec/models/work_spec.rb +++ b/spec/models/work_spec.rb @@ -10,15 +10,6 @@ subject { Work.new(doi: doi, orcid: user.uid, orcid_token: user.orcid_token, put_code: put_code) } describe "push to ORCID", order: :defined do - # describe 'post' do - # subject { Work.new(doi: doi, orcid: user.uid, orcid_token: user.orcid_token) } - - # it 'should create work' do - # response = subject.create_work(sandbox: true) - # expect(response.body["put_code"]).not_to be_blank - # end - # end - describe "get" do it "should get works" do response = subject.get_works(sandbox: true) @@ -29,13 +20,6 @@ end end - # describe 'put' do - # it 'should update work' do - # response = subject.update_work(sandbox: true) - # expect(response.body.dig("data", "work", "put_code")).to eq(put_code) - # end - # end - describe "delete" do it "should delete work" do response = subject.delete_work(sandbox: true) @@ -50,28 +34,9 @@ expect(subject.schema.errors).to be_empty end - # it 'validates data' do - # expect(subject.validation_errors).to be_empty - # end - it "validates data with errors" do allow(subject).to receive(:metadata) { OpenStruct.new } expect(subject.validation_errors).to eq(["-1:0: ERROR: The document has no document element."]) end end - - # describe 'contributors' do - # it 'valid' do - # expect(subject.contributors).to eq([{:credit_name=>"Martin Fenner", :orcid=>"https://orcid.org/0000-0003-1419-2405"}]) - # end - # end - - # it 'publication_date' do - # expect(subject.publication_date).to eq("year"=>"2016", "month"=>"12", "day"=>"20") - # end - - # it 'data' do - # xml = File.read(fixture_path + 'work.xml') - # expect(subject.data).to eq(xml) - # end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 5504fc0f..c1142223 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -91,7 +91,7 @@ # don't use transactions, use database_clear gem via support file config.use_transactional_fixtures = false - config.fixture_path = "#{::Rails.root}/spec/fixtures/" + config.fixture_paths = ["#{::Rails.root}/spec/fixtures/"] # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false