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

Update supported Ruby/Rails #1063

Merged
merged 8 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .github/workflows/current_support.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.7, "3.0"]
gemfile: [rails_6_0, rails_6_1, rails_7_0]
include:
ruby: ["3.0", 3.1, 3.2]
gemfile: [rails_6_1, rails_7_0, rails_7_1]
exclude:
# Rails < 7.0.1 is not compatible with Ruby 3.1+
- ruby: 3.1
gemfile: rails_7_0
gemfile: rails_6_1
- ruby: 3.2
gemfile: rails_7_0
gemfile: rails_6_1
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/experimental_support.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
fail-fast: false
matrix:
include:
- ruby: 3.1
- ruby: 3.2
gemfile: rails_edge
- ruby: head
gemfile: rails_7_0
gemfile: rails_7_1
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
steps:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Gemfile.lock
.~*
spec/dummy/**/*.png
spec/dummy/**/*.jpg
spec/dummy/**/*.sqlite3-journal
spec/dummy/**/*.sqlite3.db
spec/dummy/**/*.sqlite3
spec/dummy/**/*.sqlite3*
spec/support/fixtures/rails_tmp.png
*.gem
.tool-versions
Expand Down
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AllCops:
- /**/vendor/**/* # Exclude downloaded gem code in CI
NewCops: disable
SuggestExtensions: false
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0

Lint/MissingSuper:
Enabled: false
Expand Down Expand Up @@ -48,6 +48,10 @@ RSpec/NestedGroups:
Enabled: true
Max: 5

Security/MarshalLoad:
Exclude:
- spec/**/*

Style/Documentation:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
gemspec
gem 'non-digest-assets'
gem 'oj'
gem 'rails', '~> 7.0.0'
gem 'rails', '~> 7.1.0'
gem 'sassc', '!= 2.3.0' # this version segfaults
gem 'selenium-webdriver'

Expand Down
10 changes: 4 additions & 6 deletions app/apps/plugins/front_cache/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ def settings
end

