railties 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -567
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +3 -3
  5. data/README.rdoc +1 -1
  6. data/exe/rails +2 -2
  7. data/lib/rails.rb +18 -18
  8. data/lib/rails/all.rb +1 -1
  9. data/lib/rails/api/generator.rb +28 -0
  10. data/lib/rails/api/task.rb +54 -42
  11. data/lib/rails/app_loader.rb +9 -9
  12. data/lib/rails/application.rb +30 -35
  13. data/lib/rails/application/bootstrap.rb +13 -7
  14. data/lib/rails/application/configuration.rb +30 -53
  15. data/lib/rails/application/default_middleware_stack.rb +3 -5
  16. data/lib/rails/application/finisher.rb +16 -7
  17. data/lib/rails/application/routes_reloader.rb +16 -1
  18. data/lib/rails/application_controller.rb +10 -10
  19. data/lib/rails/backtrace_cleaner.rb +5 -5
  20. data/lib/rails/cli.rb +7 -5
  21. data/lib/rails/code_statistics.rb +16 -17
  22. data/lib/rails/code_statistics_calculator.rb +3 -3
  23. data/lib/rails/command.rb +111 -0
  24. data/lib/rails/command/actions.rb +42 -0
  25. data/lib/rails/command/base.rb +149 -0
  26. data/lib/rails/command/behavior.rb +123 -0
  27. data/lib/rails/command/environment_argument.rb +34 -0
  28. data/lib/rails/commands.rb +2 -4
  29. data/lib/rails/commands/application/application_command.rb +29 -0
  30. data/lib/rails/commands/console/console_command.rb +89 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
  32. data/lib/rails/commands/destroy/destroy_command.rb +21 -0
  33. data/lib/rails/commands/generate/generate_command.rb +23 -0
  34. data/lib/rails/commands/help/USAGE +15 -0
  35. data/lib/rails/commands/help/help_command.rb +13 -0
  36. data/lib/rails/commands/new/new_command.rb +15 -0
  37. data/lib/rails/commands/plugin/plugin_command.rb +43 -0
  38. data/lib/rails/commands/rake/rake_command.rb +49 -0
  39. data/lib/rails/commands/runner/USAGE +17 -0
  40. data/lib/rails/commands/runner/runner_command.rb +46 -0
  41. data/lib/rails/commands/secrets/USAGE +52 -0
  42. data/lib/rails/commands/secrets/secrets_command.rb +36 -0
  43. data/lib/rails/commands/server/server_command.rb +177 -0
  44. data/lib/rails/commands/test/test_command.rb +20 -0
  45. data/lib/rails/commands/version/version_command.rb +9 -0
  46. data/lib/rails/configuration.rb +7 -7
  47. data/lib/rails/console/app.rb +4 -4
  48. data/lib/rails/dev_caching.rb +8 -8
  49. data/lib/rails/engine.rb +62 -63
  50. data/lib/rails/engine/commands.rb +6 -13
  51. data/lib/rails/engine/configuration.rb +2 -2
  52. data/lib/rails/gem_version.rb +3 -3
  53. data/lib/rails/generators.rb +229 -313
  54. data/lib/rails/generators/actions.rb +20 -21
  55. data/lib/rails/generators/actions/create_migration.rb +24 -25
  56. data/lib/rails/generators/active_model.rb +3 -3
  57. data/lib/rails/generators/app_base.rb +123 -93
  58. data/lib/rails/generators/base.rb +32 -33
  59. data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
  60. data/lib/rails/generators/erb.rb +14 -14
  61. data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
  62. data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
  63. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
  64. data/lib/rails/generators/generated_attribute.rb +27 -27
  65. data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
  66. data/lib/rails/generators/migration.rb +8 -8
  67. data/lib/rails/generators/model_helpers.rb +2 -2
  68. data/lib/rails/generators/named_base.rb +56 -56
  69. data/lib/rails/generators/rails/app/app_generator.rb +98 -81
  70. data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
  71. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  72. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
  73. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
  74. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
  75. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  76. data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
  77. data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
  78. data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
  79. data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
  80. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
  81. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
  83. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
  85. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
  86. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  87. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
  88. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  92. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
  94. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
  95. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
  96. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
  97. data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
  98. data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
  99. data/lib/rails/generators/rails/app/templates/gitignore +5 -1
  100. data/lib/rails/generators/rails/app/templates/package.json +5 -0
  101. data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
  102. data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
  103. data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
  104. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
  105. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
  106. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
  107. data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
  109. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
  110. data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
  111. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
  112. data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
  113. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  114. data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
  115. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
  116. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
  117. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
  121. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
  123. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  124. data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
  125. data/lib/rails/generators/rails/task/task_generator.rb +1 -2
  126. data/lib/rails/generators/resource_helpers.rb +13 -10
  127. data/lib/rails/generators/test_case.rb +5 -6
  128. data/lib/rails/generators/test_unit.rb +1 -1
  129. data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
  130. data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
  131. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
  132. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
  133. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
  134. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
  135. data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
  136. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
  137. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  138. data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
  139. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
  140. data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
  141. data/lib/rails/generators/testing/assertions.rb +4 -4
  142. data/lib/rails/generators/testing/behaviour.rb +20 -21
  143. data/lib/rails/info.rb +20 -20
  144. data/lib/rails/info_controller.rb +15 -15
  145. data/lib/rails/initializable.rb +6 -2
  146. data/lib/rails/mailers_controller.rb +11 -11
  147. data/lib/rails/paths.rb +4 -5
  148. data/lib/rails/plugin/test.rb +7 -0
  149. data/lib/rails/rack/logger.rb +44 -46
  150. data/lib/rails/railtie.rb +41 -38
  151. data/lib/rails/railtie/configurable.rb +6 -6
  152. data/lib/rails/railtie/configuration.rb +1 -1
  153. data/lib/rails/ruby_version_check.rb +1 -1
  154. data/lib/rails/secrets.rb +111 -0
  155. data/lib/rails/source_annotation_extractor.rb +15 -9
  156. data/lib/rails/tasks.rb +3 -2
  157. data/lib/rails/tasks/annotations.rake +3 -3
  158. data/lib/rails/tasks/dev.rake +2 -2
  159. data/lib/rails/tasks/engine.rake +4 -4
  160. data/lib/rails/tasks/framework.rake +4 -18
  161. data/lib/rails/tasks/initializers.rake +1 -1
  162. data/lib/rails/tasks/log.rake +14 -10
  163. data/lib/rails/tasks/middleware.rake +1 -1
  164. data/lib/rails/tasks/misc.rake +10 -10
  165. data/lib/rails/tasks/restart.rake +4 -4
  166. data/lib/rails/tasks/routes.rake +3 -12
  167. data/lib/rails/tasks/statistics.rake +3 -3
  168. data/lib/rails/tasks/tmp.rake +7 -7
  169. data/lib/rails/tasks/yarn.rake +11 -0
  170. data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
  171. data/lib/rails/test_help.rb +28 -10
  172. data/lib/rails/test_unit/line_filtering.rb +69 -3
  173. data/lib/rails/test_unit/minitest_plugin.rb +139 -0
  174. data/lib/rails/test_unit/railtie.rb +2 -1
  175. data/lib/rails/test_unit/reporter.rb +3 -8
  176. data/lib/rails/test_unit/test_requirer.rb +28 -0
  177. data/lib/rails/test_unit/testing.rake +19 -14
  178. data/lib/rails/version.rb +1 -1
  179. data/lib/rails/welcome_controller.rb +1 -1
  180. metadata +53 -30
  181. data/lib/minitest/rails_plugin.rb +0 -49
  182. data/lib/rails/commands/application.rb +0 -17
  183. data/lib/rails/commands/commands_tasks.rb +0 -180
  184. data/lib/rails/commands/console.rb +0 -68
  185. data/lib/rails/commands/console_helper.rb +0 -34
  186. data/lib/rails/commands/dbconsole.rb +0 -173
  187. data/lib/rails/commands/destroy.rb +0 -11
  188. data/lib/rails/commands/generate.rb +0 -13
  189. data/lib/rails/commands/plugin.rb +0 -23
  190. data/lib/rails/commands/rake_proxy.rb +0 -41
  191. data/lib/rails/commands/runner.rb +0 -71
  192. data/lib/rails/commands/server.rb +0 -163
  193. data/lib/rails/commands/test.rb +0 -10
  194. data/lib/rails/engine/commands_tasks.rb +0 -118
  195. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
  196. data/lib/rails/rack/debugger.rb +0 -3
  197. data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,6 +1,6 @@
