routes_coverage 0.3.3 → 0.4.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: 9fb3534646a507fefba0989e3257bb6848dc92d3
4
- data.tar.gz: 68f609a43165593a150a252260ea4780a6b70c07
3
+ metadata.gz: 899581bd48d52230827553a1a8f94428f7c224cc
4
+ data.tar.gz: debceb6a0e49ef3d7b313c2733fc20ce3b08d428
5
5
  SHA512:
6
- metadata.gz: ebb1acac5797622c4155d74875953b535cb48f8fafc2d9b7749a8087ab49fc1cbedd9be15820bb50976c04002ed1794b0d3e2a69fc6c7edf15a3ab87805959a7
7
- data.tar.gz: 49505c2171c86c1b0dc473bb6636db8a1b15a61f224f89d623ffa0a5211232dd37bf2d3e69233d9d5e779e0ef38ee88026e65a9534ab9b4e9507aa19096b8747
6
+ metadata.gz: 452ab35f957e94c2122f89cb8c85599da67ea5ee8710c5090fe236d7b50a83d135221d42764fdb00d72309ebf85ea29b3e6047e30e1ef1b02dd4bc7e7ffd46f6
7
+ data.tar.gz: d0288d1afe2888e8118d09f2758acf8847cab1567b88dad93d59cfd5a84423095f2a6a6af4f4dd2206dbbc33f50d1556b40667611e93c491d3f8313fe5e2c924
data/Appraisals CHANGED
@@ -26,3 +26,8 @@ end
26
26
  appraise "rails-51" do
27
27
  gem "rails", "~>5.1.0"
28
28
  end
