regressor 0.1.7 → 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/generators/regressor/model/database/column.rb +13 -0
- data/lib/generators/regressor/model/database/index.rb +13 -0
- data/lib/generators/regressor/model/enum.rb +16 -0
- data/lib/generators/regressor/model/nested/attribute.rb +15 -0
- data/lib/generators/regressor/model/relation/belong_to.rb +13 -0
- data/lib/generators/regressor/model/relation/has_many.rb +13 -0
- data/lib/generators/regressor/model/relation/has_one.rb +13 -0
- data/lib/generators/regressor/model/validation/length.rb +27 -0
- data/lib/generators/regressor/model/validation/presence.rb +15 -0
- data/lib/generators/regressor/model_generator.rb +16 -0
- data/lib/generators/regressor/regression_model.rb +28 -0
- data/lib/generators/templates/{spec_regression_template.rb.erb → spec_regression_template.erb} +15 -6
- data/lib/regressor/version.rb +1 -1
- metadata +29 -21
- data/lib/generators/spec_regression_generator.rb +0 -12
- data/lib/regression_model.rb +0 -80
- data/lib/tasks/regressor_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4067523485e37bfe88f9fa29ac76ecf72aa5a7a
|
4
|
+
data.tar.gz: e335a88eca6d47780e23d7cbc9e01bce0e03f68b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836c34cca6b84b1b0e9cf8d0c342a8b1dc61e3afdf45b29b563154ac99460cce7cfb02131a2d0808c307608b16712ea315a5c8979a7155801ea66331c731a898
|
7
|
+
data.tar.gz: 3e7ef603731c0103de9d088c72674f8d343b2f70e611ee511905ea33938f35fb37af4106cc31858e4169da845e079dad58b043e994d24768abb311c993edd5f2
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Database
|
4
|
+
module Index
|
5
|
+
def indexes
|
6
|
+
ActiveRecord::Base.connection.indexes(@model.tableize.gsub("/", "_")).map do |indexes|
|
7
|
+
"it { is_expected.to have_db_index #{indexes.columns}}"
|
8
|
+
end.flatten.join("\n\t")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Enum
|
4
|
+
def enums
|
5
|
+
enum_specs = []
|
6
|
+
@model.constantize.defined_enums.each do |enum_k, enum_v|
|
7
|
+
enum_values = enum_v.map do |key, value|
|
8
|
+
key
|
9
|
+
end
|
10
|
+
enum_specs << "it { is_expected.to define_enum_for(:#{enum_k}).with(#{enum_values})}"
|
11
|
+
end
|
12
|
+
enum_specs.compact.uniq.join("\n\t")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Nested
|
4
|
+
module Attribute
|
5
|
+
def nested_attributes
|
6
|
+
if @model.constantize.nested_attributes_options.present?
|
7
|
+
@model.constantize.nested_attributes_options.keys.map do |key|
|
8
|
+
"it { is_expected.to accept_nested_attributes_for :#{key} }"
|
9
|
+
end.join("\n\t")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Relation
|
4
|
+
module BelongTo
|
5
|
+
def belong_to_relations
|
6
|
+
@model.constantize.reflect_on_all_associations(:belongs_to).map(&:name).map do |relation|
|
7
|
+
"it { is_expected.to belong_to :#{relation}}"
|
8
|
+
end.join("\n\t")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Relation
|
4
|
+
module HasMany
|
5
|
+
def has_many_relations
|
6
|
+
@model.constantize.reflect_on_all_associations(:has_many).map(&:name).map do |relation|
|
7
|
+
"it { is_expected.to have_many :#{relation}}"
|
8
|
+
end.join("\n\t") rescue nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Relation
|
4
|
+
module HasOne
|
5
|
+
def has_one_relations
|
6
|
+
@model.constantize.reflect_on_all_associations(:has_one).map(&:name).map do |relation|
|
7
|
+
"it { is_expected.to have_one :#{relation}}"
|
8
|
+
end.join("\n\t") rescue nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Validation
|
4
|
+
module Length
|
5
|
+
def length_validators
|
6
|
+
@model.constantize.validators.select do |validator|
|
7
|
+
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
|
21
|
+
result
|
22
|
+
end.flatten.compact.uniq.join("\n\t")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Regressor
|
2
|
+
module Model
|
3
|
+
module Validation
|
4
|
+
module Presence
|
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|
|
9
|
+
"it { is_expected.to validate_presence_of :#{attribute} }"
|
10
|
+
end.uniq.join("\n\t")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'regression_model'
|
2
|
+
|
3
|
+
module Regressor
|
4
|
+
class ModelGenerator < Rails::Generators::Base
|
5
|
+
source_root(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
def create_regression_files
|
8
|
+
Rails.application.eager_load!
|
9
|
+
ActiveRecord::Base.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }.each do |model|
|
10
|
+
@model = Regressor::RegressionModel.new(model)
|
11
|
+
create_file "#{Regressor.configuration.regression_path}/#{model.tableize.gsub("/", "_").singularize}_spec.rb", ERB.new(File.new(File.expand_path('../templates/spec_regression_template.erb', File.dirname(__FILE__))).read).result(binding)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'model/relation/belong_to'
|
2
|
+
require_relative 'model/relation/has_one'
|
3
|
+
require_relative 'model/relation/has_many'
|
4
|
+
require_relative 'model/validation/presence'
|
5
|
+
require_relative 'model/validation/length'
|
6
|
+
require_relative 'model/database/column'
|
7
|
+
require_relative 'model/database/index'
|
8
|
+
require_relative 'model/nested/attribute'
|
9
|
+
require_relative 'model/enum'
|
10
|
+
|
11
|
+
class Regressor::RegressionModel
|
12
|
+
include Regressor::Model::Relation::BelongTo
|
13
|
+
include Regressor::Model::Relation::HasOne
|
14
|
+
include Regressor::Model::Relation::HasMany
|
15
|
+
include Regressor::Model::Validation::Presence
|
16
|
+
include Regressor::Model::Validation::Length
|
17
|
+
include Regressor::Model::Database::Column
|
18
|
+
include Regressor::Model::Database::Index
|
19
|
+
include Regressor::Model::Nested::Attribute
|
20
|
+
include Regressor::Model::Enum
|
21
|
+
|
22
|
+
attr_accessor :model
|
23
|
+
|
24
|
+
def initialize(model)
|
25
|
+
@model = model
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/generators/templates/{spec_regression_template.rb.erb → spec_regression_template.erb}
RENAMED
@@ -1,18 +1,27 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe <%= @model.model %> do
|
4
|
+
|
4
5
|
# === Relations ===
|
5
6
|
<%= @model.belong_to_relations %>
|
6
7
|
<%= @model.has_one_relations %>
|
7
8
|
<%= @model.has_many_relations %>
|
9
|
+
|
8
10
|
# === Nested Attributes ===
|
9
11
|
<%= @model.nested_attributes %>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# ===
|
15
|
-
<%= @model.
|
12
|
+
|
13
|
+
# === Database (Columns) ===
|
14
|
+
<%= @model.columns %>
|
15
|
+
|
16
|
+
# === Database (Indexes) ===
|
17
|
+
<%= @model.indexes %>
|
18
|
+
|
19
|
+
# === Validations (Length) ===
|
20
|
+
<%= @model.length_validators %>
|
21
|
+
|
22
|
+
# === Validations (Presence) ===
|
23
|
+
<%= @model.presence_validators %>
|
24
|
+
|
16
25
|
<% if Regressor.configuration.include_enums %>
|
17
26
|
# === Enums ===
|
18
27
|
<%= @model.enums %>
|
data/lib/regressor/version.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-03-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: shoulda-matchers
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faker
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.3.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.3.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: generator_spec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,14 +105,22 @@ files:
|
|
105
105
|
- MIT-LICENSE
|
106
106
|
- Rakefile
|
107
107
|
- lib/generators/regressor/install_generator.rb
|
108
|
-
- lib/generators/
|
108
|
+
- lib/generators/regressor/model/database/column.rb
|
109
|
+
- lib/generators/regressor/model/database/index.rb
|
110
|
+
- lib/generators/regressor/model/enum.rb
|
111
|
+
- lib/generators/regressor/model/nested/attribute.rb
|
112
|
+
- lib/generators/regressor/model/relation/belong_to.rb
|
113
|
+
- lib/generators/regressor/model/relation/has_many.rb
|
114
|
+
- lib/generators/regressor/model/relation/has_one.rb
|
115
|
+
- lib/generators/regressor/model/validation/length.rb
|
116
|
+
- lib/generators/regressor/model/validation/presence.rb
|
117
|
+
- lib/generators/regressor/model_generator.rb
|
118
|
+
- lib/generators/regressor/regression_model.rb
|
109
119
|
- lib/generators/templates/regressor.rb
|
110
|
-
- lib/generators/templates/spec_regression_template.
|
111
|
-
- lib/regression_model.rb
|
120
|
+
- lib/generators/templates/spec_regression_template.erb
|
112
121
|
- lib/regressor.rb
|
113
122
|
- lib/regressor/version.rb
|
114
|
-
|
115
|
-
homepage: http://example.org
|
123
|
+
homepage: https://github.com/ndea/regressor
|
116
124
|
licenses:
|
117
125
|
- MIT
|
118
126
|
metadata: {}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'regression_model'
|
2
|
-
class SpecRegressionGenerator < Rails::Generators::Base
|
3
|
-
|
4
|
-
def create_regression_files
|
5
|
-
Rails.application.eager_load!
|
6
|
-
ActiveRecord::Base.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }.each do |model|
|
7
|
-
@model = RegressionModel.new(model)
|
8
|
-
create_file "#{Regressor.configuration.regression_path}/#{model.tableize.gsub("/", "_").singularize}_spec.rb", ERB.new(File.new(File.expand_path('templates/spec_regression_template.rb.erb', File.dirname(__FILE__))).read).result(binding)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
data/lib/regression_model.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
class RegressionModel
|
2
|
-
|
3
|
-
attr_accessor :model
|
4
|
-
|
5
|
-
def initialize(model)
|
6
|
-
@model = model
|
7
|
-
end
|
8
|
-
|
9
|
-
def belong_to_relations
|
10
|
-
@model.constantize.reflect_on_all_associations(:belongs_to).map(&:name).map do |relation|
|
11
|
-
"it { is_expected.to belong_to :#{relation}}"
|
12
|
-
end.join("\n\t") rescue nil
|
13
|
-
end
|
14
|
-
|
15
|
-
def has_one_relations
|
16
|
-
@model.constantize.reflect_on_all_associations(:has_one).map(&:name).map do |relation|
|
17
|
-
"it { is_expected.to have_one :#{relation}}"
|
18
|
-
end.join("\n\t") rescue nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def has_many_relations
|
22
|
-
@model.constantize.reflect_on_all_associations(:has_many).map(&:name).map do |relation|
|
23
|
-
"it { is_expected.to have_many :#{relation}}"
|
24
|
-
end.join("\n\t") rescue nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def enums
|
28
|
-
enum_specs = []
|
29
|
-
@model.constantize.defined_enums.each do |enum_k, enum_v|
|
30
|
-
enum_values = enum_v.map do |key, value|
|
31
|
-
key
|
32
|
-
end
|
33
|
-
enum_specs << "it { is_expected.to define_enum_for(:#{enum_k}).with(#{enum_values})}"
|
34
|
-
end
|
35
|
-
enum_specs.compact.uniq.join("\n\t")
|
36
|
-
end
|
37
|
-
|
38
|
-
def validators
|
39
|
-
validator_specs = []
|
40
|
-
@model.constantize.validators.each do |validator|
|
41
|
-
if validator.class.to_s == ActiveRecord::Validations::PresenceValidator.to_s
|
42
|
-
validator.attributes.each do |attribute|
|
43
|
-
validator_specs << "it { is_expected.to validate_presence_of :#{attribute} }"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
if validator.class.to_s == ActiveModel::Validations::LengthValidator.to_s
|
47
|
-
validator.attributes.each do |attribute|
|
48
|
-
minimum = validator.options[:minimum]
|
49
|
-
maximum = validator.options[:maximum]
|
50
|
-
validator_specs << "it { is_expected.to allow_value(Faker::Lorem.characters(#{minimum})).for :#{attribute} }" if minimum
|
51
|
-
validator_specs << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{minimum - 1})).for :#{attribute} }" if minimum
|
52
|
-
validator_specs << "it { is_expected.to allow_value(Faker::Lorem.characters(#{maximum})).for :#{attribute} }" if maximum
|
53
|
-
validator_specs << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{maximum + 1})).for :#{attribute} }" if maximum
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end rescue []
|
57
|
-
validator_specs.compact.uniq.join("\n\t")
|
58
|
-
end
|
59
|
-
|
60
|
-
def nested_attributes
|
61
|
-
if @model.constantize.nested_attributes_options.present?
|
62
|
-
@model.constantize.nested_attributes_options.keys.map do |key|
|
63
|
-
"it { is_expected.to accept_nested_attributes_for :#{key} }"
|
64
|
-
end.join("\n\t") rescue nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def database_columns
|
69
|
-
@model.constantize.columns.map(&:name).map do |column|
|
70
|
-
"it { is_expected.to have_db_column :#{column} }"
|
71
|
-
end.join("\n\t") rescue nil
|
72
|
-
end
|
73
|
-
|
74
|
-
def database_indexes
|
75
|
-
ActiveRecord::Base.connection.indexes(@model.tableize.gsub("/", "_")).map do |indexes|
|
76
|
-
"it { is_expected.to have_db_index #{indexes.columns}}"
|
77
|
-
end.flatten.join("\n\t") rescue nil
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|