Skip to content

Commit

Permalink
App and specs working under Ruby 3.1.4 #1138 (#1139)
Browse files Browse the repository at this point in the history
* 1138 app and specs working under Ruby 3.0.6

1138 spelling error

* Update Gemfile.lock

* 1138 upgrade brakeman

* 1138 upgrade PaperTrail, Ruby to 3.1

* 1138 update ruby version in Dockerfile

* 1138 one more attempt at updating ruby version

* 1138 update brakeman-analysis

* 1138 use yaml_column_permitted_classes config

---------

Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
  • Loading branch information
ferrisoxide and CloCkWeRX authored Aug 10, 2023
1 parent c98b94c commit 5a708d6
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/brakeman-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Setup Brakeman
env:
BRAKEMAN_VERSION: '4.10' # SARIF support is provided in Brakeman version 4.10+
BRAKEMAN_VERSION: '6.0.1' # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION
Expand Down
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 @@ -99,7 +99,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 @@ -160,7 +160,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 @@ -232,7 +232,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 @@ -254,9 +254,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 @@ -276,7 +276,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 @@ -342,7 +342,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 @@ -441,14 +441,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 @@ -496,7 +497,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 @@ -531,6 +532,7 @@ DEPENDENCIES
tzinfo-data
uglifier
webdrivers
webrick
will_paginate
zeus

Expand Down
12 changes: 12 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ 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 = false
config.active_record.yaml_column_permitted_classes = [
::ActiveRecord::Type::Time::Value,
::ActiveSupport::TimeWithZone,
::ActiveSupport::TimeZone,
::BigDecimal,
::Date,
::Symbol,
::Time
]
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 = ['mike@fatfreecrm.com', 'steveyken@gmail.com', 'daniel.oconnor@gmail.com']
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
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)
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)
end
end
23 changes: 23 additions & 0 deletions spec/lib/fat_free_crm/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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')

class TestController < ActionController::Base
include FatFreeCRM::I18n
end

describe 'I18n.t()' do
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
17 changes: 17 additions & 0 deletions spec/models/polymorphic/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@
@version = Version.where(related_id: @item.id, related_type: @item.class.name, whodunnit: PaperTrail.request.whodunnit, event: 'create').first
expect(@version).not_to eq(nil)
end

# NOTE: This to ensure that the yaml_column_permitted_classes config option in
# application.rb is set correctly. If this test fails, then you need to add the
# class to the list of permitted classes.
it "should include version object changes when updating existing #{item}" do
if @item.respond_to?(:full_name)
previous_name_attributes = @item.attributes.slice('first_name', 'last_name')
@item.update(first_name: "Billy", last_name: "Bones")
else
previous_name_attributes = @item.attributes.slice('name')
@item.update(name: "Billy Bones")
end
@version = Version.where(@conditions.merge(event: 'update')).first

expect(@version.object).to be_present
expect(@version.reify.attributes).to include(previous_name_attributes)
end
end
end

Expand Down

0 comments on commit 5a708d6

Please sign in to comment.