regressor 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3da20145433fc7502546a3a4789311489eebbab9
4
- data.tar.gz: c5a5810e0089934d2dd1fc783215d646b0112d1e
3
+ metadata.gz: 8c1246eaaa08816d2d69349994d07cdddebc4e9c
4
+ data.tar.gz: 07b40698c510b43f50596cf10d1f1979ace9fdff
5
5
  SHA512:
6
- metadata.gz: d7f3221de3e0db9fe5486582c051ed2dbb38330df05517b24542484ee3c981acd7537fdb7cee724b28bc89471d2fd93d246279e60eb2f3b233e91756d9d6d241
7
- data.tar.gz: 5ac2a8e062369acd1e7c239dbdd7cbc2c5174f3281420b88dcce947cf522a47f5055f54460f04d31e791260edb1e213670a70e43d1bd8018a7ec4f8646b625e2
6
+ metadata.gz: 30e7e590db8a891cfeb7bdfe50e5beffb4b00858fb135fc76eb103a24759956fb0168cbf719e0500246141f3ba7a2668d1877faa0bb86defb9736acd4d40bbcd
7
+ data.tar.gz: e99e35ed3082cefce63966fa55789cd6f1ea1064463ac7c351945ea3d40120f4a655dfde33bdd0d7f6afb74b7104b583cb41d476189a8d9995433e1bc86cc4b6
@@ -8,7 +8,7 @@ module Regressor
8
8
  controller_path = @controller.constantize.controller_path
9
9
  @controller.constantize.action_methods.map do |action_method|
10
10
  begin
11
- journey_route = extract_journey_route
11
+ journey_route = extract_journey_route(controller_path, action_method)
12
12
  required_parts = extract_required_parts(journey_route)
13
13
  url = url_for({controller: controller_path, action: action_method, only_path: true}.merge(required_parts))
14
14
  generate_example(journey_route, controller_path, action_method, required_parts, url)
@@ -44,7 +44,7 @@ module Regressor
44
44
  end
45
45
  end
46
46
 
47
- def extract_journey_route
47
+ def extract_journey_route(controller_path, action_method)
48
48
  Rails.application.routes.routes.routes.select do |route|
49
49
  if route.defaults.present?
50
50
  route.defaults[:controller].to_sym == controller_path.to_sym && route.defaults[:action].to_sym == action_method.to_sym
@@ -0,0 +1,11 @@
1
+ module Regressor
2
+ module Model
3
+ module Util
4
+ def extract_validators(validator_type)
5
+ @model.constantize.validators.select do |validator|
6
+ validator.class.to_s == validator_type.to_s
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,28 +3,23 @@ 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]
6
+ extract_validators(ActiveModel::Validations::LengthValidator).inject([]) do |result, validator|
7
+ result << generate_length_examples(validator, validator.options[:minimum]-1, validator.options[:minimum]) if validator.options[:minimum]
8
+ result << generate_length_examples(validator, validator.options[:maximum] + 1, validator.options[:maximum]) if validator.options[:maximum]
9
9
  result
10
10
  end.flatten.compact.uniq.join("\n\t")
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def extract_length_validators
16
- @model.constantize.validators.select do |validator|
17
- validator.class.to_s == ActiveModel::Validations::LengthValidator.to_s
18
- end
19
- end
20
-
21
- def generate_validator_examples(validator, upper_bound, lower_bound)
15
+ def generate_length_examples(validator, upper_bound, lower_bound)
22
16
  validator.attributes.inject([]) do |result, attribute|
23
17
  result << "it { is_expected.to allow_value(Faker::Lorem.characters(#{lower_bound})).for :#{attribute} }"
24
18
  result << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{upper_bound})).for :#{attribute} }"
25
19
  result
26
20
  end
27
21
  end
22
+
28
23
  end
29
24
  end
30
25
  end
