reform-rails 0.1.7 → 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 +5 -5
- data/.github/workflows/ci.yml +95 -0
- data/.gitignore +5 -2
- data/CHANGES.md +56 -1
- 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/LICENSE.txt +1 -1
- data/README.md +13 -3
- data/Rakefile +3 -1
- data/lib/reform/active_record.rb +2 -1
- data/lib/reform/form/active_model/acceptance_validator_patch.rb +36 -0
- data/lib/reform/form/active_model/result.rb +15 -0
- data/lib/reform/form/active_model/validations.rb +198 -70
- data/lib/reform/form/active_model.rb +12 -8
- data/lib/reform/form/active_record.rb +0 -2
- data/lib/reform/form/mongoid.rb +26 -0
- data/lib/reform/form/multi_parameter_attributes.rb +5 -1
- data/lib/reform/form/orm.rb +8 -1
- data/lib/reform/form/validation/unique_validator.rb +43 -5
- data/lib/reform/mongoid.rb +4 -0
- data/lib/reform/rails/railtie.rb +33 -17
- data/lib/reform/rails/version.rb +1 -1
- data/lib/reform/rails.rb +1 -0
- data/reform-rails.gemspec +7 -11
- metadata +30 -91
- data/.travis.yml +0 -18
- data/Gemfile +0 -6
- data/database.sqlite3 +0 -0
- data/gemfiles/Gemfile.rails-3.2 +0 -7
- data/gemfiles/Gemfile.rails-4.0 +0 -7
- data/gemfiles/Gemfile.rails-4.1 +0 -7
- data/gemfiles/Gemfile.rails-4.2 +0 -7
- data/log/development.log +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
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
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test-rails5:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v5
|
|
10
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
|
11
|
+
with:
|
|
12
|
+
mongodb-version: "4.4"
|
|
13
|
+
- uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
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,58 @@
|
|
|
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
|
+
|
|
13
|
+
# 0.2.6
|
|
14
|
+
|
|
15
|
+
* Allow to override `#persisted?` and friends with modules.
|
|
16
|
+
|
|
17
|
+
# 0.2.5
|
|
18
|
+
|
|
19
|
+
* Fix: Delegating from form object causes ArgumentError with 0.2.4 (https://github.com/trailblazer/reform-rails/issues/99)
|
|
20
|
+
|
|
21
|
+
# 0.2.4
|
|
22
|
+
|
|
23
|
+
* Fix keyword argument warning in `method_missing` (https://github.com/trailblazer/reform-rails/pull/97)
|
|
24
|
+
* Internal: Replace Uber::Delegates with Forwardable in Form::ActiveModel
|
|
25
|
+
|
|
26
|
+
# 0.2.3
|
|
27
|
+
|
|
28
|
+
* Fix deprecation warning related to `respond_to?`
|
|
29
|
+
|
|
30
|
+
# 0.2.2
|
|
31
|
+
|
|
32
|
+
* Support ActiveRecord 6.1
|
|
33
|
+
|
|
34
|
+
# 0.2.1
|
|
35
|
+
|
|
36
|
+
* Error's full_message with translation fixed thanks to [@marcelolx](https://github.com/trailblazer/reform-rails/pull/85)
|
|
37
|
+
|
|
38
|
+
# 0.2.0
|
|
39
|
+
|
|
40
|
+
* Needs Reform >= 2.3.0.
|
|
41
|
+
* make the inclusion of ActiveModel form builder modules optional when using dry-validation. This can be controlled via `config.reform.enable_active_model_builder_methods = true`.
|
|
42
|
+
* delegate `validates_each` method and allow it to be called outside a validation block.
|
|
43
|
+
* add `case_sensitive` option to Reform Uniqueness validation. Defaults to true.
|
|
44
|
+
* fix bug in uniqueness validation where form has different attribute name to column
|
|
45
|
+
* improve handling of persisted records in uniqueness validator
|
|
46
|
+
* remove params.merge! as it's deprecated in rails 5
|
|
47
|
+
* update to support reform 2.3, the new API means that `errors.add` is delegated to ActiveModel::Errors to support rails 5
|
|
48
|
+
* Fix nested form validation (#53)
|
|
49
|
+
* Errors supports symbol and string lookup (PR #77)
|
|
50
|
+
* Implement respond_to that delegates to AMV errors (PR #78)
|
|
51
|
+
* Drop support for activemodel before 5.0
|
|
52
|
+
|
|
53
|
+
# 0.1.8
|
|
54
|
+
* Drop support to mongoid < 4.
|
|
55
|
+
|
|
1
56
|
# 0.1.7 (0.1.6 Yanked)
|
|
2
57
|
|
|
3
58
|
* Fix a bug where requiring `form/active_model/validations` in a non-Rails environment wouldn't load all necessary files.
|
|
@@ -12,7 +67,7 @@
|
|
|
12
67
|
|
|
13
68
|
# 0.1.3
|
|
14
69
|
|
|
15
|
-
* Introduce a railtie to load either `ActiveModel::Validations` *or* `Dry::Validations`. This can be
|
|
70
|
+
* Introduce a railtie to load either `ActiveModel::Validations` *or* `Dry::Validations`. This can be controlled via `config.reform.validations = :dry`.
|
|
16
71
|
|
|
17
72
|
# 0.1.2
|
|
18
73
|
|
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/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Simply don't include this gem if you don't want to use the conventional Reform/R
|
|
|
14
14
|
|
|
15
15
|
## Documentation
|
|
16
16
|
|
|
17
|
-
The [full documentation](
|
|
17
|
+
The [full documentation](https://trailblazer.to/2.0/gems/reform/rails.html) can be found on the Trailblazer page.
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
@@ -24,9 +24,19 @@ Add this line to your application's Gemfile:
|
|
|
24
24
|
gem 'reform-rails'
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Reform-rails needs Reform >= 2.
|
|
27
|
+
Reform-rails needs Reform >= 2.3.
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
Please ensure that you test your changes against all supported ruby and rails versions
|
|
32
|
+
|
|
33
|
+
You can run tests for a specific version of rails by running the following:
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
|
|
37
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake test
|
|
38
|
+
```
|
|
28
39
|
|
|
29
40
|
## License
|
|
30
41
|
|
|
31
42
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
32
|
-
|
data/Rakefile
CHANGED
data/lib/reform/active_record.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
require "reform/form/active_model"
|
|
2
1
|
require "reform/form/orm"
|
|
2
|
+
require "reform/form/active_model"
|
|
3
3
|
require "reform/form/active_record"
|
|
4
4
|
require "reform/form/active_model/model_reflections" # only load this in AR context as simple_form currently is bound to AR.
|
|
5
|
+
require "reform/form/active_model/result"
|
|
@@ -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
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Reform::Contract::Result
|
|
2
|
+
private
|
|
3
|
+
|
|
4
|
+
def filter_for(method, *args)
|
|
5
|
+
@results.collect { |r| r.public_send(method, *args).to_h }
|
|
6
|
+
.inject({}) { |hah, err| hah.merge(err) { |key, old_v, new_v| (new_v.is_a?(Array) ? (old_v |= new_v) : old_v.merge(new_v)) } }
|
|
7
|
+
.find_all { |k, v| # filter :nested=>{:something=>["too nested!"]} #DISCUSS: do we want that here?
|
|
8
|
+
if v.is_a?(Hash)
|
|
9
|
+
nested_errors = v.select { |attr_key, val| attr_key.is_a?(Integer) && val.is_a?(Array) && val.any? }
|
|
10
|
+
v = nested_errors.to_a if nested_errors.any?
|
|
11
|
+
end
|
|
12
|
+
v.is_a?(Array) || v.class.to_s == "ActiveModel::DeprecationHandlingMessageArray"
|
|
13
|
+
}.to_h
|
|
14
|
+
end
|
|
15
|
+
end
|