diff --git a/.rspec b/.rspec index c99d2e73..a35c44f4 100644 --- a/.rspec +++ b/.rspec @@ -1 +1 @@ ---require spec_helper +--require rails_helper diff --git a/Gemfile b/Gemfile index 841320a8..69476baf 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'rails', '~> 8.0.1' gem 'selenium-webdriver' gem 'sprockets-rails', '>= 3.5.2' +gem 'capybara-lockstep' gem 'capybara-screenshot' gem 'rspec_junit_formatter' diff --git a/Gemfile.lock b/Gemfile.lock index a59944e4..73a3b90a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,11 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + capybara-lockstep (2.2.2) + activesupport (>= 4.2) + capybara (>= 3.0) + ruby2_keywords + selenium-webdriver (>= 4.0) capybara-screenshot (1.0.26) capybara (>= 1.0, < 4) launchy @@ -414,6 +419,7 @@ DEPENDENCIES byebug camaleon_cms! capybara + capybara-lockstep capybara-screenshot factory_bot_rails faker diff --git a/app/models/camaleon_cms/meta.rb b/app/models/camaleon_cms/meta.rb index e2e01fbc..2bca8fc6 100644 --- a/app/models/camaleon_cms/meta.rb +++ b/app/models/camaleon_cms/meta.rb @@ -2,5 +2,24 @@ module CamaleonCms class Meta < CamaleonRecord self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}metas" # attr_accessible :objectid, :key, :value, :object_class + + # TODO: Remove the 1st branch when support will be dropped of Rails < 7.1 + if ::Rails::VERSION::STRING < '7.1.0' + before_validation(on: %i[create update]) do + %i[value].each do |attr| + next unless new_record? || attribute_changed?(attr) + + self[attr] = ActionController::Base.helpers.sanitize( + __send__(attr)&.gsub(CamaleonRecord::TRANSLATION_TAG_HIDE_REGEX, CamaleonRecord::TRANSLATION_TAG_HIDE_MAP) + )&.gsub(CamaleonRecord::TRANSLATION_TAG_RESTORE_REGEX, CamaleonRecord::TRANSLATION_TAG_RESTORE_MAP) + end + end + else + normalizes :value, with: lambda { |field| + ActionController::Base.helpers.sanitize( + field.gsub(CamaleonRecord::TRANSLATION_TAG_HIDE_REGEX, CamaleonRecord::TRANSLATION_TAG_HIDE_MAP) + ).gsub(CamaleonRecord::TRANSLATION_TAG_RESTORE_REGEX, CamaleonRecord::TRANSLATION_TAG_RESTORE_MAP) + } + end end end diff --git a/app/models/camaleon_cms/post_comment.rb b/app/models/camaleon_cms/post_comment.rb index 079bfb35..06df778c 100644 --- a/app/models/camaleon_cms/post_comment.rb +++ b/app/models/camaleon_cms/post_comment.rb @@ -21,6 +21,24 @@ class PostComment < CamaleonRecord scope :comment_parent, -> { where(comment_parent: 'is not null') } scope :approveds, -> { where(approved: 'approved') } + # TODO: Remove the 1st branch when support will be dropped of Rails < 7.1 + if ::Rails::VERSION::STRING < '7.1.0' + before_validation(on: %i[create update]) do + %i[content].each do |attr| + next unless new_record? || attribute_changed?(attr) + + self[attr] = ActionController::Base.helpers.sanitize( + __send__(attr)&.gsub(TRANSLATION_TAG_HIDE_REGEX, TRANSLATION_TAG_HIDE_MAP) + )&.gsub(TRANSLATION_TAG_RESTORE_REGEX, TRANSLATION_TAG_RESTORE_MAP) + end + end + else + normalizes :content, with: lambda { |field| + ActionController::Base.helpers.sanitize(field.gsub(TRANSLATION_TAG_HIDE_REGEX, TRANSLATION_TAG_HIDE_MAP)) + .gsub(TRANSLATION_TAG_RESTORE_REGEX, TRANSLATION_TAG_RESTORE_MAP) + } + end + validates :content, presence: true validates_presence_of :author, :author_email, if: proc { |c| c.is_anonymous.present? } after_create :update_counter diff --git a/app/models/camaleon_cms/term_taxonomy.rb b/app/models/camaleon_cms/term_taxonomy.rb index abe88f86..57a549f3 100644 --- a/app/models/camaleon_cms/term_taxonomy.rb +++ b/app/models/camaleon_cms/term_taxonomy.rb @@ -3,12 +3,6 @@ class TermTaxonomy < CamaleonRecord include CamaleonCms::Metas include CamaleonCms::CustomFieldsRead - TRANSLATION_TAG_HIDE_MAP = { '' => '--!' }.freeze - TRANSLATION_TAG_HIDE_REGEX = Regexp.new(TRANSLATION_TAG_HIDE_MAP.keys.map { |x| Regexp.escape(x) }.join('|')).freeze - TRANSLATION_TAG_RESTORE_MAP = { '--!' => '-->', '!--' => '' => '--!' }.freeze + TRANSLATION_TAG_HIDE_REGEX = Regexp.new(TRANSLATION_TAG_HIDE_MAP.keys.map { |x| Regexp.escape(x) }.join('|')).freeze + TRANSLATION_TAG_RESTORE_MAP = { '--!' => '-->', '!--' => '