Skip to content

Commit 2487bea

Browse files
committed
Add Rails 8.0 compatibility
Add class parameter to Uniqueness validator as per rails/rails#53598
1 parent 135f0a3 commit 2487bea

File tree

9 files changed

+65
-28
lines changed

9 files changed

+65
-28
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'

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: "../"

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": {

test/active_record/cases/test_uniqueness_validator.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@ class UniquenessValidatorTest < ClientSideValidations::ActiveRecordTestBase
77
def test_uniqueness_client_side_hash
88
expected_hash = { message: 'has already been taken' }
99

10-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name]).client_side_hash(@user, :name)
10+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name]).client_side_hash(@user, :name)
1111
end
1212

1313
def test_uniqueness_client_side_hash_allowing_blank
1414
expected_hash = { message: 'has already been taken', allow_blank: true }
1515

16-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], allow_blank: true).client_side_hash(@user, :name)
16+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], allow_blank: true).client_side_hash(@user, :name)
1717
end
1818

1919
def test_uniqueness_client_side_hash_allowing_nil
2020
expected_hash = { message: 'has already been taken', allow_blank: true }
2121

22-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], allow_nil: true).client_side_hash(@user, :name)
22+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], allow_nil: true).client_side_hash(@user, :name)
2323
end
2424

2525
def test_uniqueness_client_side_hash_case_insensitive
2626
expected_hash = { message: 'has already been taken' }
2727

28-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], case_sensitive: false).client_side_hash(@user, :name)
28+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], case_sensitive: false).client_side_hash(@user, :name)
2929
end
3030

3131
def test_uniqueness_client_side_hash_case_sensitive
3232
expected_hash = { message: 'has already been taken', case_sensitive: true }
3333

34-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], case_sensitive: true).client_side_hash(@user, :name)
34+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], case_sensitive: true).client_side_hash(@user, :name)
3535
end
3636

3737
def test_uniqueness_client_side_hash_with_custom_message
3838
expected_hash = { message: 'is not available' }
3939

40-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], message: 'is not available').client_side_hash(@user, :name)
40+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], message: 'is not available').client_side_hash(@user, :name)
4141
end
4242

4343
def test_uniqueness_client_side_hash_with_existing_record
4444
@user.stubs(:new_record?).returns(false)
4545
@user.stubs(:id).returns(1)
4646
expected_hash = { message: 'has already been taken', id: 1 }
4747

48-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name]).client_side_hash(@user, :name)
48+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name]).client_side_hash(@user, :name)
4949
end
5050

5151
def test_uniqueness_client_side_hash_with_single_scope_item
5252
@user.stubs(:age).returns(30)
5353
@user.stubs(:title).returns('test title')
5454
expected_hash = { message: 'has already been taken', scope: { title: 'test title' } }
55-
result_hash = UniquenessValidator.new(attributes: [:name], scope: :title).client_side_hash(@user, :name)
55+
result_hash = UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], scope: :title).client_side_hash(@user, :name)
5656

5757
assert_equal expected_hash, result_hash
5858
end
@@ -61,14 +61,14 @@ def test_uniqueness_client_side_hash_with_multiple_scope_items
6161
@user.stubs(:age).returns(30)
6262
@user.stubs(:title).returns('test title')
6363
expected_hash = { message: 'has already been taken', scope: { age: 30, title: 'test title' } }
64-
result_hash = UniquenessValidator.new(attributes: [:name], scope: %i[age title]).client_side_hash(@user, :name)
64+
result_hash = UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], scope: %i[age title]).client_side_hash(@user, :name)
6565

6666
assert_equal expected_hash, result_hash
6767
end
6868

6969
def test_uniqueness_client_side_hash_with_empty_scope_array
7070
expected_hash = { message: 'has already been taken' }
71-
result_hash = UniquenessValidator.new(attributes: [:name], scope: []).client_side_hash(@user, :name)
71+
result_hash = UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], scope: []).client_side_hash(@user, :name)
7272

7373
assert_equal expected_hash, result_hash
7474
end
@@ -77,14 +77,14 @@ def test_uniqueness_client_side_hash_when_nested_module
7777
@user = ActiveRecordTestModule::User2.new
7878
expected_hash = { message: 'has already been taken', class: 'active_record_test_module/user2' }
7979

80-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name]).client_side_hash(@user, :name)
80+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name]).client_side_hash(@user, :name)
8181
end
8282

8383
def test_uniqueness_client_side_hash_with_class_from_options
8484
@user = UserForm.new
8585
expected_hash = { message: 'has already been taken', class: 'user' }
8686

87-
assert_equal expected_hash, UniquenessValidator.new(attributes: [:name], client_validations: { class: 'User' }).client_side_hash(@user, :name)
87+
assert_equal expected_hash, UniquenessValidator.new(class: ClientSideValidations::ActiveRecordTestBase, attributes: [:name], client_validations: { class: 'User' }).client_side_hash(@user, :name)
8888
end
8989
end
9090
end

0 commit comments

Comments
 (0)