Skip to content

Commit

Permalink
upgrade to ruby 3.1.4 (#160)
Browse files Browse the repository at this point in the history
* upgrade to ruby 3.1.4

* update the rubocop ruby version

* bump google protobuf gem version up

* disable rubocop style

* remove dockerfile entry

* disable rubocop check

* appease our rubocop overlords

* rework error serializer due to deprecation warning

* fix spec

* fix spec

* fix spec

* fix specs. fix json serialization. upgrade postrank gem.

* bump the vcr gem version up

* configure passenger

---------

Co-authored-by: Wendel Fabian Chinsamy <[email protected]>
  • Loading branch information
wendelfabianchinsamy and Wendel Fabian Chinsamy authored Apr 25, 2024
1 parent 538eedc commit dc00344
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ jobs:
JWT_PUBLIC_KEY: ${{ secrets.JWT_PUBLIC_KEY }}
steps:
- uses: actions/checkout@v3
- name: Set up Ruby 2.6
- name: Set up Ruby 3.1.4
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.1.4
- uses: actions/cache@v2
with:
path: vendor/bundle
Expand Down
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.1
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Expand Down Expand Up @@ -89,7 +89,7 @@ Layout/EmptyLinesAroundModuleBody:

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true
Enabled: false

Layout/FirstArgumentIndentation:
Enabled: true
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM phusion/passenger-full:2.0.0
FROM phusion/passenger-full:2.5.1
LABEL maintainer="[email protected]"

# Set correct environment variables
Expand All @@ -15,8 +15,8 @@ RUN groupmod -g 1000 app
# Use baseimage-docker's init process
CMD ["/sbin/my_init"]

# Use Ruby 2.6.8
RUN bash -lc 'rvm --default use ruby-2.6.8'
# Use Ruby 3.1.4
RUN bash -lc 'rvm --default use ruby-3.1.4'

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
Expand Down
12 changes: 7 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ gem "aws-sdk-sqs", "~> 1.23", ">= 1.23.1"
gem "base32-crockford-checksum", "~> 0.2.3"
gem "config", "~> 2.2", ">= 2.2.1"
gem "dotenv", "~> 2.7", ">= 2.7.5"
gem "fast_jsonapi", "~> 1.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-active_support_cache_store"
gem "flipper-api"
Expand All @@ -24,7 +27,7 @@ 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 "postrank-uri", "~> 1.0", ">= 1.0.24"
gem "postrank-uri", "~> 1.1"
gem "pwqgen.rb", "~> 0.1.0"
gem "rake", "~> 12.0"
gem "sentry-raven", "~> 2.13"
Expand Down Expand Up @@ -66,7 +69,7 @@ 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 "google-protobuf", "3.10.0.rc.1"
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"
Expand Down Expand Up @@ -102,7 +105,6 @@ group :development do
gem "spring"
gem "spring-commands-rspec"
gem "spring-watcher-listen", "~> 2.0.0"
# gem "httplog", "~> 1.0"
end

group :test do
Expand All @@ -117,7 +119,7 @@ group :test do
gem "shoulda-matchers", "~> 4.1", ">= 4.1.2"
gem "simplecov", "~> 0.17.1"
gem "test-prof", "~> 0.10.2"
gem "vcr", "~> 3.0.3"
gem "vcr", "~> 6.2"
gem "webmock", "~> 3.1"
gem "with_env", "~> 1.1"
end
28 changes: 13 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ GEM
faraday_middleware-aws-sigv4 (0.2.4)
aws-sigv4 (~> 1.0)
faraday (>= 0.9)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ferrum (0.11)
addressable (~> 2.5)
cliver (~> 0.3)
Expand Down Expand Up @@ -318,7 +316,7 @@ GEM
rchardet (~> 1.8)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (3.10.0.rc.1)
google-protobuf (3.19.6)
graphql (1.12.16)
graphql-batch (0.4.3)
graphql (>= 1.3, < 2)
Expand Down Expand Up @@ -352,6 +350,8 @@ GEM
json-ld (~> 3.2)
rdf (~> 3.2)
jsonapi-renderer (0.2.2)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
jsonlint (0.3.0)
oj (~> 3)
optimist (~> 3)
Expand All @@ -372,10 +372,9 @@ GEM
launchy (2.5.0)
addressable (~> 2.7)
link_header (0.0.8)
listen (3.1.5)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lograge (0.11.2)
actionpack (>= 4)
activesupport (>= 4)
Expand Down Expand Up @@ -479,12 +478,12 @@ GEM
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
postrank-uri (1.0.24)
postrank-uri (1.1)
addressable (>= 2.4.0)
nokogiri (>= 1.8.0)
public_suffix (>= 2.0.0, < 2.1)
public_suffix (>= 4.0.0, < 5)
promise.rb (0.7.4)
public_suffix (2.0.5)
public_suffix (4.0.7)
pwqgen.rb (0.1.0)
docopt (~> 0.5)
sysrandom
Expand Down Expand Up @@ -615,7 +614,6 @@ GEM
ruby-enum (0.9.0)
i18n
ruby-progressbar (1.11.0)
ruby_dep (1.5.0)
ruby_dig (0.0.2)
scanf (1.0.0)
sentry-raven (2.13.0)
Expand Down Expand Up @@ -675,7 +673,7 @@ GEM
unicode_utils (1.4.0)
validates_email_format_of (1.6.3)
i18n
vcr (3.0.3)
vcr (6.2.0)
warden (1.2.9)
rack (>= 2.0.9)
webmock (3.14.0)
Expand Down Expand Up @@ -725,21 +723,21 @@ DEPENDENCIES
email_spec (~> 2.2)
factory_bot_rails (~> 4.8, >= 4.8.2)
faraday_middleware-aws-sigv4 (~> 0.2.4)
fast_jsonapi (~> 1.5)
flipper (~> 0.17.2)
flipper-active_support_cache_store
flipper-api
flipper-redis
flipper-ui
git (~> 1.5)
google-protobuf (= 3.10.0.rc.1)
google-protobuf (= 3.19.6)
graphql (~> 1.9, >= 1.9.16)
graphql-batch (~> 0.4.1)
graphql-cache (~> 0.6.0)
graphql-errors (~> 0.4.0)
gravtastic (~> 3.2, >= 3.2.6)
hashdiff (>= 1.0.0.beta1, < 2.0.0)
hashie
jsonapi-serializer (~> 2.2)
jwt (~> 2.2, >= 2.2.1)
kaminari (~> 1.2)
listen (>= 3.0.5, < 3.2)
Expand All @@ -762,7 +760,7 @@ DEPENDENCIES
omniauth-orcid (~> 2.0)
omniauth-rails_csrf_protection (~> 1.0)
orcid_client (~> 0.11.0)
postrank-uri (~> 1.0, >= 1.0.24)
postrank-uri (~> 1.1)
pwqgen.rb (~> 0.1.0)
rack-cors (~> 1.0)
rack-jwt
Expand Down Expand Up @@ -795,9 +793,9 @@ DEPENDENCIES
tzinfo-data (~> 1.2019, >= 1.2019.3)
uglifier (~> 2.7, >= 2.7.2)
validates_email_format_of (~> 1.6, >= 1.6.3)
vcr (~> 3.0.3)
vcr (~> 6.2)
webmock (~> 3.1)
with_env (~> 1.1)

BUNDLED WITH
2.4.22
2.4.22
11 changes: 5 additions & 6 deletions app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def show
options[:include] = @include
options[:is_collection] = false

render json: ClaimSerializer.new(@claim, options).serialized_json, status: :ok
render json: ClaimSerializer.new(@claim, options).serializable_hash.to_json, status: :ok
end

def index
Expand Down Expand Up @@ -84,9 +84,9 @@ def index

fields = fields_from_params(params)
if fields
render json: ClaimSerializer.new(response.results, options.merge(fields: fields)).serialized_json, status: :ok
render json: ClaimSerializer.new(response.results, options.merge(fields: fields)).serializable_hash.to_json, status: :ok
else
render json: ClaimSerializer.new(response.results, options).serialized_json, status: :ok
render json: ClaimSerializer.new(response.results, options).serializable_hash.to_json, status: :ok
end
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
Raven.capture_exception(e)
Expand All @@ -112,13 +112,12 @@ def create
end

if @claim.save

@claim.queue_claim_job

options = {}
options[:include] = @include
options[:is_collection] = false
render json: ClaimSerializer.new(@claim, options).serialized_json, status: :accepted
render json: ClaimSerializer.new(@claim, options).serializable_hash.to_json, status: :accepted
else
logger.error @claim.errors.inspect
render json: serialize_errors(@claim.errors), include: @include, status: :unprocessable_entity
Expand All @@ -137,7 +136,7 @@ def destroy
options = {}
options[:include] = @include
options[:is_collection] = false
render json: ClaimSerializer.new(@claim, options).serialized_json, status: :accepted
render json: ClaimSerializer.new(@claim, options).serializable_hash.to_json, status: :accepted
else
logger.error @claim.errors.inspect
render json: serialize_errors(@claim.errors), include: @include, status: :unprocessable_entity
Expand Down
21 changes: 13 additions & 8 deletions app/controllers/concerns/error_serializable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ module ErrorSerializable
extend ActiveSupport::Concern

included do
def serialize_errors(errors)
def serialize_errors(errors, options = {})
return nil if errors.nil?

arr = Array.wrap(errors).reduce([]) do |sum, err|
source = err.keys.first
errors_arr = []

Array.wrap(err.values.first).each do |title|
sum << { source: source, title: title.is_a?(String) ? title.capitalize : title.to_s }
errors.each do |err|
unless errors_arr.any? { |e| e[:source] == err.attribute }
new_err = { source: err.attribute, title: capitalize_error_message(err) }
new_err[:uid] = options[:uid] if options[:uid].present?
errors_arr << new_err
end

sum
end

{ errors: arr }.to_json
{ errors: errors_arr }.to_json
end
end

private
def capitalize_error_message(error)
error.message.sub(/^./, &:upcase)
end
end
10 changes: 5 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def show
options[:is_collection] = false
options[:params] = { current_ability: current_ability }

render json: UserSerializer.new(@user, options).serialized_json, status: :ok
render json: UserSerializer.new(@user, options).serializable_hash.to_json, status: :ok
end

def index
Expand Down Expand Up @@ -78,9 +78,9 @@ def index

fields = fields_from_params(params)
if fields
render json: UserSerializer.new(response.results, options.merge(fields: fields)).serialized_json, status: :ok
render json: UserSerializer.new(response.results, options.merge(fields: fields)).serializable_hash.to_json, status: :ok
else
render json: UserSerializer.new(response.results, options).serialized_json, status: :ok
render json: UserSerializer.new(response.results, options).serializable_hash.to_json, status: :ok
end
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
Raven.capture_exception(e)
Expand All @@ -98,7 +98,7 @@ def create
if @user.save
options = {}
options[:is_collection] = false
render json: UserSerializer.new(@user, options).serialized_json, status: :created
render json: UserSerializer.new(@user, options).serializable_hash.to_json, status: :created
else
logger.error @user.errors.inspect
render json: serialize_errors(@user.errors), status: :unprocessable_entity
Expand All @@ -122,7 +122,7 @@ def update
if @user.save
options = {}
options[:is_collection] = false
render json: UserSerializer.new(@user, options).serialized_json, status: status
render json: UserSerializer.new(@user, options).serializable_hash.to_json, status: status
else
logger.error @user.errors.inspect
render json: serialize_errors(@user.errors), status: :unprocessable_entity
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/claim_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ClaimSerializer
include FastJsonapi::ObjectSerializer
include JSONAPI::Serializer
set_key_transform :camel_lower
set_type :claims
set_id :uuid
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class UserSerializer
include FastJsonapi::ObjectSerializer
include JSONAPI::Serializer
set_key_transform :camel_lower
set_type :users
set_id :uid
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

# Format used for DOI validation
# The prefix is 10.x where x is 4-5 digits. The suffix can be anything, but can"t be left off
DOI_FORMAT = %r(\A10\.\d{4,5}/.+).freeze
DOI_FORMAT = %r(\A10\.\d{4,5}/.+)

# Format used for URL validation
URL_FORMAT = %r(\A(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z).freeze
URL_FORMAT = %r(\A(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z)

# Form queue options
QUEUE_OPTIONS = ["high", "default", "low"].freeze
Expand Down
Loading

0 comments on commit dc00344

Please sign in to comment.