regressor 0.3.2 → 0.3.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 +4 -4
- data/lib/generators/regressor/model/validation/length.rb +18 -14
- data/lib/regressor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3da20145433fc7502546a3a4789311489eebbab9
|
4
|
+
data.tar.gz: c5a5810e0089934d2dd1fc783215d646b0112d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f3221de3e0db9fe5486582c051ed2dbb38330df05517b24542484ee3c981acd7537fdb7cee724b28bc89471d2fd93d246279e60eb2f3b233e91756d9d6d241
|
7
|
+
data.tar.gz: 5ac2a8e062369acd1e7c239dbdd7cbc2c5174f3281420b88dcce947cf522a47f5055f54460f04d31e791260edb1e213670a70e43d1bd8018a7ec4f8646b625e2
|
@@ -3,23 +3,27 @@ module Regressor
|
|
3
3
|
module Validation
|
4
4
|
module Length
|
5
5
|
def length_validators
|
6
|
+
extract_length_validators.inject([]) do |result, validator|
|
7
|
+
result << generate_validator_examples(validator, validator.options[:minimum]-1, validator.options[:minimum]) if validator.options[:minimum]
|
8
|
+
result << generate_validator_examples(validator, validator.options[:maximum] + 1, validator.options[:maximum]) if validator.options[:maximum]
|
9
|
+
result
|
10
|
+
end.flatten.compact.uniq.join("\n\t")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def extract_length_validators
|
6
16
|
@model.constantize.validators.select do |validator|
|
7
17
|
validator.class.to_s == ActiveModel::Validations::LengthValidator.to_s
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if validator.options[:maximum]
|
16
|
-
validator.attributes.each do |attribute|
|
17
|
-
result << "it { is_expected.to allow_value(Faker::Lorem.characters(#{validator.options[:maximum]})).for :#{attribute} }"
|
18
|
-
result << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{validator.options[:maximum] + 1})).for :#{attribute} }"
|
19
|
-
end
|
20
|
-
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_validator_examples(validator, upper_bound, lower_bound)
|
22
|
+
validator.attributes.inject([]) do |result, attribute|
|
23
|
+
result << "it { is_expected.to allow_value(Faker::Lorem.characters(#{lower_bound})).for :#{attribute} }"
|
24
|
+
result << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{upper_bound})).for :#{attribute} }"
|
21
25
|
result
|
22
|
-
end
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/regressor/version.rb
CHANGED