1
1
  desc "Print out all defined initializers in the order they are invoked by Rails."
2
2
  task initializers: :environment do
3
3
  Rails.application.initializers.tsort_each do |initializer|
4
- puts initializer.name
4
+ puts "#{initializer.context_class}.#{initializer.name}"
5
5
  end
6
6
  end
@@ -1,9 +1,9 @@
1
1
  namespace :log do
2
-
3
- ##
2
+
3
+ ##
4
4
  # Truncates all/specified log files
5
- # ENV['LOGS']
6
- # - defaults to standard environment log files i.e. 'development,test,production'
5
+ # ENV['LOGS']
6
+ # - defaults to all environments log files i.e. 'development,test,production'
7
7
  # - ENV['LOGS']=all truncates all files i.e. log/*.log
8
8
  # - ENV['LOGS']='test,development' truncates only specified files
9
9
  desc "Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
@@ -14,23 +14,27 @@ namespace :log do
14
14
  end
15
15
 
16
16
  def log_files
17
- if ENV['LOGS'] == 'all'
17
+ if ENV["LOGS"] == "all"
18
18
  FileList["log/*.log"]
19
- elsif ENV['LOGS']
20
- log_files_to_truncate(ENV['LOGS'])
19
+ elsif ENV["LOGS"]
20
+ log_files_to_truncate(ENV["LOGS"])
21
21
  else
