regressor 0.3.1 → 0.3.2

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: ef0984425573a1e4cd428276b17ae736cf570008
4
- data.tar.gz: e5e4e56f8a4c0336f2b76c10ddef6947712981a8
3
+ metadata.gz: 0b6976e039d3e3cb93759a984eadcdc617f2bcf9
4
+ data.tar.gz: 6c20bbc08b4f80b0aa6662d1fb782183aa094e13
5
5
  SHA512:
6
- metadata.gz: dd777bcfe7d77e595cf106a62b5f5fbbb7a47e112976f33438837c152b6ec97acf974a1319d39cbde745801c57836fd7ba70eb9768b541c80b7bc7e25f0ee3b6
7
- data.tar.gz: 5c09d5d3ed4747f1144d66bca17633c0bc2aaa551de2e5a2648c9a98ca2d6d0c4782043c75605bf4e184d7375244500083db185a2d71440500c5360ba53a962e
6
+ metadata.gz: 13219132e9fdf9aca87ebf8c431bc2f6525318adde7ab469a5c64476bd6efa9dc57d4228715d8856fd426fe9076f9cab50660340833e2a7c43eb8431200db9b9
7
+ data.tar.gz: 29575ffc4aeb4067035cd0947ff68096497caf6519c1e5cac4dcee3a4c32aade857a364804c973677f1dd4b8419dbecba0ee89e003a9e1a6d522765f01138897
@@ -8,38 +8,52 @@ 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 = Rails.application.routes.routes.routes.select do |route|
12
- if route.defaults.present?
13
- route.defaults[:controller].to_sym == controller_path.to_sym && route.defaults[:action].to_sym == action_method.to_sym
14
- else
15
- false
16
- end
17
- end.first
18
-
19
- required_parts = journey_route.required_parts.inject({}) do |required_part_hash, required_part|
20
- required_part_hash.merge!({
21
- required_part => 1
22
- })
23
- end
11
+ journey_route = extract_journey_route
12
+ required_parts = extract_required_parts(journey_route)
24
13
  url = url_for({controller: controller_path, action: action_method, only_path: true}.merge(required_parts))
25
-
26
- if journey_route.constraints[:request_method].match('GET')
27
- "it { should route(:get, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
28
- elsif journey_route.constraints[:request_method].match('POST')
29
- "it { should route(:post, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
30
- elsif journey_route.constraints[:request_method].match('PUT')
31
- "it { should route(:put, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
32
- elsif journey_route.constraints[:request_method].match('PATCH')
33
- "it { should route(:patch, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
34
- elsif journey_route.constraints[:request_method].match('DELETE')
35
- "it { should route(:delete, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
36
- end
14
+ generate_example(journey_route, controller_path, action_method, required_parts, url)
37
15
  rescue
38
16
  puts "Could not generate regression spec for controller #{controller_path} with action: #{action_method}"
39
17
  nil
40
18
  end
41
19
  end.uniq.compact.join("\n\t")
42
20
  end
21
+
22
+ private
23
+
24
+ def generate_example(journey_route, controller_path, action_method, required_parts, url)
25
+ request_method = journey_route.constraints[:request_method]
26
+ if request_method.match('GET')
27
+ "it { should route(:get, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
28
+ elsif request_method.match('POST')
29
+ "it { should route(:post, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
30
+ elsif request_method.match('PUT')
31
+ "it { should route(:put, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
32
+ elsif request_method.match('PATCH')
33
+ "it { should route(:patch, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
34
+ elsif request_method.match('DELETE')
35
+ "it { should route(:delete, '#{url}').to(#{{controller: controller_path, action: action_method}.merge(required_parts).to_s}) } "
36
+ end
37
+ end
38
+
39
+ def extract_required_parts(journey_route)
40
+ journey_route.required_parts.inject({}) do |required_part_hash, required_part|
41
+ required_part_hash.merge!({
42
+ required_part => 1
43
+ })
44
+ end
45
+ end
46
+
47
+ def extract_journey_route
48
+ Rails.application.routes.routes.routes.select do |route|
49
+ if route.defaults.present?
50
+ route.defaults[:controller].to_sym == controller_path.to_sym && route.defaults[:action].to_sym == action_method.to_sym
51
+ else
52
+ false
53
+ end
54
+ end.first
55
+ end
56
+
43
57
  end
44
58
  end
45
59
  end
@@ -7,8 +7,12 @@ module Regressor
7
7
  def create_regression_files
8
8
  Rails.application.eager_load!
9
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)
10
+ begin
11
+ @model = Regressor::RegressionModel.new(model)
12
+ 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)
13
+ rescue Exception
14
+ puts "Cannot create Model Regression for: #{model}"
15
+ end
12
16
  end
13
17
  end
14
18
 
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
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.1
4
+ version: 0.3.2
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-15 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda-matchers