regressor 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4067523485e37bfe88f9fa29ac76ecf72aa5a7a
4
- data.tar.gz: e335a88eca6d47780e23d7cbc9e01bce0e03f68b
3
+ metadata.gz: 795f3adddccc068387b7f54e11669723c4bb73c2
4
+ data.tar.gz: bc3e3f93a3c4675658eebdb1208712b907fe1fbc
5
5
  SHA512:
6
- metadata.gz: 836c34cca6b84b1b0e9cf8d0c342a8b1dc61e3afdf45b29b563154ac99460cce7cfb02131a2d0808c307608b16712ea315a5c8979a7155801ea66331c731a898
7
- data.tar.gz: 3e7ef603731c0103de9d088c72674f8d343b2f70e611ee511905ea33938f35fb37af4106cc31858e4169da845e079dad58b043e994d24768abb311c993edd5f2
6
+ metadata.gz: 920e3277925ef020cd0b3f9bbe34b987ea51d4759bcdeb3d5618191361dedf6b8ce7f3e73f737baf1daeaa220da0fc08950437c26dce892344f2661737a096bc
7
+ data.tar.gz: c57c7d37d2ba882633d1774d9440da1a630b6f4d21d2bcd00a198a541ab765bf7591462b56880cbb6400c743da44ca95ad8ed43b53f45bd9bd76691b78a31160
@@ -0,0 +1,13 @@
1
+ module Regressor
2
+ module Controller
3
+ module Callback
4
+ module AfterFilter
5
+ def after_callbacks
6
+ after_filters.map do |filter_name|
7
+ "it { should use_after_filter(:#{filter_name}) }"
8
+ end.compact.uniq.join("\n\t")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Regressor
2
+ module Controller
3
+ module Callback
4
+ module AroundFilter
5
+ def around_callbacks
6
+ around_filters.map do |filter_name|
7
+ "it { should use_around_filter(:#{filter_name}) }"
8
+ end.compact.uniq.join("\n\t")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Regressor
2
+ module Controller
3
+ module Callback
4
+ module BeforeFilter
5
+ def before_callbacks
6
+ before_filters.map do |filter_name|
7
+ "it { should use_before_filter(:#{filter_name}) }"
8
+ end.compact.uniq.join("\n\t")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ module Regressor
2
+ module Controller
3
+ module Routing
4
+ module Rest
5
+ module Routes
6
+ def rest_routes
7
+ controller_path = @controller.constantize.controller_path
8
+ @controller.constantize.action_methods.map do |action_method|
9
+ journey_route = Rails.application.routes.routes.routes.select do |route|
10
+ if route.defaults.present?
11
+ route.defaults[:controller].to_sym == controller_path.to_sym && route.defaults[:action].to_sym == action_method.to_sym
12
+ else
13
+ false
14
+ end
15
+ end.first
16
+
17
+ required_parts = journey_route.required_parts.inject({}) do |required_part_hash, required_part|
18
+ required_part_hash.merge!({
19
+ required_part => 1
20
+ })
21
+ end
22
+ url = url_for({controller: controller_path, action: action_method, only_path: true}.merge(required_parts))
23
+
24
+ if journey_route.constraints[:request_method].match('GET')
25
+ "it { should route(:get, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
26
+ elsif journey_route.constraints[:request_method].match('POST')
27
+ "it { should route(:post, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
28
+ elsif journey_route.constraints[:request_method].match('PUT')
29
+ "it { should route(:put, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
30
+ elsif journey_route.constraints[:request_method].match('PATCH')
31
+ "it { should route(:patch, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
32
+ elsif journey_route.constraints[:request_method].match('DELETE')
33
+ "it { should route(:delete, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
34
+ end
35
+
36
+ end.uniq.compact.join("\n\t")
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ module Regressor
2
+ module Controller
3
+ module Util
4
+
5
+ def before_filters
6
+ filters(:before)
7
+ end
8
+
9
+ def after_filters
10
+ filters(:after)
11
+ end
12
+
13
+ def around_filters
14
+ filters(:around)
15
+ end
16
+
17
+ private
18
+ def filters(kind = nil)
19
+ controller = @controller.constantize
20
+ all_filters = controller._process_action_callbacks
21
+ all_filters = all_filters.select { |f| f.kind == kind } if kind
22
+ all_filters.map(&:filter)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'regression_controller'
2
+
3
+ module Regressor
4
+ class ControllerGenerator < Rails::Generators::Base
5
+ source_root(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ def create_regression_files
8
+ Rails.application.eager_load!
9
+ ApplicationController.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_controllers.include? x }.each do |controller|
10
+ @controller = Regressor::RegressionController.new(controller)
11
+ create_file "#{Regressor.configuration.regression_controller_path}/#{controller.underscore}_spec.rb", ERB.new(File.new(File.expand_path('../templates/controller/controller_spec_template.erb', File.dirname(__FILE__))).read).result(binding)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../../lib/generators/regressor/controller/util'
2
+ require_relative '../../../lib/generators/regressor/controller/routing/rest/routes'
3
+ require_relative '../../../lib/generators/regressor/controller/callback/before_filter'
4
+ require_relative '../../../lib/generators/regressor/controller/callback/after_filter'
5
+ require_relative '../../../lib/generators/regressor/controller/callback/around_filter'
6
+
7
+ class Regressor::RegressionController
8
+ include Rails.application.routes.url_helpers
9
+ include ActionDispatch::Routing
10
+
11
+ include Regressor::Controller::Util
12
+ include Regressor::Controller::Routing::Rest::Routes
13
+ include Regressor::Controller::Callback::BeforeFilter
14
+ include Regressor::Controller::Callback::AfterFilter
15
+ include Regressor::Controller::Callback::AroundFilter
16
+
17
+ attr_accessor :controller
18
+
19
+ def initialize(controller)
20
+ @controller = controller
21
+ end
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails_helper'
2
+
3
+ describe <%= @controller.controller %> do
4
+ # === Routes (REST) ===
5
+ <%= @controller.rest_routes %>
6
+ # === Callbacks (Before) ===
7
+ <%= @controller.before_callbacks %>
8
+ # === Callbacks (After) ===
9
+ <%= @controller.after_callbacks %>
10
+ # === Callbacks (Around) ===
11
+ <%= @controller.around_callbacks %>
12
+ end
@@ -1,15 +1,22 @@
1
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
- # Defines the path where the generated files will be placed
4
+ # Defines the path where the generated files for your models will be placed
5
5
  # config.regression_path = 'spec/models/regression'
