railway_inspector 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d839b13160dcc2272bc734e4534517e42802602
4
+ data.tar.gz: 8380456bff93454501a6c530c2a11ecec98d2ab0
5
+ SHA512:
6
+ metadata.gz: 1a826eeb7d1fdae2091c918ff42b33b0ed2ba9addfb94f666a64a4cd3834d1fadd590e709379fb7b01004a84415c1df3d490426b83842da8dbd8e9473e789da9
7
+ data.tar.gz: c8750f92698af83e6ef935a9c430695e1bdbc43111bc5c1df6a98aafb16e9fe6c062ee30f83163913bd8febd1bef552824229dc820e5196a9f124dbd88d0d21c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in railway_inspector.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # RailwayInspector
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/railway_inspector`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'railway_inspector'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install railway_inspector
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/railway_inspector.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "railway_inspector"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "railway_inspector/version"
2
+ require "railway_inspector/runner"
3
+
4
+ module RailwayInspector
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,29 @@
1
+ module RailwayInspector
2
+ class Routes
3
+
4
+ def initialize
5
+ @routes = Rails.application.routes.routes
6
+ end
7
+
8
+ def all_routes
9
+ @routes.to_a.map { |route|
10
+ {
11
+ verbs: verbs_for(route),
12
+ path: path_for(route),
13
+ action: route.defaults[:action],
14
+ controller: route.defaults[:controller],
15
+ }
16
+ }
17
+ end
18
+
19
+ private def verbs_for route
20
+ route.verb.source.to_s.gsub("^","").gsub("$","").downcase.split('|')
21
+ end
22
+
23
+ private def path_for route
24
+ route.path.spec.to_s.gsub('(.:format)', '')
25
+ end
26
+
27
+ end
28
+ end
29
+
@@ -0,0 +1,61 @@
1
+ require 'railway_inspector/routes'
2
+ require 'httparty'
3
+ require 'factory_girl'
4
+
5
+ module RailwayInspector
6
+ class Runner
7
+
8
+ def initialize
9
+ @all_routes = RailwayInspector::Routes.new.all_routes
10
+ @ok = []
11
+ @bad = []
12
+ @not_run = []
13
+ end
14
+
15
+ def handle_response response, route
16
+ if response.code == 200
17
+ @ok << response
18
+ puts Term::ANSIColor.green + "OK: #{route[:path]}"
19
+ else
20
+ @bad << response
21
+ puts Term::ANSIColor.red + "Broken: #{route[:path]} with code #{response.code} #{response.message}"
22
+ end
23
+ end
24
+
25
+ def handle_path_error path, route
26
+ @not_run << route
27
+ puts Term::ANSIColor.yellow + "NA: #{route[:path]} could not run because: #{path[:error].message}"
28
+ end
29
+
30
+ def create_path route
31
+ if route[:path].match(/.*\/:id/)
32
+ begin
33
+ model = FactoryGirl.create(route[:controller].gsub(/s$/, '').to_sym)
34
+ { path: 'http://localhost:3000' + route[:path].gsub(':id', model.id.to_s) }
35
+ rescue => e
36
+ { error: e }
37
+ end
38
+ else
39
+ { path: 'http://localhost:3000' + route[:path] }
40
+ end
41
+ end
42
+
43
+ def run
44
+ FactoryGirl.find_definitions
45
+ @all_routes.each do|route|
46
+ next unless route[:verbs].include? 'get'
47
+ path = create_path(route)
48
+ if path[:error]
49
+ handle_path_error(path, route)
50
+ else
51
+ response = HTTParty.get(path[:path])
52
+ handle_response(response, route)
53
+ end
54
+ end
55
+
56
+ puts Term::ANSIColor.yellow + "There are #{@not_run.length} routes we could not test"
57
+ puts Term::ANSIColor.red + "There are #{@bad.length} broken routes"
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,3 @@
1
+ module RailwayInspector
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'railway_inspector/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "railway_inspector"
8
+ spec.version = RailwayInspector::VERSION
9
+ spec.authors = ["Richard Vickerstaff"]
10
+ spec.email = ["richardiv.rv@googlemail.com"]
11
+
12
+ spec.summary = %q{Test rails routes}
13
+ spec.description = %q{Test every route in your routes file.}
14
+ spec.homepage = "https://github.com/RichardVickerstaff/railway_inspector"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "httparty"
24
+ spec.add_runtime_dependency "term-ansicolor"
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railway_inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Vickerstaff
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: term-ansicolor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Test every route in your routes file.
84
+ email:
85
+ - richardiv.rv@googlemail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/railway_inspector.rb
99
+ - lib/railway_inspector/routes.rb
100
+ - lib/railway_inspector/runner.rb
101
+ - lib/railway_inspector/version.rb
102
+ - railway_inspector.gemspec
103
+ homepage: https://github.com/RichardVickerstaff/railway_inspector
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.8
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Test rails routes
126
+ test_files: []