reform-rails 0.2.6 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +87 -20
- data/.gitignore +1 -1
- data/CHANGES.md +12 -0
- data/Gemfile-rails5 +9 -0
- data/Gemfile-rails6.0 +9 -0
- data/Gemfile-rails6.1 +9 -0
- data/Gemfile-rails7.0 +9 -0
- data/Gemfile-rails7.1 +9 -0
- data/Gemfile-rails7.2 +9 -0
- data/Gemfile-rails8 +9 -0
- data/README.md +5 -4
- data/lib/reform/form/active_model/acceptance_validator_patch.rb +36 -0
- data/lib/reform/form/orm.rb +5 -1
- data/lib/reform/form/validation/unique_validator.rb +25 -1
- data/lib/reform/rails/railtie.rb +11 -0
- data/lib/reform/rails/version.rb +1 -1
- data/reform-rails.gemspec +3 -0
- metadata +56 -7
- data/Gemfile +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11444b229bdc2a6b09fc130b3ce39b799be05f9caf0b6ced962cb9162651de05
|
4
|
+
data.tar.gz: 15b2965904cf1083b20a682feb667fe3a44dee3f5f424235b62ffae4e6297eef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f405809a0c4e33711233bdff60a14ad6c87b0a8e90b94a71b025a5dbb2025b3c3bea9d0b6c6e4c51f20afd4ad06bb513d8ab0d134f6ee22da2545a8436d8e141
|
7
|
+
data.tar.gz: 6c975e0e7c4d66124e909a1ae73b7415e95886a46fda82164dd55eb6f36603a0d69c8ebc9e39ab8a4793e213c59d14c1c30e9f502b8192e81a33e39cdd776127
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,28 +1,95 @@
|
|
1
1
|
name: CI
|
2
|
+
|
2
3
|
on: [push, pull_request]
|
4
|
+
|
3
5
|
jobs:
|
4
|
-
test:
|
5
|
-
strategy:
|
6
|
-
fail-fast: false
|
7
|
-
matrix:
|
8
|
-
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
-
ruby: [2.5, 2.6, 2.7, '3.0', head]
|
10
|
-
rails: ['6.1', '6.0', '5.2']
|
11
|
-
mongodb-version: ['4.4']
|
12
|
-
exclude:
|
13
|
-
- ruby: '3.0'
|
14
|
-
rails: 5.2
|
15
|
-
- ruby: head
|
16
|
-
rails: 5.2
|
6
|
+
test-rails5:
|
17
7
|
runs-on: ubuntu-latest
|
18
8
|
steps:
|
19
|
-
- uses: actions/checkout@
|
20
|
-
- uses: supercharge/mongodb-github-action@1.
|
9
|
+
- uses: actions/checkout@v5
|
10
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
21
11
|
with:
|
22
|
-
mongodb-version:
|
12
|
+
mongodb-version: "4.4"
|
23
13
|
- uses: ruby/setup-ruby@v1
|
24
14
|
with:
|
25
|
-
ruby-version:
|
26
|
-
|
27
|
-
- run:
|
28
|
-
|
15
|
+
ruby-version: "2.5"
|
16
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails5 bundle install
|
17
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails5 bundle exec rake
|
18
|
+
|
19
|
+
test-rails6_0:
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v5
|
23
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
24
|
+
with:
|
25
|
+
mongodb-version: "4.4"
|
26
|
+
- uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: "2.6"
|
29
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle install
|
30
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle exec rake
|
31
|
+
|
32
|
+
test-rails6_1:
|
33
|
+
runs-on: ubuntu-latest
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v5
|
36
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
37
|
+
with:
|
38
|
+
mongodb-version: "4.4"
|
39
|
+
- uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: "3.0"
|
42
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle install
|
43
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle exec rake
|
44
|
+
|
45
|
+
test-rails7_0:
|
46
|
+
runs-on: ubuntu-latest
|
47
|
+
steps:
|
48
|
+
- uses: actions/checkout@v5
|
49
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
50
|
+
with:
|
51
|
+
mongodb-version: "4.4"
|
52
|
+
- uses: ruby/setup-ruby@v1
|
53
|
+
with:
|
54
|
+
ruby-version: "3.0"
|
55
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
|
56
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake
|
57
|
+
|
58
|
+
test-rails7_1:
|
59
|
+
runs-on: ubuntu-latest
|
60
|
+
steps:
|
61
|
+
- uses: actions/checkout@v5
|
62
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
63
|
+
with:
|
64
|
+
mongodb-version: "4.4"
|
65
|
+
- uses: ruby/setup-ruby@v1
|
66
|
+
with:
|
67
|
+
ruby-version: "3.2"
|
68
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle install
|
69
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle exec rake
|
70
|
+
|
71
|
+
test-rails7_2:
|
72
|
+
runs-on: ubuntu-latest
|
73
|
+
steps:
|
74
|
+
- uses: actions/checkout@v5
|
75
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
76
|
+
with:
|
77
|
+
mongodb-version: "4.4"
|
78
|
+
- uses: ruby/setup-ruby@v1
|
79
|
+
with:
|
80
|
+
ruby-version: "3.3"
|
81
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle install
|
82
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle exec rake
|
83
|
+
|
84
|
+
test-rails8:
|
85
|
+
runs-on: ubuntu-latest
|
86
|
+
steps:
|
87
|
+
- uses: actions/checkout@v5
|
88
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
89
|
+
with:
|
90
|
+
mongodb-version: "4.4"
|
91
|
+
- uses: ruby/setup-ruby@v1
|
92
|
+
with:
|
93
|
+
ruby-version: "3.3"
|
94
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails8 bundle install
|
95
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails8 bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# 0.3.1
|
2
|
+
|
3
|
+
* Fix: ActiveModel acceptance validator wasn't properly monkey patched
|
4
|
+
Now this will work in environments where active model and active record is
|
5
|
+
not loaded by default. In addition, it will work with all the Rails versions
|
6
|
+
we support
|
7
|
+
|
8
|
+
# 0.3.0
|
9
|
+
|
10
|
+
* Add `conditions` option to Reform Uniqueness validation.
|
11
|
+
* ActiveModel acceptance validation works
|
12
|
+
|
1
13
|
# 0.2.6
|
2
14
|
|
3
15
|
* Allow to override `#persisted?` and friends with modules.
|
data/Gemfile-rails5
ADDED
data/Gemfile-rails6.0
ADDED
data/Gemfile-rails6.1
ADDED
data/Gemfile-rails7.0
ADDED
data/Gemfile-rails7.1
ADDED
data/Gemfile-rails7.2
ADDED
data/Gemfile-rails8
ADDED
data/README.md
CHANGED
@@ -28,14 +28,15 @@ Reform-rails needs Reform >= 2.3.
|
|
28
28
|
|
29
29
|
## Contributing
|
30
30
|
|
31
|
-
|
32
|
-
Please ensure that you test your changes against all supported ruby and rails versions (see .travis.yml)
|
31
|
+
Please ensure that you test your changes against all supported ruby and rails versions
|
33
32
|
|
34
33
|
You can run tests for a specific version of rails by running the following:
|
35
34
|
|
36
|
-
|
35
|
+
```shell
|
36
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
|
37
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake test
|
38
|
+
```
|
37
39
|
|
38
40
|
## License
|
39
41
|
|
40
42
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Reform::Form::ActiveModel
|
2
|
+
module AcceptanceValidatorPatch
|
3
|
+
def self.apply!
|
4
|
+
return if defined?(::ActiveModel::Validations::ReformAcceptanceValidator)
|
5
|
+
|
6
|
+
klass = Class.new(::ActiveModel::EachValidator) do
|
7
|
+
def initialize(options)
|
8
|
+
super({ allow_nil: true, accept: ["1", true] }.merge!(options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate_each(record, attribute, value)
|
12
|
+
unless acceptable_option?(value)
|
13
|
+
if Gem::Version.new(::ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
|
14
|
+
record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
|
15
|
+
else
|
16
|
+
record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def acceptable_option?(value)
|
24
|
+
Array(options[:accept]).include?(value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Assign the class to a constant for tracking
|
29
|
+
::ActiveModel::Validations.const_set(:ReformAcceptanceValidator, klass)
|
30
|
+
|
31
|
+
# Override the built-in validator
|
32
|
+
::ActiveModel::Validations.send(:remove_const, :AcceptanceValidator)
|
33
|
+
::ActiveModel::Validations.const_set(:AcceptanceValidator, klass)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/reform/form/orm.rb
CHANGED
@@ -20,7 +20,11 @@ module Reform::Form::ORM
|
|
20
20
|
@klass = record.class # this is usually done in the super-sucky #setup method.
|
21
21
|
super(record).tap do |res|
|
22
22
|
if record.errors.present?
|
23
|
-
error =
|
23
|
+
error = if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
|
24
|
+
self.class.name.include?("Mongoid") ? record.errors.first.type : :taken
|
25
|
+
else
|
26
|
+
self.class.name.include?("Mongoid") ? record.errors.first.last : :taken
|
27
|
+
end
|
24
28
|
form.errors.add(property, error)
|
25
29
|
end
|
26
30
|
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# validates :title, unique: { case_sensitive: false }
|
15
15
|
#
|
16
16
|
# = Scope
|
17
|
-
# A scope can be
|
17
|
+
# A scope can be used to filter the records that need to be compare with the
|
18
18
|
# current value to validate. A scope array can have one to many fields define.
|
19
19
|
#
|
20
20
|
# A scope can be define the following ways:
|
@@ -33,6 +33,20 @@
|
|
33
33
|
# This use case is useful if album_id is set to a Song this way:
|
34
34
|
# song = album.songs.new
|
35
35
|
# album_id is automatically set and can't be change by the operation
|
36
|
+
#
|
37
|
+
# = Conditions
|
38
|
+
# A condition can be passed to filter the records with partial indexes
|
39
|
+
#
|
40
|
+
# Conditions can be define the following ways:
|
41
|
+
# validates :title, unique: { conditions: -> { where(archived_at: nil) } }
|
42
|
+
# - This will check that the title is unique for non archived records
|
43
|
+
# validates :title, unique: {
|
44
|
+
# conditions: ->(record) {
|
45
|
+
# published_at = record.published_at
|
46
|
+
# where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
47
|
+
# }
|
48
|
+
# }
|
49
|
+
#
|
36
50
|
|
37
51
|
class Reform::Form::UniqueValidator < ActiveModel::EachValidator
|
38
52
|
def validate_each(form, attribute, value)
|
@@ -57,6 +71,16 @@ class Reform::Form::UniqueValidator < ActiveModel::EachValidator
|
|
57
71
|
query = query.where(field => form.send(field))
|
58
72
|
end
|
59
73
|
|
74
|
+
if options[:conditions]
|
75
|
+
conditions = options[:conditions]
|
76
|
+
|
77
|
+
query = if conditions.arity.zero?
|
78
|
+
query.instance_exec(&conditions)
|
79
|
+
else
|
80
|
+
query.instance_exec(form, &conditions)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
60
84
|
form.errors.add(attribute, :taken) if query.count > 0
|
61
85
|
end
|
62
86
|
end
|
data/lib/reform/rails/railtie.rb
CHANGED
@@ -57,6 +57,17 @@ module Reform
|
|
57
57
|
include Reform::Form::Dry
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
61
|
+
initializer "reform.patch_acceptance_validator" do
|
62
|
+
require "reform/form/active_model/acceptance_validator_patch"
|
63
|
+
|
64
|
+
if defined?(::ActiveModel::Validations::AcceptanceValidator)
|
65
|
+
Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply!
|
66
|
+
else
|
67
|
+
ActiveSupport.on_load(:active_record) { Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply! }
|
68
|
+
Rails.application.config.to_prepare { Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply! }
|
69
|
+
end
|
70
|
+
end
|
60
71
|
end # Railtie
|
61
72
|
end
|
62
73
|
end
|
data/lib/reform/rails/version.rb
CHANGED
data/reform-rails.gemspec
CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency "reform", ">= 2.3.1", "< 3.0.0"
|
24
24
|
spec.add_dependency "activemodel", ">= 5.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency "minitest-line"
|
27
|
+
spec.add_development_dependency "debug"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reform-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform
|
@@ -44,6 +44,48 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest-line
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: debug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
47
89
|
description: Automatically load and include all common Reform features for a standard
|
48
90
|
Rails environment.
|
49
91
|
email:
|
@@ -55,12 +97,19 @@ files:
|
|
55
97
|
- ".github/workflows/ci.yml"
|
56
98
|
- ".gitignore"
|
57
99
|
- CHANGES.md
|
58
|
-
- Gemfile
|
100
|
+
- Gemfile-rails5
|
101
|
+
- Gemfile-rails6.0
|
102
|
+
- Gemfile-rails6.1
|
103
|
+
- Gemfile-rails7.0
|
104
|
+
- Gemfile-rails7.1
|
105
|
+
- Gemfile-rails7.2
|
106
|
+
- Gemfile-rails8
|
59
107
|
- LICENSE.txt
|
60
108
|
- README.md
|
61
109
|
- Rakefile
|
62
110
|
- lib/reform/active_record.rb
|
63
111
|
- lib/reform/form/active_model.rb
|
112
|
+
- lib/reform/form/active_model/acceptance_validator_patch.rb
|
64
113
|
- lib/reform/form/active_model/form_builder_methods.rb
|
65
114
|
- lib/reform/form/active_model/model_reflections.rb
|
66
115
|
- lib/reform/form/active_model/model_validations.rb
|
@@ -80,7 +129,7 @@ homepage: https://github.com/trailblazer/reform-rails
|
|
80
129
|
licenses:
|
81
130
|
- MIT
|
82
131
|
metadata: {}
|
83
|
-
post_install_message:
|
132
|
+
post_install_message:
|
84
133
|
rdoc_options: []
|
85
134
|
require_paths:
|
86
135
|
- lib
|
@@ -95,8 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
144
|
- !ruby/object:Gem::Version
|
96
145
|
version: '0'
|
97
146
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
147
|
+
rubygems_version: 3.3.27
|
148
|
+
signing_key:
|
100
149
|
specification_version: 4
|
101
150
|
summary: Automatically load and include all common Rails form features.
|
102
151
|
test_files: []
|
data/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
git_source(:github) do |repo_name|
|
2
|
-
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
3
|
-
"https://github.com/#{repo_name}.git"
|
4
|
-
end
|
5
|
-
|
6
|
-
source "https://rubygems.org"
|
7
|
-
gemspec
|
8
|
-
|
9
|
-
# gem 'pry-byebug'
|
10
|
-
gem "minitest-line"
|
11
|
-
|
12
|
-
case ENV["GEMS_SOURCE"]
|
13
|
-
when "local"
|
14
|
-
gem "reform", path: "../reform"
|
15
|
-
when "github"
|
16
|
-
gem "reform", github: "trailblazer/reform"
|
17
|
-
end
|
18
|
-
|
19
|
-
rails_version = ENV.fetch("RAILS_VERSION", "6.0.0")
|
20
|
-
|
21
|
-
# bored of wrestling with rails...
|
22
|
-
|
23
|
-
gem("mongoid", "< 7.0") unless rails_version.to_i >= 6
|
24
|
-
|
25
|
-
|
26
|
-
gem "activerecord", "~> #{rails_version}"
|
27
|
-
gem "railties", "~> #{rails_version}"
|
28
|
-
if rails_version.to_i >= 6
|
29
|
-
gem "sqlite3", "~> 1.4"
|
30
|
-
else
|
31
|
-
gem "sqlite3", "~> 1.3", "< 1.4"
|
32
|
-
end
|
33
|
-
puts "Rails version #{rails_version}"
|