6
6
 
7
+ # Defines the path where the generated files for your controllers will be placed
8
+ # config.regression_controller_path = 'spec/controllers/regression'
9
+
7
10
  # Exclude Models for regression spec generation.
8
11
  # Provide model names as String (e.g. 'User')
9
12
  # config.excluded_models = []
10
13
 
14
+ # Exclude Controllers for regression generation.
15
+ # Provide controller names as String (e.g. 'UsersController').
16
+ # config.excluded_controllers = []
17
+
11
18
  # If you are using enums in Rails 4 enable this option to generate regression specs for enums.
12
19
  # If your Rails version is =< Rails 3 set this option to false.
13
20
  # Default this option is set to true.
14
21
  # config.include_enums = true
15
- end
22
+ end
data/lib/regressor.rb CHANGED
@@ -9,11 +9,17 @@ module Regressor
9
9
  end
10
10
 
11
11
  class Configuration
12
- attr_accessor :regression_path, :excluded_models, :include_enums
12
+ attr_accessor :regression_path,
13
+ :regression_controller_path,
14
+ :excluded_models,
15
+ :excluded_controllers,
16
+ :include_enums
13
17
 
14
18
  def initialize
15
19
  @regression_path = 'spec/models/regression'
20
+ @regression_controller_path = 'spec/controllers/regression'
16
21
  @excluded_models = []
22
+ @excluded_controllers = []
17
23
  @include_enums = true
18
24
  end
19
25
  end
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens
@@ -104,6 +104,12 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - MIT-LICENSE
106
106
  - Rakefile
107
+ - lib/generators/regressor/controller/callback/after_filter.rb
108
+ - lib/generators/regressor/controller/callback/around_filter.rb
109
+ - lib/generators/regressor/controller/callback/before_filter.rb
110
+ - lib/generators/regressor/controller/routing/rest/routes.rb
111
+ - lib/generators/regressor/controller/util.rb
112
+ - lib/generators/regressor/controller_generator.rb
107
113
  - lib/generators/regressor/install_generator.rb
108
114
  - lib/generators/regressor/model/database/column.rb
109
115
  - lib/generators/regressor/model/database/index.rb
@@ -115,7 +121,9 @@ files:
115
121
  - lib/generators/regressor/model/validation/length.rb
116
122
  - lib/generators/regressor/model/validation/presence.rb
117
123
  - lib/generators/regressor/model_generator.rb
124
+ - lib/generators/regressor/regression_controller.rb
118
125
  - lib/generators/regressor/regression_model.rb
126
+ - lib/generators/templates/controller/controller_spec_template.erb
119
127
  - lib/generators/templates/regressor.rb
120
128
  - lib/generators/templates/spec_regression_template.erb
121
129
  - lib/regressor.rb