routes_revealer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81f7f72e31318a592a2e85816eccbb667b84ba56
4
+ data.tar.gz: f5b8364df30ef5da05c5620263b1263aacfb1b53
5
+ SHA512:
6
+ metadata.gz: 0cfca7f8ca36ebf0723d3b5bdaf0fc7b9cd10f38d584d94913a3454ce99b69806997b7978ae6e4f35c3a8369b42970add72a91018587a63012a2c5f796c962de
7
+ data.tar.gz: e7aa2c5b3f9701f2a921b99fb9b01c53c0632313ff1cb709fe5ae283990ec069e35d86816828350f85120f896db5990014ad465725a905a4dc029e771c963476
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RoutesRevealer'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,25 @@
1
+ module RoutesRevealer
2
+ class RoutesController < ApplicationController
3
+ skip_filter(*_process_action_callbacks.map(&:filter))
4
+
5
+ def index
6
+ output = []
7
+ Rails.application.routes.routes.each do |r|
8
+ route_string = r.path.spec.to_s.sub('(.:format)', '')
9
+ unless ignore_route?(route_string)
10
+ output.push route_string if r.defaults[:controller]
11
+ end
12
+ end
13
+
14
+ output.push Rails.application.class.config.assets.prefix
15
+
16
+ render json: output
17
+ end
18
+
19
+ private
20
+
21
+ def ignore_route?(route_string)
22
+ route_string =~ /(\/[0-9]{3})|(^\/routes)|(^\/rails)|(^\/$)/
23
+ end
24
+ end
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ RoutesRevealer::Engine.routes.draw do
2
+ get 'routes', to: 'routes#index'
3
+ end
@@ -0,0 +1,5 @@
1
+ module RoutesRevealer
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RoutesRevealer
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RoutesRevealer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "routes_revealer/engine"
2
+
3
+ module RoutesRevealer
4
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe RoutesRevealer::RoutesController do
4
+ describe '#index' do
5
+
6
+ let(:good_defaults) { { controller: true } }
7
+ let(:bad_defaults) { { controller: nil } }
8
+ let(:good_route1) { double("good_route1", path: double("path", spec: "/good/route1(.:format)"), defaults: good_defaults) }
9
+ let(:good_route2) { double("good_route2", path: double("path", spec: "/good/route2(.:format)"), defaults: good_defaults) }
10
+ let(:bad_route1) { double("bad_route1", path: double("path", spec: "/404(.:format)"), defaults: good_defaults) }
11
+ let(:bad_route2) { double("bad_route2", path: double("path", spec: "/rails(.:format)"), defaults: good_defaults) }
12
+ let(:bad_route3) { double("bad_route3", path: double("path", spec: "/routes(.:format)"), defaults: good_defaults) }
13
+ let(:bad_route4) { double("bad_route4", path: double("path", spec: "/(.:format)"), defaults: good_defaults) }
14
+ let(:bad_route5) { double("bad_route5", path: double("path", spec: "/asdf(.:format)"), defaults: bad_defaults) }
15
+ let(:routes) { [good_route1, good_route2, bad_route1, bad_route2, bad_route3, bad_route4] }
16
+
17
+ before do
18
+ allow(Rails).to receive_message_chain(:application, :routes, :routes).and_return(routes)
19
+ allow(Rails).to receive_message_chain(:application, :class, :config, :assets, :prefix).and_return("/assets")
20
+ get :index
21
+ end
22
+
23
+ it { expect(response.status).to eq 200 }
24
+ it { expect(JSON.parse(response.body).length).to eq 3 }
25
+ it { expect(JSON.parse(response.body)[0]).to eq "/good/route1" }
26
+ it { expect(JSON.parse(response.body)[1]).to eq "/good/route2" }
27
+ it { expect(JSON.parse(response.body)[2]).to eq "/assets" }
28
+
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require 'pry'
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
8
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ config.include RSpec::Rails::RailsExampleGroup
12
+ config.expose_current_running_example_as :example
13
+ config.infer_spec_type_from_file_location!
14
+ config.infer_base_class_for_anonymous_controllers = false
15
+
16
+ config.include ControllerHelpers, type: :controller
17
+ end
@@ -0,0 +1,7 @@
1
+ module ControllerHelpers
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ routes { RoutesRevealer::Engine.routes }
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: routes_revealer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Consumer Development
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.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.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
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: binding_of_caller
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
+ - !ruby/object:Gem::Dependency
84
+ name: better_errors
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ description: The /routes route will list all of the consuming application's routes
98
+ except for external redirects, generic HTTP status pages, and default Rails routes
99
+ email:
100
+ - ConsumerDevelopment@careerbuilder.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - app/controllers/routes_revealer/routes_controller.rb
106
+ - config/routes.rb
107
+ - lib/routes_revealer.rb
108
+ - lib/routes_revealer/engine.rb
109
+ - lib/routes_revealer/version.rb
110
+ - Rakefile
111
+ - spec/spec_helper.rb
112
+ - spec/controllers/routes_controller_spec.rb
113
+ - spec/support/helpers/controller_helpers.rb
114
+ homepage: ''
115
+ licenses: []
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.0.14
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Provides the route /routes which will list the applications routes
137
+ test_files:
138
+ - spec/spec_helper.rb
139
+ - spec/controllers/routes_controller_spec.rb
140
+ - spec/support/helpers/controller_helpers.rb