Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App and specs working under Ruby 3.1.4 #1138 #1139

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7'] # , '2.7', '3.0'
ruby-version: ['3.1'] # , '2.7', '3.0'

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Design

.passenger
.vagrant
storage/
storage/
.byebug_history
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.1

Bundler/OrderedGems:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.5
3.1.4
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# docker-compose up
# docker-compose exec web bundle exec rake db:create db:schema:load ffcrm:demo:load

FROM ruby:2.7
FROM ruby:3.1

LABEL author="Steve Kenworthy"

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ group :test do
gem 'zeus', platform: :ruby unless ENV["CI"]
gem 'timecop'
gem 'sqlite3', '~> 1.4.0'
gem 'webrick'
end

group :heroku do
Expand Down
22 changes: 12 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ GEM
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.9.2, < 3)
sassc-rails (>= 2.0.0)
brakeman (5.4.1)
brakeman (6.0.1)
builder (3.2.4)
byebug (11.1.3)
cancancan (3.5.0)
Expand Down Expand Up @@ -159,7 +159,7 @@ GEM
devise-i18n (1.11.0)
devise (>= 4.9.0)
diff-lcs (1.5.0)
dynamic_form (1.1.4)
dynamic_form (1.2.0)
email_reply_parser_ffcrm (0.5.0)
erubi (1.12.0)
execjs (2.8.1)
Expand Down Expand Up @@ -231,7 +231,7 @@ GEM
mini_mime (1.1.2)
mini_racer (0.6.4)
libv8-node (~> 16.19.0.0)
minitest (5.18.1)
minitest (5.19.0)
msgpack (1.6.0)
nenv (0.3.0)
net-imap (0.3.6)
Expand All @@ -253,9 +253,9 @@ GEM
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
paper_trail (12.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
paper_trail (15.0.0)
activerecord (>= 6.1)
request_store (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand All @@ -275,7 +275,7 @@ GEM
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.7.4)
Expand Down Expand Up @@ -341,7 +341,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.8.1)
request_store (1.5.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
actionpack (>= 5.2)
Expand Down Expand Up @@ -439,14 +439,15 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webrick (1.8.1)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
will_paginate (4.0.0)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.11)
zeus (0.15.14)
method_source (>= 0.6.7)

Expand Down Expand Up @@ -494,7 +495,7 @@ DEPENDENCIES
mini_magick
mini_racer
nokogiri (>= 1.8.1)
paper_trail (~> 12.0.0)
paper_trail (~> 15.0.0)
pg
premailer
pry-rails
Expand Down Expand Up @@ -529,6 +530,7 @@ DEPENDENCIES
tzinfo-data
uglifier
webdrivers
webrick
will_paginate
zeus

Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Application < Rails::Application

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += %i[password encrypted_password password_salt password_confirmation]

# Enable support for loading via Psych, required by PaperTrail
config.active_record.use_yaml_unsafe_load = true
Copy link
Member

@CloCkWeRX CloCkWeRX Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config.active_record.use_yaml_unsafe_load = true
config.active_record.use_yaml_unsafe_load = false
config.active_record.yaml_column_permitted_classes = [
::ActiveRecord::Type::Time::Value,
::ActiveSupport::TimeWithZone,
::ActiveSupport::TimeZone,
::BigDecimal,
::Date,
::Symbol,
::Time
]

https://github.com/paper-trail-gem/paper_trail/blob/master/doc/pt_13_yaml_safe_load.md#to-continue-using-the-yaml-serializer might be worth looking through, so that people upgrading don't have any issues with legacy data (but also no security issues)

not sure if we just need to add a bunch of internal models (Account, Lead, Opportunity etc) as well

Copy link
Contributor Author

@ferrisoxide ferrisoxide Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we just need to add a bunch of internal models (Account, Lead, Opportunity etc) as well

