From 55edd8a57148449036251cbb200bfc91c820508d Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 27 Mar 2019 10:58:10 +0100 Subject: [PATCH 1/7] Change how we start puma Puma is integrated with rails server, no need to start it manually. Takes care of logging etc. We also shouldn't run multiple workers unless we absolutely want to. --- Procfile | 2 +- config/puma.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Procfile b/Procfile index 84cab0c9..8b9e764c 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -web: bundle exec puma -C config/puma.rb +web: bundle exec rails server -b 0.0.0.0 worker: bundle exec rails jobs:work diff --git a/config/puma.rb b/config/puma.rb index fa11fb8f..9886e1e5 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -21,7 +21,7 @@ environment ENV.fetch("RAILS_ENV") { "development" } # Workers do not work on JRuby or Windows (both of which do not support # processes). # -workers ENV.fetch("WEB_CONCURRENCY") { 2 } +workers ENV.fetch("WEB_CONCURRENCY") { 1 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code From b3716985f011a1a581c13f65d50ad5bac5801356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Fri, 3 May 2019 17:14:14 +0200 Subject: [PATCH 2/7] Stop using reload argument in associations Deprecated force reload argument in association readers is deprecated and has been removed in Rails 5.1: https://github.com/rails/rails/commit/09cac8c67af --- app/models/registration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/registration.rb b/app/models/registration.rb index f7c032ea..a071af28 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -76,7 +76,7 @@ class Registration < ApplicationRecord end def registration_limit_not_exceed - if conference.registration_limit > 0 && conference.registrations(:reload).count >= conference.registration_limit + if conference.registration_limit > 0 && conference.registrations.count >= conference.registration_limit errors.add(:base, 'Registration limit exceeded') end end From a8d2f8caa441315d887ed1bb015974c9aa58d339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Fri, 3 May 2019 17:33:14 +0200 Subject: [PATCH 3/7] Drop halt_callback_chains_on_return_false ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2. Stop using it and return `throw(:abort)` instead in the callbacks which need it. --- app/models/conference.rb | 1 - app/models/program.rb | 2 -- app/models/role.rb | 2 +- config/initializers/new_framework_defaults.rb | 3 --- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 89ca5d19..ca37e6d0 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -1120,7 +1120,6 @@ class Conference < ApplicationRecord # def create_email_settings build_email_settings - true end ## diff --git a/app/models/program.rb b/app/models/program.rb index 6c3a3b4a..0dadee15 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -211,7 +211,6 @@ class Program < ApplicationRecord EventType.create(title: 'Workshop', length: 60, color: '#0000FF', description: 'Interactive hands-on practice', minimum_abstract_length: 0, maximum_abstract_length: 500, program_id: id) - true end ## @@ -227,7 +226,6 @@ class Program < ApplicationRecord DifficultyLevel.create(title: 'Hard', description: 'Events require expert knowledge of the topic.', color: '#EF6E69', program_id: id) - true end ## diff --git a/app/models/role.rb b/app/models/role.rb index d759f47d..2be87d7b 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -18,6 +18,6 @@ class Role < ApplicationRecord # Needed to ensure that removing all user from role doesn't remove role. def cancel - false + throw(:abort) end end diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index cbf423a8..534a2396 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -20,6 +20,3 @@ ActiveSupport.to_time_preserves_timezone = false # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = false - -# Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = true From 32764d9498b61b0f1f3050d6b01da01b172d6664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Fri, 3 May 2019 17:39:30 +0200 Subject: [PATCH 4/7] Create roles when not found in test Otherwise the test fails at least some times. --- spec/models/role_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 1d2c60a4..58c2e287 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' describe Role do let(:conference) { create(:conference) } - let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } - let!(:cfp_role) { Role.find_by(name: 'cfp', resource: conference) } + let!(:organizer_role) { Role.find_or_create_by(name: 'organizer', resource: conference) } + let!(:cfp_role) { Role.find_or_create_by(name: 'cfp', resource: conference) } let!(:organizer) { create(:organizer, resource: conference) } let(:user) { create(:user) } From ca320242686da24588598386dd9100e43c2e4e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 4 May 2019 20:48:16 +0200 Subject: [PATCH 5/7] s/skip_before_filter/skip_before_action/ `skip_before_filter` was deprecated in Rails 4.2 and removed in Rails 5.1 in favor of `skip_before_action`. --- app/controllers/users/omniauth_callbacks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 03ae4044..8d0f80dd 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -2,7 +2,7 @@ module Users class OmniauthCallbacksController < Devise::OmniauthCallbacksController - skip_before_filter :verify_authenticity_token + skip_before_action :verify_authenticity_token skip_authorization_check User.omniauth_providers.each do |provider| From 41d6fad7a51b865e369169f49de7e40d701298a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 4 May 2019 20:58:18 +0200 Subject: [PATCH 6/7] s/redirect_to :back/redirect_back/ `redirect_to` has been removed in Rails 5.1 in favor of: ``` redirect_back(fallback_location: root_path) ``` --- app/controllers/admin/commercials_controller.rb | 2 +- app/controllers/openids_controller.rb | 2 +- app/controllers/proposals_controller.rb | 4 ++-- app/controllers/surveys_controller.rb | 2 +- app/helpers/application_helper.rb | 3 +-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/commercials_controller.rb b/app/controllers/admin/commercials_controller.rb index 003e04bf..0680b436 100644 --- a/app/controllers/admin/commercials_controller.rb +++ b/app/controllers/admin/commercials_controller.rb @@ -70,7 +70,7 @@ module Admin flash[:error] = errors_text end - redirect_to :back + redirect_back(fallback_location: root_path) end private diff --git a/app/controllers/openids_controller.rb b/app/controllers/openids_controller.rb index 3bccba2f..82af86d0 100644 --- a/app/controllers/openids_controller.rb +++ b/app/controllers/openids_controller.rb @@ -6,6 +6,6 @@ class OpenidsController < ApplicationController def destroy @openid.destroy - redirect_to :back + redirect_back(fallback_location: root_path) end end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index d59cc2d8..692b4db0 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -104,7 +104,7 @@ class ProposalsController < ApplicationController @event.event_schedules.destroy_all end rescue Transitions::InvalidTransition - redirect_to :back, error: "Event can't be withdrawn" + redirect_back(fallback_location: root_path, error: "Event can't be withdrawn") return end @@ -124,7 +124,7 @@ class ProposalsController < ApplicationController begin @event.confirm rescue Transitions::InvalidTransition - redirect_to :back, error: "Event can't be confirmed" + redirect_back(fallback_location: root_path, error: "Event can't be confirmed") return end diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index 5c0af57e..349bc34b 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -40,6 +40,6 @@ class SurveysController < ApplicationController end end - redirect_to :back + redirect_back(fallback_location: root_path) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 36adbb0b..c8b9acbe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -88,10 +88,9 @@ module ApplicationHelper end end - # Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to() def redirect_back_or_to(options = {}, response_status = {}) if request.env['HTTP_REFERER'] - redirect_to :back + redirect_back(fallback_location: root_path) else redirect_to options, response_status end From 7473e889ee9cab4f5b909589fd3e8e96124983c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 4 May 2019 21:03:08 +0200 Subject: [PATCH 7/7] Define ticket_purchases before through association In the User model, a has_many :through association 'User#physical_tickets' which goes through 'User#ticket_purchases' was defined before the through association was defined. This doesn't work in Rails 5.1. --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index bc71f61f..ec3132e1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,7 @@ class User < ApplicationRecord # prevent N+1 queries with has_cached_role? by preloading roles *always* default_scope { preload(:roles) } + has_many :ticket_purchases, dependent: :destroy has_many :physical_tickets, through: :ticket_purchases do def by_conference(conference) where('ticket_purchases.conference_id = ?', conference) @@ -67,7 +68,6 @@ class User < ApplicationRecord end end has_many :events_registrations, through: :registrations - has_many :ticket_purchases, dependent: :destroy has_many :payments, dependent: :destroy has_many :tickets, through: :ticket_purchases, source: :ticket do def for_registration conference