roundabout 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in roundabout.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Akira Matsuda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Roundabout
2
+
3
+ A Rails Engine that generates a page transition diagram for your Rails app.
4
+
5
+
6
+ ## Requirements
7
+
8
+ - Ruby 1.9 or 2.0
9
+
10
+ - Rails 3 or 4
11
+
12
+ - RSpec 2
13
+
14
+ - Capybara 1 or 2
15
+
16
+
17
+ ## Installation
18
+
19
+ Add this line to your Rails app's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'roundabout'
23
+ ```
24
+
25
+ And execute:
26
+
27
+ ```bash
28
+ % bundle
29
+ ```
30
+
31
+ Then add this line to your `spec/spec\_helper.rb`:
32
+
33
+ ```ruby
34
+ require 'roundabout/rspec'
35
+ ```
36
+
37
+
38
+ ## Usage
39
+
40
+ Firstly, run the whole test (I suppose parallel spec is not supported ATM)
41
+
42
+ ```bash
43
+ % rake spec
44
+ ```
45
+
46
+ Then browse at your `http://localhost:3000/roundabout`
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_self
3
+ *= require_tree .
4
+ */
@@ -0,0 +1,5 @@
1
+ module Roundabout
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'pp'
2
+ require 'roundabout/application_controller'
3
+ require 'graphviz'
4
+
5
+ module Roundabout
6
+ class RoundaboutController < ::Roundabout::ApplicationController
7
+ def index
8
+ if (json = Rails.root.join('doc/roundabout.json')).exist?
9
+ transitions = ActiveSupport::JSON.decode json.read
10
+ GraphViz.new(:G, type: :digraph, rankdir: 'LR') {|g|
11
+ transitions.each do |t|
12
+ from = g.add_nodes t['from'], shape: 'box'
13
+ to = g.add_nodes t['to'], shape: 'box'
14
+ color = case t['type']
15
+ when 'redirect'
16
+ 'red'
17
+ when 'form'
18
+ 'purple'
19
+ else
20
+ 'blue'
21
+ end
22
+ g.add_edges from, to, color: color
23
+ end
24
+ }.output(png: Rails.root.join('public/images/roundabout.png'))
25
+ else
26
+ render 'readme'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Transition Diagram</title>
6
+ <%= stylesheet_link_tag 'roundabout/application', :media => 'all' %>
7
+ <%= javascript_include_tag 'roundabout/application' %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,2 @@
1
+ <%- pp @transitions %>
2
+ <%= image_tag '/images/roundabout.png' %>
@@ -0,0 +1,15 @@
1
+ <p>You need to generate the page transition data first.</p>
2
+
3
+ Add this line to your <strong>spec/spec_helper.rb</strong>:
4
+
5
+ <pre>
6
+ require 'roundabout/rspec'
7
+ </pre>
8
+
9
+ And run the specs.
10
+
11
+ <pre>
12
+ % rake spec
13
+ </pre>
14
+
15
+ Then reload this page.
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Roundabout::Engine.routes.draw do
2
+ get '/' => 'roundabout#index'
3
+ root :to => 'roundabout#index'
4
+ end
@@ -0,0 +1,5 @@
1
+ module Roundabout
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Roundabout
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module ActionController
2
+ module Redirecting
3
+ def redirect_to_with_recording(options = {}, response_status = {})
4
+ redirect_to_without_recording options, response_status
5
+ begin
6
+ h = @_request.env['action_dispatch.request.path_parameters'].with_indifferent_access
7
+ Roundabout.record_transition "#{h[:controller]}##{h[:action]}", Roundabout.normalize_url(self.location), :get, :redirect
8
+ rescue => e
9
+ p e
10
+ end
11
+ end
12
+ alias_method_chain :redirect_to, :recording
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require 'capybara'
2
+
3
+ class Capybara::RackTest::Browser
4
+ def follow_with_recording(method, path, attributes = {})
5
+ return if path.gsub(/^#{request_path}/, '').start_with?('#')
6
+ begin
7
+ Roundabout.record_transition Roundabout.normalize_url(URI.parse(driver.current_url).path), Roundabout.normalize_url(path), method, :link
8
+ rescue => e
9
+ p e
10
+ end
11
+
12
+ follow_without_recording method, path, attributes
13
+ end
14
+ alias_method_chain :follow, :recording
15
+
16
+ def submit_with_recording(method, path, attributes)
17
+ begin
18
+ p = (path.nil? || path.empty?) ? request_path : path
19
+ m = attributes['_method'] || method
20
+ Roundabout.record_transition Roundabout.normalize_url(URI.parse(driver.current_url).path), Roundabout.normalize_url(p, m), m, :form
21
+ rescue => e
22
+ p e
23
+ end
24
+
25
+ submit_without_recording method, path, attributes
26
+ end
27
+ alias_method_chain :submit, :recording
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails'
2
+ require 'roundabout/engine'
3
+
4
+ module Roundabout
5
+ class Railtie < ::Rails::Railtie #:nodoc:
6
+ initializer 'roundabout' do |app|
7
+ ActiveSupport.on_load(:action_controller) do
8
+ require 'roundabout/monkey/action_controller'
9
+ end
10
+ ActiveSupport.on_load(:after_initialize) do
11
+ if Rails.env.development?
12
+ Rails.application.routes.append do
13
+ mount Roundabout::Engine, :at => '/roundabout'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'set'
2
+
3
+ module Roundabout
4
+ class Recorder
5
+ attr_reader :transitions
6
+
7
+ def initialize
8
+ @transitions = Set.new
9
+ end
10
+
11
+ def record_transition(from, to, method, type)
12
+ @transitions << {from: from, to: to, method: method, type: type}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.after :suite do
3
+ transitions = Roundabout.compile_page_transitions
4
+ Rails.root.join('doc/roundabout.json').open('w') {|f| f.write transitions.to_json} unless transitions.empty?
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Roundabout
2
+ VERSION = "0.0.1"
3
+ end
data/lib/roundabout.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'roundabout/version'
2
+ require 'roundabout/railtie'
3
+ require 'roundabout/recorder'
4
+ require 'roundabout/monkey/capybara'
5
+
6
+ module Roundabout
7
+ def self.record_transition(from, to, method, type)
8
+ recorder.record_transition from, to, method, type
9
+ end
10
+
11
+ def self.recorder
12
+ @recorder ||= Recorder.new
13
+ end
14
+
15
+ def self.compile_page_transitions
16
+ recorder.transitions
17
+ end
18
+
19
+ def self.normalize_url(path, method = nil)
20
+ h = Rails.application.routes.recognize_path(path, method: method)
21
+ "#{h[:controller]}##{h[:action]}"
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'roundabout/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "roundabout"
8
+ gem.version = Roundabout::VERSION
9
+ gem.authors = ["Akira Matsuda"]
10
+ gem.email = ["ronnie@dio.jp"]
11
+ gem.description = 'A Rails Engine that generates a page transition diagram for your Rails app from request specs'
12
+ gem.summary = 'A Rails Engine that generates a page transition diagram for your Rails app from request specs'
13
+ gem.homepage = 'https://github.com/amatsuda/roundabout'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'capybara', ['>= 1.0.0']
21
+ gem.add_runtime_dependency 'rspec', ['>= 2.0.0']
22
+ gem.add_runtime_dependency 'ruby-graphviz', ['>= 1.0.0']
23
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roundabout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Akira Matsuda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-graphviz
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ description: A Rails Engine that generates a page transition diagram for your Rails
63
+ app from request specs
64
+ email:
65
+ - ronnie@dio.jp
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - MIT-LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - app/assets/javascripts/roundabout/application.js
76
+ - app/assets/stylesheets/roundabout/application.css
77
+ - app/controllers/roundabout/application_controller.rb
78
+ - app/controllers/roundabout/roundabout_controller.rb
79
+ - app/views/layouts/roundabout/application.html.erb
80
+ - app/views/roundabout/roundabout/index.html.erb
81
+ - app/views/roundabout/roundabout/readme.html.erb
82
+ - config/routes.rb
83
+ - lib/roundabout.rb
84
+ - lib/roundabout/engine.rb
85
+ - lib/roundabout/monkey/action_controller.rb
86
+ - lib/roundabout/monkey/capybara.rb
87
+ - lib/roundabout/railtie.rb
88
+ - lib/roundabout/recorder.rb
89
+ - lib/roundabout/rspec.rb
90
+ - lib/roundabout/version.rb
91
+ - roundabout.gemspec
92
+ homepage: https://github.com/amatsuda/roundabout
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: A Rails Engine that generates a page transition diagram for your Rails app
116
+ from request specs
117
+ test_files: []