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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTI4MDc4MTVlZTMzYTk3NDU3ZDBmNmJmNjEyNzU5OTJjYjY4ZTAxNQ==
4
+ NTNmNTZlODFiMmJhMGVjYWI4ZmM2MTNlMTc5NzUyMzA2NjRiZjc5Zg==
5
5
  data.tar.gz: !binary |-
6
- NzAwZmExNjNkMmJlMTBiNDg1OTIwYzZhNWNjMDkzYmRiM2Y2MGFjMQ==
6
+ MjA4NmQ1NzlhYzE5M2JmNmI1YTM3ZWIwNWQ0ZjQ5Nzg2YWU4YjcwZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDM5OWQ1NjdiYjBjNmM1MTdjNjA2MmYzMDMwMTFiOTk2MTI0NWRmMTJlMzE1
10
- YjMxN2M2MjllNGZmODJjODhkYWI1ZjVlODQxZjAyMTNiZTBhZDA3MDdmODg2
11
- Y2Q2ZDMyNzQ0ZGJmMTVmNWQyZTcwMmVjZmVmODFlOGI5MjViMTM=
9
+ YzIyYTY4ZmFhNTUzOWI1M2U5MDYxMWQxMzUxZjJhM2Q0OWU5YjcwMWNiMjgw
10
+ MDJiN2U3MjM3MzQ2Y2ZkYzM5YjlkNmJlOTRlMTkxMDIwNjM2YzgyNDkxN2Fh
11
+ YWQwODg3MGJjZWMwNzcxMjFlMDhmYzQ1MmQ4ODdkYjYyNTYwZjM=
12
12
  data.tar.gz: !binary |-
13
- MGYwZDY5NjBlMDY3ZTM5YmE4MmY4MDhkOTBhNzc0MzVlNTFhMjdlM2Y5NDU4
14
- NWE3N2E1Y2M5NzE2OGMwNDY2OTAyYWU4ZjRlMzNmZGEzMzllMDdjZmQ1NDc2
15
- MmYxMGQxNWUwY2Q4Yzk4NjY0Yjk0NDFmNTJmZmNkN2U5NTIyYzE=
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
 
@@ -24,7 +24,7 @@ module ValidationDelegation
24
24
  end
25
25
 
26
26
  def format_attribute(attribute_name)
27
- attribute_name.to_s.humanize.downcase.gsub(/\./, " ")
27
+ self.class.human_attribute_name(attribute_name).downcase
28
28
  end
29
29
 
30
30
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module ValidationDelegation
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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 "an method is supplied" do
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 "reformats nested attribute errors" do
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("associated class attribute is bananas").on(:my_method)
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.2
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-03 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport