reform-rails 0.2.0.rc3 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4f1ac1e0e188391ad063e8f61c6dafbc25554d8f
4
- data.tar.gz: 6ddf5369a091079b68013c66c49bda0a4b7d1fe6
2
+ SHA256:
3
+ metadata.gz: 7d315dbb4f57ba5ca99e97471777bc21c1a1825107b8c134b57806711b57df61
4
+ data.tar.gz: 3d796966db787d3c58093252543edb5c0ef1c7ab02dad056b5ca3c6ed10a4844
5
5
  SHA512:
6
- metadata.gz: 144fd8cb2e456c2af911bd69e7cacd9f198fd17626265cc2dd86296bcf098a03743de2f496b564bad73d4f92412c076290e113220a22398cdc4e03c8e38ac91d
7
- data.tar.gz: 364f34a9e3ecfadd3fb4edd4e7489888b460f586fecc687fcb2ff75b2df35a74db6ac64818ad262c56641d24ccd1d520eb080299dec4a1d22a2f998b6d126c34
6
+ metadata.gz: ae19a0207cd6e0004777f61d2a9390a00c0571c679f5192c672580b3310b0c199720294f017720aa5dc686f6b66a8e746f68a26ebea0270baa849f0d66db5770
7
+ data.tar.gz: eb1fcac6f076d2f226d71a43af3134c6227dbb7191a4068b9551c28befdfdfd7ca50bef0753ce79876dc0fa940c5c615022679756eef170e510fc7847bb55820
@@ -0,0 +1,28 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ 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
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: supercharge/mongodb-github-action@1.6.0
21
+ with:
22
+ mongodb-version: ${{ matrix.mongodb-version }}
23
+ - uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ # bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27
+ - run: RAILS_VERSION=${{ matrix.rails }} bundle install
28
+ - run: RAILS_VERSION=${{ matrix.rails }} bundle exec rake
data/CHANGES.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.2.3
2
+
3
+ * Fix deprecation warning related to `respond_to?`
4
+
5
+ # 0.2.2
6
+
7
+ * Support ActiveRecord 6.1
8
+
9
+ # 0.2.1
10
+
11
+ * Error's full_message with translation fixed thanks to [@marcelolx](https://github.com/trailblazer/reform-rails/pull/85)
12
+
1
13
  # 0.2.0
2
14
 
3
15
  * Needs Reform >= 2.3.0.
