railties 4.2.11.3 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +262 -206
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1 -1
  5. data/{bin → exe}/rails +0 -0
  6. data/lib/rails.rb +19 -1
  7. data/lib/rails/all.rb +10 -9
  8. data/lib/rails/api/task.rb +7 -14
  9. data/lib/rails/{app_rails_loader.rb → app_loader.rb} +4 -3
  10. data/lib/rails/application.rb +31 -41
  11. data/lib/rails/application/bootstrap.rb +1 -14
  12. data/lib/rails/application/configuration.rb +94 -95
  13. data/lib/rails/application/default_middleware_stack.rb +30 -16
  14. data/lib/rails/application/finisher.rb +11 -2
  15. data/lib/rails/application/routes_reloader.rb +1 -3
  16. data/lib/rails/application_controller.rb +1 -1
  17. data/lib/rails/cli.rb +2 -2
  18. data/lib/rails/code_statistics.rb +6 -8
  19. data/lib/rails/code_statistics_calculator.rb +8 -1
  20. data/lib/rails/command.rb +70 -0
  21. data/lib/rails/commands.rb +5 -3
  22. data/lib/rails/commands/commands_tasks.rb +25 -14
  23. data/lib/rails/commands/console.rb +7 -52
  24. data/lib/rails/commands/console_helper.rb +34 -0
  25. data/lib/rails/commands/dbconsole.rb +59 -78
  26. data/lib/rails/commands/dev_cache.rb +21 -0
  27. data/lib/rails/commands/plugin.rb +1 -1
  28. data/lib/rails/commands/rake_proxy.rb +34 -0
  29. data/lib/rails/commands/runner.rb +0 -1
  30. data/lib/rails/commands/server.rb +29 -36
  31. data/lib/rails/commands/test.rb +9 -0
  32. data/lib/rails/configuration.rb +21 -5
  33. data/lib/rails/console/app.rb +5 -0
  34. data/lib/rails/console/helpers.rb +1 -1
  35. data/lib/rails/engine.rb +68 -58
  36. data/lib/rails/engine/commands.rb +4 -2
  37. data/lib/rails/engine/configuration.rb +4 -10
  38. data/lib/rails/gem_version.rb +4 -4
  39. data/lib/rails/generators.rb +30 -7
  40. data/lib/rails/generators/.named_base.rb.swp +0 -0
  41. data/lib/rails/generators/actions.rb +19 -5
  42. data/lib/rails/generators/app_base.rb +65 -45
  43. data/lib/rails/generators/base.rb +6 -6
  44. data/lib/rails/generators/erb/mailer/mailer_generator.rb +5 -8
  45. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +9 -7
  46. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  47. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
  48. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  49. data/lib/rails/generators/generated_attribute.rb +5 -1
  50. data/lib/rails/generators/migration.rb +7 -7
  51. data/lib/rails/generators/named_base.rb +21 -5
  52. data/lib/rails/generators/rails/app/USAGE +0 -1
  53. data/lib/rails/generators/rails/app/app_generator.rb +75 -11
  54. data/lib/rails/generators/rails/app/templates/Gemfile +17 -13
  55. data/lib/rails/generators/rails/app/templates/{README.rdoc → README.md} +1 -5
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +7 -0
  57. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +11 -0
  59. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -3
  60. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +5 -0
  62. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +3 -1
  63. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb +2 -0
  64. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb +4 -0
  65. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb +3 -0
  66. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +20 -17
  67. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
  68. data/lib/rails/generators/{erb/mailer/templates/layout.text.erb → rails/app/templates/app/views/layouts/mailer.text.erb.tt} +0 -0
  69. data/lib/rails/generators/rails/app/templates/bin/setup +17 -12
  70. data/lib/rails/generators/rails/app/templates/bin/update +28 -0
  71. data/lib/rails/generators/rails/app/templates/config.ru.tt +11 -0
  72. data/lib/rails/generators/rails/app/templates/config/application.rb +9 -14
  73. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +20 -3
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +18 -11
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -3
  78. data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +5 -0
  79. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +6 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +5 -0
  81. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb +16 -0
  83. data/lib/rails/generators/rails/app/templates/config/initializers/request_forgery_protection.rb +4 -0
  84. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  85. data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +9 -0
  86. data/lib/rails/generators/rails/app/templates/config/routes.rb +3 -53
  87. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +3 -3
  88. data/lib/rails/generators/rails/app/templates/gitignore +7 -1
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +6 -4
  90. data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
  91. data/lib/rails/generators/rails/model/USAGE +6 -1
  92. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  93. data/lib/rails/generators/rails/plugin/plugin_generator.rb +88 -35
  94. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +6 -9
  95. data/lib/rails/generators/rails/plugin/templates/Gemfile +3 -7
  96. data/lib/rails/generators/rails/plugin/templates/README.md +3 -0
  97. data/lib/rails/generators/rails/plugin/templates/Rakefile +2 -2
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
  101. data/lib/rails/generators/rails/plugin/templates/app/models/application_record.rb.tt +6 -0
  102. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +14 -0
  103. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +8 -0
  105. data/lib/rails/generators/rails/plugin/templates/config/routes.rb +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/gitignore +2 -3
  107. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb +5 -0
  108. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb +7 -0
  109. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb +1 -0
  110. data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%name%_tasks.rake → %namespaced_name%_tasks.rake} +1 -1
  111. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +3 -3
  112. data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js +11 -0
  113. data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js +6 -0
  114. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
  115. data/lib/rails/generators/rails/plugin/templates/rails/routes.rb +1 -2
  116. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +3 -3
  117. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb +7 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +4 -2
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +0 -1
  120. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -1
  121. data/lib/rails/generators/rails/scaffold/USAGE +1 -1
  122. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
  123. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +35 -7
  124. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +4 -1
  125. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb +61 -0
  126. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  127. data/lib/rails/generators/resource_helpers.rb +3 -3
  128. data/lib/rails/generators/test_unit/controller/templates/.functional_test.rb.swp +0 -0
  129. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +3 -5
  130. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -3
  131. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +2 -2
  132. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +4 -4
  133. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  134. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -0
  135. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
  136. data/lib/rails/generators/test_unit/scaffold/templates/.api_functional_test.rb.swp +0 -0
  137. data/lib/rails/generators/test_unit/scaffold/templates/.functional_test.rb.swp +0 -0
  138. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +44 -0
  139. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +14 -14
  140. data/lib/rails/generators/testing/assertions.rb +0 -2
  141. data/lib/rails/generators/testing/behaviour.rb +4 -17
  142. data/lib/rails/info.rb +2 -2
  143. data/lib/rails/info_controller.rb +23 -2
  144. data/lib/rails/mailers_controller.rb +2 -2
  145. data/lib/rails/paths.rb +14 -6
  146. data/lib/rails/rack.rb +1 -3
  147. data/lib/rails/rack/debugger.rb +2 -23
  148. data/lib/rails/rack/logger.rb +4 -0
  149. data/lib/rails/ruby_version_check.rb +3 -3
  150. data/lib/rails/source_annotation_extractor.rb +1 -1
  151. data/lib/rails/tasks.rb +4 -1
  152. data/lib/rails/tasks/engine.rake +1 -1
  153. data/lib/rails/tasks/framework.rake +18 -16
  154. data/lib/rails/tasks/initializers.rake +6 -0
  155. data/lib/rails/tasks/restart.rake +5 -0
  156. data/lib/rails/tasks/statistics.rake +5 -6
  157. data/lib/rails/tasks/tmp.rake +4 -12
  158. data/lib/rails/templates/rails/mailers/email.html.erb +17 -3
  159. data/lib/rails/templates/rails/welcome/index.html.erb +10 -3
  160. data/lib/rails/test_help.rb +7 -8
  161. data/lib/rails/test_unit/minitest_plugin.rb +91 -0
  162. data/lib/rails/test_unit/reporter.rb +74 -0
  163. data/lib/rails/test_unit/test_requirer.rb +28 -0
  164. data/lib/rails/test_unit/testing.rake +18 -39
  165. metadata +80 -33
  166. data/lib/rails/deprecation.rb +0 -19
  167. data/lib/rails/generators/erb/mailer/templates/layout.html.erb +0 -5
  168. data/lib/rails/generators/rails/app/templates/config.ru +0 -4
  169. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +0 -10
  170. data/lib/rails/generators/rails/plugin/templates/README.rdoc +0 -3
  171. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -5
  172. data/lib/rails/generators/rails/plugin/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
  173. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
  174. data/lib/rails/generators/rails/plugin/templates/lib/%name%.rb +0 -6
  175. data/lib/rails/generators/rails/plugin/templates/lib/%name%/engine.rb +0 -7
  176. data/lib/rails/generators/rails/plugin/templates/lib/%name%/version.rb +0 -3
  177. data/lib/rails/generators/rails/plugin/templates/test/%name%_test.rb +0 -7
  178. data/lib/rails/rack/log_tailer.rb +0 -38
  179. data/lib/rails/tasks/documentation.rake +0 -70
  180. data/lib/rails/test_unit/sub_test_task.rb +0 -126
