railties 4.0.13 → 4.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +155 -385
- data/README.rdoc +1 -1
- data/bin/rails +1 -1
- data/lib/rails.rb +11 -13
- data/lib/rails/all.rb +1 -0
- data/lib/rails/api/task.rb +9 -12
- data/lib/rails/app_rails_loader.rb +2 -2
- data/lib/rails/application.rb +154 -149
- data/lib/rails/application/configuration.rb +1 -14
- data/lib/rails/application/default_middleware_stack.rb +99 -0
- data/lib/rails/application/finisher.rb +2 -0
- data/lib/rails/application_controller.rb +16 -0
- data/lib/rails/cli.rb +1 -2
- data/lib/rails/commands.rb +2 -94
- data/lib/rails/commands/application.rb +2 -28
- data/lib/rails/commands/commands_tasks.rb +174 -0
- data/lib/rails/commands/console.rb +2 -2
- data/lib/rails/commands/dbconsole.rb +1 -1
- data/lib/rails/commands/plugin.rb +23 -0
- data/lib/rails/commands/runner.rb +1 -1
- data/lib/rails/commands/server.rb +46 -30
- data/lib/rails/configuration.rb +4 -1
- data/lib/rails/console/helpers.rb +6 -0
- data/lib/rails/engine.rb +29 -18
- data/lib/rails/engine/commands.rb +1 -1
- data/lib/rails/engine/railties.rb +0 -8
- data/lib/rails/generators.rb +4 -3
- data/lib/rails/generators/actions.rb +1 -1
- data/lib/rails/generators/active_model.rb +0 -8
- data/lib/rails/generators/app_base.rb +213 -74
- data/lib/rails/generators/base.rb +17 -16
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -3
- data/lib/rails/generators/migration.rb +18 -26
- data/lib/rails/generators/named_base.rb +4 -7
- data/lib/rails/generators/rails/app/app_generator.rb +91 -5
- data/lib/rails/generators/rails/app/templates/Gemfile +20 -15
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -3
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +2 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +7 -10
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +11 -31
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +25 -29
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +8 -10
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +8 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +6 -3
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -22
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +7 -9
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +9 -12
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +8 -8
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +7 -17
- data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/{initializers/secret_token.rb.tt → secrets.yml} +10 -2
- data/lib/rails/generators/rails/app/templates/public/404.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/422.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/500.html +19 -10
- data/lib/rails/generators/rails/controller/USAGE +1 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +35 -1
- data/lib/rails/generators/rails/generator/USAGE +1 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/rails/model/USAGE +5 -5
- data/lib/rails/generators/rails/{plugin_new → plugin}/USAGE +0 -0
- data/lib/rails/generators/rails/{plugin_new/plugin_new_generator.rb → plugin/plugin_generator.rb} +10 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/%name%.gemspec +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Gemfile +16 -1
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/MIT-LICENSE +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/README.rdoc +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Rakefile +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/controllers/%name%/application_controller.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/helpers/%name%/application_helper.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/views/layouts/%name%/application.html.erb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/bin/rails.tt +0 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/config/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/gitignore +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/engine.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/version.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/tasks/%name%_tasks.rake +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/application.rb +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/boot.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/javascripts.js +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/stylesheets.css +5 -3
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/%name%_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/test_helper.rb +0 -0
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/resource_helpers.rb +20 -5
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +26 -0
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb +16 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -1
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb +11 -0
- data/lib/rails/generators/testing/assertions.rb +1 -1
- data/lib/rails/generators/testing/behaviour.rb +3 -13
- data/lib/rails/info.rb +5 -3
- data/lib/rails/info_controller.rb +5 -15
- data/lib/rails/mailers_controller.rb +73 -0
- data/lib/rails/paths.rb +13 -18
- data/lib/rails/rack/debugger.rb +2 -2
- data/lib/rails/rack/logger.rb +1 -1
- data/lib/rails/railtie.rb +38 -2
- data/lib/rails/source_annotation_extractor.rb +2 -2
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/tasks/documentation.rake +0 -5
- data/lib/rails/tasks/engine.rake +1 -1
- data/lib/rails/tasks/framework.rake +2 -12
- data/lib/rails/templates/layouts/application.html.erb +2 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +98 -0
- data/lib/rails/templates/rails/mailers/index.html.erb +8 -0
- data/lib/rails/templates/rails/mailers/mailer.html.erb +6 -0
- data/lib/rails/test_help.rb +4 -1
- data/lib/rails/test_unit/sub_test_task.rb +44 -3
- data/lib/rails/test_unit/testing.rake +9 -111
- data/lib/rails/version.rb +3 -3
- data/lib/rails/welcome_controller.rb +4 -3
- metadata +99 -76
- data/lib/rails/commands/plugin_new.rb +0 -9
- data/lib/rails/generators/actions/create_migration.rb +0 -68
data/lib/rails/rack/debugger.rb
CHANGED
@@ -12,8 +12,8 @@ module Rails
|
|
12
12
|
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
|
13
13
|
puts "=> Debugger enabled"
|
14
14
|
rescue LoadError
|
15
|
-
puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle
|
16
|
-
exit
|
15
|
+
puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again."
|
16
|
+
exit(1)
|
17
17
|
end
|
18
18
|
|
19
19
|
def call(env)
|
data/lib/rails/rack/logger.rb
CHANGED
data/lib/rails/railtie.rb
CHANGED
@@ -112,7 +112,6 @@ module Rails
|
|
112
112
|
# Be sure to look at the documentation of those specific classes for more information.
|
113
113
|
#
|
114
114
|
class Railtie
|
115
|
-
autoload :Configurable, "rails/railtie/configurable"
|
116
115
|
autoload :Configuration, "rails/railtie/configuration"
|
117
116
|
|
118
117
|
include Initializable
|
@@ -121,6 +120,7 @@ module Rails
|
|
121
120
|
|
122
121
|
class << self
|
123
122
|
private :new
|
123
|
+
delegate :config, to: :instance
|
124
124
|
|
125
125
|
def subclasses
|
126
126
|
@subclasses ||= []
|
@@ -128,7 +128,6 @@ module Rails
|
|
128
128
|
|
129
129
|
def inherited(base)
|
130
130
|
unless base.abstract_railtie?
|
131
|
-
base.send(:include, Railtie::Configurable)
|
132
131
|
subclasses << base
|
133
132
|
end
|
134
133
|
end
|
@@ -166,14 +165,51 @@ module Rails
|
|
166
165
|
@railtie_name ||= generate_railtie_name(self.name)
|
167
166
|
end
|
168
167
|
|
168
|
+
# Since Rails::Railtie cannot be instantiated, any methods that call
|
169
|
+
# +instance+ are intended to be called only on subclasses of a Railtie.
|
170
|
+
def instance
|
171
|
+
@instance ||= new
|
172
|
+
end
|
173
|
+
|
174
|
+
def respond_to_missing?(*args)
|
175
|
+
instance.respond_to?(*args) || super
|
176
|
+
end
|
177
|
+
|
178
|
+
# Allows you to configure the railtie. This is the same method seen in
|
179
|
+
# Railtie::Configurable, but this module is no longer required for all
|
180
|
+
# subclasses of Railtie so we provide the class method here.
|
181
|
+
def configure(&block)
|
182
|
+
instance.configure(&block)
|
183
|
+
end
|
184
|
+
|
169
185
|
protected
|
170
186
|
def generate_railtie_name(class_or_module)
|
171
187
|
ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_")
|
172
188
|
end
|
189
|
+
|
190
|
+
# If the class method does not have a method, then send the method call
|
191
|
+
# to the Railtie instance.
|
192
|
+
def method_missing(name, *args, &block)
|
193
|
+
if instance.respond_to?(name)
|
194
|
+
instance.public_send(name, *args, &block)
|
195
|
+
else
|
196
|
+
super
|
197
|
+
end
|
198
|
+
end
|
173
199
|
end
|
174
200
|
|
175
201
|
delegate :railtie_name, to: :class
|
176
202
|
|
203
|
+
def initialize
|
204
|
+
if self.class.abstract_railtie?
|
205
|
+
raise "#{self.class.name} is abstract, you cannot instantiate it directly."
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def configure(&block)
|
210
|
+
instance_eval(&block)
|
211
|
+
end
|
212
|
+
|
177
213
|
def config
|
178
214
|
@config ||= Railtie::Configuration.new
|
179
215
|
end
|
@@ -67,7 +67,7 @@ class SourceAnnotationExtractor
|
|
67
67
|
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
|
68
68
|
# with their annotations. Only files with annotations are included. Files
|
69
69
|
# with extension +.builder+, +.rb+, +.erb+, +.haml+, +.slim+, +.css+,
|
70
|
-
# +.scss+, +.js+, +.coffee+, and +.
|
70
|
+
# +.scss+, +.js+, +.coffee+, +.rake+, +.sass+ and +.less+
|
71
71
|
# are taken into account.
|
72
72
|
def find_in(dir)
|
73
73
|
results = {}
|
@@ -82,7 +82,7 @@ class SourceAnnotationExtractor
|
|
82
82
|
case item
|
83
83
|
when /\.(builder|rb|coffee|rake)$/
|
84
84
|
/#\s*(#{tag}):?\s*(.*)$/
|
85
|
-
when /\.(css|scss|js)$/
|
85
|
+
when /\.(css|scss|sass|less|js)$/
|
86
86
|
/\/\/\s*(#{tag}):?\s*(.*)$/
|
87
87
|
when /\.erb$/
|
88
88
|
/<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/
|
data/lib/rails/tasks.rb
CHANGED
@@ -44,11 +44,6 @@ else
|
|
44
44
|
end
|
45
45
|
|
46
46
|
namespace :doc do
|
47
|
-
def gem_path(gem_name)
|
48
|
-
path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first
|
49
|
-
yield File.dirname(path) if path
|
50
|
-
end
|
51
|
-
|
52
47
|
RDocTaskWithoutDescriptions.new("app") { |rdoc|
|
53
48
|
rdoc.rdoc_dir = 'doc/app'
|
54
49
|
rdoc.template = ENV['template'] if ENV['template']
|
data/lib/rails/tasks/engine.rake
CHANGED
@@ -26,7 +26,7 @@ namespace :db do
|
|
26
26
|
desc "Display status of migrations"
|
27
27
|
app_task "migrate:status"
|
28
28
|
|
29
|
-
desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all
|
29
|
+
desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)'
|
30
30
|
app_task "create"
|
31
31
|
app_task "create:all"
|
32
32
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :rails do
|
2
|
-
desc "Update configs and some other initially generated files (or use just update:configs
|
3
|
-
task update: [ "update:configs", "update:bin"
|
2
|
+
desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
|
3
|
+
task update: [ "update:configs", "update:bin" ]
|
4
4
|
|
5
5
|
desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
|
6
6
|
task :template do
|
@@ -62,15 +62,5 @@ namespace :rails do
|
|
62
62
|
task :bin do
|
63
63
|
invoke_from_app_generator :create_bin_files
|
64
64
|
end
|
65
|
-
|
66
|
-
# desc "Rename application.rb to application_controller.rb"
|
67
|
-
task :application_controller do
|
68
|
-
old_style = Rails.root + '/app/controllers/application.rb'
|
69
|
-
new_style = Rails.root + '/app/controllers/application_controller.rb'
|
70
|
-
if File.exist?(old_style) && !File.exist?(new_style)
|
71
|
-
FileUtils.mv(old_style, new_style)
|
72
|
-
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
|
73
|
-
end
|
74
|
-
end
|
75
65
|
end
|
76
66
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8" />
|
5
|
-
<title
|
5
|
+
<title><%= @page_title %></title>
|
6
6
|
<style>
|
7
7
|
body { background-color: #fff; color: #333; }
|
8
8
|
|
@@ -29,7 +29,7 @@
|
|
29
29
|
</style>
|
30
30
|
</head>
|
31
31
|
<body>
|
32
|
-
|
32
|
+
|
33
33
|
<%= yield %>
|
34
34
|
|
35
35
|
</body>
|
@@ -0,0 +1,98 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html><head>
|
3
|
+
<meta name="viewport" content="width=device-width" />
|
4
|
+
<style type="text/css">
|
5
|
+
header {
|
6
|
+
width: 100%;
|
7
|
+
padding: 10px 0 0 0;
|
8
|
+
margin: 0;
|
9
|
+
background: white;
|
10
|
+
font: 12px "Lucida Grande", sans-serif;
|
11
|
+
border-bottom: 1px solid #dedede;
|
12
|
+
overflow: hidden;
|
13
|
+
}
|
14
|
+
|
15
|
+
dl {
|
16
|
+
margin: 0 0 10px 0;
|
17
|
+
padding: 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
dt {
|
21
|
+
width: 80px;
|
22
|
+
padding: 1px;
|
23
|
+
float: left;
|
24
|
+
clear: left;
|
25
|
+
text-align: right;
|
26
|
+
color: #7f7f7f;
|
27
|
+
}
|
28
|
+
|
29
|
+
dd {
|
30
|
+
margin-left: 90px; /* 80px + 10px */
|
31
|
+
padding: 1px;
|
32
|
+
}
|
33
|
+
|
34
|
+
iframe {
|
35
|
+
border: 0;
|
36
|
+
width: 100%;
|
37
|
+
height: 800px;
|
38
|
+
}
|
39
|
+
</style>
|
40
|
+
</head>
|
41
|
+
|
42
|
+
<body>
|
43
|
+
<header>
|
44
|
+
<dl>
|
45
|
+
<% if @email.respond_to?(:smtp_envelope_from) && Array(@email.from) != Array(@email.smtp_envelope_from) %>
|
46
|
+
<dt>SMTP-From:</dt>
|
47
|
+
<dd><%= @email.smtp_envelope_from %></dd>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
<% if @email.respond_to?(:smtp_envelope_to) && @email.to != @email.smtp_envelope_to %>
|
51
|
+
<dt>SMTP-To:</dt>
|
52
|
+
<dd><%= @email.smtp_envelope_to %></dd>
|
53
|
+
<% end %>
|
54
|
+
|
55
|
+
<dt>From:</dt>
|
56
|
+
<dd><%= @email.header['from'] %></dd>
|
57
|
+
|
58
|
+
<% if @email.reply_to %>
|
59
|
+
<dt>Reply-To:</dt>
|
60
|
+
<dd><%= @email.header['reply-to'] %></dd>
|
61
|
+
<% end %>
|
62
|
+
|
63
|
+
<dt>To:</dt>
|
64
|
+
<dd><%= @email.header['to'] %></dd>
|
65
|
+
|
66
|
+
<% if @email.cc %>
|
67
|
+
<dt>CC:</dt>
|
68
|
+
<dd><%= @email.header['cc'] %></dd>
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
<dt>Date:</dt>
|
72
|
+
<dd><%= Time.current.rfc2822 %></dd>
|
73
|
+
|
74
|
+
<dt>Subject:</dt>
|
75
|
+
<dd><strong><%= @email.subject %></strong></dd>
|
76
|
+
|
77
|
+
<% unless @email.attachments.nil? || @email.attachments.empty? %>
|
78
|
+
<dt>Attachments:</dt>
|
79
|
+
<dd>
|
80
|
+
<%= @email.attachments.map { |a| a.respond_to?(:original_filename) ? a.original_filename : a.filename }.inspect %>
|
81
|
+
</dd>
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
<% if @email.multipart? %>
|
85
|
+
<dd>
|
86
|
+
<select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;">
|
87
|
+
<option <%= request.format == Mime::HTML ? 'selected' : '' %> value="?part=text%2Fhtml">View as HTML email</option>
|
88
|
+
<option <%= request.format == Mime::TEXT ? 'selected' : '' %> value="?part=text%2Fplain">View as plain-text email</option>
|
89
|
+
</select>
|
90
|
+
</dd>
|
91
|
+
<% end %>
|
92
|
+
</dl>
|
93
|
+
</header>
|
94
|
+
|
95
|
+
<iframe seamless name="messageBody" src="?part=<%= Rack::Utils.escape(@part.mime_type) %>"></iframe>
|
96
|
+
|
97
|
+
</body>
|
98
|
+
</html>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% @previews.each do |preview| %>
|
2
|
+
<h3><%= link_to preview.preview_name.titleize, "/rails/mailers/#{preview.preview_name}" %></h3>
|
3
|
+
<ul>
|
4
|
+
<% preview.emails.each do |email| %>
|
5
|
+
<li><%= link_to email, "/rails/mailers/#{preview.preview_name}/#{email}" %></li>
|
6
|
+
<% end %>
|
7
|
+
</ul>
|
8
|
+
<% end %>
|
data/lib/rails/test_help.rb
CHANGED
@@ -6,10 +6,13 @@ require 'active_support/testing/autorun'
|
|
6
6
|
require 'active_support/test_case'
|
7
7
|
require 'action_controller/test_case'
|
8
8
|
require 'action_dispatch/testing/integration'
|
9
|
+
require 'rails/generators/test_case'
|
9
10
|
|
10
11
|
# Config Rails backtrace in tests.
|
11
12
|
require 'rails/backtrace_cleaner'
|
12
|
-
|
13
|
+
if ENV["BACKTRACE"].nil?
|
14
|
+
MiniTest.backtrace_filter = Rails.backtrace_cleaner
|
15
|
+
end
|
13
16
|
|
14
17
|
if defined?(ActiveRecord::Base)
|
15
18
|
class ActiveSupport::TestCase
|
@@ -2,13 +2,53 @@ require 'rake/testtask'
|
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
class TestTask < Rake::TestTask # :nodoc: all
|
5
|
+
# A utility class which is used primarily in "rails/test_unit/testing.rake"
|
6
|
+
# to help define rake tasks corresponding to <tt>rake test</tt>.
|
7
|
+
#
|
8
|
+
# This class takes a TestInfo class and defines the appropriate rake task
|
9
|
+
# based on the information, then invokes it.
|
10
|
+
class TestCreator
|
11
|
+
def initialize(info)
|
12
|
+
@info = info
|
13
|
+
end
|
14
|
+
|
15
|
+
def invoke_rake_task
|
16
|
+
if @info.files.any?
|
17
|
+
create_and_run_single_test
|
18
|
+
reset_application_tasks
|
19
|
+
else
|
20
|
+
Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_and_run_single_test
|
27
|
+
Rails::TestTask.new('test:single') { |t|
|
28
|
+
t.test_files = @info.files
|
29
|
+
}
|
30
|
+
ENV['TESTOPTS'] ||= @info.opts
|
31
|
+
Rake::Task['test:single'].invoke
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset_application_tasks
|
35
|
+
Rake.application.top_level_tasks.replace @info.tasks
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# This is a utility class used by the <tt>TestTask::TestCreator</tt> class.
|
40
|
+
# This class takes a set of test tasks and checks to see if they correspond
|
41
|
+
# to test files (or can be transformed into test files). Calling <tt>files</tt>
|
42
|
+
# provides the set of test files and is used when initializing tests after
|
43
|
+
# a call to <tt>rake test</tt>.
|
5
44
|
class TestInfo
|
6
45
|
def initialize(tasks)
|
7
46
|
@tasks = tasks
|
47
|
+
@files = nil
|
8
48
|
end
|
9
49
|
|
10
50
|
def files
|
11
|
-
@tasks.map { |task|
|
51
|
+
@files ||= @tasks.map { |task|
|
12
52
|
[task, translate(task)].find { |file| test_file?(file) }
|
13
53
|
}.compact
|
14
54
|
end
|
@@ -53,8 +93,9 @@ module Rails
|
|
53
93
|
end
|
54
94
|
end
|
55
95
|
|
56
|
-
def self.
|
57
|
-
TestInfo.new
|
96
|
+
def self.test_creator(tasks)
|
97
|
+
info = TestInfo.new(tasks)
|
98
|
+
TestCreator.new(info)
|
58
99
|
end
|
59
100
|
|
60
101
|
def initialize(name = :test)
|
@@ -1,65 +1,12 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rails/test_unit/sub_test_task'
|
4
|
-
require 'active_support/deprecation'
|
5
|
-
|
6
|
-
TEST_CHANGES_SINCE = Time.now - 600
|
7
|
-
|
8
|
-
# Look up tests for recently modified sources.
|
9
|
-
def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
|
10
|
-
FileList[source_pattern].map do |path|
|
11
|
-
if File.mtime(path) > touched_since
|
12
|
-
tests = []
|
13
|
-
source_dir = File.dirname(path).split("/")
|
14
|
-
source_file = File.basename(path, '.rb')
|
15
|
-
|
16
|
-
# Support subdirs in app/models and app/controllers
|
17
|
-
modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path
|
18
|
-
|
19
|
-
# For modified files in app/ run the tests for it. ex. /test/controllers/account_controller.rb
|
20
|
-
test = "#{modified_test_path}/#{source_file}_test.rb"
|
21
|
-
tests.push test if File.exist?(test)
|
22
|
-
|
23
|
-
# For modified files in app, run tests in subdirs too. ex. /test/controllers/account/*_test.rb
|
24
|
-
test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"
|
25
|
-
FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test)
|
26
|
-
|
27
|
-
return tests
|
28
|
-
|
29
|
-
end
|
30
|
-
end.flatten.compact
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
# Recreated here from Active Support because :uncommitted needs it before Rails is available
|
35
|
-
module Kernel
|
36
|
-
remove_method :silence_stderr # Removing old method to prevent method redefined warning
|
37
|
-
def silence_stderr
|
38
|
-
old_stderr = STDERR.dup
|
39
|
-
STDERR.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
40
|
-
STDERR.sync = true
|
41
|
-
yield
|
42
|
-
ensure
|
43
|
-
STDERR.reopen(old_stderr)
|
44
|
-
end
|
45
|
-
end
|
46
4
|
|
47
5
|
task default: :test
|
48
6
|
|
49
|
-
desc 'Runs test:units, test:functionals, test:integration together'
|
7
|
+
desc 'Runs test:units, test:functionals, test:generators, test:integration together'
|
50
8
|
task :test do
|
51
|
-
|
52
|
-
if info.files.any?
|
53
|
-
Rails::TestTask.new('test:single') { |t|
|
54
|
-
t.test_files = info.files
|
55
|
-
}
|
56
|
-
ENV['TESTOPTS'] ||= info.opts
|
57
|
-
Rake.application.top_level_tasks.replace info.tasks
|
58
|
-
|
59
|
-
Rake::Task['test:single'].invoke
|
60
|
-
else
|
61
|
-
Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke
|
62
|
-
end
|
9
|
+
Rails::TestTask.test_creator(Rake.application.top_level_tasks).invoke_rake_task
|
63
10
|
end
|
64
11
|
|
65
12
|
namespace :test do
|
@@ -67,7 +14,7 @@ namespace :test do
|
|
67
14
|
# Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
|
68
15
|
end
|
69
16
|
|
70
|
-
task :run => ['test:units', 'test:functionals', 'test:integration']
|
17
|
+
task :run => ['test:units', 'test:functionals', 'test:generators', 'test:integration']
|
71
18
|
|
72
19
|
# Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html
|
73
20
|
desc "Run tests quickly by merging all types and not resetting db"
|
@@ -80,72 +27,23 @@ namespace :test do
|
|
80
27
|
task :db => %w[db:test:prepare test:all]
|
81
28
|
end
|
82
29
|
|
83
|
-
# Display deprecation message
|
84
|
-
task :deprecated do
|
85
|
-
ActiveSupport::Deprecation.warn "`rake #{ARGV.first}` is deprecated with no replacement."
|
86
|
-
end
|
87
|
-
|
88
|
-
Rake::TestTask.new(recent: ["test:deprecated", "test:prepare"]) do |t|
|
89
|
-
since = TEST_CHANGES_SINCE
|
90
|
-
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
|
91
|
-
recent_tests('app/models/**/*.rb', 'test/models', since) +
|
92
|
-
recent_tests('app/models/**/*.rb', 'test/unit', since) +
|
93
|
-
recent_tests('app/controllers/**/*.rb', 'test/controllers', since) +
|
94
|
-
recent_tests('app/controllers/**/*.rb', 'test/functional', since)
|
95
|
-
|
96
|
-
t.test_files = touched.uniq
|
97
|
-
end
|
98
|
-
Rake::Task['test:recent'].comment = "Deprecated; Test recent changes"
|
99
|
-
|
100
|
-
Rake::TestTask.new(uncommitted: ["test:deprecated", "test:prepare"]) do |t|
|
101
|
-
def t.file_list
|
102
|
-
if File.directory?(".svn")
|
103
|
-
changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] }
|
104
|
-
elsif system "git rev-parse --git-dir 2>&1 >/dev/null"
|
105
|
-
changed_since_checkin = silence_stderr { `git ls-files --modified --others --exclude-standard` }.split.map { |path| path.chomp }
|
106
|
-
else
|
107
|
-
abort "Not a Subversion or Git checkout."
|
108
|
-
end
|
109
|
-
|
110
|
-
models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
|
111
|
-
controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
|
112
|
-
|
113
|
-
unit_tests = models.map { |model| "test/models/#{File.basename(model, '.rb')}_test.rb" } +
|
114
|
-
models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" } +
|
115
|
-
functional_tests = controllers.map { |controller| "test/controllers/#{File.basename(controller, '.rb')}_test.rb" } +
|
116
|
-
controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }
|
117
|
-
(unit_tests + functional_tests).uniq.select { |file| File.exist?(file) }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
Rake::Task['test:uncommitted'].comment = "Deprecated; Test changes since last checkin (only Subversion and Git)"
|
121
|
-
|
122
30
|
Rails::TestTask.new(single: "test:prepare")
|
123
31
|
|
124
|
-
|
125
|
-
|
32
|
+
["models", "helpers", "controllers", "mailers", "integration"].each do |name|
|
33
|
+
Rails::TestTask.new(name => "test:prepare") do |t|
|
34
|
+
t.pattern = "test/#{name}/**/*_test.rb"
|
35
|
+
end
|
126
36
|
end
|
127
37
|
|
128
|
-
Rails::TestTask.new(
|
129
|
-
t.pattern =
|
38
|
+
Rails::TestTask.new(generators: "test:prepare") do |t|
|
39
|
+
t.pattern = "test/lib/generators/**/*_test.rb"
|
130
40
|
end
|
131
41
|
|
132
42
|
Rails::TestTask.new(units: "test:prepare") do |t|
|
133
43
|
t.pattern = 'test/{models,helpers,unit}/**/*_test.rb'
|
134
44
|
end
|
135
45
|
|
136
|
-
Rails::TestTask.new(controllers: "test:prepare") do |t|
|
137
|
-
t.pattern = 'test/controllers/**/*_test.rb'
|
138
|
-
end
|
139
|
-
|
140
|
-
Rails::TestTask.new(mailers: "test:prepare") do |t|
|
141
|
-
t.pattern = 'test/mailers/**/*_test.rb'
|
142
|
-
end
|
143
|
-
|
144
46
|
Rails::TestTask.new(functionals: "test:prepare") do |t|
|
145
47
|
t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb'
|
146
48
|
end
|
147
|
-
|
148
|
-
Rails::TestTask.new(integration: "test:prepare") do |t|
|
149
|
-
t.pattern = 'test/integration/**/*_test.rb'
|
150
|
-
end
|
151
49
|
end
|