reform 1.2.0.beta1 → 1.2.0.beta2
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 -1
- data/database.sqlite3 +0 -0
- data/lib/reform/contract/errors.rb +3 -1
- data/lib/reform/schema.rb +7 -3
- data/lib/reform/version.rb +1 -1
- data/test/errors_test.rb +13 -0
- data/test/form_test.rb +2 -0
- data/test/sync_test.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d54671e9b119dc5bbe6b8b405c0f2f947a3004b
|
4
|
+
data.tar.gz: bc1ed19c08fd3f91435cc4b20e512fc9c34262c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a53b1ec82dca50a28734ad805a0555e30e2c9d403d0e9ca51765bceffe19cf32f325f20ed7b2356853463053aff56d1953b1eca027a3936cd877840a248f63d
|
7
|
+
data.tar.gz: ca494adb0607285f727a3562609526c06ad9f4fb0ff25143395731db5d9ad17dec892ba14bf7dadc58f27ab5deaee468947bd61c679ce80a32b43cb90d97ddbd
|
data/CHANGES.md
CHANGED
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
* `Form#save` with `Composition` now returns true only if all composite models saved.
|
17
17
|
* `Form::copy_validations_from` allows copying custom validators now.
|
18
|
-
* `::validates_uniqueness_of` now accepts options like `:scope`. Thanks to @cveneziani for a failing test and insight.
|
19
18
|
* New call style for `::properties`. Instead of an array, it's now `properties :title, :genre`.
|
20
19
|
* All options are evaluated with `pass_options: true`.
|
21
20
|
|
@@ -34,7 +33,14 @@
|
|
34
33
|
* :sync
|
35
34
|
* :save
|
36
35
|
* `Sync::SkipUnchanged`.
|
36
|
+
* Adding `:base` errors now works. Thanks to @bethesque.
|
37
37
|
|
38
|
+
```ruby
|
39
|
+
errors.add(:base, "You are too awesome!")
|
40
|
+
```
|
41
|
+
|
42
|
+
This will prefix the error with `:base`.
|
43
|
+
* Added `Form::schema` to generate a pure representer from the form's representer.
|
38
44
|
|
39
45
|
## 1.1.1
|
40
46
|
|
data/database.sqlite3
CHANGED
Binary file
|
@@ -16,7 +16,9 @@ class Reform::Contract::Errors < ActiveModel::Errors
|
|
16
16
|
|
17
17
|
# TODO: merge into AM.
|
18
18
|
errors.messages.each do |field, msgs|
|
19
|
-
|
19
|
+
unless field.to_sym == :base
|
20
|
+
field = (prefix+[field]).join(".").to_sym # TODO: why is that a symbol in Rails?
|
21
|
+
end
|
20
22
|
|
21
23
|
msgs = [msgs] if Reform.rails3_0? # DISCUSS: fix in #each?
|
22
24
|
|
data/lib/reform/schema.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Reform
|
2
2
|
module Schema
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# Converts the Representer->Form->Representer->Form tree into Representer->Representer.
|
4
|
+
# It becomes obvious that the form will be the main schema-defining instance in Trb, so this
|
5
|
+
# method makes sense. Consider private. This is experimental.
|
6
|
+
#
|
7
|
+
# This allows generating representers from forms. As you can see, only little code is needed thanks to representable.
|
6
8
|
class Converter
|
7
9
|
def self.from(representer_class) # TODO: can we re-use this for all the decorator logic in #validate, etc?
|
8
10
|
representer = Class.new(representer_class)
|
9
11
|
representer.representable_attrs.each do |dfn|
|
10
12
|
next unless form = dfn[:form]
|
13
|
+
|
11
14
|
dfn.merge!(:extend => from(form.representer_class))
|
15
|
+
dfn.delete!(:prepare) # not sure if this is gonna stay. also, this is representable 2.1, only.
|
12
16
|
end
|
13
17
|
|
14
18
|
representer
|
data/lib/reform/version.rb
CHANGED
data/test/errors_test.rb
CHANGED
@@ -15,11 +15,18 @@ class ErrorsTest < MiniTest::Spec
|
|
15
15
|
end
|
16
16
|
|
17
17
|
property :band do # yepp, people do crazy stuff like that.
|
18
|
+
property :name
|
18
19
|
property :label do
|
19
20
|
property :name
|
20
21
|
validates :name, :presence => true
|
21
22
|
end
|
22
23
|
# TODO: make band a required object.
|
24
|
+
|
25
|
+
validate :validate_musical_taste
|
26
|
+
|
27
|
+
def validate_musical_taste
|
28
|
+
errors.add(:base, "You are a bad person") if name == 'Nickelback'
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
validates :title, :presence => true
|
@@ -105,6 +112,12 @@ class ErrorsTest < MiniTest::Spec
|
|
105
112
|
it { form.errors.messages.must_equal({:"songs.title"=>["can't be blank"], :"band.label.name"=>["can't be blank"]}) }
|
106
113
|
end
|
107
114
|
|
115
|
+
describe "#validate with nested form using :base invalid" do
|
116
|
+
before { @result = form.validate("songs"=>[{"title" => "Someday"}], "band" => {"name" => "Nickelback", "label" => {"name" => "Roadrunner Records"}}) }
|
117
|
+
|
118
|
+
it { @result.must_equal false }
|
119
|
+
it { form.errors.messages.must_equal({:base=>["You are a bad person"]}) }
|
120
|
+
end
|
108
121
|
|
109
122
|
describe "correct #validate" do
|
110
123
|
before { @result = form.validate(
|
data/test/form_test.rb
CHANGED
@@ -43,6 +43,8 @@ class FormTest < MiniTest::Spec
|
|
43
43
|
# hit is clone.
|
44
44
|
it { schema.representable_attrs.get(:hit).representer_module.object_id.wont_equal AlbumForm.representer_class.representable_attrs.get(:hit).representer_module.object_id }
|
45
45
|
it { assert schema.representable_attrs.get(:hit).representer_module < Representable::Decorator }
|
46
|
+
# we delete :prepare from schema.
|
47
|
+
it { schema.representable_attrs.get(:hit)[:prepare].must_equal nil }
|
46
48
|
|
47
49
|
# band:label is clone.
|
48
50
|
# this test might look ridiculous but it is mission-critical to assert that schema is really a clone and doesn't mess up the original structure.
|
data/test/sync_test.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class SyncTest < BaseTest
|
4
|
+
|
5
|
+
Band = Struct.new(:name, :label)
|
6
|
+
|
4
7
|
describe "populated" do
|
5
8
|
let (:params) {
|
6
9
|
{
|
@@ -15,7 +18,7 @@ class SyncTest < BaseTest
|
|
15
18
|
let (:hit) { Song.new }
|
16
19
|
let (:song1) { Song.new }
|
17
20
|
let (:song2) { Song.new }
|
18
|
-
let (:band) { Band.new(label) }
|
21
|
+
let (:band) { Band.new("The Police", label) }
|
19
22
|
let (:label) { Label.new }
|
20
23
|
|
21
24
|
subject { ErrorsTest::AlbumForm.new(album) }
|
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: 1.2.0.
|
4
|
+
version: 1.2.0.beta2
|
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: 2014-
|
12
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: representable
|