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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b6976e039d3e3cb93759a984eadcdc617f2bcf9
4
- data.tar.gz: 6c20bbc08b4f80b0aa6662d1fb782183aa094e13
3
+ metadata.gz: 3da20145433fc7502546a3a4789311489eebbab9
4
+ data.tar.gz: c5a5810e0089934d2dd1fc783215d646b0112d1e
5
5
  SHA512:
6
- metadata.gz: 13219132e9fdf9aca87ebf8c431bc2f6525318adde7ab469a5c64476bd6efa9dc57d4228715d8856fd426fe9076f9cab50660340833e2a7c43eb8431200db9b9
7
- data.tar.gz: 29575ffc4aeb4067035cd0947ff68096497caf6519c1e5cac4dcee3a4c32aade857a364804c973677f1dd4b8419dbecba0ee89e003a9e1a6d522765f01138897
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.inject([]) do |result, validator|
9
- if validator.options[:minimum]
10
- validator.attributes.each do |attribute|
11
- result << "it { is_expected.to allow_value(Faker::Lorem.characters(#{validator.options[:minimum]})).for :#{attribute} }"
12
- result << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{validator.options[:minimum] - 1})).for :#{attribute} }"
13
- end
14
- end
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.flatten.compact.uniq.join("\n\t")
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens