reform 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -2
- data/README.md +19 -3
- data/database.sqlite3 +0 -0
- data/lib/reform/contract.rb +2 -17
- data/lib/reform/form.rb +1 -1
- data/lib/reform/form/active_model.rb +15 -0
- data/lib/reform/form/active_record.rb +2 -0
- data/lib/reform/form/validation/unique_validator.rb +6 -3
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +1 -1
- data/test/form_option_test.rb +4 -1
- data/test/lotus/lotus_test.rb +4 -0
- data/test/unique_test.rb +23 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a355251cb556bceba19de085db87c09ad464b1
|
4
|
+
data.tar.gz: 6bb5c660b9a1192d869003d4f5cbfa60f30b5cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9e1b8d28f8b696f78fb076e2897ba00a0a2becc2f2be97abe60d508bc7cf7dfcb2989230699e5b8af7d1112e0851536e3ffc3e2424323b9a5f41ab62d8d0c7
|
7
|
+
data.tar.gz: efa2c7b4482fa007dbc9a7a18b8d1c905c650afcd6b9b4bc03e1569c291aa345e28e6843868ea0bdd74b6e023555d973f34c653247ff4a0e540a5005e8a011bc
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
## 2.0.2
|
2
|
+
|
3
|
+
* Fix `unique: true` validation in combination with `Composition`.
|
4
|
+
* Use newest Disposable 0.1.8 which does not set `:pass_options` anymore.
|
5
|
+
|
1
6
|
## 2.0.1
|
2
7
|
|
3
|
-
* Fix `ActiveModel::Validations` where translations in custom validations would error. This is now handled by delegating back to the `
|
8
|
+
* Fix `ActiveModel::Validations` where translations in custom validations would error. This is now handled by delegating back to the `Validator` object in Reform.
|
4
9
|
|
5
10
|
## 2.0.0
|
6
11
|
|
@@ -342,4 +347,4 @@ The reason for this confusion is that you don't blog enough about Reform. Only a
|
|
342
347
|
|
343
348
|
## 0.1.0
|
344
349
|
|
345
|
-
* Oh yeah.
|
350
|
+
* Oh yeah.
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ class AlbumForm < Reform::Form
|
|
28
28
|
end
|
29
29
|
```
|
30
30
|
|
31
|
-
Fields are declared using `::property`. Validations work exactly as you know it from Rails or other frameworks. Note that validations no longer
|
31
|
+
Fields are declared using `::property`. Validations work exactly as you know it from Rails or other frameworks. Note that validations no longer go into the model.
|
32
32
|
|
33
33
|
|
34
34
|
## The API
|
@@ -802,7 +802,7 @@ class SongForm < Reform::Form
|
|
802
802
|
end
|
803
803
|
```
|
804
804
|
|
805
|
-
If you're not happy with the `model_name` result, configure it manually
|
805
|
+
If you're not happy with the `model_name` result, configure it manually via `::model`.
|
806
806
|
|
807
807
|
```ruby
|
808
808
|
class CoverSongForm < Reform::Form
|
@@ -812,6 +812,8 @@ class CoverSongForm < Reform::Form
|
|
812
812
|
end
|
813
813
|
```
|
814
814
|
|
815
|
+
`::model` will configure ActiveModel's naming logic. With `Composition`, this configures the main model of the form and should be called once.
|
816
|
+
|
815
817
|
This is especially helpful when your framework tries to render `cover_song_path` although you want to go with `song_path`.
|
816
818
|
|
817
819
|
|
@@ -853,7 +855,21 @@ class SongForm < Reform::Form
|
|
853
855
|
|
854
856
|
## Multiparameter Dates
|
855
857
|
|
856
|
-
Composed multi-parameter dates as created by the Rails date helper are processed automatically. As soon as Reform detects an incoming `release_date(i1)` or the like it is gonna be converted into a date.
|
858
|
+
Composed multi-parameter dates as created by the Rails date helper are processed automatically when `multi_params: true` is set for the date property and the `MultiParameterAttributes` feature is included. As soon as Reform detects an incoming `release_date(i1)` or the like it is gonna be converted into a date.
|
859
|
+
|
860
|
+
```ruby
|
861
|
+
class AlbumForm < Reform::Form
|
862
|
+
feature Reform::Form::ActiveModel::FormBuilderMethods
|
863
|
+
feature Reform::Form::MultiParameterAttributes
|
864
|
+
|
865
|
+
collection :songs do
|
866
|
+
feature Reform::Form::ActiveModel::FormBuilderMethods
|
867
|
+
property :title
|
868
|
+
property :release_date, :multi_params => true
|
869
|
+
validates :title, :presence => true
|
870
|
+
end
|
871
|
+
end
|
872
|
+
```
|
857
873
|
|
858
874
|
Note that the date will be `nil` when one of the components (year/month/day) is missing.
|
859
875
|
|
data/database.sqlite3
CHANGED
Binary file
|
data/lib/reform/contract.rb
CHANGED
@@ -25,6 +25,8 @@ module Reform
|
|
25
25
|
options[:twin] = twin
|
26
26
|
end
|
27
27
|
|
28
|
+
options[:pass_options] = true
|
29
|
+
|
28
30
|
if validates_options = options[:validates]
|
29
31
|
validates name, validates_options.dup # .dup for RAils 3.x.
|
30
32
|
end
|
@@ -50,23 +52,6 @@ module Reform
|
|
50
52
|
extend ValidatesWarning
|
51
53
|
|
52
54
|
private
|
53
|
-
# DISCUSS: can we achieve that somehow via features in build_inline?
|
54
|
-
# TODO: check out if that is needed with Lotus::Validations and make it a AM feature.
|
55
|
-
def self.process_inline!(mod, definition)
|
56
|
-
_name = definition.name
|
57
|
-
mod.instance_eval do
|
58
|
-
@_name = _name.singularize.camelize
|
59
|
-
# this adds Form::name for AM::Validations and I18N.
|
60
|
-
# i have a feeling that this is also needed for Rails autoloader, which is scary.
|
61
|
-
# beside that, it is a nice way for debugging to find out which anonymous form class you're working on:
|
62
|
-
# anonymous_nested_form.class.name
|
63
|
-
def name
|
64
|
-
@_name
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
55
|
# DISCUSS: separate file?
|
71
56
|
module Readonly
|
72
57
|
def readonly?(name)
|
data/lib/reform/form.rb
CHANGED
@@ -49,7 +49,7 @@ module Reform
|
|
49
49
|
# default:
|
50
50
|
# add Sync populator to nested forms.
|
51
51
|
# FIXME: this is, of course, ridiculous and needs a better structuring.
|
52
|
-
if (deserializer_options == {} || deserializer_options.keys == [:skip_parse]) &&
|
52
|
+
if (deserializer_options == {} || deserializer_options.keys == [:skip_parse]) && definition[:twin] && !options[:inherit] # FIXME: hmm. not a fan of this: only add when no other option given?
|
53
53
|
deserializer_options.merge!(instance: Populator::Sync.new(nil), setter: nil)
|
54
54
|
end
|
55
55
|
|
@@ -27,6 +27,21 @@ module Reform::Form::ActiveModel
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# DISCUSS: can we achieve that somehow via features in build_inline?
|
31
|
+
def process_inline!(mod, definition)
|
32
|
+
_name = definition.name
|
33
|
+
mod.instance_eval do
|
34
|
+
@_name = _name.singularize.camelize
|
35
|
+
# this adds Form::name for AM::Validations and I18N.
|
36
|
+
# i have a feeling that this is also needed for Rails autoloader, which is scary.
|
37
|
+
# beside that, it is a nice way for debugging to find out which anonymous form class you're working on:
|
38
|
+
# anonymous_nested_form.class.name
|
39
|
+
def name
|
40
|
+
@_name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
|
31
46
|
# Set a model name for this form if the infered is wrong.
|
32
47
|
#
|
@@ -1,17 +1,20 @@
|
|
1
|
+
# Reform's own implementation for uniqueness which does not write to model.
|
1
2
|
class Reform::Form::UniqueValidator < ActiveModel::EachValidator
|
2
3
|
def validate_each(form, attribute, value)
|
4
|
+
model = form.model_for_property(attribute)
|
5
|
+
|
3
6
|
# search for models with attribute equals to form field value
|
4
|
-
query =
|
7
|
+
query = model.class.where(attribute => value)
|
5
8
|
|
6
9
|
# if model persisted, excluded own model from query
|
7
|
-
query = query.merge(
|
10
|
+
query = query.merge(model.class.where("id <> ?", model.id)) if model.persisted?
|
8
11
|
|
9
12
|
# if any models found, add error on attribute
|
10
13
|
form.errors.add(attribute, "#{attribute} must be unique.") if query.any?
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
# FIXME: ActiveModel loads validators via const_get(#{name}Validator).
|
17
|
+
# FIXME: ActiveModel loads validators via const_get(#{name}Validator). This magic forces us to
|
15
18
|
# make the new :unique validator available here.
|
16
19
|
Reform::Form::ActiveModel::Validations::Validator.class_eval do
|
17
20
|
UniqueValidator = Reform::Form::UniqueValidator
|
data/lib/reform/version.rb
CHANGED
data/reform.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "disposable", "~> 0.1.
|
20
|
+
spec.add_dependency "disposable", "~> 0.1.9"
|
21
21
|
spec.add_dependency "uber", "~> 0.0.11"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler"
|
data/test/form_option_test.rb
CHANGED
@@ -14,6 +14,9 @@ class FormOptionTest < MiniTest::Spec
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it do
|
17
|
-
AlbumForm.new(Album.new(Song.new("When It Comes To You")))
|
17
|
+
form = AlbumForm.new(Album.new(Song.new("When It Comes To You")))
|
18
|
+
form.song.title.must_equal "When It Comes To You"
|
19
|
+
|
20
|
+
form.validate(song: {title: "Run For Cover"})
|
18
21
|
end
|
19
22
|
end
|
data/test/lotus/lotus_test.rb
CHANGED
data/test/unique_test.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
require "reform/form/validation/unique_validator.rb"
|
4
|
+
require "reform/form/active_record"
|
4
5
|
|
5
6
|
class UniquenessValidatorOnCreateTest < MiniTest::Spec
|
6
7
|
class SongForm < Reform::Form
|
8
|
+
include ActiveRecord
|
7
9
|
property :title
|
8
10
|
validates :title, unique: true
|
9
11
|
end
|
@@ -21,8 +23,10 @@ class UniquenessValidatorOnCreateTest < MiniTest::Spec
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
26
|
+
|
24
27
|
class UniquenessValidatorOnUpdateTest < MiniTest::Spec
|
25
28
|
class SongForm < Reform::Form
|
29
|
+
include ActiveRecord
|
26
30
|
property :title
|
27
31
|
validates :title, unique: true
|
28
32
|
end
|
@@ -39,3 +43,22 @@ class UniquenessValidatorOnUpdateTest < MiniTest::Spec
|
|
39
43
|
form.validate("title" => "How Many Tears").must_equal true
|
40
44
|
end
|
41
45
|
end
|
46
|
+
|
47
|
+
|
48
|
+
class UniqueWithCompositionTest < MiniTest::Spec
|
49
|
+
class SongForm < Reform::Form
|
50
|
+
include ActiveRecord
|
51
|
+
include Composition
|
52
|
+
|
53
|
+
property :title, on: :song
|
54
|
+
validates :title, unique: true
|
55
|
+
end
|
56
|
+
|
57
|
+
it do
|
58
|
+
Song.delete_all
|
59
|
+
|
60
|
+
form = SongForm.new(song: Song.new)
|
61
|
+
form.validate("title" => "How Many Tears").must_equal true
|
62
|
+
form.save
|
63
|
+
end
|
64
|
+
end
|
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.0.
|
4
|
+
version: 2.0.2
|
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: 2015-07-
|
12
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: disposable
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.1.
|
20
|
+
version: 0.1.9
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.1.
|
27
|
+
version: 0.1.9
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: uber
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|