daily_affirmation 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/daily_affirmation.gemspec +1 -0
- data/lib/daily_affirmation/validator.rb +18 -1
- data/lib/daily_affirmation/validators/absence_validator.rb +3 -1
- data/lib/daily_affirmation/validators/acceptance_validator.rb +3 -1
- data/lib/daily_affirmation/validators/confirmation_validator.rb +3 -1
- data/lib/daily_affirmation/validators/exclusion_validator.rb +3 -1
- data/lib/daily_affirmation/validators/format_validator.rb +3 -1
- data/lib/daily_affirmation/validators/inclusion_validator.rb +4 -1
- data/lib/daily_affirmation/validators/length_validator.rb +4 -1
- data/lib/daily_affirmation/validators/numericality_validator.rb +3 -1
- data/lib/daily_affirmation/validators/presence_validator.rb +3 -1
- data/lib/daily_affirmation/version.rb +1 -1
- data/spec/support/default.yml +4 -0
- data/spec/support/generic.yml +5 -0
- data/spec/support/specific.yml +6 -0
- data/spec/validator_spec.rb +45 -4
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bebab94b6507fded2c3c6b8620064c31753fbd7
|
4
|
+
data.tar.gz: 7ec0f8b962d6981a99f62d3475524437ecdec690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73c9f489458982f747535fa715dd90f6a10d8f7cf7814b9f00c247b99aa521f4b53a1a70d56794b38961aabeef41f4722ac98931afd535bc160a21460aa6dbf
|
7
|
+
data.tar.gz: 3cd11055f9b7fc591796320fb951324d522481835e69e8e588bf6360a425f9e642945d8929ce86189d1f13b1c984ba0d8df4022ca8013793aa83a4627ec17e99
|
data/README.md
CHANGED
@@ -51,12 +51,12 @@ TeamAffirmation.new(team1).valid? #=> false
|
|
51
51
|
|
52
52
|
## Roadmap
|
53
53
|
|
54
|
-
-
|
55
|
-
- Add a way to build custom validations (example validating a password)
|
54
|
+
- Allow error messages to use i18n.
|
55
|
+
- Add a way to build custom validations (example validating a password).
|
56
56
|
|
57
57
|
## Contributing
|
58
58
|
|
59
|
-
1. Fork it
|
59
|
+
1. Fork it ( http://github.com/teamsnap/daily_affirmation/fork )
|
60
60
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
61
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
62
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/daily_affirmation.gemspec
CHANGED
@@ -16,11 +16,28 @@ module DailyAffirmation
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def error_message
|
19
|
-
|
19
|
+
i18n_error_message(:none)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
attr_accessor :object, :attribute, :value, :opts
|
25
|
+
|
26
|
+
def i18n_error_message(type, default: "#{attribute} failed validation")
|
27
|
+
if defined?(I18n)
|
28
|
+
args = opts.merge(
|
29
|
+
{
|
30
|
+
:default => [
|
31
|
+
:"daily_affirmation.errors.messages.#{type}", default
|
32
|
+
],
|
33
|
+
:attribute => attribute,
|
34
|
+
:value => value
|
35
|
+
}
|
36
|
+
)
|
37
|
+
I18n.t(:"daily_affirmation.errors.messages.#{type}.#{attribute}", args)
|
38
|
+
else
|
39
|
+
default
|
40
|
+
end
|
41
|
+
end
|
25
42
|
end
|
26
43
|
end
|
@@ -8,7 +8,10 @@ module DailyAffirmation
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def error_message
|
11
|
-
@error_message ||=
|
11
|
+
@error_message ||= i18n_error_message(
|
12
|
+
:inclusion,
|
13
|
+
:default => "#{attribute} is not included in #{opts[:list]}"
|
14
|
+
)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -8,7 +8,10 @@ module DailyAffirmation
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def error_message
|
11
|
-
@error_message ||=
|
11
|
+
@error_message ||= i18n_error_message(
|
12
|
+
:length,
|
13
|
+
:default => "#{attribute} is the wrong length (allowed #{opts[:range]})"
|
14
|
+
)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
data/spec/validator_spec.rb
CHANGED
@@ -11,14 +11,55 @@ describe "Validator" do
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "uses a generic error message if one is not provied" do
|
15
15
|
cls = Class.new(DailyAffirmation::Validator) do
|
16
16
|
def valid?; false; end
|
17
17
|
end
|
18
18
|
obj = double(:age => 13)
|
19
19
|
|
20
|
-
expect
|
21
|
-
|
22
|
-
|
20
|
+
expect(cls.new(obj, :age).error_message).to eq("age failed validation")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "i18n required" do
|
24
|
+
before(:all) { require "i18n" }
|
25
|
+
after(:all) { Object.send(:remove_const, :I18n) if defined?(I18n) }
|
26
|
+
|
27
|
+
it "uses specific translation if available" do
|
28
|
+
I18n.load_path = [File.expand_path("../support/specific.yml", __FILE__)]
|
29
|
+
I18n.backend.load_translations
|
30
|
+
|
31
|
+
cls = Class.new(DailyAffirmation::Validator) do
|
32
|
+
def valid?; false; end
|
33
|
+
end
|
34
|
+
obj = double(:age => 13)
|
35
|
+
|
36
|
+
expect(cls.new(obj, :age).error_message).to eq("must include age yo!")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "uses generic translation if specific is not available" do
|
40
|
+
I18n.load_path = [File.expand_path("../support/generic.yml", __FILE__)]
|
41
|
+
I18n.backend.load_translations
|
42
|
+
|
43
|
+
cls = Class.new(DailyAffirmation::Validator) do
|
44
|
+
def valid?; false; end
|
45
|
+
end
|
46
|
+
obj = double(:age => 13)
|
47
|
+
|
48
|
+
expect(cls.new(obj, :age, :range => 10..20).error_message).to eq(
|
49
|
+
"egads man, you must have age (10..20, 13)"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "uses default if both translations are unavailable" do
|
54
|
+
I18n.load_path = [File.expand_path("../support/default.yml", __FILE__)]
|
55
|
+
I18n.backend.load_translations
|
56
|
+
|
57
|
+
cls = Class.new(DailyAffirmation::Validator) do
|
58
|
+
def valid?; false; end
|
59
|
+
end
|
60
|
+
obj = double(:age => 13)
|
61
|
+
|
62
|
+
expect(cls.new(obj, :age).error_message).to eq("age failed validation")
|
63
|
+
end
|
23
64
|
end
|
24
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daily_affirmation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0.beta1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.9
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.9
|
55
69
|
description: A simple library for external validations of POROs
|
56
70
|
email:
|
57
71
|
- oss@teamsnap.com
|
@@ -80,6 +94,9 @@ files:
|
|
80
94
|
- lib/daily_affirmation/version.rb
|
81
95
|
- spec/daily_affirmation_spec.rb
|
82
96
|
- spec/spec_helper.rb
|
97
|
+
- spec/support/default.yml
|
98
|
+
- spec/support/generic.yml
|
99
|
+
- spec/support/specific.yml
|
83
100
|
- spec/validator_spec.rb
|
84
101
|
- spec/validators/absence_validator_spec.rb
|
85
102
|
- spec/validators/acceptance_validator_spec.rb
|
@@ -117,6 +134,9 @@ summary: A simple library for external validations of POROs
|
|
117
134
|
test_files:
|
118
135
|
- spec/daily_affirmation_spec.rb
|
119
136
|
- spec/spec_helper.rb
|
137
|
+
- spec/support/default.yml
|
138
|
+
- spec/support/generic.yml
|
139
|
+
- spec/support/specific.yml
|
120
140
|
- spec/validator_spec.rb
|
121
141
|
- spec/validators/absence_validator_spec.rb
|
122
142
|
- spec/validators/acceptance_validator_spec.rb
|