@@ -11,6 +23,7 @@
11
23
  * Fix nested form validation (#53)
12
24
  * Errors supports symbol and string lookup (PR #77)
13
25
  * Implement respond_to that delegates to AMV errors (PR #78)
26
+ * Drop support for activemodel before 5.0
14
27
 
15
28
  # 0.1.8
16
29
  * Drop support to mongoid < 4.
data/Gemfile CHANGED
@@ -16,18 +16,16 @@ case ENV["GEMS_SOURCE"]
16
16
  gem "reform", github: "trailblazer/reform"
17
17
  end
18
18
 
19
- rails_version = ENV.fetch("RAILS_VERSION", "5.2.0")
19
+ rails_version = ENV.fetch("RAILS_VERSION", "6.0.0")
20
20
 
21
21
  # bored of wrestling with rails...
22
- if rails_version.include? "4.0"
23
- gem "mongoid", "~> 4"
24
- else
25
- gem("mongoid", "< 7.0") unless rails_version.include?('6.0')
26
- end
22
+
23
+ gem("mongoid", "< 7.0") unless rails_version.to_i >= 6
24
+
27
25
 
28
26
  gem "activerecord", "~> #{rails_version}"
29
27
  gem "railties", "~> #{rails_version}"
30
- if rails_version.include?('6.0')
28
+ if rails_version.to_i >= 6
31
29
  gem "sqlite3", "~> 1.4"
32
30
  else
33
31
  gem "sqlite3", "~> 1.3", "< 1.4"
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/rails.html) 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,16 +24,16 @@ 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
28
 
29
29
  ## Contributing
30
30
 
31
- By default your tests will run against rails 4.2.0.
31
+ By default your tests will run against rails 6.0.1.
32
32
  Please ensure that you test your changes against all supported ruby and rails versions (see .travis.yml)
33
33
 
34
34
  You can run tests for a specific version of rails by running the following:
35
35
 
36
- `export RAILS_VERSION=4.2.0; bundle update; bundle exec rake test`
36
+ `export RAILS_VERSION=5.0.0; bundle update; bundle exec rake test`
37
37
 
38
38
  ## License
39
39
 
@@ -2,3 +2,4 @@ require "reform/form/orm"
2
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,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
@@ -143,7 +143,8 @@ module Reform
143
143
 
144
144
  def add(key, error_text)
145
145
  # use rails magic to get the correct error_text and make sure we still update details and fields
146
- text = @amv_errors.add(key, error_text)
146
+ error = @amv_errors.add(key, error_text)
147
+ error = [error.message] unless error.is_a?(Array)
147
148
 
148
149
  # using error_text instead of text to either keep the symbol which will be
149
150
  # magically replaced with the translate or directly the string - this is also
@@ -153,7 +154,7 @@ module Reform
153
154
 
154
155
  # but since messages method is actually already defined in `Reform::Contract::Result::Errors
155
156
  # we need to update the @dotted_errors instance variable to add or merge a new error
156
- @dotted_errors.key?(key) ? @dotted_errors[key] |= text : @dotted_errors[key] = text
157
+ @dotted_errors.key?(key) ? @dotted_errors[key] |= error : @dotted_errors[key] = error
157
158
  instance_variable_set(:@dotted_errors, @dotted_errors)
158
159
  end
159
160
 
@@ -161,8 +162,37 @@ module Reform
161
162
  @amv_errors.send(m, *args, &block) # send all methods to the AMV errors, even privates.
162
163
  end
163
164
 
164
- def respond_to?(method)
165
- @amv_errors.respond_to?(method) ? true : super
165
+ def respond_to?(method, include_all = false)
166
+ @amv_errors.respond_to?(method, include_all) ? true : super
167
+ end
168
+
169
+ def full_messages
170
+ base_errors = @amv_errors.full_messages
171
+ form_fields = @amv_errors.instance_variable_get(:@base).instance_variable_get(:@fields)
172
+ nested_errors = full_messages_for_nested_fields(form_fields)
173
+
174
+ [base_errors, nested_errors].flatten.compact
175
+ end
176
+
177
+ private
178
+
179
+ def full_messages_for_nested_fields(form_fields)
180
+ form_fields.map { |field| full_messages_for_twin(field[1]) }
181
+ end
182
+
183
+ def full_messages_for_twin(object)
184
+ return get_collection_errors(object) if object.is_a? Disposable::Twin::Collection
185
+ return get_amv_errors(object) if object.is_a? Disposable::Twin
186
+
187
+ nil
188
+ end
189
+
190
+ def get_collection_errors(twin_collection)
191
+ twin_collection.map { |twin| get_amv_errors(twin) }
192
+ end
193
+
194
+ def get_amv_errors(object)
195
+ object.instance_variable_get(:@amv_errors).full_messages
166
196
  end
167
197
  end
168
198
  end
@@ -1,5 +1,5 @@
1
1
  module Reform
2
2
  module Rails
3
- VERSION = "0.2.0.rc3"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
data/reform-rails.gemspec CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "reform", ">= 2.3.0.rc1", "< 3.0.0"
24
- spec.add_dependency "activemodel", ">= 3.2"
23
+ spec.add_dependency "reform", ">= 2.3.1", "< 3.0.0"
24
+ spec.add_dependency "activemodel", ">= 5.0"
25
25
  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.2.0.rc3
4
+ version: 0.2.3
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: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.0.rc1
19
+ version: 2.3.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 3.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 2.3.0.rc1
29
+ version: 2.3.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.0.0
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '3.2'
39
+ version: '5.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '3.2'
46
+ version: '5.0'
47
47
  description: Automatically load and include all common Reform features for a standard
48
48
  Rails environment.
49
49
  email:
@@ -52,10 +52,10 @@ executables: []
52
52
  extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
+ - ".github/workflows/ci.yml"
55
56
  - ".gitignore"
56
57
  - ".rubocop.yml"
57
58
  - ".rubocop_todo.yml"
58
- - ".travis.yml"
59
59
  - CHANGES.md
60
60
  - Gemfile
61
61
  - LICENSE.txt
@@ -66,6 +66,7 @@ files:
66
66
  - lib/reform/form/active_model/form_builder_methods.rb
67
67
  - lib/reform/form/active_model/model_reflections.rb
68
68
  - lib/reform/form/active_model/model_validations.rb
69
+ - lib/reform/form/active_model/result.rb
69
70
  - lib/reform/form/active_model/validations.rb
70
71
  - lib/reform/form/active_record.rb
71
72
  - lib/reform/form/mongoid.rb
@@ -81,7 +82,7 @@ homepage: https://github.com/trailblazer/reform-rails
81
82
  licenses:
82
83
  - MIT
83
84
  metadata: {}
84
- post_install_message:
85
+ post_install_message:
85
86
  rdoc_options: []
86
87
  require_paths:
87
88
  - lib
@@ -92,13 +93,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - ">"
96
+ - - ">="
96
97
  - !ruby/object:Gem::Version
97
- version: 1.3.1
98
+ version: '0'
98
99
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.6.14.3
101
- signing_key:
100
+ rubygems_version: 3.0.8
101
+ signing_key:
102
102
  specification_version: 4
103
103
  summary: Automatically load and include all common Rails form features.
104
104
  test_files: []
data/.travis.yml DELETED
@@ -1,38 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- before_install:
4
- - gem update --system
5
- - gem install bundler
6
- rvm:
7
- - 2.4.6
8
- - 2.5.5
9
- - 2.6.3
10
- services:
11
- - mongodb
12
- env:
13
- - "RAILS_VERSION=6.0.0"
14
- - "RAILS_VERSION=5.2.0"
15
- - "RAILS_VERSION=5.1.0"
16
- - "RAILS_VERSION=5.0.0"
17
- - "RAILS_VERSION=4.2.0"
18
- - "RAILS_VERSION=4.1.0"
19
- - "RAILS_VERSION=4.0.0"
20
- matrix:
21
- fast_finish: true
22
- exclude:
23
- - rvm: 2.4.6
24
- env: "RAILS_VERSION=4.0.0"
25
- - rvm: 2.4.6
26
- env: "RAILS_VERSION=4.1.0"
27
- - rvm: 2.4.6
28
- env: "RAILS_VERSION=6.0.0"
29
-
30
- - rvm: 2.5.5
31
- env: "RAILS_VERSION=4.0.0"
32
- - rvm: 2.5.5
33
- env: "RAILS_VERSION=4.1.0"
34
-
35
- - rvm: 2.6.3
36
- env: "RAILS_VERSION=4.0.0"
37
- - rvm: 2.6.3
38
- env: "RAILS_VERSION=4.1.0"