def save_settings
current_site.set_meta('front_cache_elements', { paths: ((params[:cache][:paths] || []).delete_if do |a|
!a.present?
end || []),
posts: (params[:cache][:posts] || []),
post_types: (params[:cache][:post_type] || []),
skip_posts: (params[:cache][:skip_posts] || []),
current_site.set_meta('front_cache_elements', { paths: (params[:cache][:paths] || []).compact_blank || [],
posts: params[:cache][:posts] || [],
post_types: params[:cache][:post_type] || [],
skip_posts: params[:cache][:skip_posts] || [],
cache_login: params[:cache][:cache_login],
home: params[:cache][:home],
preserve_cache_on_restart: params[:cache][:preserve_cache_on_restart],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def add_items
end

if params[:custom_items].present? # custom menu items
params[:custom_items].each do |_index, item|
params[:custom_items].each_value do |item|
type = item['kind'].present? ? item['kind'] : 'external'
item = @nav_menu.append_menu_item({ label: item['label'], link: item['url'], type: type })
items << item
end
end

if params[:items].present?
params[:items].each do |_index, item|
params[:items].each_value do |item|
item = @nav_menu.append_menu_item({ label: 'auto', link: item['id'], type: item['kind'] })
items << item
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/camaleon_cms/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def site_saved
flash[:notice] = t('camaleon_cms.admin.settings.message.site_updated')
args = { action: :site }
args[:host], args[:port] = @site.get_domain.to_s.split(':') if cache_slug != @site.slug
redirect_to(args)
redirect_to(args, allow_other_host: true)
else
render 'site'
end
Expand Down
8 changes: 8 additions & 0 deletions app/decorators/camaleon_cms/application_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class ApplicationDecorator < Draper::Decorator
@_deco_locale = nil
include CamaleonCms::MetasDecoratorMethods

def marshal_dump
@object
end

def marshal_load(obj)
@object = obj
end

# return the keywords for this model
def the_keywords
k = object.get_option('keywords', '')
Expand Down
4 changes: 2 additions & 2 deletions app/decorators/camaleon_cms/post_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def the_thumb_url(default = nil)
if th.present?
th
else
(default || object.post_type.get_option('default_thumb',
nil) || h.asset_url('camaleon_cms/image-not-found.png'))
default || object.post_type.get_option('default_thumb',
nil) || h.asset_url('camaleon_cms/image-not-found.png')
end
end
alias the_image_url the_thumb_url
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/camaleon_cms/html_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ def cama_draw_pre_asset_contents
def cama_draw_custom_assets
cama_html_helpers_init unless @_assets_libraries.present?
libs = []
@_assets_libraries.each do |_key, assets|
@_assets_libraries.each_value do |assets|
libs += assets[:css] if assets[:css].present?
end
stylesheets = libs.uniq
css = stylesheet_link_tag(*stylesheets, media: 'all')

libs = []
@_assets_libraries.each do |_key, assets|
@_assets_libraries.each_value do |assets|
libs += assets[:js] if assets[:js].present?
end
javascripts = libs.uniq
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/camaleon_cms/short_code_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def shortcodes_init
return args[:shortcode] unless attrs.present?

cama_load_libraries(*attrs['data'].to_s.split(','))
return ''
''
},
"Permit to load libraries on demand, sample: [load_libraries data='datepicker,tinymce']")

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/camaleon_cms/uploader_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def upload_file(uploaded_io, settings = {})
generate_thumb: true,
temporal_time: 0,
filename: begin
(cached_name || uploaded_io.original_filename)
cached_name || uploaded_io.original_filename
rescue StandardError
uploaded_io.path.split('/').last
end.cama_fix_filename,
Expand Down
2 changes: 1 addition & 1 deletion app/models/camaleon_cms/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_theme_slug
# return theme model with slug theme_slug for this site
# theme_slug: (optional) if it is null, this will return current theme for this site
def get_theme(theme_slug = nil)
themes.where(slug: (theme_slug || get_theme_slug), status: nil).first_or_create!
themes.where(slug: theme_slug || get_theme_slug, status: nil).first_or_create!
end

# return plugin model with slug plugin_slug
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/camaleon_cms/custom_fields_read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_field_values(_key, group_number = 0)
# puts res[0]['my_slug1'].first ==> "val 1"
def get_fields_grouped(field_keys)
res = []
custom_field_values.where(custom_field_slug: field_keys).order(group_number: :asc).group_by(&:group_number).each do |_group_number, group_fields|
custom_field_values.where(custom_field_slug: field_keys).order(group_number: :asc).group_by(&:group_number).each_value do |group_fields|
group = {}
field_keys.each do |field_key|
_tmp = []
Expand Down Expand Up @@ -243,7 +243,7 @@ def set_field_values(datas = {})

ActiveRecord::Base.transaction do
custom_field_values.delete_all
datas.each do |_index, fields_data|
datas.each_value do |fields_data|
fields_data.each do |field_key, values|
next unless values[:values].present?

Expand Down
2 changes: 1 addition & 1 deletion app/views/camaleon_cms/default_theme/sitemap.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ xml.urlset 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
end
end

@r[:custom].each do |_key, item|
@r[:custom].each_value do |item|
xml.url do
xml.loc item[:url]
xml.lastmod item[:lastmod] || Date.today.to_s
Expand Down
6 changes: 3 additions & 3 deletions camaleon_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Gem::Specification.new do |s|
s.description = 'Camaleon CMS is a dynamic and advanced content management system based on Ruby on Rails as an alternative to Wordpress.'
s.license = 'MIT'

s.required_ruby_version = '>= 2.7'
s.requirements << 'rails >= 6.0'
s.requirements << 'ruby >= 2.7'
s.required_ruby_version = '>= 3.0'
s.requirements << 'rails >= 6.1'
s.requirements << 'ruby >= 3.0'
s.requirements << 'imagemagick'
# s.post_install_message = "Thank you for install Camaleon CMS."

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6_0.gemfile → gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'faker'
gem 'oj'
gem 'puma'
gem 'rack_session_access'
gem 'rails', '~> 6.0.0'
gem 'rails', '~> 7.1.2'
gem 'rspec_junit_formatter'
gem 'selenium-webdriver'
gem 'sqlite3'
2 changes: 1 addition & 1 deletion lib/ext/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def to_attr_url_format

# used for hash of objects
def find_by(val, attr = 'id')
each do |_key, p|
each_value do |p|
return p if p[attr].to_s == val.to_s
end
nil
Expand Down
25 changes: 25 additions & 0 deletions spec/decorators/application_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe CamaleonCms::SiteDecorator, type: :model do
%i[post_type post site user].each do |klass|
describe 'Marshal compatibility' do
let!(:object) { create(klass) }
let!(:decorator) { object.decorate }

it 'Marshal dumps and loads the same object' do
dump = Marshal.dump(decorator)
recovered_decorator = Marshal.load(dump)
expect(recovered_decorator).to eql(decorator)
expect(recovered_decorator.object).to eql(object)
end

it 'Writes to the Rails cache' do
Rails.cache.write(klass, decorator)
cache_result = Rails.cache.read klass
expect(cache_result.object).to eql(object)
end
end
end
end
3 changes: 2 additions & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

module Dummy
class Application < Rails::Application
config.load_defaults Rails.version.to_f
config.active_record.belongs_to_required_by_default = false
config.autoloader = :zeitwerk
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand All @@ -34,7 +36,6 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
# config.active_record.raise_in_transactional_callbacks = true
config.active_record.sqlite3.represent_boolean_as_integer = true if Rails.version.start_with? == '5.2.'

config.active_record.legacy_connection_handling = false if Rails.version.to_f >= 6.1 && Rails.version.to_f < 7.1
end
Expand Down
Binary file added spec/dummy/db/test.sqlite3-shm
Binary file not shown.
Empty file added spec/dummy/db/test.sqlite3-wal
Empty file.
4 changes: 2 additions & 2 deletions spec/helpers/email_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe '#send_email (old way)' do
it 'returns empty' do
expect(helper.send_email('test@gmail.com', 'Test Email', 'test content', 'owenperedo@gmail.com'))
.to be_a_kind_of(Rails.version.to_i >= 7 ? ActionMailer::MailDeliveryJob : ActionMailer::DeliveryJob)
.to be_a_kind_of(ActionMailer::MailDeliveryJob)
end
end

Expand All @@ -15,7 +15,7 @@
expect(
helper.cama_send_email('test@gmail.com', 'Test Email',
{ content: 'test content', from: 'owenperedo@gmail.com' })
).to be_a_kind_of(Rails.version.to_i >= 7 ? ActionMailer::MailDeliveryJob : ActionMailer::DeliveryJob)
).to be_a_kind_of(ActionMailer::MailDeliveryJob)
end
end
end