validation_delegation 0.0.2 → 0.0.3
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 +8 -8
- data/README.md +10 -0
- data/lib/validation_delegation.rb +1 -1
- data/lib/validation_delegation/version.rb +1 -1
- data/spec/validation_delegation_spec.rb +14 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTNmNTZlODFiMmJhMGVjYWI4ZmM2MTNlMTc5NzUyMzA2NjRiZjc5Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjA4NmQ1NzlhYzE5M2JmNmI1YTM3ZWIwNWQ0ZjQ5Nzg2YWU4YjcwZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzIyYTY4ZmFhNTUzOWI1M2U5MDYxMWQxMzUxZjJhM2Q0OWU5YjcwMWNiMjgw
|
10
|
+
MDJiN2U3MjM3MzQ2Y2ZkYzM5YjlkNmJlOTRlMTkxMDIwNjM2YzgyNDkxN2Fh
|
11
|
+
YWQwODg3MGJjZWMwNzcxMjFlMDhmYzQ1MmQ4ODdkYjYyNTYwZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzUwNWNjY2U3MmU4MWFkZGUzMzM1NjkzZjYxZjE4YTRlMTAyOWUzMzA5N2E5
|
14
|
+
ZTY5MTk0OTI5MTgwNjg5OGNiNGIyYTM3ODNiZDljNjFjMGQ5MTgyZGYyNjZk
|
15
|
+
ZjJmYjAxOTg2MTA3MmFmZDhhZGViNGUxZmM1N2IwNTU4ZGZjODk=
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ end
|
|
31
31
|
|
32
32
|
class SignUp
|
33
33
|
include ActiveModel::Validations
|
34
|
+
include ValidationDelegation
|
34
35
|
|
35
36
|
# delegate validation to the user
|
36
37
|
delegate_validation to: :user
|
@@ -83,6 +84,7 @@ If you do not want to copy errors directly onto the composing object, you can sp
|
|
83
84
|
```Ruby
|
84
85
|
class SignUp
|
85
86
|
include ActiveModel::Model
|
87
|
+
include ValidationDelegation
|
86
88
|
|
87
89
|
delegate_validation :organization, to: :organization
|
88
90
|
|
@@ -114,6 +116,8 @@ signup.errors.full_messages
|
|
114
116
|
|
115
117
|
```Ruby
|
116
118
|
class SignUp
|
119
|
+
# ...
|
120
|
+
|
117
121
|
delegate_validation to: :user, if: :validate_user?
|
118
122
|
|
119
123
|
def validate_user?
|
@@ -126,6 +130,8 @@ end
|
|
126
130
|
|
127
131
|
```Ruby
|
128
132
|
class SignUp
|
133
|
+
# ...
|
134
|
+
|
129
135
|
delegate_validation to: :user, unless: :skip_validation?
|
130
136
|
|
131
137
|
def skip_validation?
|
@@ -138,6 +144,8 @@ end
|
|
138
144
|
|
139
145
|
```Ruby
|
140
146
|
class SignUp
|
147
|
+
# ...
|
148
|
+
|
141
149
|
delegate_validation to: :user, only: :email
|
142
150
|
end
|
143
151
|
|
@@ -154,6 +162,8 @@ signup.errors.full_messages
|
|
154
162
|
|
155
163
|
```Ruby
|
156
164
|
class SignUp
|
165
|
+
# ...
|
166
|
+
|
157
167
|
delegate_validation to: :user, except: :email
|
158
168
|
end
|
159
169
|
|
@@ -85,7 +85,7 @@ describe ValidationDelegation do
|
|
85
85
|
expect(subject).to have_error("is invalid").on(:attr)
|
86
86
|
end
|
87
87
|
|
88
|
-
context "
|
88
|
+
context "a method is supplied" do
|
89
89
|
it "copies errors to the specified method and prefixes the attribute name" do
|
90
90
|
TestClass.delegate_validation :my_method, to: :validator
|
91
91
|
expect(subject).to have_error("attr is invalid").on(:my_method)
|
@@ -99,11 +99,21 @@ describe ValidationDelegation do
|
|
99
99
|
expect(subject).to have_error("attr is bananas").on(:my_method)
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "translates errors if possible" do
|
103
|
+
TestClass.delegate_validation :my_method, to: :validator
|
104
|
+
|
105
|
+
allow(TestClass).to receive(:human_attribute_name)
|
106
|
+
.with(:attr)
|
107
|
+
.and_return("Human attribute")
|
108
|
+
|
109
|
+
expect(subject).to have_error("human attribute is invalid").on(:my_method)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "translates nested attribute errors" do
|
103
113
|
TestClass.delegate_validation :my_method, to: :validator
|
104
114
|
validator.errors[:"associated_class.attribute"] << "is bananas"
|
105
115
|
|
106
|
-
expect(subject).to have_error("
|
116
|
+
expect(subject).to have_error("attribute is bananas").on(:my_method)
|
107
117
|
end
|
108
118
|
|
109
119
|
it "copies errors if the :if option is true" do
|
@@ -143,5 +153,4 @@ describe ValidationDelegation do
|
|
143
153
|
expect(subject).to have_error("attr is invalid").on(:my_method)
|
144
154
|
end
|
145
155
|
end
|
146
|
-
|
147
|
-
end
|
156
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_delegation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Eddy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|