regressor 0.1.5 → 0.1.6

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: 5d564786d3d03ee8a4b8392c5a294e496ee54ad7
4
- data.tar.gz: 2573af0c8dc7d338054f9b0c18ab6a3ba6276396
3
+ metadata.gz: 0a9762ad61cc0732c76bdedc8cc81638bfd963ab
4
+ data.tar.gz: 889ef8f16687215eb57dac9ab8591d11121762fa
5
5
  SHA512:
6
- metadata.gz: 8c5c50ad58c8697b8a617ce70521a367702bf95b17b46fd1e07b7919922c914eb59003e3cf01f2b3edede1f241c7de758346fda6ea601f092519f31e5bb3e711
7
- data.tar.gz: b00214ac80f05be70f5f8f315275bc74e3d5b3de0e9a5260a192d9e632bdb883b35ff66b383772559a6a85b84d1c96fe4cb63e3db4c30efe20843d60e3eb8633
6
+ metadata.gz: 83aecd15b83dc28a72c51e5d4c147b59505a4e5079c8a582035e5291bb66f0a793aa103dcee3f929a3a7c4afe1592e8dca0211f2bc680efb8b115201e83be3c3
7
+ data.tar.gz: ae53b7aa764d1a9431006f6a03584df75bb439c5d1288611a8252761c70d38c8ed4bd731cbdccc09a86fd5e9a0da178a1a3e6b4afa081e00fb1583a05166d7ee
@@ -1,22 +1,9 @@
1
1
  require 'regression_model'
2
2
  class SpecRegressionGenerator < Rails::Generators::Base
3
3
 
4
- def all_models
5
- # must eager load all the classes...
6
- Dir.glob("#{Rails.root}/app/models/**/*.rb") do |model_path|
7
- begin
8
- require model_path
9
- rescue
10
- # ignore
11
- end
12
- end
13
- # simply return them
14
- ActiveRecord::Base.send(:subclasses)
15
- end
16
-
17
-
18
4
  def create_regression_files
19
- all_models.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }.each do |model|
5
+ Rails.application.eager_load!
6
+ ActiveRecord::Base.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }.each do |model|
20
7
  @model = RegressionModel.new(model)
21
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)
22
9
  end
@@ -1,4 +1,4 @@
1
- # If the regressor gem is inside a group wrap your initializer in
1
+ # If the regressor gem is inside a group wrap your initializer in
2
2
  # if defined?(Regressor) do .. end
3
3
  Regressor.configure do |config|
4
4
  # Defines the path where the generated files will be placed
@@ -7,4 +7,4 @@ Regressor.configure do |config|
7
7
  # Exclude Models for regression spec generation.
8
8
  # Provide model names as String (e.g. 'User')
9
9
  # config.excluded_models = []
10
- end
10
+ end
@@ -13,4 +13,8 @@ RSpec.describe <%= @model.model %> do
13
13
  <%= @model.database_indexes %>
14
14
  # === Validations ===
15
15
  <%= @model.validators %>
16
+ <% if Regressor.configuration.include_enums %>
17
+ # === Enums ===
18
+ <%= @model.enums %>
19
+ <% end %>
16
20
  end
@@ -24,6 +24,17 @@ class RegressionModel
24
24
  end.join("\n\t") rescue nil
25
25
  end
26
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
+
27
38
  def validators
28
39
  validator_specs = []
29
40
  @model.constantize.validators.each do |validator|
@@ -62,7 +73,7 @@ class RegressionModel
62
73
 
63
74
  def database_indexes
64
75
  ActiveRecord::Base.connection.indexes(@model.tableize.gsub("/", "_")).map do |indexes|
65
- "it { is_expected.to have_db_index #{indexes.columns}}"
76
+ "it { is_expected.to have_db_index #{indexes.columns}}"
66
77
  end.flatten.join("\n\t") rescue nil
67
78
  end
68
79
 
data/lib/regressor.rb CHANGED
@@ -9,11 +9,12 @@ module Regressor
9
9
  end
10
10
 
11
11
  class Configuration
12
- attr_accessor :regression_path, :excluded_models
12
+ attr_accessor :regression_path, :excluded_models, :include_enums
13
13
 
14
14
  def initialize
15
15
  @regression_path = 'spec/models/regression'
16
16
  @excluded_models = []
17
+ @include_enums = true
17
18
  end
18
19
  end
19
20
  end
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
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.1.5
4
+ version: 0.1.6
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-02-18 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: generator_spec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Regressor generates regression specs based on ActiveRecord models. Currently
84
98
  relations, validations, attributes, and database indexes are supported.
85
99
  email:
@@ -118,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
132
  version: '0'
119
133
  requirements: []
120
134
  rubyforge_project:
121
- rubygems_version: 2.2.2
135
+ rubygems_version: 2.4.6
122
136
  signing_key:
123
137
  specification_version: 4
124
138
  summary: Regressor generates regression specs based on ActiveRecord models