code_metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +33 -0
- data/bin/code_metrics +22 -0
- data/bin/code_metrics-profile +15 -0
- data/lib/code_metrics.rb +10 -0
- data/lib/code_metrics/profiler.rb +96 -0
- data/lib/code_metrics/railtie.rb +11 -0
- data/lib/code_metrics/statistics.rb +106 -0
- data/lib/code_metrics/statistics_calculator.rb +81 -0
- data/lib/code_metrics/stats_directories.rb +28 -0
- data/lib/code_metrics/version.rb +3 -0
- data/lib/tasks/statistics.rake +14 -0
- data/test/active_support_testing_isolation.rb +136 -0
- data/test/code_metrics_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +309 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/isolation_abstract_unit.rb +287 -0
- data/test/rake_test.rb +15 -0
- data/test/statistics_calculator_test.rb +288 -0
- data/test/test_helper.rb +15 -0
- metadata +177 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,287 @@
|
|
1
|
+
# # Note:
|
2
|
+
# # It is important to keep this file as light as possible
|
3
|
+
# # the goal for tests that require this is to test booting up
|
4
|
+
# # rails from an empty state, so anything added here could
|
5
|
+
# # hide potential failures
|
6
|
+
# #
|
7
|
+
# # It is also good to know what is the bare minimum to get
|
8
|
+
# # Rails booted up.
|
9
|
+
# require 'fileutils'
|
10
|
+
#
|
11
|
+
# require 'bundler/setup' unless defined?(Bundler)
|
12
|
+
# require 'active_support/testing/autorun'
|
13
|
+
# require 'active_support/test_case'
|
14
|
+
#
|
15
|
+
# RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
|
16
|
+
#
|
17
|
+
# # These files do not require any others and are needed
|
18
|
+
# # to run the tests
|
19
|
+
# require "active_support/testing/isolation"
|
20
|
+
# require "active_support/core_ext/kernel/reporting"
|
21
|
+
# require 'tmpdir'
|
22
|
+
#
|
23
|
+
# module TestHelpers
|
24
|
+
# module Paths
|
25
|
+
# def app_template_path
|
26
|
+
# File.join Dir.tmpdir, 'app_template'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def tmp_path(*args)
|
30
|
+
# @tmp_path ||= File.realpath(Dir.mktmpdir)
|
31
|
+
# File.join(@tmp_path, *args)
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# def app_path(*args)
|
35
|
+
# tmp_path(*%w[app] + args)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def framework_path
|
39
|
+
# RAILS_FRAMEWORK_ROOT
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# def rails_root
|
43
|
+
# app_path
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# module Rack
|
48
|
+
# def app(env = "production")
|
49
|
+
# old_env = ENV["RAILS_ENV"]
|
50
|
+
# @app ||= begin
|
51
|
+
# ENV["RAILS_ENV"] = env
|
52
|
+
# require "#{app_path}/config/environment"
|
53
|
+
# Rails.application
|
54
|
+
# end
|
55
|
+
# ensure
|
56
|
+
# ENV["RAILS_ENV"] = old_env
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# def extract_body(response)
|
60
|
+
# "".tap do |body|
|
61
|
+
# response[2].each {|chunk| body << chunk }
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# def get(path)
|
66
|
+
# @app.call(::Rack::MockRequest.env_for(path))
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# def assert_welcome(resp)
|
70
|
+
# assert_equal 200, resp[0]
|
71
|
+
# assert resp[1]["Content-Type"] = "text/html"
|
72
|
+
# assert extract_body(resp).match(/Welcome aboard/)
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# def assert_success(resp)
|
76
|
+
# assert_equal 202, resp[0]
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# def assert_missing(resp)
|
80
|
+
# assert_equal 404, resp[0]
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def assert_header(key, value, resp)
|
84
|
+
# assert_equal value, resp[1][key.to_s]
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# def assert_body(expected, resp)
|
88
|
+
# assert_equal expected, extract_body(resp)
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# module Generation
|
93
|
+
# # Build an application by invoking the generator and going through the whole stack.
|
94
|
+
# def build_app(options = {})
|
95
|
+
# @prev_rails_env = ENV['RAILS_ENV']
|
96
|
+
# ENV['RAILS_ENV'] = 'development'
|
97
|
+
#
|
98
|
+
# FileUtils.rm_rf(app_path)
|
99
|
+
# FileUtils.cp_r(app_template_path, app_path)
|
100
|
+
#
|
101
|
+
# # Delete the initializers unless requested
|
102
|
+
# unless options[:initializers]
|
103
|
+
# Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
|
104
|
+
# File.delete(initializer)
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# gemfile_path = "#{app_path}/Gemfile"
|
109
|
+
# if options[:gemfile].blank? && File.exist?(gemfile_path)
|
110
|
+
# File.delete gemfile_path
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# routes = File.read("#{app_path}/config/routes.rb")
|
114
|
+
# if routes =~ /(\n\s*end\s*)\Z/
|
115
|
+
# File.open("#{app_path}/config/routes.rb", 'w') do |f|
|
116
|
+
# f.puts $` + "\nmatch ':controller(/:action(/:id))(.:format)', via: :all\n" + $1
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# add_to_config <<-RUBY
|
121
|
+
# config.eager_load = false
|
122
|
+
# config.secret_key_base = "3b7cd727ee24e8444053437c36cc66c4"
|
123
|
+
# config.session_store :cookie_store, key: "_myapp_session"
|
124
|
+
# config.active_support.deprecation = :log
|
125
|
+
# config.action_controller.allow_forgery_protection = false
|
126
|
+
# RUBY
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# def teardown_app
|
130
|
+
# ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# # Make a very basic app, without creating the whole directory structure.
|
134
|
+
# # This is faster and simpler than the method above.
|
135
|
+
# def make_basic_app
|
136
|
+
# require "rails"
|
137
|
+
# require "action_controller/railtie"
|
138
|
+
#
|
139
|
+
# app = Class.new(Rails::Application)
|
140
|
+
# app.config.eager_load = false
|
141
|
+
# app.config.secret_key_base = "3b7cd727ee24e8444053437c36cc66c4"
|
142
|
+
# app.config.session_store :cookie_store, key: "_myapp_session"
|
143
|
+
# app.config.active_support.deprecation = :log
|
144
|
+
#
|
145
|
+
# yield app if block_given?
|
146
|
+
# app.initialize!
|
147
|
+
#
|
148
|
+
# app.routes.draw do
|
149
|
+
# get "/" => "omg#index"
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# require 'rack/test'
|
153
|
+
# extend ::Rack::Test::Methods
|
154
|
+
# end
|
155
|
+
#
|
156
|
+
# def simple_controller
|
157
|
+
# controller :foo, <<-RUBY
|
158
|
+
# class FooController < ApplicationController
|
159
|
+
# def index
|
160
|
+
# render text: "foo"
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
# RUBY
|
164
|
+
#
|
165
|
+
# app_file 'config/routes.rb', <<-RUBY
|
166
|
+
# AppTemplate::Application.routes.draw do
|
167
|
+
# get ':controller(/:action)'
|
168
|
+
# end
|
169
|
+
# RUBY
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# class Bukkit
|
173
|
+
# attr_reader :path
|
174
|
+
#
|
175
|
+
# def initialize(path)
|
176
|
+
# @path = path
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
# def write(file, string)
|
180
|
+
# path = "#{@path}/#{file}"
|
181
|
+
# FileUtils.mkdir_p(File.dirname(path))
|
182
|
+
# File.open(path, "w") {|f| f.puts string }
|
183
|
+
# end
|
184
|
+
#
|
185
|
+
# def delete(file)
|
186
|
+
# File.delete("#{@path}/#{file}")
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
#
|
190
|
+
# def engine(name)
|
191
|
+
# dir = "#{app_path}/random/#{name}"
|
192
|
+
# FileUtils.mkdir_p(dir)
|
193
|
+
#
|
194
|
+
# app = File.readlines("#{app_path}/config/application.rb")
|
195
|
+
# app.insert(2, "$:.unshift(\"#{dir}/lib\")")
|
196
|
+
# app.insert(3, "require #{name.inspect}")
|
197
|
+
#
|
198
|
+
# File.open("#{app_path}/config/application.rb", 'r+') do |f|
|
199
|
+
# f.puts app
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# Bukkit.new(dir).tap do |bukkit|
|
203
|
+
# yield bukkit if block_given?
|
204
|
+
# end
|
205
|
+
# end
|
206
|
+
#
|
207
|
+
# def script(script)
|
208
|
+
# Dir.chdir(app_path) do
|
209
|
+
# `#{Gem.ruby} #{app_path}/bin/rails #{script}`
|
210
|
+
# end
|
211
|
+
# end
|
212
|
+
#
|
213
|
+
# def add_to_config(str)
|
214
|
+
# environment = File.read("#{app_path}/config/application.rb")
|
215
|
+
# if environment =~ /(\n\s*end\s*end\s*)\Z/
|
216
|
+
# File.open("#{app_path}/config/application.rb", 'w') do |f|
|
217
|
+
# f.puts $` + "\n#{str}\n" + $1
|
218
|
+
# end
|
219
|
+
# end
|
220
|
+
# end
|
221
|
+
#
|
222
|
+
# def add_to_env_config(env, str)
|
223
|
+
# environment = File.read("#{app_path}/config/environments/#{env}.rb")
|
224
|
+
# if environment =~ /(\n\s*end\s*)\Z/
|
225
|
+
# File.open("#{app_path}/config/environments/#{env}.rb", 'w') do |f|
|
226
|
+
# f.puts $` + "\n#{str}\n" + $1
|
227
|
+
# end
|
228
|
+
# end
|
229
|
+
# end
|
230
|
+
#
|
231
|
+
# def remove_from_config(str)
|
232
|
+
# file = "#{app_path}/config/application.rb"
|
233
|
+
# contents = File.read(file)
|
234
|
+
# contents.sub!(/#{str}/, "")
|
235
|
+
# File.open(file, "w+") { |f| f.puts contents }
|
236
|
+
# end
|
237
|
+
#
|
238
|
+
# def app_file(path, contents)
|
239
|
+
# FileUtils.mkdir_p File.dirname("#{app_path}/#{path}")
|
240
|
+
# File.open("#{app_path}/#{path}", 'w') do |f|
|
241
|
+
# f.puts contents
|
242
|
+
# end
|
243
|
+
# end
|
244
|
+
#
|
245
|
+
# def remove_file(path)
|
246
|
+
# FileUtils.rm_rf "#{app_path}/#{path}"
|
247
|
+
# end
|
248
|
+
#
|
249
|
+
# def controller(name, contents)
|
250
|
+
# app_file("app/controllers/#{name}_controller.rb", contents)
|
251
|
+
# end
|
252
|
+
#
|
253
|
+
# def use_frameworks(arr)
|
254
|
+
# to_remove = [:actionmailer,
|
255
|
+
# :activerecord] - arr
|
256
|
+
# $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' }
|
257
|
+
# end
|
258
|
+
#
|
259
|
+
# def boot_rails
|
260
|
+
# require File.expand_path('../../../../load_paths', __FILE__)
|
261
|
+
# end
|
262
|
+
# end
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# class ActiveSupport::TestCase
|
266
|
+
# include TestHelpers::Paths
|
267
|
+
# include TestHelpers::Rack
|
268
|
+
# include TestHelpers::Generation
|
269
|
+
# end
|
270
|
+
#
|
271
|
+
# # Create a scope and build a fixture rails app
|
272
|
+
# Module.new do
|
273
|
+
# extend TestHelpers::Paths
|
274
|
+
#
|
275
|
+
# # Build a rails app
|
276
|
+
# FileUtils.rm_rf(app_template_path)
|
277
|
+
# FileUtils.mkdir(app_template_path)
|
278
|
+
#
|
279
|
+
# environment = File.expand_path('../../../../load_paths', __FILE__)
|
280
|
+
# require_environment = "-r #{environment}"
|
281
|
+
#
|
282
|
+
# `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails new #{app_template_path} --skip-gemfile --no-rc`
|
283
|
+
# File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
|
284
|
+
# f.puts "require '#{environment}'"
|
285
|
+
# f.puts "require 'rails/all'"
|
286
|
+
# end
|
287
|
+
# end unless defined?(RAILS_ISOLATED_ENGINE)
|