22
- log_files_to_truncate("development,test,production")
22
+ log_files_to_truncate(all_environments.join(","))
23
23
  end
24
24
  end
25
25
 
26
26
  def log_files_to_truncate(envs)
27
- envs.split(',')
27
+ envs.split(",")
28
28
  .map { |file| "log/#{file.strip}.log" }
29
29
  .select { |file| File.exist?(file) }
30
30
  end
31
-
31
+
32
32
  def clear_log_file(file)
33
33
  f = File.open(file, "w")
34
34
  f.close
35
35
  end
36
+
37
+ def all_environments
38
+ Dir["config/environments/*.rb"].map { |fname| File.basename(fname, ".*") }
39
+ end
36
40
  end
@@ -1,4 +1,4 @@
1
- desc 'Prints out your Rack middleware stack'
1
+ desc "Prints out your Rack middleware stack"
2
2
  task middleware: :environment do
3
3
  Rails.configuration.middleware.each do |middleware|
4
4
  puts "use #{middleware.inspect}"
@@ -1,16 +1,16 @@
1
- desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
1
+ desc "Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)."
2
2
  task :secret do
3
- require 'securerandom'
3
+ require "securerandom"
4
4
  puts SecureRandom.hex(64)
5
5
  end
6
6
 
7
- desc 'List versions of all Rails frameworks and the environment'
7
+ desc "List versions of all Rails frameworks and the environment"
8
8
  task about: :environment do
9
9
  puts Rails::Info
10
10
  end
11
11
 
12
12
  namespace :time do
13
- desc 'List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)'
13
+ desc "List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)"
14
14
  task :zones, :country_or_offset do |t, args|
15
15
  zones, offset = ActiveSupport::TimeZone.all, nil
16
16
 
@@ -38,8 +38,8 @@ namespace :time do
38
38
 
39
39
  # desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
40
40
  task :local do
41
- require 'active_support'
42
- require 'active_support/time'
41
+ require "active_support"
42
+ require "active_support/time"
43
43
 
44
44
  jan_offset = Time.now.beginning_of_year.utc_offset
45
45
  jul_offset = Time.now.beginning_of_year.change(month: 7).utc_offset
@@ -49,12 +49,12 @@ namespace :time do
49
49
  end