@@ -32,35 +32,37 @@ namespace :rails do
32
32
  FileUtils.cp_r src_name, dst_name
33
33
  end
34
34
  end
35
- end
35
+ end
36
36
  end
37
37
 
38
38
  namespace :update do
39
- def invoke_from_app_generator(method)
40
- app_generator.send(method)
41
- end
39
+ class RailsUpdate
40
+ def self.invoke_from_app_generator(method)
41
+ app_generator.send(method)
42
+ end
42
43
 
43
- def app_generator
44
- @app_generator ||= begin
45
- require 'rails/generators'
46
- require 'rails/generators/rails/app/app_generator'
47
- gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
48
- destination_root: Rails.root
49
- File.exist?(Rails.root.join("config", "application.rb")) ?
50
- gen.send(:app_const) : gen.send(:valid_const?)
51
- gen
44
+ def self.app_generator
45
+ @app_generator ||= begin
46
+ require 'rails/generators'
47
+ require 'rails/generators/rails/app/app_generator'
48
+ gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
49
+ destination_root: Rails.root
50
+ File.exist?(Rails.root.join("config", "application.rb")) ?
51
+ gen.send(:app_const) : gen.send(:valid_const?)
52
+ gen
53
+ end
52
54
  end
53
55
  end
54
56
 
