Skip to content

Commit

Permalink
Add Rails 8.0 compatibility
Browse files Browse the repository at this point in the history
Add class parameter to Uniqueness validator as per rails/rails#53598
  • Loading branch information
tagliala committed Nov 12, 2024
1 parent 135f0a3 commit 2487bea
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 28 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
gemfile: [rails_6.1, rails_7.0, rails_7.1, rails_7.2]
gemfile: [rails_6.1, rails_7.0, rails_7.1, rails_7.2, rails_8.0]
channel: ['stable']

include:
Expand All @@ -32,15 +32,24 @@ jobs:
- ruby-version: 'head'
gemfile: rails_7.2
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_8.0
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_edge
channel: 'experimental'

exclude:
- ruby-version: '2.7'
gemfile: rails_7.2
- ruby-version: '2.7'
gemfile: rails_8.0
- ruby-version: '3.0'
gemfile: rails_7.2
- ruby-version: '3.0'
gemfile: rails_8.0
- ruby-version: '3.1'
gemfile: rails_8.0
- ruby-version: '3.2'
gemfile: rails_6.1
- ruby-version: '3.3'
Expand Down
5 changes: 4 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ end

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

appraise 'rails-7.2' do
gem 'rails', '~> 7.2.0'
end

appraise 'rails-8.0' do
gem 'rails', '~> 8.0.0'
end

appraise 'rails-edge' do
gem 'rails', git: 'https://github.com/rails/rails.git', branch: 'main'
end
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Changelog

## main / unreleased
## 22.3.0 / 2024-11-08

* [FEATURE] Rails 8.0 compatibility
* [ENHANCEMENT] Update QUnit to 2.22.0
* [ENHANCEMENT] Prefer `require_relative` for internal requires

## 22.2.0 / 2026-06-01
## 22.2.0 / 2024-06-01

* [FEATURE] Allow Rails 8.0 alpha
* [ENHANCEMENT] Test against Ruby 3.3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![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)


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

## Project Goals ##

Expand Down
4 changes: 2 additions & 2 deletions client_side_validations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.email = ['[email protected]', '[email protected]']

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

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

spec.add_dependency 'js_regex', '~> 3.7'
spec.add_dependency 'rails', '>= 6.1', '< 8.0'
spec.add_dependency 'rails', '>= 6.1'
end
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem "shotgun"
gem "simplecov"
gem "simplecov-lcov"
gem "sinatra"
gem "sqlite3", "~> 1.7"
gem "sqlite3"
gem "webrick"
gem "rails", "~> 7.1.0"

Expand Down
25 changes: 25 additions & 0 deletions gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "byebug"
gem "m"
gem "minitest"
gem "mocha"
gem "rake"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-packaging"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rake"
gem "shotgun"
gem "simplecov"
gem "simplecov-lcov"
gem "sinatra"
gem "sqlite3"
gem "webrick"
gem "rails", "~> 8.0.0"

gemspec path: "../"
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@client-side-validations/client-side-validations",
"description": "Client Side Validations made easy for your Rails 6.1 / 7.x applications",
"description": "Client Side Validations made easy for your Rails 6.1, 7.x, and 8.0 applications",
"repository": {
"type": "git",
"url": "git+https://github.com/DavyJonesLocker/client_side_validations.git"
Expand All @@ -22,15 +22,15 @@
"test": "test/javascript/run-qunit.mjs"
},
"devDependencies": {
"@babel/core": "^7.25.8",
"@babel/preset-env": "^7.25.8",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.3.0",
"chrome-launcher": "^1.1.2",
"eslint": "^9.12.0",
"neostandard": "^0.11.6",
"puppeteer-core": "^23.5.3",
"rollup": "^4.24.0",
"eslint": "^9.14.0",
"neostandard": "^0.11.7",
"puppeteer-core": "^23.7.1",
"rollup": "^4.25.0",
"rollup-plugin-copy": "^3.5.0"
},
"peerDependencies": {
Expand Down
24 changes: 12 additions & 12 deletions test/active_record/cases/test_uniqueness_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,52 @@ class UniquenessValidatorTest < ClientSideValidations::ActiveRecordTestBase
def test_uniqueness_client_side_hash
expected_hash = { message: 'has already been taken' }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

assert_equal expected_hash, result_hash
end

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

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

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

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

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

0 comments on commit 2487bea

Please sign in to comment.