Allowing all classes to be serialized/deserialized via Psych isn't great, but you can't specify the model classes in application.rb (they haven't been loaded at this point). Naively moving the configuration to an initializer breaks, with some Active Support classes being marked as a disallowed class in specs. I'm not sure why just yet.

I'm also a bit worried about serialization of associated objects - I suspect we'd have to declare all possible compositions, not just the base model classes.

Fixing this might be tricky. I'd suggest that we look at securing serialization in a separate ticket as I've no idea how far down the rabbit hole this is going to go. Right now, leaving use_yaml_unsafe_load set to true is no more unsafe than what is present in the app - and only appears to impact Paper Trail versions records that can't be directly manipulated by users.

In a perfect world we wouldn't be using YAML serialization for Paper Trail, but I think JSON-based serialization is only available on Postgres. I see you've already identified this as an issue per #1146.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Actually, scrap that. The proposed change seems to be working without adding models - at least in specs. I'll be more comfortable making this change after I've given the front end a manual test - will look at doing that tomorrow.

end
end

Expand Down
4 changes: 2 additions & 2 deletions fat_free_crm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.email = ['[email protected]', '[email protected]', '[email protected]']
gem.files = Dir["{app,config,db,lib,vendor,public,bin,log/script}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "config.ru", "CHANGELOG.md", "CONTRIBUTING.md"]
gem.version = FatFreeCRM::VERSION::STRING
gem.required_ruby_version = '>= 2.7.0'
gem.required_ruby_version = '>= 3.1'
gem.license = 'MIT'

gem.add_dependency 'rails', '~> 6.1.0'
Expand All @@ -27,7 +27,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'select2-rails'
gem.add_dependency 'simple_form'
gem.add_dependency 'will_paginate'
gem.add_dependency 'paper_trail', '~> 12.0.0'
gem.add_dependency 'paper_trail', '~> 15.0.0'
gem.add_dependency 'devise', '~> 4.6'
gem.add_dependency 'devise-encryptable', '~> 0.2.0'
gem.add_dependency 'acts_as_commentable', '~> 6.0.0'
Expand Down
12 changes: 2 additions & 10 deletions lib/fat_free_crm/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ def self.included(base)
end
end

def each_with_explicit_error
attribute_names.each do |attribute|
self[attribute].each do |error|
if error.start_with?('^')
yield :base, error[1..-1] # Drop the attribute.
else
yield attribute, error # This is default Rails3 behavior.
end
end
end
def each_with_explicit_error(&block)
@errors.each(&block)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fat_free_crm/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def t(*args)
if args.size == 1
super(args.first, default: args.first.to_s)
elsif args.second.is_a?(Hash)
super(*args)
super(args.first, **args.second)
elsif args.second.is_a?(Integer)
super(args.first, count: args.second)
else
Expand Down
14 changes: 7 additions & 7 deletions spec/features/support/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

if ENV['BROWSER'] == 'chrome'
Capybara.register_driver :selenium do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w[no-sandbox headless disable-gpu] })
Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
options = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w[no-sandbox headless disable-gpu] })
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }.

Style/HashSyntax: Omit the hash value.
end
else
# For local testing in an environment with a display or remote X server configured
# such as WSL2, use NO_HEADLESS=1 bundle exec rspec spec/features
#
# For modern firefox, use MARIONETTE=1 bundle exec rspec spec/features
# NB the marionette setting is deprecated. For modern firefox, install the geckodriver.
Capybara.register_driver :selenium do |app|
options = Selenium::WebDriver::Firefox::Options.new
options.args << '--headless' unless ENV['NO_HEADLESS'].present?
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: ENV['MARIONETTE'].present?)
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, desired_capabilities: capabilities)
options = Selenium::WebDriver::Options.firefox
options.add_argument('-headless') unless ENV['NO_HEADLESS'].present?

Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }.

Style/HashSyntax: Omit the hash value.
end
end
24 changes: 24 additions & 0 deletions spec/lib/fat_free_crm/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe 'I18n.t()' do

Fixed Show fixed Hide fixed
class TestController < ActionController::Base
Fixed Show fixed Hide fixed
include FatFreeCRM::I18n
end

let(:entity_string) { 'entities' }
let(:hidden_count) { 10 }
let(:test_controller) { TestController.new }

it 'should translate hash arguments' do
expect(test_controller.t(:not_showing_hidden_entities, entity: entity_string, count: hidden_count))
.to eq("Not showing 10 hidden entities.")
end
end