50
50
 
51
51
  # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
52
- def build_time_zone_list(zones, offset = ENV['OFFSET'])
53
- require 'active_support'
54
- require 'active_support/time'
52
+ def build_time_zone_list(zones, offset = ENV["OFFSET"])
53
+ require "active_support"
54
+ require "active_support/time"
55
55
  if offset
56
56
  offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
57
- sign = $1 == '-' ? -1 : 1
57
+ sign = $1 == "-" ? -1 : 1
58
58
  hours, minutes = $2.to_f, $3.to_f
59
59
  ((hours * 3600) + (minutes.to_f * 60)) * sign
60
60
  elsif offset.to_f.abs <= 13
@@ -1,8 +1,8 @@
1
- desc 'Restart app by touching tmp/restart.txt'
1
+ desc "Restart app by touching tmp/restart.txt"
2
2
  task :restart do
3
3
  verbose(false) do
4
- mkdir_p 'tmp'
5
- touch 'tmp/restart.txt'
6
- rm_f 'tmp/pids/server.pid'
4
+ mkdir_p "tmp"
5
+ touch "tmp/restart.txt"
6
+ rm_f "tmp/pids/server.pid"
7
7
  end
8
8
  end
@@ -1,21 +1,12 @@
1
- require 'active_support/deprecation'
2
- require 'active_support/core_ext/string/strip' # for strip_heredoc
3
- require 'optparse'
1
+ require "optparse"
4
2
 
5
- desc 'Print out all defined routes in match order, with names. Target specific controller with -c option, or grep routes using -g option'
3
+ desc "Print out all defined routes in match order, with names. Target specific controller with -c option, or grep routes using -g option"
6
4
  task routes: :environment do
7
5
  all_routes = Rails.application.routes.routes
8
- require 'action_dispatch/routing/inspector'
6
+ require "action_dispatch/routing/inspector"
9
7
  inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
10
- if ARGV.any?{ |argv| argv.start_with? 'CONTROLLER' }
11
- puts <<-eow.strip_heredoc
12
- Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.
13
- Please use `bin/rails routes -c controller_name` instead.
14
- eow
15
- end
16
8
 
17
9
  routes_filter = nil
18
- routes_filter = { controller: ENV['CONTROLLER'] } if ENV['CONTROLLER']
19
10
 
20
11
  OptionParser.new do |opts|
21
12
  opts.banner = "Usage: rails routes [options]"
