reform 2.3.0.rc2 → 2.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: d820c5f61dcb3ef74ab8ac15bbc662bd8e9490a8
4
- data.tar.gz: aa023d388b19459ebe7dd4c19862f8bc85364697
2
+ SHA256:
3
+ metadata.gz: f22b2268e248120b5738d5387d464d8563d661d6749a6c371ed1172d9c3fb18b
4
+ data.tar.gz: 534162094e74586a1c73634f1394f8ef8f37bb79b970c7003d37773c1f2109a1
5
5
  SHA512:
6
- metadata.gz: 48f9fcbc0917b9478d1124900146d6597e32e613a2ab4d61d504d359fb546b42d44ae958fff089df1bc315983c1fb70701b4246fb4a85b79341113f9460e5278
7
- data.tar.gz: eac447cc3824c9e09926e64fb33437e8e9c0b3e86a7dfd24ec1cc71407c23550854fd6c64ea25538de01cb1350fb6302bb033e542bebb1f52a65ea1a7d8674e9
6
+ metadata.gz: d1f26ff2eb879a16cea3a230fb0fccf97525cf72321941b48312d47ed47e5a9759f67e44c9cd68057adf020ec0374706ae4991b9b29141b46ee963ef4e218d31
7
+ data.tar.gz: 77c4f8dc39bb7616e12b2b8c74f3f45e0b9285bd95dcc0a9a7206e35905c1b4ef956ab87eef49b20b87efc322578e047caa0f84cc30024ff236320af93764308
data/.gitignore CHANGED
@@ -4,7 +4,6 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
- gemfiles/*.lock
8
7
  InstalledFiles
9
8
  _yardoc
10
9
  coverage
@@ -18,3 +17,6 @@ test/version_tmp
18
17
  tmp
19
18
  .rubocop-https*
20
19
  .byebug_history
20
+ .idea
21
+ *.iml
22
+ gemfiles/*.gemfile.lock
data/.travis.yml CHANGED
@@ -3,30 +3,14 @@ cache: bundler
3
3
  bundler_args: --without benchmarks tools
4
4
  rvm:
5
5
  - ruby-head
6
+ - 2.7
7
+ - 2.6
6
8
  - 2.5
7
9
  - 2.4
8
- env:
9
- - "DRY_VALIDATION='~> 1.3.0'"
10
- - "DRY_VALIDATION='~> 1.2.0'"
11
- - "DRY_VALIDATION='~> 1.1.0'"
12
- - "DRY_VALIDATION='~> 1.0.0'"
13
- - "DRY_VALIDATION='~> 0.13.0'"
14
- - "DRY_VALIDATION='~> 0.12.0'"
10
+ gemfile:
11
+ - gemfiles/1.5.0.gemfile
12
+ - gemfiles/0.13.0.gemfile
15
13
  matrix:
16
14
  fast_finish: true
17
15
  allow_failures:
18
16
  - rvm: ruby-head
19
- include:
20
- - { rvm: 2.2, env: "DRY_VALIDATION='~> 0.11.0'" }
21
- - { rvm: 2.3, env: "DRY_VALIDATION='~> 0.12.0'" }
22
- - { rvm: 2.3, env: "DRY_VALIDATION='~> 0.13.0'" }
23
-
24
-
25
- # maybe move this to slack in a private channel
26
- # notifications:
27
- # webhooks:
28
- # urls:
29
- # - https://webhooks.gitter.im/e/680e86d98056f2ae2fd7
30
- # on_success: change # options: [always|never|change] default: always
31
- # on_failure: always # options: [always|never|change] default: always
32
- # on_start: never # options: [always|never|change] default: always
data/Appraisals ADDED
@@ -0,0 +1,8 @@
1
+ appraise "1.5.0" do
2
+ gem 'dry-monads', "1.3.5"
3
+ gem 'dry-validation', '~> 1.5.0'
4
+ end
5
+
6
+ appraise "0.13.0" do
7
+ gem 'dry-validation', '~> 0.13.0'
8
+ end
data/CHANGES.md CHANGED
@@ -3,6 +3,11 @@
3
3
  [* Removed `Reform::Contract` ?]
4
4
  [* Move Form#deserializer to Form::deserializer]
5
5
 
6
+ ## 2.3.1
7
+ * With dry-validation 1.5 the form is always injected. Just add option :form to access it in the schema.
8
+ * Removed global monkey patching of Dry::Schema::DSL
9
+ * Tests in ruby 2.7
10
+
6
11
  ## 2.3.0
7
12
 
8
13
  You can upgrade from 2.2.0 without worries.
data/Gemfile CHANGED
@@ -2,10 +2,4 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- # gem "disposable", path: "../disposable"
6
-
7
- # just trying to add `dry-monads` correct version in base on dry-validation
8
- dry_v_version = ENV.fetch('DRY_VALIDATION', '~> 0.13.0')
9
- dry_m_version = "~> #{dry_v_version.gsub("~>", "").to_f}.0"
10
- gem 'dry-monads', dry_m_version if dry_v_version.gsub("~>", "").to_f >= 1
11
- gem 'dry-validation', ENV.fetch('DRY_VALIDATION', '~> 0.13.0')
5
+ gem "appraisal", "~> 2.2"
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 - 2016 Nick Sutterer
1
+ Copyright (c) 2013 - 2020 Nick Sutterer
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
  require "rubocop/rake_task"
4
+ require "dry/types/version"
4
5
 
5
6
  task default: %i[test]
6
7
 
@@ -10,8 +11,7 @@ TEST_WITH_OLD_AND_NEW_API = %w[
10
11
  ].freeze
11
12
 
12
13
  def dry_v_test_files
13
- dry_v_version = ENV.fetch("DRY_VALIDATION", "~> 0.13.0")
14
- api = dry_v_version.gsub("~>", "").to_f >= 1.0 ? "new" : "old"
14
+ api = Gem::Version.new(Dry::Types::VERSION).to_s.split('.').first.to_i >= 1 ? "new" : "old"
15
15
  TEST_WITH_OLD_AND_NEW_API.map { |file| "test/#{file}_#{api}_api.rb" }
16
16
  end
17
17
 
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.2"
6
+ gem "dry-validation", "~> 0.13.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.2"
6
+ gem "dry-monads", "1.3.5"
7
+ gem "dry-validation", "~> 1.5.0"
8
+
9
+ gemspec path: "../"
@@ -1,6 +1,9 @@
1
+ ::Dry::Validation.load_extensions(:hints)
2
+
1
3
  module Reform::Form::Dry
2
4
  module NewApi
3
- class Contract < Dry::Validation::Contract
5
+
6
+ class Contract < ::Dry::Validation::Contract
4
7
  end
5
8
 
6
9
  module Validations
@@ -18,39 +21,24 @@ module Reform::Form::Dry
18
21
  include InputHash
19
22
 
20
23
  def initialize(options = {})
21
- options ||= {}
22
- @validator = options[:schema] || Reform::Form::Dry::NewApi::Contract
23
-
24
- @schema_inject_params = options[:with] || {}
24
+ @validator = options.fetch(:schema, Contract)
25
+ @schema_inject_params = options.fetch(:with, {})
25
26
  end
26
27
 
27
28
  def instance_exec(&block)
28
- Dry::Validation.load_extensions(:hints)
29
29
  @block = block
30
30
  end
31
31
 
32
32
  def call(form)
33
- dynamic_options = {}
34
- dynamic_options[:form] = form if @schema_inject_params[:form]
35
- inject_options = @schema_inject_params.merge(dynamic_options)
36
-
37
- Dry::Schema::DSL.class_eval do
38
- inject_options.each do |key, value|
39
- define_method(key) { value }
40
- end
41
- end
42
-
43
33
  # when passing options[:schema] the class instance is already created so we just need to call
44
34
  # "call"
45
- @validator = @validator.build(&@block) if @validator == Reform::Form::Dry::NewApi::Contract
46
-
47
- # TODO: only pass submitted values to Schema#call?
48
- dry_result = @validator.call(input_hash(form))
49
- # dry_messages = dry_result.messages
50
-
51
- return dry_result
35
+ if @validator.is_a?(Class) && @validator <= ::Dry::Validation::Contract
36
+ dynamic_options = {form: form}
37
+ inject_options = @schema_inject_params.merge(dynamic_options)
38
+ @validator = @validator.build(inject_options, &@block)
39
+ end
52
40
 
53
- _reform_errors = Reform::Contract::Errors.new(dry_result) # TODO: dry should be merged here.
41
+ @validator.call(input_hash(form))
54
42
  end
55
43
  end
56
44
  end
@@ -1,3 +1,3 @@
1
1
  module Reform
2
- VERSION = "2.3.0.rc2".freeze
2
+ VERSION = "2.3.1".freeze
3
3
  end
data/reform.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "minitest"
26
26
  spec.add_development_dependency "minitest-line"
27
- spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "pry-byebug"
28
28
  spec.add_development_dependency "multi_json"
29
29
  spec.add_development_dependency "rake"
30
30
  spec.add_development_dependency "rubocop"
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ require "minitest/autorun"
3
3
  require "representable/debug"
4
4
  require "declarative/testing"
5
5
  require "pp"
6
- require "byebug"
6
+ require "pry-byebug"
7
7
 
8
8
  require "reform/form/dry"
9
9
 
@@ -73,21 +73,21 @@ class DryValidationErrorsAPITest < Minitest::Spec
73
73
  form.to_result.hints.must_equal(title: ["size cannot be less than 2"])
74
74
  form.artist.to_result.errors.must_equal(email: ["must be filled"])
75
75
  form.artist.to_result.messages.must_equal(email: ["must be filled"])
76
- form.artist.to_result.hints.must_equal(email: [])
76
+ form.artist.to_result.hints.must_equal({})
77
77
  form.artist.label.to_result.errors.must_equal(location: ["must be filled"])
78
78
  form.artist.label.to_result.messages.must_equal(location: ["must be filled"])
79
- form.artist.label.to_result.hints.must_equal(location: [])
79
+ form.artist.label.to_result.hints.must_equal({})
80
80
  form.songs[0].to_result.errors.must_equal({})
81
81
  form.songs[0].to_result.messages.must_equal({})
82
82
  form.songs[0].to_result.hints.must_equal({})
83
83
  form.songs[1].to_result.errors.must_equal(title: ["must be filled"])
84
84
  form.songs[1].to_result.messages.must_equal(title: ["must be filled"])
85
- form.songs[1].to_result.hints.must_equal(title: [])
85
+ form.songs[1].to_result.hints.must_equal({})
86
86
  form.songs[1].to_result.errors(locale: :de).must_equal(title: ["muss abgefüllt sein"])
87
87
  # seems like dry-v when calling Dry::Schema::Result#messages locale option is ignored
88
88
  # started a topic in their forum https://discourse.dry-rb.org/t/dry-result-messages-ignore-locale-option/910
89
89
  # form.songs[1].to_result.messages(locale: :de).must_equal(title: ["muss abgefüllt sein"])
90
- form.songs[1].to_result.hints(locale: :de).must_equal(title: [])
90
+ form.songs[1].to_result.hints(locale: :de).must_equal({})
91
91
  end
92
92
 
93
93
  it "only nested property is invalid." do
@@ -195,8 +195,14 @@ class DryValidationDefaultGroupTest < Minitest::Spec
195
195
  params { required(:confirm_password).filled }
196
196
  end
197
197
 
198
- validation name: :dynamic_args, with: {form: true} do
199
- params { required(:color).maybe(included_in?: form.colors) }
198
+ validation name: :dynamic_args do
199
+ option :form
200
+ params { optional(:color) }
201
+ rule(:color) do
202
+ if value
203
+ key.failure("must be one of: #{form.colors}") unless form.colors.include? value
204
+ end
205
+ end
200
206
  end
201
207
 
202
208
  def colors
@@ -208,15 +214,15 @@ class DryValidationDefaultGroupTest < Minitest::Spec
208
214
 
209
215
  # valid.
210
216
  it do
211
- form.validate(
217
+ assert form.validate(
212
218
  username: "Helloween",
213
219
  email: "yep",
214
220
  starts_at: "01/01/2000 - 11:00",
215
221
  active: "true",
216
222
  confirm_password: "pA55w0rd"
217
- ).must_equal true
218
- form.active.must_equal true
219
- form.errors.messages.inspect.must_equal "{}"
223
+ )
224
+ assert form.active
225
+ assert_equal "{}", form.errors.messages.inspect
220
226
  end
221
227
 
222
228
  it "invalid" do
@@ -309,8 +315,12 @@ class ValidationGroupsTest < MiniTest::Spec
309
315
  property :username
310
316
 
311
317
  validation name: :default, with: {user: OpenStruct.new(name: "Nick")} do
318
+ option :user
312
319
  params do
313
- required(:username).filled(eql?: user.name)
320
+ required(:username).filled
321
+ end
322
+ rule(:username) do
323
+ key.failure("must be equal to #{user.name}") unless user.name == value
314
324
  end
315
325
  end
316
326
  end
@@ -471,7 +481,7 @@ class ValidationGroupsTest < MiniTest::Spec
471
481
  # TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
472
482
  form.producers[0].to_result.errors.must_equal(name: ["must be filled"])
473
483
  form.producers[0].to_result.messages.must_equal(name: ["must be filled"])
474
- form.producers[0].to_result.hints.must_equal(name: [])
484
+ form.producers[0].to_result.hints.must_equal({})
475
485
  end
476
486
 
477
487
  # FIXME: fix the "must be filled error"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.rc2
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-05 00:00:00.000000000 Z
12
+ date: 2020-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: disposable
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: byebug
111
+ name: pry-byebug
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
@@ -175,6 +175,7 @@ files:
175
175
  - ".rubocop.yml"
176
176
  - ".rubocop_todo.yml"
177
177
  - ".travis.yml"
178
+ - Appraisals
178
179
  - CHANGES.md
179
180
  - CONTRIBUTING.md
180
181
  - Gemfile
@@ -183,6 +184,8 @@ files:
183
184
  - README.md
184
185
  - Rakefile
185
186
  - TODO.md
187
+ - gemfiles/0.13.0.gemfile
188
+ - gemfiles/1.5.0.gemfile
186
189
  - lib/reform.rb
187
190
  - lib/reform/contract.rb
188
191
  - lib/reform/contract/custom_error.rb
@@ -271,12 +274,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
274
  version: '0'
272
275
  required_rubygems_version: !ruby/object:Gem::Requirement
273
276
  requirements:
274
- - - ">"
277
+ - - ">="
275
278
  - !ruby/object:Gem::Version
276
- version: 1.3.1
279
+ version: '0'
277
280
  requirements: []
278
- rubyforge_project:
279
- rubygems_version: 2.6.14.3
281
+ rubygems_version: 3.0.6
280
282
  signing_key:
281
283
  specification_version: 4
282
284
  summary: Form object decoupled from models with validation, population and presentation.