regressor 0.5.8 → 0.6.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/controller/callback/after_filter.rb +1 -1
- data/lib/controller/callback/around_filter.rb +1 -1
- data/lib/controller/callback/before_filter.rb +1 -1
- data/lib/controller/util.rb +2 -1
- data/lib/generators/regressor/factory_generator.rb +45 -0
- data/lib/model/active_record/validation.rb +31 -0
- data/lib/model/active_record/validation/length.rb +11 -10
- data/lib/model/active_record/validation/numericality.rb +6 -5
- data/lib/model/active_record/validation/presence.rb +6 -3
- data/lib/model/active_record_model.rb +3 -0
- data/lib/model/factory_model.rb +13 -0
- data/lib/regressor.rb +2 -0
- data/lib/regressor/version.rb +1 -1
- data/lib/templates/factory/factory_template.erb +8 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccfb10d1fd8a5fdc9ad01688d0467054945c949
|
4
|
+
data.tar.gz: dd774a46ce48e915590195e0044947cc36231240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514cf199208a5835383a4ae2cb034510b55f1507a87953ea0339e3b00180501ac7eeefe5de6cf88dc5fc74357fb84d27228867dfba17377a58bcf04d0b1b4873
|
7
|
+
data.tar.gz: 51080b07d9aeece110b6fa6bb7b66c6bd57f7abf06d35bd19973c4eb05ff607acfcd7dd2f269c017b619f533edd0ee7dec799a5307660607ca94fc260b8dfd7e
|
data/lib/controller/util.rb
CHANGED
@@ -20,7 +20,8 @@ module Regressor
|
|
20
20
|
all_filters = controller._process_action_callbacks
|
21
21
|
all_filters = all_filters.select { |f| f.kind == kind } if kind
|
22
22
|
# Reject procs
|
23
|
-
all_filters.map(&:raw_filter).reject{|filter| filter.class == Proc}
|
23
|
+
all_filters = all_filters.map(&:raw_filter).reject{|filter| filter.class == Proc}
|
24
|
+
all_filters.map {|filter| filter.is_a?(Symbol) ? ":#{filter}" : filter.to_s}
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'model/factory_model'
|
2
|
+
|
3
|
+
module Regressor
|
4
|
+
class FactoryGenerator < Rails::Generators::Base
|
5
|
+
source_root(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
def create_regression_files
|
8
|
+
load_application
|
9
|
+
generate_factories
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def generate_factories
|
15
|
+
load_ar_models.each do |model|
|
16
|
+
save_generate(model) do
|
17
|
+
@model = ::Regressor::Model::FactoryModel.new(model)
|
18
|
+
create_file "#{Regressor.configuration.regression_factory_path}/#{model.underscore.singularize}_factory.rb",
|
19
|
+
ERB.new(File.new(File.expand_path('../../templates/factory/factory_template.erb', File.dirname(__FILE__))).read).result(binding)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_application
|
25
|
+
Rails.application.try(:eager_load!)
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_ar_models
|
29
|
+
if defined?(::ActiveRecord::Base)
|
30
|
+
ActiveRecord::Base.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }
|
31
|
+
else
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def save_generate(model)
|
37
|
+
begin
|
38
|
+
yield
|
39
|
+
rescue => e
|
40
|
+
puts "Cannot create factory for #{model}. Reason #{e.message}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Validation
|
4
|
+
def wrap_conditional_validations validator, specs
|
5
|
+
if_mock = if_condition_mock validator
|
6
|
+
unless_mock = unless_condition_mock validator
|
7
|
+
padding = if_mock.blank? && unless_mock.blank? ? '' : ' '
|
8
|
+
specs = specs.map do |spec|
|
9
|
+
"#{padding}#{spec}"
|
10
|
+
end.uniq.join("\n ")
|
11
|
+
if if_mock.blank? && unless_mock.blank?
|
12
|
+
specs
|
13
|
+
else
|
14
|
+
"context \"with conditions\" do\n before do\n#{if_mock}#{unless_mock} end\n\n#{specs}\n end\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def if_condition_mock validator
|
19
|
+
if_condition = validator.options[:if]
|
20
|
+
return '' unless if_condition && if_condition.is_a?(Symbol)
|
21
|
+
" allow(subject).to receive(:#{if_condition.to_s}).and_return(true)\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
def unless_condition_mock validator
|
25
|
+
unless_condition = validator.options[:unless]
|
26
|
+
return '' unless unless_condition && unless_condition.is_a?(Symbol)
|
27
|
+
" allow(subject).to receive(:#{unless_condition.to_s}).and_return(false)\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,23 +3,24 @@ module Regressor
|
|
3
3
|
module Validation
|
4
4
|
module Length
|
5
5
|
def length_validators
|
6
|
-
extract_validators(::ActiveModel::Validations::LengthValidator).
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
extract_validators(::ActiveModel::Validations::LengthValidator).flatten.map do |validator|
|
7
|
+
specs = []
|
8
|
+
specs.concat generate_length_examples(validator, validator.options[:minimum]-1, validator.options[:minimum]) if validator.options[:minimum]
|
9
|
+
specs.concat generate_length_examples(validator, validator.options[:maximum] + 1, validator.options[:maximum]) if validator.options[:maximum]
|
10
|
+
wrap_conditional_validations validator, specs.flatten.compact.uniq
|
11
|
+
end.join("\n ")
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def generate_length_examples(validator, upper_bound, lower_bound)
|
16
|
-
validator.attributes.
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
validator.attributes.map do |attribute|
|
18
|
+
[
|
19
|
+
"it { is_expected.to allow_value(Faker::Lorem.characters(#{lower_bound})).for :#{attribute} }",
|
20
|
+
"it { is_expected.not_to allow_value(Faker::Lorem.characters(#{upper_bound})).for :#{attribute} }"
|
21
|
+
]
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -3,14 +3,15 @@ module Regressor
|
|
3
3
|
module Validation
|
4
4
|
module Numericality
|
5
5
|
def numericality_validators
|
6
|
-
extract_validators(::ActiveModel::Validations::NumericalityValidator).
|
6
|
+
extract_validators(::ActiveModel::Validations::NumericalityValidator).flatten.map do |validator|
|
7
|
+
specs = []
|
7
8
|
if validator.options.blank?
|
8
|
-
|
9
|
+
specs.concat validator_without_options(validator)
|
9
10
|
else
|
10
|
-
|
11
|
+
specs.concat validator_with_options(validator)
|
11
12
|
end
|
12
|
-
|
13
|
-
end.
|
13
|
+
wrap_conditional_validations validator, specs.flatten.compact.uniq
|
14
|
+
end.join("\n ")
|
14
15
|
end
|
15
16
|
|
16
17
|
private
|
@@ -3,9 +3,12 @@ module Regressor
|
|
3
3
|
module Validation
|
4
4
|
module Presence
|
5
5
|
def presence_validators
|
6
|
-
extract_validators(::ActiveRecord::Validations::PresenceValidator).
|
7
|
-
|
8
|
-
|
6
|
+
extract_validators(::ActiveRecord::Validations::PresenceValidator).flatten.map do |validator|
|
7
|
+
specs = validator.attributes.map do |attribute|
|
8
|
+
"it { is_expected.to validate_presence_of :#{attribute} }"
|
9
|
+
end.uniq
|
10
|
+
wrap_conditional_validations validator, specs
|
11
|
+
end.join("\n ")
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
@@ -9,6 +9,8 @@ require_relative 'active_record/database/column'
|
|
9
9
|
require_relative 'active_record/database/index'
|
10
10
|
require_relative 'active_record/nested/attribute'
|
11
11
|
require_relative 'active_record/enum'
|
12
|
+
require_relative 'active_record/validation'
|
13
|
+
|
12
14
|
|
13
15
|
module Regressor
|
14
16
|
module Model
|
@@ -17,6 +19,7 @@ module Regressor
|
|
17
19
|
include Relation::BelongTo
|
18
20
|
include Relation::HasOne
|
19
21
|
include Relation::HasMany
|
22
|
+
include Validation
|
20
23
|
include Validation::Presence
|
21
24
|
include Validation::Length
|
22
25
|
include Validation::Numericality
|
data/lib/regressor.rb
CHANGED
@@ -11,6 +11,7 @@ module Regressor
|
|
11
11
|
class Configuration
|
12
12
|
attr_accessor :regression_path,
|
13
13
|
:regression_controller_path,
|
14
|
+
:regression_factory_path,
|
14
15
|
:excluded_models,
|
15
16
|
:excluded_controllers,
|
16
17
|
:include_enums
|
@@ -18,6 +19,7 @@ module Regressor
|
|
18
19
|
def initialize
|
19
20
|
@regression_path = 'spec/models/regression'
|
20
21
|
@regression_controller_path = 'spec/controllers/regression'
|
22
|
+
@regression_factory_path = 'spec/factories'
|
21
23
|
@excluded_models = []
|
22
24
|
@excluded_controllers = []
|
23
25
|
@include_enums = true
|
data/lib/regressor/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.0
|
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-08-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda-matchers
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/controller/routing/rest/routes.rb
|
138
138
|
- lib/controller/util.rb
|
139
139
|
- lib/generators/regressor/controller_generator.rb
|
140
|
+
- lib/generators/regressor/factory_generator.rb
|
140
141
|
- lib/generators/regressor/install_generator.rb
|
141
142
|
- lib/generators/regressor/model_generator.rb
|
142
143
|
- lib/generators/regressor/mongoid/model_generator.rb
|
@@ -148,11 +149,13 @@ files:
|
|
148
149
|
- lib/model/active_record/relation/has_many.rb
|
149
150
|
- lib/model/active_record/relation/has_one.rb
|
150
151
|
- lib/model/active_record/util.rb
|
152
|
+
- lib/model/active_record/validation.rb
|
151
153
|
- lib/model/active_record/validation/length.rb
|
152
154
|
- lib/model/active_record/validation/numericality.rb
|
153
155
|
- lib/model/active_record/validation/presence.rb
|
154
156
|
- lib/model/active_record_model.rb
|
155
157
|
- lib/model/expression.rb
|
158
|
+
- lib/model/factory_model.rb
|
156
159
|
- lib/model/mongoid/database/field.rb
|
157
160
|
- lib/model/mongoid/document/timestamp.rb
|
158
161
|
- lib/model/mongoid/document/version.rb
|
@@ -164,6 +167,7 @@ files:
|
|
164
167
|
- lib/regressor.rb
|
165
168
|
- lib/regressor/version.rb
|
166
169
|
- lib/templates/controller/controller_spec_template.erb
|
170
|
+
- lib/templates/factory/factory_template.erb
|
167
171
|
- lib/templates/model/active_record/model_template.erb
|
168
172
|
- lib/templates/model/mongoid/model_template.erb
|
169
173
|
- lib/templates/regressor.rb
|