@@ -8,9 +8,8 @@ STATS_DIRECTORIES = [
8
8
  %w(Models app/models),
9
9
  %w(Mailers app/mailers),
10
10
  %w(Channels app/channels),
11
- %w(Javascripts app/assets/javascripts),
11
+ %w(JavaScripts app/assets/javascripts),
12
12
  %w(Libraries lib/),
13
- %w(Tasks lib/tasks),
14
13
  %w(APIs app/apis),
15
14
  %w(Controller\ tests test/controllers),
16
15
  %w(Helper\ tests test/helpers),
@@ -18,12 +17,13 @@ STATS_DIRECTORIES = [
18
17
  %w(Mailer\ tests test/mailers),
19
18
  %w(Job\ tests test/jobs),
20
19
  %w(Integration\ tests test/integration),
20
+ %w(System\ tests test/system),
21
21
  ].collect do |name, dir|
22
22
  [ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
23
23
  end.select { |name, dir| File.directory?(dir) }
24
24
 
25
25
  desc "Report code statistics (KLOCs, etc) from the application or engine"
26
26
  task :stats do
27
- require 'rails/code_statistics'
27
+ require "rails/code_statistics"
28
28
  CodeStatistics.new(*STATS_DIRECTORIES).to_s
29
29
  end
@@ -2,10 +2,10 @@ namespace :tmp do
2
2
  desc "Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)"
3
3
  task clear: ["tmp:cache:clear", "tmp:sockets:clear"]
4
4
 
5
- tmp_dirs = [ 'tmp/cache',
6
- 'tmp/sockets',
7
- 'tmp/pids',
8
- 'tmp/cache/assets' ]
5
+ tmp_dirs = [ "tmp/cache",
6
+ "tmp/sockets",
7
+ "tmp/pids",
8
+ "tmp/cache/assets" ]
9
9
 
10
10
  tmp_dirs.each { |d| directory d }
11
11
 
@@ -15,21 +15,21 @@ namespace :tmp do
15
15
  namespace :cache do
16
16
  # desc "Clears all files and directories in tmp/cache"
17
17
  task :clear do
18
- rm_rf Dir['tmp/cache/[^.]*'], verbose: false
18
+ rm_rf Dir["tmp/cache/[^.]*"], verbose: false
19
19
  end
20
20
  end
21
21
 
22
22
  namespace :sockets do
23
23
  # desc "Clears all files in tmp/sockets"
24
24
  task :clear do
25
- rm Dir['tmp/sockets/[^.]*'], verbose: false
25
+ rm Dir["tmp/sockets/[^.]*"], verbose: false
26
26
  end
27
27
  end
28
28
 
29
29
  namespace :pids do
30
30
  # desc "Clears all files in tmp/pids"
31
31
  task :clear do
32
- rm Dir['tmp/pids/[^.]*'], verbose: false
32
+ rm Dir["tmp/pids/[^.]*"], verbose: false
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,11 @@
1
+ namespace :yarn do
2
+ desc "Install all JavaScript dependencies as specified via Yarn"
3
+ task :install do
4
+ system("./bin/yarn install --no-progress")
5
+ end
6
+ end
7
+
8
+ # Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
9
+ if Rake::Task.task_defined?("assets:precompile")
10
+ Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
11
+ end
@@ -88,7 +88,10 @@
88
88
  <% unless @email.attachments.nil? || @email.attachments.empty? %>
89
89
  <dt>Attachments:</dt>
90
90
  <dd>
91
- <%= @email.attachments.map { |a| a.respond_to?(:original_filename) ? a.original_filename : a.filename }.join(', ') %>
91
+ <% @email.attachments.each do |a| %>
92
+ <% filename = a.respond_to?(:original_filename) ? a.original_filename : a.filename %>
93
+ <%= link_to filename, "data:application/octet-stream;charset=utf-8;base64,#{Base64.encode64(a.body.to_s)}", download: filename %>
94
+ <% end %>
92
95
  </dd>
93
96
  <% end %>
94
97
 
@@ -2,21 +2,28 @@
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/test_case'
6
- require 'action_controller'
7
- require 'action_controller/test_case'
8
- require 'action_dispatch/testing/integration'
9
- require 'rails/generators/test_case'
5
+ require "rails/test_unit/minitest_plugin"
6
+ require "active_support/test_case"
7
+ require "action_controller"
8
+ require "action_controller/test_case"
9
+ require "action_dispatch/testing/integration"
10
+ require "rails/generators/test_case"
10
11
 
11
- require 'active_support/testing/autorun'
12
+ require "active_support/testing/autorun"
13
+
14
+ if defined?(Capbyara)
15
+ require "action_dispatch/system_test_case"
16
+ end
12
17
 
13
18
  if defined?(ActiveRecord::Base)
14
19
  ActiveRecord::Migration.maintain_test_schema!
15
20
 
16
- class ActiveSupport::TestCase
17
- include ActiveRecord::TestFixtures
18
- self.fixture_path = "#{Rails.root}/test/fixtures/"
19
- self.file_fixture_path = self.fixture_path + "files"
21
+ module ActiveSupport
22
+ class TestCase
23
+ include ActiveRecord::TestFixtures
24
+ self.fixture_path = "#{Rails.root}/test/fixtures/"
25
+ self.file_fixture_path = fixture_path + "files"
26
+ end
20
27
  end
21
28
 
22
29
  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
@@ -26,6 +33,8 @@ if defined?(ActiveRecord::Base)
26
33
  end
27
34
  end
28
35
 
36
+ # :enddoc:
37
+
29
38
  class ActionController::TestCase
30
39
  def before_setup # :nodoc:
31
40
  @routes = Rails.application.routes
@@ -39,3 +48,12 @@ class ActionDispatch::IntegrationTest
39
48
  super
40
49
  end
41
50
  end
51
+
52
+ if defined? Capybara
53
+ class ActionDispatch::SystemTestCase
54
+ def before_setup # :nodoc:
55
+ @routes = Rails.application.routes
56
+ super
57
+ end
58
+ end
59
+ end
@@ -1,12 +1,78 @@
1
- require 'method_source'
2
- require "rails/test_unit/runner"
1
+ require "method_source"
3
2
 
4
3
  module Rails
5
4
  module LineFiltering # :nodoc:
6
5
  def run(reporter, options = {})
7
- options[:filter] = Rails::TestUnit::Runner.compose_filter(self, options[:filter])
6
+ if options[:patterns] && options[:patterns].any? { |p| p =~ /:\d+/ }
7
+ options[:filter] = \
8
+ CompositeFilter.new(self, options[:filter], options[:patterns])
9
+ end
8
10
 
9
11
  super
10
12
  end
11
13
  end
14
+
15
+ class CompositeFilter # :nodoc:
16
+ attr_reader :named_filter
17
+
18
+ def initialize(runnable, filter, patterns)
19
+ @runnable = runnable
20
+ @named_filter = derive_named_filter(filter)
21
+ @filters = [ @named_filter, *derive_line_filters(patterns) ].compact
22
+ end
23
+
24
+ # Minitest uses === to find matching filters.
25
+ def ===(method)
26
+ @filters.any? { |filter| filter === method }
27
+ end
28
+
29
+ private
30
+ def derive_named_filter(filter)
31
+ if filter.respond_to?(:named_filter)
32
+ filter.named_filter
33
+ elsif filter =~ %r%/(.*)/% # Regexp filtering copied from Minitest.
34
+ Regexp.new $1
35
+ elsif filter.is_a?(String)
36
+ filter
37
+ end
38
+ end
39
+
40
+ def derive_line_filters(patterns)
41
+ patterns.flat_map do |file_and_line|
42
+ file, *lines = file_and_line.split(":")
43
+
44
+ if lines.empty?
45
+ Filter.new(@runnable, file, nil) if file
46
+ else
47
+ lines.map { |line| Filter.new(@runnable, file, line) }
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ class Filter # :nodoc:
54
+ def initialize(runnable, file, line)
55
+ @runnable, @file = runnable, File.expand_path(file)
56
+ @line = line.to_i if line
57
+ end
58
+
59
+ def ===(method)
60
+ return unless @runnable.method_defined?(method)
61
+
62
+ if @line
63
+ test_file, test_range = definition_for(@runnable.instance_method(method))
64
+ test_file == @file && test_range.include?(@line)
65
+ else
66
+ @runnable.instance_method(method).source_location.first == @file
67
+ end
68
+ end
69
+
70
+ private
71
+ def definition_for(method)
72
+ file, start_line = method.source_location
73
+ end_line = method.source.count("\n") + start_line - 1
74
+
75
+ return file, start_line..end_line
76
+ end
77
+ end
12
78
  end
@@ -0,0 +1,139 @@
1
+ require "active_support/core_ext/module/attribute_accessors"
2
+ require "rails/test_unit/reporter"
3
+ require "rails/test_unit/test_requirer"
4
+ require "shellwords"
5
+
6
+ module Minitest
7
+ class SuppressedSummaryReporter < SummaryReporter
8
+ # Disable extra failure output after a run if output is inline.
9
+ def aggregated_results
10
+ super unless options[:output_inline]
11
+ end
12
+ end
13
+
14
+ def self.plugin_rails_options(opts, options)
15
+ executable = ::Rails::TestUnitReporter.executable
16
+ opts.separator ""
17
+ opts.separator "Usage: #{executable} [options] [files or directories]"
18
+ opts.separator "You can run a single test by appending a line number to a filename:"
19
+ opts.separator ""
20
+ opts.separator " #{executable} test/models/user_test.rb:27"
21
+ opts.separator ""
22
+ opts.separator "You can run multiple files and directories at the same time:"
23
+ opts.separator ""
24
+ opts.separator " #{executable} test/controllers test/integration/login_test.rb"
25
+ opts.separator ""
26
+ opts.separator "By default test failures and errors are reported inline during a run."
27
+ opts.separator ""
28
+
29
+ opts.separator "Rails options:"
30
+ opts.on("-e", "--environment ENV",
31
+ "Run tests in the ENV environment") do |env|
32
+ options[:environment] = env.strip
33
+ end
34
+
35
+ opts.on("-b", "--backtrace",
36
+ "Show the complete backtrace") do
37
+ options[:full_backtrace] = true
38
+ end
39
+
40
+ opts.on("-d", "--defer-output",
41
+ "Output test failures and errors after the test run") do
42
+ options[:output_inline] = false
43
+ end
44
+
45
+ opts.on("-f", "--fail-fast",
46
+ "Abort test run on first failure or error") do
47
+ options[:fail_fast] = true
48
+ end
49
+
50
+ opts.on("-c", "--[no-]color",
51
+ "Enable color in the output") do |value|
52
+ options[:color] = value
53
+ end
54
+
55
+ opts.on("-w", "--warnings",
56
+ "Enable ruby warnings") do
57
+ $VERBOSE = true
58
+ end
59
+
60
+ options[:color] = true
61
+ options[:output_inline] = true
62
+ options[:patterns] = opts.order! unless run_via.rake?
63
+ end
64
+
65
+ def self.rake_run(patterns) # :nodoc:
66
+ self.run_via = :rake unless run_via.set?
67
+ ::Rails::TestRequirer.require_files(patterns)
68
+ autorun
69
+ end
70
+
71
+ module RunRespectingRakeTestopts
72
+ def run(args = [])
73
+ if run_via.rake?
74
+ args = Shellwords.split(ENV["TESTOPTS"] || "")
75
+ end
76
+
77
+ super
78
+ end
79
+ end
80
+
81
+ singleton_class.prepend RunRespectingRakeTestopts
82
+
83
+ # Owes great inspiration to test runner trailblazers like RSpec,
84
+ # minitest-reporters, maxitest and others.
85
+ def self.plugin_rails_init(options)
86
+ ENV["RAILS_ENV"] = options[:environment] || "test"
87
+
88
+ # If run via `ruby` we've been passed the files to run directly, or if run
89
+ # via `rake` then they have already been eagerly required.
90
+ unless run_via.ruby? || run_via.rake?
91
+ ::Rails::TestRequirer.require_files(options[:patterns])
92
+ end
93
+
94
+ unless options[:full_backtrace] || ENV["BACKTRACE"]
95
+ # Plugin can run without Rails loaded, check before filtering.
96
+ Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
97
+ end
98
+
99
+ # Replace progress reporter for colors.
100
+ reporter.reporters.delete_if { |reporter| reporter.kind_of?(SummaryReporter) || reporter.kind_of?(ProgressReporter) }
101
+ reporter << SuppressedSummaryReporter.new(options[:io], options)
102
+ reporter << ::Rails::TestUnitReporter.new(options[:io], options)
103
+ end
104
+
105
+ def self.run_via=(runner)
106
+ if run_via.set?
107
+ raise ArgumentError, "run_via already assigned"
108
+ else
109
+ run_via.runner = runner
110
+ end
111
+ end
112
+
113
+ class RunVia
114
+ attr_accessor :runner
115
+ alias set? runner
116
+
117
+ # Backwardscompatibility with Rails 5.0 generated plugin test scripts.
118
+ def []=(runner, *)
119
+ @runner = runner
120
+ end
121
+
122
+ def ruby?
123
+ runner == :ruby
124
+ end
125
+
126
+ def rake?
127
+ runner == :rake
128
+ end
129
+ end
130
+
131
+ mattr_reader(:run_via) { RunVia.new }
132
+ end
133
+
134
+ # Put Rails as the first plugin minitest initializes so other plugins
135
+ # can override or replace our default reporter setup.
136
+ # Since minitest only loads plugins if its extensions are empty we have
137
+ # to call `load_plugins` first.
138
+ Minitest.load_plugins
139
+ Minitest.extensions.unshift "rails"