@@ -0,0 +1,65 @@
1
+ module Regressor
2
+ module Model
3
+ module Validation
4
+ module Numericality
5
+ def numericality_validators
6
+ extract_validators(ActiveModel::Validations::NumericalityValidator).inject([]) do |result, validator|
7
+ validator.options.each do |k, v|
8
+ case k
9
+ when :even
10
+ validator.attributes.each do |attribute|
11
+ result << "it { is_expected.to validate_numericality_of(:#{attribute}).even}"
12
+ end
13
+ when :only_integer
14
+ validator.attributes.each do |attribute|
15
+ result << "it { is_expected.to validate_numericality_of(:#{attribute}).only_integer}"
16
+ end
17
+ when :allow_nil
18
+ validator.attributes.each do |attribute|
19
+ result << "it { is_expected.to validate_numericality_of(:#{attribute}).allow_nil}"
20
+ end
21
+ end
22
+ end
23
+ result
24
+ end.uniq.join("\n\t")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # * <tt>:message</tt> - A custom error message (default is: "is not a number").
32
+ # * <tt>:only_integer</tt> - Specifies whether the value has to be an
33
+ # integer, e.g. an integral value (default is +false+).
34
+ # * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is
35
+ # +false+). Notice that for fixnum and float columns empty strings are
36
+ # converted to +nil+.
37
+ # * <tt>:greater_than</tt> - Specifies the value must be greater than the
38
+ # supplied value.
39
+ # * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be
40
+ # greater than or equal the supplied value.
41
+ # * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied
42
+ # value.
43
+ # * <tt>:less_than</tt> - Specifies the value must be less than the
44
+ # supplied value.
45
+ # * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less
46
+ # than or equal the supplied value.
47
+ # * <tt>:other_than</tt> - Specifies the value must be other than the
48
+ # supplied value.
49
+ # * <tt>:odd</tt> - Specifies the value must be an odd number.
50
+ # * <tt>:even</tt> - Specifies the value must be an even number.
51
+ #
52
+ # There is also a list of default options supported by every validator:
53
+ # +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
54
+ # See <tt>ActiveModel::Validation#validates</tt> for more information
55
+ #
56
+ # The following checks can also be supplied with a proc or a symbol which
57
+ # corresponds to a method:
58
+ #
59
+ # * <tt>:greater_than</tt>
60
+ # * <tt>:greater_than_or_equal_to</tt>
61
+ # * <tt>:equal_to</tt>
62
+ # * <tt>:less_than</tt>
63
+ # * <tt>:less_than_or_equal_to</tt>
64
+ # * <tt>:only_integer</tt>
65
+ #
@@ -3,13 +3,11 @@ module Regressor
3
3
  module Validation
4
4
  module Presence
5
5
  def presence_validators
6
- @model.constantize.validators.select do |validator|
7
- validator.class.to_s == ActiveRecord::Validations::PresenceValidator.to_s
8
- end.map(&:attributes).flatten.map do |attribute|
6
+ extract_validators(ActiveRecord::Validations::PresenceValidator).map(&:attributes).flatten.map do |attribute|
9
7
  "it { is_expected.to validate_presence_of :#{attribute} }"
10
8
  end.uniq.join("\n\t")
11
9
  end
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,8 +1,10 @@
1
+ require_relative 'model/util'
1
2
  require_relative 'model/relation/belong_to'
2
3
  require_relative 'model/relation/has_one'
3
4
  require_relative 'model/relation/has_many'
4
5
  require_relative 'model/validation/presence'
5
6
  require_relative 'model/validation/length'
7
+ require_relative 'model/validation/numericality'
6
8
  require_relative 'model/database/column'
7
9
  require_relative 'model/database/index'
8
10
  require_relative 'model/nested/attribute'
@@ -14,10 +16,12 @@ class Regressor::RegressionModel
14
16
  include Regressor::Model::Relation::HasMany
15
17
  include Regressor::Model::Validation::Presence
16
18
  include Regressor::Model::Validation::Length
19
+ include Regressor::Model::Validation::Numericality
17
20
  include Regressor::Model::Database::Column
18
21
  include Regressor::Model::Database::Index
19
22
  include Regressor::Model::Nested::Attribute
20
23
  include Regressor::Model::Enum
24
+ include Regressor::Model::Util
21
25
 
22
26
  attr_accessor :model
23
27
 
@@ -22,6 +22,9 @@ RSpec.describe <%= @model.model %> do
22
22
  # === Validations (Presence) ===
23
23
  <%= @model.presence_validators %>
24
24
 
25
+ # === Validations (Numericality) ===
26
+ <%= @model.numericality_validators %>
27
+
25
28
  <% if Regressor.configuration.include_enums %>
26
29
  # === Enums ===
27
30
  <%= @model.enums %>
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda-matchers
@@ -118,7 +118,9 @@ files:
118
118
  - lib/generators/regressor/model/relation/belong_to.rb
119
119
  - lib/generators/regressor/model/relation/has_many.rb
120
120
  - lib/generators/regressor/model/relation/has_one.rb
121
+ - lib/generators/regressor/model/util.rb
121
122
  - lib/generators/regressor/model/validation/length.rb
123
+ - lib/generators/regressor/model/validation/numericality.rb
122
124
  - lib/generators/regressor/model/validation/presence.rb
123
125
  - lib/generators/regressor/model_generator.rb
124
126
  - lib/generators/regressor/regression_controller.rb