Skip to content

Commit 97fde95

Browse files
authored
Add Rails 8.0 compatibility (#952)
- Add class parameter to Uniqueness validator as per rails/rails#53598 - Test new edge methods textarea and checkbox - Allow new Rails 8 helper names like `textarea` (close #941)
1 parent 135f0a3 commit 97fde95

File tree

15 files changed

+228
-30
lines changed

15 files changed

+228
-30
lines changed

.github/workflows/ruby.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
19-
gemfile: [rails_6.1, rails_7.0, rails_7.1, rails_7.2]
19+
gemfile: [rails_6.1, rails_7.0, rails_7.1, rails_7.2, rails_8.0]
2020
channel: ['stable']
2121

2222
include:
@@ -32,15 +32,24 @@ jobs:
3232
- ruby-version: 'head'
3333
gemfile: rails_7.2
3434
channel: 'experimental'
35+
- ruby-version: 'head'
36+
gemfile: rails_8.0
37+
channel: 'experimental'
3538
- ruby-version: 'head'
3639
gemfile: rails_edge
3740
channel: 'experimental'
3841

3942
exclude:
4043
- ruby-version: '2.7'
4144
gemfile: rails_7.2
45+
- ruby-version: '2.7'
46+
gemfile: rails_8.0
4247
- ruby-version: '3.0'
4348
gemfile: rails_7.2
49+
- ruby-version: '3.0'
50+
gemfile: rails_8.0
51+
- ruby-version: '3.1'
52+
gemfile: rails_8.0
4453
- ruby-version: '3.2'
4554
gemfile: rails_6.1
4655
- ruby-version: '3.3'

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Metrics/MethodLength:
4949
- 'test/**/*'
5050

5151
Metrics/ModuleLength:
52-
Max: 101
52+
Max: 109
5353
Exclude:
5454
- 'test/**/*'
5555

Appraisals

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ end
1212

1313
appraise 'rails-7.1' do
1414
gem 'rails', '~> 7.1.0'
15-
gem 'sqlite3', '~> 1.7' # FIXME: remove after rails/rails#51592
1615
end
1716

1817
appraise 'rails-7.2' do
1918
gem 'rails', '~> 7.2.0'
2019
end
2120

21+
appraise 'rails-8.0' do
22+
gem 'rails', '~> 8.0.0'
23+
end
24+
2225
appraise 'rails-edge' do
2326
gem 'rails', git: 'https://github.com/rails/rails.git', branch: 'main'
2427
end

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Changelog
22

3-
## main / unreleased
3+
## 22.3.0 / 2024-11-08
44

5+
* [FEATURE] Rails 8.0 compatibility
56
* [ENHANCEMENT] Update QUnit to 2.22.0
6-
* [ENHANCEMENT] Prefer `require_relative` for internal requires
77

8-
## 22.2.0 / 2026-06-01
8+
## 22.2.0 / 2024-06-01
99

1010
* [FEATURE] Allow Rails 8.0 alpha
1111
* [ENHANCEMENT] Test against Ruby 3.3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![Coverage Status](https://coveralls.io/repos/github/DavyJonesLocker/client_side_validations/badge.svg?branch=main)](https://coveralls.io/github/DavyJonesLocker/client_side_validations?branch=main)
99

1010

11-
`ClientSideValidations` made easy for your Rails 6.1 / 7.x applications!
11+
`ClientSideValidations` made easy for your Rails 6.1, 7.x, and 8.0 applications!
1212

1313
## Project Goals ##
1414

client_side_validations.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
1111
1212

1313
spec.summary = 'Client Side Validations'
14-
spec.description = 'Client Side Validations made easy for your Rails 6.1 and 7.x applications'
14+
spec.description = 'Client Side Validations made easy for your Rails 6.1, 7.x, and 8.0 applications'
1515
spec.homepage = 'https://github.com/DavyJonesLocker/client_side_validations'
1616
spec.license = 'MIT'
1717

@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
2828
spec.required_ruby_version = '>= 2.7'
2929

3030
spec.add_dependency 'js_regex', '~> 3.7'
31-
spec.add_dependency 'rails', '>= 6.1', '< 8.0'
31+
spec.add_dependency 'rails', '>= 6.1'
3232
end

gemfiles/rails_7.1.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gem "shotgun"
1818
gem "simplecov"
1919
gem "simplecov-lcov"
2020
gem "sinatra"
21-
gem "sqlite3", "~> 1.7"
21+
gem "sqlite3"
2222
gem "webrick"
2323
gem "rails", "~> 7.1.0"
2424

gemfiles/rails_8.0.gemfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "appraisal"
6+
gem "byebug"
7+
gem "m"
8+
gem "minitest"
9+
gem "mocha"
10+
gem "rake"
11+
gem "rubocop"
12+
gem "rubocop-minitest"
13+
gem "rubocop-packaging"
14+
gem "rubocop-performance"
15+
gem "rubocop-rails"
16+
gem "rubocop-rake"
17+
gem "shotgun"
18+
gem "simplecov"
19+
gem "simplecov-lcov"
20+
gem "sinatra"
21+
gem "sqlite3"
22+
gem "webrick"
23+
gem "rails", "~> 8.0.0"
24+
25+
gemspec path: "../"

lib/client_side_validations/action_view/form_builder.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module ActionView
55
module Helpers
66
module FormBuilder
77
def self.prepended(base)
8-
(base.field_helpers - %i[label check_box radio_button fields_for fields hidden_field file_field]).each do |selector|
8+
selectors = base.field_helpers - %i[label check_box checkbox radio_button fields_for fields hidden_field file_field]
9+
10+
selectors.each do |selector|
911
base.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
1012
# Cannot call super here, rewrite all
1113
def #{selector}(method, options = {}) # def text_field(method, options = {})
@@ -19,6 +21,10 @@ def #{selector}(method, options = {}) # def text_field(method, options = {
1921
end # end
2022
RUBY_EVAL
2123
end
24+
25+
base.class_eval do
26+
alias_method :text_area, :textarea if ::ActionView::Helpers::FormBuilder.field_helpers.include?(:textarea)
27+
end
2228
end
2329

2430
def initialize(object_name, object, template, options)
@@ -47,6 +53,7 @@ def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
4753
options.delete(:validate)
4854
super
4955
end
56+
alias checkbox check_box if ::ActionView::Helpers::FormBuilder.field_helpers.include?(:checkbox)
5057

5158
%i[collection_check_boxes collection_radio_buttons].each do |method_name|
5259
define_method method_name do |method, collection, value_method, text_method, options = {}, html_options = {}, &block|
@@ -56,6 +63,10 @@ def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
5663
end
5764
end
5865

66+
if ::ActionView::Helpers::FormBuilder.public_instance_methods.include?(:collection_checkboxes)
67+
alias collection_checkboxes collection_check_boxes
68+
end
69+
5970
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
6071
build_validation_options(method, html_options.merge(name: options[:name]))
6172
html_options.delete(:validate)

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@client-side-validations/client-side-validations",
3-
"description": "Client Side Validations made easy for your Rails 6.1 / 7.x applications",
3+
"description": "Client Side Validations made easy for your Rails 6.1, 7.x, and 8.0 applications",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/DavyJonesLocker/client_side_validations.git"
@@ -22,15 +22,15 @@
2222
"test": "test/javascript/run-qunit.mjs"
2323
},
2424
"devDependencies": {
25-
"@babel/core": "^7.25.8",
26-
"@babel/preset-env": "^7.25.8",
25+
"@babel/core": "^7.26.0",
26+
"@babel/preset-env": "^7.26.0",
2727
"@rollup/plugin-babel": "^6.0.4",
2828
"@rollup/plugin-node-resolve": "^15.3.0",
2929
"chrome-launcher": "^1.1.2",
30-
"eslint": "^9.12.0",
31-
"neostandard": "^0.11.6",
32-
"puppeteer-core": "^23.5.3",
33-
"rollup": "^4.24.0",
30+
"eslint": "^9.14.0",
31+
"neostandard": "^0.11.7",
32+
"puppeteer-core": "^23.7.1",
33+
"rollup": "^4.25.0",
3434
"rollup-plugin-copy": "^3.5.0"
3535
},
3636
"peerDependencies": {

0 commit comments

Comments
 (0)