poro_validator 0.1.2 → 0.2.0
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 +4 -4
- data/lib/poro_validator/validator/factory.rb +3 -2
- data/lib/poro_validator/validator/validation.rb +5 -3
- data/lib/poro_validator/version.rb +1 -1
- data/lib/poro_validator.rb +5 -1
- data/poro_validator.gemspec +1 -0
- data/spec/features/configurable_error_messages_spec.rb +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4d11e09f822043d4a06bf638d63d1340203a0b
|
4
|
+
data.tar.gz: a3190629a9fcd8f330cb3b9305b84f75a07a6c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 131f42ab7e0cd7e2df6ab86e2d6227680107e2b0b62f08690e32b1b5204b296b7bcd0bd579821a7dce6d295b86ee5bdb9ed72e8710282bf3672de71ea85ebf47
|
7
|
+
data.tar.gz: c9fc039ac60eb4cc055e95411627f60be31bac40f66ab59e45c997ba84e93429f1d6db2e387f6866050b7e4f0494e980c4587e5ae4b6d45044dbd0fb0fe5ebe2
|
@@ -9,8 +9,9 @@ module PoroValidator
|
|
9
9
|
PoroValidator.const_get(klass).new(attr_name, options)
|
10
10
|
rescue NameError => e
|
11
11
|
raise(::PoroValidator::ValidatorNotFound.new(
|
12
|
-
|
13
|
-
|
12
|
+
"Validator not found: ::PoroValidator::#{klass} exception: #{e}"
|
13
|
+
)
|
14
|
+
)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -11,9 +11,11 @@ module PoroValidator
|
|
11
11
|
# e.g, message:, on:, etc.
|
12
12
|
def self.build(attr_name, validator, options)
|
13
13
|
b = new(attr_name, validator, options)
|
14
|
-
b = Factory::Validators.set_validator(
|
15
|
-
|
16
|
-
|
14
|
+
b = Factory::Validators.set_validator(
|
15
|
+
b.attr_name,
|
16
|
+
b.validator,
|
17
|
+
b.options
|
18
|
+
)
|
17
19
|
b
|
18
20
|
end
|
19
21
|
|
data/lib/poro_validator.rb
CHANGED
data/poro_validator.gemspec
CHANGED
@@ -68,6 +68,7 @@ Gem::Specification.new do |spec|
|
|
68
68
|
lib/poro_validator/version.rb
|
69
69
|
poro_validator.gemspec
|
70
70
|
spec/features/composable_validations_spec.rb
|
71
|
+
spec/features/configurable_error_messages_spec.rb
|
71
72
|
spec/features/inheritable_spec.rb
|
72
73
|
spec/features/nested_validations_spec.rb
|
73
74
|
spec/features/validate_hash_object_spec.rb
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Allow configuration for error messages", type: :feature do
|
4
|
+
let(:custom_message) { proc { "manbearpig" } }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
::PoroValidator.configure do |config|
|
8
|
+
config.message.set(:integer, custom_message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "customize existing validator messages" do
|
13
|
+
validator = Class.new do
|
14
|
+
include PoroValidator.validator
|
15
|
+
|
16
|
+
validates :amount, integer: true
|
17
|
+
end.new
|
18
|
+
|
19
|
+
entity = OpenStruct.new(amount: 'abc')
|
20
|
+
validator.valid?(entity)
|
21
|
+
expect(validator.errors.on(:amount)).to eq(
|
22
|
+
[custom_message.call]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
# reset the custom messages
|
28
|
+
# if this is not done, there will be flapping test wherever
|
29
|
+
# the integer validator is used and it's default error message
|
30
|
+
# matched
|
31
|
+
::PoroValidator.configure do |config|
|
32
|
+
config.message.instance_variable_set(:@messages, {})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poro_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kareem Gan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/poro_validator/version.rb
|
148
148
|
- poro_validator.gemspec
|
149
149
|
- spec/features/composable_validations_spec.rb
|
150
|
+
- spec/features/configurable_error_messages_spec.rb
|
150
151
|
- spec/features/inheritable_spec.rb
|
151
152
|
- spec/features/nested_validations_spec.rb
|
152
153
|
- spec/features/validate_hash_object_spec.rb
|