55
57
  # desc "Update config/boot.rb from your current rails install"
56
58
  task :configs do
57
- invoke_from_app_generator :create_boot_file
58
- invoke_from_app_generator :update_config_files
59
+ RailsUpdate.invoke_from_app_generator :create_boot_file
60
+ RailsUpdate.invoke_from_app_generator :update_config_files
59
61
  end
60
62
 
61
63
  # desc "Adds new executables to the application bin/ directory"
62
64
  task :bin do
63
- invoke_from_app_generator :create_bin_files
65
+ RailsUpdate.invoke_from_app_generator :create_bin_files
64
66
  end
65
67
  end
66
68
  end
@@ -0,0 +1,6 @@
1
+ desc "Print out all defined initializers in the order they are invoked by Rails."
2
+ task initializers: :environment do
3
+ Rails.application.initializers.tsort_each do |initializer|
4
+ puts initializer.name
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ desc "Restart app by touching tmp/restart.txt"
2
+ task :restart do
3
+ FileUtils.mkdir_p('tmp')
4
+ FileUtils.touch('tmp/restart.txt')
5
+ end
@@ -1,6 +1,6 @@
1
- # while having global constant is not good,
2
- # many 3rd party tools depend on it, like rspec-rails, cucumber-rails, etc
3
- # so if will be removed - deprecation warning is needed
1
+ # While global constants are bad, many 3rd party tools depend on this one (e.g
2
+ # rspec-rails & cucumber-rails). So a deprecation warning is needed if we want
3
+ # to remove it.
4
4
  STATS_DIRECTORIES = [
5
5
  %w(Controllers app/controllers),
6
6
  %w(Helpers app/helpers),
@@ -9,15 +9,14 @@ STATS_DIRECTORIES = [
9
9
  %w(Mailers app/mailers),
10
10
  %w(Javascripts app/assets/javascripts),
11
11
  %w(Libraries lib/),
12
+ %w(Tasks lib/tasks),
12
13
  %w(APIs app/apis),
13
14
  %w(Controller\ tests test/controllers),
14
15
  %w(Helper\ tests test/helpers),
15
16
  %w(Model\ tests test/models),
16
17
  %w(Mailer\ tests test/mailers),
17
- %w(Job\ tests test/jobs),
18
+ %w(Job\ tests test/jobs),
18
19
  %w(Integration\ tests test/integration),
19
- %w(Functional\ tests\ (old) test/functional),
20
- %w(Unit\ tests \ (old) test/unit)
21
20
  ].collect do |name, dir|
22
21
  [ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
23
22
  end.select { |name, dir| File.directory?(dir) }
@@ -1,9 +1,8 @@
1
1
  namespace :tmp do
2
- desc "Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)"
3
- task clear: [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"]
2
+ desc "Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)"
3
+ task clear: ["tmp:cache:clear", "tmp:sockets:clear"]
4
4
 
5
- tmp_dirs = [ 'tmp/sessions',
6
- 'tmp/cache',
5
+ tmp_dirs = [ 'tmp/cache',
7
6
  'tmp/sockets',
8
7
  'tmp/pids',
9
8
  'tmp/cache/assets/development',
@@ -12,16 +11,9 @@ namespace :tmp do
12
11
 
13
12
  tmp_dirs.each { |d| directory d }
14
13
 
15
- desc "Creates tmp directories for sessions, cache, sockets, and pids"
14
+ desc "Creates tmp directories for cache, sockets, and pids"
16
15
  task create: tmp_dirs
17
16
 
18
- namespace :sessions do
19
- # desc "Clears all files in tmp/sessions"
20
- task :clear do
21
- FileUtils.rm(Dir['tmp/sessions/[^.]*'])
22
- end
23
- end
24
-
25
17
  namespace :cache do
26
18
  # desc "Clears all files and directories in tmp/cache"
27
19
  task :clear do
@@ -94,9 +94,9 @@
94
94
 
95
95
  <% if @email.multipart? %>
96
96
  <dd>
97
- <select onchange="document.getElementsByName('messageBody')[0].src=this.options[this.selectedIndex].value;">
98
- <option <%= request.format == Mime::HTML ? 'selected' : '' %> value="?part=text%2Fhtml">View as HTML email</option>
99
- <option <%= request.format == Mime::TEXT ? 'selected' : '' %> value="?part=text%2Fplain">View as plain-text email</option>
97
+ <select onchange="formatChanged(this);">
98
+ <option <%= request.format == Mime[:html] ? 'selected' : '' %> value="?part=text%2Fhtml">View as HTML email</option>
99
+ <option <%= request.format == Mime[:text] ? 'selected' : '' %> value="?part=text%2Fplain">View as plain-text email</option>
100
100
  </select>
101
101
  </dd>
102
102
  <% end %>
@@ -112,5 +112,19 @@
112
112
  </p>
113
113
  <% end %>
114
114
 
115
+ <script>
116
+ function formatChanged(form) {
117
+ var part_name = form.options[form.selectedIndex].value
118
+ var iframe =document.getElementsByName('messageBody')[0];
119
+ iframe.contentWindow.location.replace(part_name);
120
+
121
+ if (history.replaceState) {
122
+ var url = location.pathname.replace(/\.(txt|html)$/, '');
123
+ var format = /html/.test(part_name) ? '.html' : '.txt';
124
+ window.history.replaceState({}, '', url + format);
125
+ }
126
+ }
127
+ </script>
128
+
115
129
  </body>
116
130
  </html>
@@ -18,7 +18,9 @@
18
18
  color: #000;
19
19
  }
20
20
 
21
- a {color: #03c}
21
+ a {
22
+ color: #03c;
23
+ }
22
24
 
23
25
  a:hover {
24
26
  background-color: #03c;
@@ -64,7 +66,10 @@
64
66
  height: 64px;
65
67
  }
66
68
 
67
- #header h1, #header h2 {margin: 0}
69
+ #header h1,
70
+ #header h2 {
71
+ margin: 0;
72
+ }
68
73
 
69
74
  #header h2 {
70
75
  color: #888;
@@ -104,7 +109,9 @@
104
109
  color: #555;
105
110
  }
106
111
 
107
- #about-content td.value {color: #000}
112
+ #about-content td.value {
113
+ color: #000;
114
+ }
108
115
 
109
116
  #about-content ul {
110
117
  padding: 0;
@@ -2,18 +2,14 @@
2
2
  # so fixtures aren't loaded into that environment
3
3
  abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
4
4
 
5
- require 'active_support/testing/autorun'
5
+ require "rails/test_unit/minitest_plugin"
6
6
  require 'active_support/test_case'
7
7
  require 'action_controller'
8
8
  require 'action_controller/test_case'
9
9
  require 'action_dispatch/testing/integration'
10
10
  require 'rails/generators/test_case'
11
11
 
12
- # Config Rails backtrace in tests.
13
- require 'rails/backtrace_cleaner'
14
- if ENV["BACKTRACE"].nil?
15
- Minitest.backtrace_filter = Rails.backtrace_cleaner
16
- end
12
+ require 'active_support/testing/autorun'
17
13
 
18
14
  if defined?(ActiveRecord::Base)
19
15
  ActiveRecord::Migration.maintain_test_schema!
@@ -21,6 +17,7 @@ if defined?(ActiveRecord::Base)
21
17
  class ActiveSupport::TestCase
22
18
  include ActiveRecord::TestFixtures
23
19
  self.fixture_path = "#{Rails.root}/test/fixtures/"
20
+ self.file_fixture_path = self.fixture_path + "files"
24
21
  end
25
22
 
26
23
  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
@@ -31,13 +28,15 @@ if defined?(ActiveRecord::Base)
31
28
  end
32
29
 
33
30
  class ActionController::TestCase
34
- setup do
31
+ def before_setup # :nodoc:
35
32
  @routes = Rails.application.routes
33
+ super
36
34
  end
37
35
  end
38
36
 
39
37
  class ActionDispatch::IntegrationTest
40
- setup do
38
+ def before_setup # :nodoc:
41
39
  @routes = Rails.application.routes
40
+ super
42
41
  end
43
42
  end
@@ -0,0 +1,91 @@
1
+ require "active_support/core_ext/module/attribute_accessors"
2
+ require "rails/test_unit/reporter"
3
+ require "rails/test_unit/test_requirer"
4
+
5
+ module Minitest
6
+ mattr_accessor(:hide_aggregated_results) { false }
7
+
8
+ module AggregatedResultSuppresion
9
+ def aggregated_results
10
+ super unless Minitest.hide_aggregated_results
11
+ end
12
+ end
13
+
14
+ SummaryReporter.prepend AggregatedResultSuppresion
15
+
16
+ def self.plugin_rails_options(opts, options)
17
+ executable = ::Rails::TestUnitReporter.executable
18
+ opts.separator ""
19
+ opts.separator "Usage: #{executable} [options] [files or directories]"
20
+ opts.separator "You can run a single test by appending a line number to a filename:"
21
+ opts.separator ""
22
+ opts.separator " #{executable} test/models/user_test.rb:27"
23
+ opts.separator ""
24
+ opts.separator "You can run multiple files and directories at the same time:"
25
+ opts.separator ""
26
+ opts.separator " #{executable} test/controllers test/integration/login_test.rb"
27
+ opts.separator ""
28
+ opts.separator "By default test failures and errors are reported inline during a run."
29
+ opts.separator ""
30
+
31
+ opts.separator "Rails options:"
32
+ opts.on("-e", "--environment ENV",
33
+ "Run tests in the ENV environment") do |env|
34
+ options[:environment] = env.strip
35
+ end
36
+
37
+ opts.on("-b", "--backtrace",
38
+ "Show the complete backtrace") do
39
+ options[:full_backtrace] = true
40
+ end
41
+
42
+ opts.on("-d", "--defer-output",
43
+ "Output test failures and errors after the test run") do
44
+ options[:output_inline] = false
45
+ end
46
+
47
+ opts.on("-f", "--fail-fast",
48
+ "Abort test run on first failure") do
49
+ options[:fail_fast] = true
50
+ end
51
+
52
+ options[:output_inline] = true
53
+ options[:patterns] = opts.order!
54
+ end
55
+
56
+ # Running several Rake tasks in a single command would trip up the runner,
57
+ # as the patterns would also contain the other Rake tasks.
58
+ def self.rake_run(patterns) # :nodoc:
59
+ @rake_patterns = patterns
60
+ passed = run
61
+ exit passed unless passed
62
+ passed
63
+ end
64
+
65
+ def self.plugin_rails_init(options)
66
+ self.run_with_rails_extension = true
67
+
68
+ ENV["RAILS_ENV"] = options[:environment] || "test"
69
+
70
+ unless run_with_autorun
71
+ patterns = defined?(@rake_patterns) ? @rake_patterns : options[:patterns]
72
+ ::Rails::TestRequirer.require_files(patterns)
73
+ end
74
+
75
+ unless options[:full_backtrace] || ENV["BACKTRACE"]
76
+ # Plugin can run without Rails loaded, check before filtering.
77
+ Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
78
+ end
79
+
80
+ # Disable the extra failure output after a run, unless output is deferred.
81
+ self.hide_aggregated_results = options[:output_inline]
82
+
83
+ self.reporter << ::Rails::TestUnitReporter.new(options[:io], options)
84
+ end
85
+
86
+ mattr_accessor(:run_with_autorun) { false }
87
+ mattr_accessor(:run_with_rails_extension) { false }
88
+ end
89
+
90
+ Minitest.load_plugins
91
+ Minitest.extensions << 'rails'
@@ -0,0 +1,74 @@
1
+ require "active_support/core_ext/class/attribute"
2
+ require "minitest"
3
+
4
+ module Rails
5
+ class TestUnitReporter < Minitest::StatisticsReporter
6
+ class_attribute :executable
7
+ self.executable = "bin/rails test"
8
+
9
+ def record(result)
10
+ super
11
+
12
+ if output_inline? && result.failure && (!result.skipped? || options[:verbose])
13
+ io.puts
14
+ io.puts
15
+ io.puts result.failures.map(&:message)
16
+ io.puts
17
+ io.puts format_rerun_snippet(result)
18
+ io.puts
19
+ end
20
+
21
+ if fail_fast? && result.failure && !result.error? && !result.skipped?
22
+ raise Interrupt
23
+ end
24
+ end
25
+
26
+ def report
27
+ return if output_inline? || filtered_results.empty?
28
+ io.puts
29
+ io.puts "Failed tests:"
30
+ io.puts
31
+ io.puts aggregated_results
32
+ end
33
+
34
+ def aggregated_results # :nodoc:
35
+ filtered_results.map { |result| format_rerun_snippet(result) }.join "\n"
36
+ end
37
+
38
+ def filtered_results
39
+ if options[:verbose]
40
+ results
41
+ else
42
+ results.reject(&:skipped?)
43
+ end
44
+ end
45
+
46
+ def relative_path_for(file)
47
+ file.sub(/^#{app_root}\/?/, '')
48
+ end
49
+
50
+ private
51
+ def output_inline?
52
+ options[:output_inline]
53
+ end
54
+
55
+ def fail_fast?
56
+ options[:fail_fast]
57
+ end
58
+
59
+ def format_rerun_snippet(result)
60
+ # Try to extract path to assertion from backtrace.
61
+ if result.location =~ /\[(.*)\]\z/
62
+ assertion_path = $1
63
+ else
64
+ assertion_path = result.method(result.name).source_location.join(':')
65
+ end
66
+
67
+ "#{self.executable} #{relative_path_for(assertion_path)}"
68
+ end
69
+
70
+ def app_root
71
+ @app_root ||= defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'rake/file_list'
3
+
4
+ module Rails
5
+ class TestRequirer # :nodoc:
6
+ class << self
7
+ def require_files(patterns)
8
+ patterns = expand_patterns(patterns)
9
+
10
+ Rake::FileList[patterns.compact.presence || 'test/**/*_test.rb'].to_a.each do |file|
11
+ require File.expand_path(file)
12
+ end
13
+ end
14
+
15
+ private
16
+ def expand_patterns(patterns)
17
+ patterns.map do |arg|
18
+ arg = arg.gsub(/:(\d+)?$/, '')
19
+ if Dir.exist?(arg)
20
+ "#{arg}/**/*_test.rb"
21
+ else
22
+ arg
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,11 +1,13 @@
1
- require 'rake/testtask'
2
- require 'rails/test_unit/sub_test_task'
1
+ gem 'minitest'
2
+ require 'minitest'
3
+ require 'rails/test_unit/minitest_plugin'
3
4
 
4
5
  task default: :test
5
6
 
6
7
  desc "Runs all tests in test folder"
7
8
  task :test do
8
- Rails::TestTask.test_creator(Rake.application.top_level_tasks).invoke_rake_task
9
+ $: << "test"
10
+ Minitest.rake_run(["test"])
9
11
  end
10
12
 
11
13
  namespace :test do
@@ -14,53 +16,30 @@ namespace :test do
14
16
  # If used with Active Record, this task runs before the database schema is synchronized.
15
17
  end
16
18
 
17
- Rails::TestTask.new(:run) do |t|
18
- t.pattern = "test/**/*_test.rb"
19
- end
19
+ task :run => %w[test]
20
20
 
21
21
  desc "Run tests quickly, but also reset db"
22
22
  task :db => %w[db:test:prepare test]
23
23
 
24
- desc "Run tests quickly by merging all types and not resetting db"
25
- Rails::TestTask.new(:all) do |t|
26
- t.pattern = "test/**/*_test.rb"
27
- end
28
-
29
- Rake::Task["test:all"].enhance do
30
- Rake::Task["test:deprecate_all"].invoke
31
- end
32
-
33
- task :deprecate_all do
34
- ActiveSupport::Deprecation.warn "rake test:all is deprecated and will be removed in Rails 5. " \
35
- "Use rake test to run all tests in test directory."
36
- end
37
-
38
- namespace :all do
39
- desc "Run tests quickly, but also reset db"
40
- task :db => %w[db:test:prepare test:all]
41
-
42
- Rake::Task["test:all:db"].enhance do
43
- Rake::Task["test:deprecate_all"].invoke
44
- end
45
- end
46
-
47
- Rails::TestTask.new(single: "test:prepare")
48
-
49
24
  ["models", "helpers", "controllers", "mailers", "integration", "jobs"].each do |name|
50
- Rails::TestTask.new(name => "test:prepare") do |t|
51
- t.pattern = "test/#{name}/**/*_test.rb"
25
+ task name => "test:prepare" do
26
+ $: << "test"
27
+ Minitest.rake_run(["test/#{name}"])
52
28
  end
53
29
  end
54
30
 
55
- Rails::TestTask.new(generators: "test:prepare") do |t|
56
- t.pattern = "test/lib/generators/**/*_test.rb"
31
+ task :generators => "test:prepare" do
32
+ $: << "test"
33
+ Minitest.rake_run(["test/lib/generators"])
57
34
  end
58
35
 
59
- Rails::TestTask.new(units: "test:prepare") do |t|
60
- t.pattern = 'test/{models,helpers,unit}/**/*_test.rb'
36
+ task :units => "test:prepare" do
37
+ $: << "test"
38
+ Minitest.rake_run(["test/models", "test/helpers", "test/unit"])
61
39
  end
62
40
 
63
- Rails::TestTask.new(functionals: "test:prepare") do |t|
64
- t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb'
41
+ task :functionals => "test:prepare" do
42
+ $: << "test"
43
+ Minitest.rake_run(["test/controllers", "test/mailers", "test/functional"])
65
44
  end
66
45
  end