routes_dont_work 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +57 -0
- data/lib/routes_dont_work.rb +1 -0
- data/lib/routes_dont_work/route_checker.rb +32 -0
- data/lib/routes_dont_work/rspec.rb +7 -0
- data/lib/routes_dont_work/version.rb +5 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9cdc3f3bb10c9d198432e4be5d3aac146fc01c68
|
4
|
+
data.tar.gz: 8beaa937a7bd12868b11dc3d561a264881fc3f4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5487c86ad54b75d714b823dc765d260ae7ac71df786d336177a02ad6987de817b00dfaaef4bfef6520ca8b44278fb40c953ead247d478ed764d479447e0d119
|
7
|
+
data.tar.gz: 659baea02a4e5768300b812cf04a86d751eb5ee8e6a66b2efd341800b5510cd908dc04b4c51ec454e34449d7d6bc0446dd8b62e9bbdc7b8f759a6dda8a92e9f3
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
routes_dont_work provides a test to ensure that all the routes in your Rails app actually route to something. In
|
2
|
+
particular, it tests that:
|
3
|
+
|
4
|
+
- The referenced controller exists.
|
5
|
+
- The controller has a public method named the same as the action, or a view exists in the view lookup path for that
|
6
|
+
controller.
|
7
|
+
|
8
|
+
A very common case of broken routes is the use of RESTful routes without defining all the actions (index, show, new, create, edit, update, and destroy). If you don't need all of these actions, you can use the [`only` and `except` options of the `resources` block](http://guides.rubyonrails.org/routing.html#restricting-the-routes-created).
|
9
|
+
|
10
|
+
After routes_dont_work identifies these routes, you should fix or remove them. Be careful if removing, because if, for example, you have a view that generates a link with the broken route, removing the route without removing the reference will make the view raise an exception.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Include routes_dont_work in your Gemfile in the 'test' group.
|
15
|
+
```ruby
|
16
|
+
group :test do
|
17
|
+
gem 'routes_dont_work'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
For rspec, include the 'routes_dont_work' shared example in one of your tests, for example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'spec_helper'
|
25
|
+
require 'routes_dont_work/rspec'
|
26
|
+
|
27
|
+
describe 'routes' do
|
28
|
+
include_examples 'routes_dont_work'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
If this was in routes.rb,
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
get 'this_doesnt_exist' => 'fake_controller/fake_action'
|
36
|
+
```
|
37
|
+
|
38
|
+
your test suite would fail with:
|
39
|
+
|
40
|
+
```
|
41
|
+
Failures:
|
42
|
+
|
43
|
+
1) routes has no broken routes
|
44
|
+
Failure/Error: expect(RoutesDontWork::RouteChecker.get_broken_routes(Rails.application)).to be_empty
|
45
|
+
expected `[{:action=>"this_doesnt_exist", :controller=>"fake_controller/fake_action", :path=>"/this_doesnt_exist(.:format)"}].empty?` to return true, got false
|
46
|
+
Shared Example Group: "routes_dont_work" called from ./spec/controllers/routes_spec.rb:5
|
47
|
+
# ~/routes_dont_work/lib/routes_dont_work/rspec.rb:5:in `block (2 levels) in <top (required)>'
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Limitations
|
52
|
+
|
53
|
+
- routes_dont_work will only check the existence of the controller/action/view. It will not guarantee that any request for
|
54
|
+
the routes will succeed.
|
55
|
+
- Your app may have special dynamic craziness that can confuse routes_dont_work. You should verify that what
|
56
|
+
routes_dont_work says is true.
|
57
|
+
- routes_dont_work currently only works with rspec. Feel free to contribute changes to support other frameworks.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'routes_dont_work/route_checker'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RoutesDontWork
|
2
|
+
class RouteChecker
|
3
|
+
class << self
|
4
|
+
def get_broken_routes(app)
|
5
|
+
broken_routes = app.routes.routes.select do |r|
|
6
|
+
controller_name = r.defaults[:controller].try(:camelize)
|
7
|
+
|
8
|
+
# There's some built-in Rails ones like /assets that have no controller. Ignore those.
|
9
|
+
next false if controller_name.nil?
|
10
|
+
|
11
|
+
action_name = r.defaults[:action]
|
12
|
+
|
13
|
+
begin
|
14
|
+
controller_class = (controller_name + 'Controller').constantize
|
15
|
+
rescue NameError
|
16
|
+
# Controller doesn't exist
|
17
|
+
next true
|
18
|
+
end
|
19
|
+
|
20
|
+
# Controller exists, but action doesn't? Note that this correctly handles cases where there is no method on a
|
21
|
+
# controller, but a view exists at the right place.
|
22
|
+
next controller_class.new.method_for_action(action_name).nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
# Just to get a readable error if it fails
|
26
|
+
broken_routes.map!{|r| r.defaults.merge(path: r.path.spec.to_s)}
|
27
|
+
|
28
|
+
return broken_routes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: routes_dont_work
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Barnabe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Provide a test to check if all the routes in a Rails app go to a controller
|
84
|
+
or view
|
85
|
+
email: jason.barnabe@canadadrugs.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- README.md
|
91
|
+
- lib/routes_dont_work.rb
|
92
|
+
- lib/routes_dont_work/route_checker.rb
|
93
|
+
- lib/routes_dont_work/rspec.rb
|
94
|
+
- lib/routes_dont_work/version.rb
|
95
|
+
homepage: https://github.com/canadadrugs/routes_dont_work
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options:
|
101
|
+
- --charset=UTF-8
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: routes_dont_work-1.0.0
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|