29
+
30
+ appraise 'rails-3' do
31
+ gem 'rails', '~>3.2.22'
32
+ gem 'test-unit'
33
+ end
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~>3.2.22"
6
+ gem "simplecov", require: false
7
+ gem "sprockets"
8
+ gem "sass"
9
+ gem "test-unit"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ routes_coverage (0.4.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionmailer (3.2.22.5)
10
+ actionpack (= 3.2.22.5)
11
+ mail (~> 2.5.4)
12
+ actionpack (3.2.22.5)
13
+ activemodel (= 3.2.22.5)
14
+ activesupport (= 3.2.22.5)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ journey (~> 1.0.4)
18
+ rack (~> 1.4.5)
19
+ rack-cache (~> 1.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.2.1)
22
+ activemodel (3.2.22.5)
23
+ activesupport (= 3.2.22.5)
24
+ builder (~> 3.0.0)
25
+ activerecord (3.2.22.5)
26
+ activemodel (= 3.2.22.5)
27
+ activesupport (= 3.2.22.5)
28
+ arel (~> 3.0.2)
29
+ tzinfo (~> 0.3.29)
30
+ activeresource (3.2.22.5)
31
+ activemodel (= 3.2.22.5)
32
+ activesupport (= 3.2.22.5)
33
+ activesupport (3.2.22.5)
34
+ i18n (~> 0.6, >= 0.6.4)
35
+ multi_json (~> 1.0)
36
+ appraisal (2.2.0)
37
+ bundler
38
+ rake
39
+ thor (>= 0.14.0)
40
+ arel (3.0.3)
41
+ builder (3.0.4)
42
+ docile (1.1.5)
43
+ erubis (2.7.0)
44
+ hike (1.2.3)
45
+ i18n (0.8.4)
46
+ journey (1.0.4)
47
+ json (1.8.6)
48
+ mail (2.5.4)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ mime-types (1.25.1)
52
+ minitest (5.10.2)
53
+ multi_json (1.12.1)
54
+ polyglot (0.3.5)
55
+ power_assert (0.3.1)
56
+ rack (1.4.7)
57
+ rack-cache (1.6.1)
58
+ rack (>= 0.4)
59
+ rack-ssl (1.3.4)
60
+ rack
61
+ rack-test (0.6.3)
62
+ rack (>= 1.0)
63
+ rails (3.2.22.5)
64
+ actionmailer (= 3.2.22.5)
65
+ actionpack (= 3.2.22.5)
66
+ activerecord (= 3.2.22.5)
67
+ activeresource (= 3.2.22.5)
68
+ activesupport (= 3.2.22.5)
69
+ bundler (~> 1.0)
70
+ railties (= 3.2.22.5)
71
+ railties (3.2.22.5)
72
+ actionpack (= 3.2.22.5)
73
+ activesupport (= 3.2.22.5)
74
+ rack-ssl (~> 1.3.2)
75
+ rake (>= 0.8.7)
76
+ rdoc (~> 3.4)
77
+ thor (>= 0.14.6, < 2.0)
78
+ rake (10.5.0)
79
+ rdoc (3.12.2)
80
+ json (~> 1.4)
81
+ sass (3.4.24)
82
+ simplecov (0.14.1)
83
+ docile (~> 1.1.0)
84
+ json (>= 1.8, < 3)
85
+ simplecov-html (~> 0.10.0)
86
+ simplecov-html (0.10.1)
87
+ sprockets (2.2.3)
88
+ hike (~> 1.2)
89
+ multi_json (~> 1.0)
90
+ rack (~> 1.0)
91
+ tilt (~> 1.1, != 1.3.0)
92
+ test-unit (3.2.2)
93
+ power_assert
94
+ thor (0.19.4)
95
+ tilt (1.4.1)
96
+ treetop (1.4.15)
97
+ polyglot
98
+ polyglot (>= 0.3.1)
99
+ tzinfo (0.3.53)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ appraisal
106
+ bundler (~> 1.14)
107
+ minitest
108
+ rails (~> 3.2.22)
109
+ rake (~> 10.0)
110
+ routes_coverage!
111
+ sass
112
+ simplecov
113
+ sprockets
114
+ test-unit
115
+
116
+ BUNDLED WITH
117
+ 1.15.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.3.3)
4
+ routes_coverage (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,14 +2,30 @@ module RoutesCoverage
2
2
  module Formatters
3
3
  class FullText < SummaryText
4
4
 
5
-
6
- class RouteFormatter < ActionDispatch::Routing::ConsoleFormatter
5
+ class RouteFormatter
6
+ attr_reader :buffer
7
7
 
8
8
  def initialize result=nil, _settings=nil, output_hits=false
9
+ @buffer = []
9
10
  @result = result
10
11
  @output_hits = output_hits
11
12
  @output_prefix = false
12
- super()
13
+ end
14
+
15
+ def result
16
+ @buffer.join("\n")
17
+ end
18
+
19
+ def section_title(title)
20
+ @buffer << "\n#{title}:"
21
+ end
22
+
23
+ def section(routes)
24
+ @buffer << draw_section(routes)
25
+ end
26
+
27
+ def header(routes)
28
+ @buffer << draw_header(routes)
13
29
  end
14
30
 
15
31
  def no_routes _routes_from_rails5=nil
@@ -27,7 +43,11 @@ module RoutesCoverage
27
43
  # puts "route is #{r.inspect}"
28
44
  if @output_hits
29
45
  # hits = " ?"
30
- original_route = r[:original].__getobj__ # SimpleDelegator
46
+ if r[:original].respond_to?(:__getobj__)
47
+ original_route = r[:original].__getobj__ # SimpleDelegator
48
+ else
49
+ original_route = r[:original]
50
+ end
31
51
  hits = " #{@result.route_hit_counts[original_route]}"
32
52
  end
33
53
  "#{r[:name].rjust(name_width) if @output_prefix} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs].ljust(reqs_width)}#{hits}"
@@ -49,24 +69,34 @@ module RoutesCoverage
49
69
  end
50
70
  end
51
71
 
72
+
73
+ def routes_section formatter, title, routes
74
+ formatter.buffer << title
75
+
76
+ if routes.none?
77
+ formatter.no_routes
78
+ else
79
+ formatter.header routes
80
+ formatter.section routes
81
+ end
82
+
83
+ formatter.result
84
+ end
85
+
52
86
  def hit_routes
53
87
  routes = result.hit_routes
88
+ # engine routes now are in the same list
89
+ if Result::Inspector::NEW_RAILS
90
+ hit_routes = Result::Inspector.new(result.hit_routes).collect_all_routes
91
+ pending_routes = Result::Inspector.new(result.pending_routes).collect_all_routes
92
+ else
93
+ #rails 3
94
+ hit_routes = Result::Inspector.new.collect_all_routes(result.hit_routes)
95
+ pending_routes = Result::Inspector.new.collect_all_routes(result.pending_routes)
96
+ end
54
97
 
55
- # verb_width = routes.map{ |r| r[:verb].length }.max
56
- # path_width = routes.map{ |r| r[:path].length }.max
57
-
58
- [
59
- "Covered routes:",
60
- # "#{"Verb".ljust(verb_width)} #{"Path".ljust(path_width)} Reqs",
61
- # routes.map do |r|
62
- # "#{r.verb.ljust(verb_width)} #{r.path.ljust(path_width)} #{r.reqs}"
63
- # end
64
- #TODO: replace formatter
65
- Result::Inspector.new(routes).format(RouteFormatter.new(result, settings, true)),
66
- nil,
67
- "Pending routes:",
68
- Result::Inspector.new(result.pending_routes).format(RouteFormatter.new),
69
- ].flatten.join("\n")
98
+ return routes_section(RouteFormatter.new(result, settings, true), "Covered routes:", hit_routes) + "\n\n" +
99
+ routes_section(RouteFormatter.new(result, settings), "Pending routes:", pending_routes)
70
100
  end
71
101
 
72
102
  def format
@@ -1,8 +1,91 @@
1
1
  require 'active_support/core_ext/string' # needed for rails5 version of inspector
2
- require 'action_dispatch/routing/inspector'
3
2
 
4
3
  module RoutesCoverage
5
4
  class Result
5
+
6
+ begin
7
+ require 'action_dispatch/routing/inspector'
8
+ class Inspector < ActionDispatch::Routing::RoutesInspector
9
+ NEW_RAILS = true
10
+ def collect_all_routes
11
+ res = collect_routes(@routes)
12
+ #TODO: test with engines
13
+ @engines.each do |engine_name, engine_routes|
14
+ res += engine_routes.map{|er|
15
+ er.merge({ engine_name: engine_name })
16
+ }
17
+ end
18
+ res
19
+ end
20
+
21
+ def collect_routes(routes)
22
+ routes.collect do |route|
23
+ ActionDispatch::Routing::RouteWrapper.new(route)
24
+ end.reject do |route|
25
+ route.internal?
26
+ end.collect do |route|
27
+ collect_engine_routes(route)
28
+
29
+ { name: route.name,
30
+ verb: route.verb,
31
+ path: route.path,
32
+ reqs: route.reqs,
33
+ # regexp: route.json_regexp, # removed, this is not present in rails5
34
+ # added:
35
+ original: route,
36
+ }
37
+ end
38
+ end
39
+ end
40
+
41
+ rescue LoadError
42
+ #rails 3
43
+ require 'rails/application/route_inspector'
44
+ class Inspector < Rails::Application::RouteInspector
45
+ NEW_RAILS = false
46
+ def collect_all_routes(routes)
47
+ res = collect_routes(routes)
48
+ @engines.each do |engine_name, engine_routes|
49
+ res += engine_routes.map{|er|
50
+ er.merge({ engine_name: engine_name })
51
+ }
52
+ end
53
+ res
54
+ end
55
+
56
+ def collect_routes(routes)
57
+ routes = routes.collect do |route|
58
+ route_reqs = route.requirements
59
+
60
+ rack_app = discover_rack_app(route.app)
61
+
62
+ controller = route_reqs[:controller] || ':controller'
63
+ action = route_reqs[:action] || ':action'
64
+
65
+ endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}"
66
+ constraints = route_reqs.except(:controller, :action)
67
+
68
+ reqs = endpoint
69
+ reqs += " #{constraints.inspect}" unless constraints.empty?
70
+
71
+ collect_engine_routes(reqs, rack_app)
72
+
73
+ { name: route.name.to_s,
74
+ verb: route.verb.source.gsub(/[$^]/, ''),
75
+ path: route.path.spec.to_s,
76
+ reqs: reqs,
77
+ # added:
78
+ original: route,
79
+ }
80
+ end
81
+
82
+ # Skip the route if it's internal info route
83
+ routes.reject { |r| r[:path] =~ %r{/rails/info/properties|^#{Rails.application.config.assets.prefix}} }
84
+ end
85
+ end
86
+
87
+ end
88
+
6
89
  def initialize all_routes, hit_routes, settings
7
90
  @all_routes = all_routes
8
91
  @route_hit_counts = hit_routes
@@ -75,44 +158,16 @@ module RoutesCoverage
75
158
  end
76
159
 
77
160
  def all_routes_with_hits
78
- res = Inspector.new(all_routes).collect_all_routes
161
+ if Inspector::NEW_RAILS
162
+ res = Inspector.new(all_routes).collect_all_routes
163
+ else
164
+ res = Inspector.new.collect_all_routes(all_routes)
165
+ end
79
166
  res.each{|val|
80
167
  val[:hits] = @route_hit_counts[val[:original]] || 0
81
168
  }
82
169
  res
83
170
  end
84
171
 
85
- class Inspector < ActionDispatch::Routing::RoutesInspector
86
- def collect_all_routes
87
- res = collect_routes(@routes)
88
- #TODO: test with engines
89
- @engines.each do |engine_name, engine_routes|
90
- res += engine_routes.map{|er|
91
- er.merge({ engine_name: engine_name })
92
- }
93
- end
94
- res
95
- end
96
-
97
- def collect_routes(routes)
98
- routes.collect do |route|
99
- ActionDispatch::Routing::RouteWrapper.new(route)
100
- end.reject do |route|
101
- route.internal?
102
- end.collect do |route|
103
- collect_engine_routes(route)
104
-
105
- { name: route.name,
106
- verb: route.verb,
107
- path: route.path,
108
- reqs: route.reqs,
109
- # regexp: route.json_regexp, # removed, this is not present in rails5
110
- # added:
111
- original: route,
112
- }
113
- end
114
- end
115
- end
116
-
117
172
  end
118
173
  end
@@ -1,3 +1,3 @@
1
1
  module RoutesCoverage
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routes_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Fedoseyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,8 @@ files:
87
87
  - compiled_assets/routes.css
88
88
  - compiled_assets/routes.js
89
89
  - gemfiles/.bundle/config
90
+ - gemfiles/rails_3.gemfile
91
+ - gemfiles/rails_3.gemfile.lock
90
92
  - gemfiles/rails_40.gemfile
91
93
  - gemfiles/rails_40.gemfile.lock
92
94
  - gemfiles/rails_40_rspec.gemfile