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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ef8e06973cbbd53737de0a7d0afe1250bdba0814
4
- data.tar.gz: 986c4d29338ecdc03fb3dea2ab7c75f6c9253ce6
2
+ SHA256:
3
+ metadata.gz: 11444b229bdc2a6b09fc130b3ce39b799be05f9caf0b6ced962cb9162651de05
4
+ data.tar.gz: 15b2965904cf1083b20a682feb667fe3a44dee3f5f424235b62ffae4e6297eef
5
5
  SHA512:
6
- metadata.gz: 314925db393628f4f0d7a2dc32808217c7b2d17d0e27d86d69299b14df875917a1598857c291ea3eec8605bbcfb4e31e1d908c12df66ad3c4dd25a8fae6bc3ce
7
- data.tar.gz: 9f8f292731ef5b34f8abe6a046d738d18bd98b9192564ba592e8d922bfef02e0f61ba3feddee77d69cc2e590b4e91310bc925ec749fedbfcbee1b0ba458c0869
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
@@ -1,6 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
3
+ /*.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
@@ -8,4 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.gem
11
- test/dummy/log/*.log
11
+ *.sqlite3
12
+ .byebug*
13
+ *.log
14
+ .rubocop-https*
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 controller via `config.reform.validations = :dry`.
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
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 2.5'
5
+
6
+ gem "mongoid", "< 7.0"
7
+ gem "activerecord", "~> 5.2"
8
+ gem "railties", "~> 5.2"
9
+ gem "sqlite3", "~> 1.3", "< 1.4"
data/Gemfile-rails6.0 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 2.6'
5
+
6
+ gem "activerecord", "~> 6.0.0"
7
+ gem "railties", "~> 6.0.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails6.1 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.0'
5
+
6
+ gem "activerecord", "~> 6.1.0"
7
+ gem "railties", "~> 6.1.0"
8
+ gem "sqlite3", "~> 1.4"
9
+ gem "mongoid"
data/Gemfile-rails7.0 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.0'
5
+
6
+ gem "activerecord", "~> 7.0.0"
7
+ gem "railties", "~> 7.0.0"
8
+ gem "sqlite3", "~> 1.4"
9
+ gem "mongoid"
data/Gemfile-rails7.1 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.2'
5
+
6
+ gem "activerecord", "~> 7.1.0"
7
+ gem "railties", "~> 7.1.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails7.2 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.3'
5
+
6
+ gem "activerecord", "~> 7.2.0"
7
+ gem "railties", "~> 7.2.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/Gemfile-rails8 ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ ruby '~> 3.2'
5
+
6
+ gem "activerecord", "~> 8.0.0"
7
+ gem "railties", "~> 8.0.0"
8
+ gem "sqlite3"
9
+ gem "mongoid"
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Nick Sutterer
3
+ Copyright (c) 2015-2021 Nick Sutterer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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](http://trailblazer.to/gems/reform/#reform-rails) can be found on the Trailblazer page.
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.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
@@ -4,7 +4,9 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.warning = false
9
+ t.verbose = true
8
10
  end
9
11
 
10
12
  task :default => :test
@@ -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