Bump rails to 5.2 and update rubocop

This commit is contained in:
John Lees-Miller
2020-05-30 09:40:57 +01:00
parent df28c040d4
commit 80216c6740
78 changed files with 373 additions and 149 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ActiveAdmin.register Attendee do
scope :child?
scope :diet?

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ActiveAdmin.register Guest do
permit_params :email, :first_name, :last_name, :attending, :diet, :songs,
:notes

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
ActiveAdmin.register PlusOne do
permit_params :first_name, :last_name, :diet, :child

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class GuestsController < ApplicationController
def new
respond_to :html

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class PlusOnesController < ApplicationController
before_action do
@guest = Guest.find_by_id_token(params[:guest_id])
@ -41,7 +43,7 @@ class PlusOnesController < ApplicationController
def destroy
respond_to :html
@plus_one = @guest.plus_ones.find_by(id: params[:id])
@plus_one.destroy if @plus_one
@plus_one&.destroy
redirect_to guest_plus_ones_path(@guest)
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class WelcomeController < ApplicationController
def index
@google_maps_url = 'https://goo.gl/maps/nBAxNAsmPSS2'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ApplicationHelper
def flash_class(key)
case key
@ -10,6 +12,7 @@ module ApplicationHelper
def errors_for(object)
return unless object.errors.any?
content_tag(:div, class: 'mb-3 card border-danger') do
concat(content_tag(:div, class: 'card-header bg-danger text-white') do
concat "Oops, #{pluralize(object.errors.count, 'problem')}:"

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module GuestsHelper
end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module PlusOnesHelper
end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module WelcomeHelper
end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class GuestMailer < ApplicationMailer
default from: ENV['FROM_EMAIL'], reply_to: ENV['CONTACT_EMAIL']

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
#
# ActiveAdmin console user.
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
#
# A guest or plus one.
#

View File

@ -1,10 +1,12 @@
# frozen_string_literal: true
#
# Make a model findable only when a secure token is provided.
#
module FindableWithToken
extend ActiveSupport::Concern
ID_TOKEN_RX = /\A(\d+)-(\w+)\z/
ID_TOKEN_RX = /\A(\d+)-(\w+)\z/.freeze
included do
has_secure_token
@ -15,12 +17,14 @@ module FindableWithToken
def self.find_by_id_token(id_token)
raise ActiveRecord::RecordNotFound unless id_token =~ ID_TOKEN_RX
id = Regexp.last_match(1)
token = Regexp.last_match(2)
record = find(id)
raise ActiveRecord::RecordNotFound unless
ActiveSupport::SecurityUtils.secure_compare(record.token, token)
record
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
#
# A primary guest.
#
@ -26,6 +28,7 @@ class Guest < ApplicationRecord
def email_safe_salutation
return 'Hello,' if
first_name.blank? || first_name !~ /\A[\p{Word}\s'-]{1,30}\z/i
"Dear #{first_name},"
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
#
# An extra guest.
#