railties 5.0.0.beta1.1 → 5.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -6
  3. data/MIT-LICENSE +2 -2
  4. data/RDOC_MAIN.rdoc +1 -1
  5. data/lib/rails/application/default_middleware_stack.rb +1 -1
  6. data/lib/rails/application/finisher.rb +1 -1
  7. data/lib/rails/code_statistics.rb +1 -1
  8. data/lib/rails/commands/runner.rb +7 -1
  9. data/lib/rails/commands/server.rb +7 -3
  10. data/lib/rails/engine/commands.rb +3 -32
  11. data/lib/rails/engine/commands_tasks.rb +116 -0
  12. data/lib/rails/gem_version.rb +1 -1
  13. data/lib/rails/generators/actions.rb +2 -2
  14. data/lib/rails/generators/actions/create_migration.rb +1 -1
  15. data/lib/rails/generators/app_base.rb +22 -1
  16. data/lib/rails/generators/generated_attribute.rb +3 -2
  17. data/lib/rails/generators/named_base.rb +4 -0
  18. data/lib/rails/generators/rails/app/app_generator.rb +18 -2
  19. data/lib/rails/generators/rails/app/templates/Gemfile +0 -3
  20. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +1 -1
  21. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +1 -1
  22. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +1 -1
  23. data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -3
  24. data/lib/rails/generators/rails/app/templates/config/cable.yml +10 -0
  25. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
  26. data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +3 -2
  27. data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +3 -2
  28. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +2 -1
  29. data/lib/rails/generators/rails/app/templates/config/initializers/per_form_csrf_tokens.rb +4 -0
  30. data/lib/rails/generators/rails/app/templates/config/puma.rb +44 -0
  31. data/lib/rails/generators/rails/app/templates/config/secrets.yml +1 -1
  32. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
  33. data/lib/rails/generators/rails/model/USAGE +4 -4
  34. data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -1
  35. data/lib/rails/generators/rails/plugin/templates/README.md +26 -1
  36. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +7 -0
  37. data/lib/rails/generators/rails/plugin/templates/app/models/{application_record.rb.tt → %namespaced_name%/application_record.rb.tt} +0 -0
  38. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +1 -1
  39. data/lib/rails/generators/rails/scaffold/USAGE +1 -1
  40. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +1 -1
  41. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -2
  42. data/lib/rails/rack/logger.rb +0 -6
  43. data/lib/rails/tasks/engine.rake +2 -2
  44. data/lib/rails/tasks/log.rake +19 -6
  45. data/lib/rails/tasks/routes.rake +30 -2
  46. data/lib/rails/templates/rails/welcome/index.html.erb +61 -265
  47. data/lib/rails/test_unit/line_filtering.rb +70 -0
  48. data/lib/rails/test_unit/minitest_plugin.rb +12 -9
  49. data/lib/rails/test_unit/railtie.rb +6 -0
  50. data/lib/rails/test_unit/reporter.rb +37 -1
  51. data/lib/rails/test_unit/test_requirer.rb +1 -1
  52. data/lib/rails/test_unit/testing.rake +6 -1
  53. metadata +17 -13
  54. data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +0 -9
  55. data/lib/rails/generators/rails/plugin/templates/app/mailers/.empty_directory +0 -0
  56. data/lib/rails/generators/rails/plugin/templates/app/models/.empty_directory +0 -0
@@ -23,8 +23,9 @@ module Rails
23
23
  type = type.to_sym if type
24
24
 
25
25
  if type && reference?(type)
26
- references_index = UNIQ_INDEX_OPTIONS.include?(has_index) ? { unique: true } : true
27
- attr_options[:index] = references_index
26
+ if UNIQ_INDEX_OPTIONS.include?(has_index)
27
+ attr_options[:index] = { unique: true }
28
+ end
28
29
  end
29
30
 
30
31
  new(name, type, has_index, attr_options)
@@ -161,6 +161,10 @@ module Rails
161
161
  @route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name
162
162
  end
163
163
 
164
+ def url_helper_prefix
165
+ @url_helper_prefix ||= (class_path + [file_name]).join('_')
166
+ end
167
+
164
168
  # Tries to retrieve the application name or simply return application.
165
169
  def application_name
166
170
  if defined?(Rails) && Rails.application
@@ -57,7 +57,7 @@ module Rails
57
57
  directory 'app'
58
58
 
59
59
  keep_file 'app/assets/images'
60
- keep_file 'app/assets/javascripts/channels' unless options[:skip_action_cable]
60
+ empty_directory_with_keep_file 'app/assets/javascripts/channels' unless options[:skip_action_cable]
61
61
 
62
62
  keep_file 'app/controllers/concerns'
63
63
  keep_file 'app/models/concerns'
@@ -78,11 +78,12 @@ module Rails
78
78
  template "application.rb"
79
79
  template "environment.rb"
80
80
  template "secrets.yml"
81
+ template "cable.yml" unless options[:skip_action_cable]
82
+ template "puma.rb" unless options[:skip_puma]
81
83
 
82
84
  directory "environments"
83
85
  directory "initializers"
84
86
  directory "locales"
85
- directory "redis" unless options[:skip_action_cable]
86
87
  end
87
88
  end
88
89
 
@@ -313,11 +314,26 @@ module Rails
313
314
  end
314
315
  end
315
316
 
317
+ def delete_action_cable_files_skipping_action_cable
318
+ if options[:skip_action_cable]
319
+ remove_file 'config/cable.yml'
320
+ remove_file 'app/assets/javascripts/cable.coffee'
321
+ remove_dir 'app/channels'
322
+ end
323
+ end
324
+
316
325
  def delete_non_api_initializers_if_api_option
317
326
  if options[:api]
318
327
  remove_file 'config/initializers/session_store.rb'
319
328
  remove_file 'config/initializers/cookies_serializer.rb'
320
329
  remove_file 'config/initializers/request_forgery_protection.rb'
330
+ remove_file 'config/initializers/per_form_csrf_tokens.rb'
331
+ end
332
+ end
333
+
334
+ def delete_api_initializers
335
+ unless options[:api]
336
+ remove_file 'config/initializers/cors.rb'
321
337
  end
322
338
  end
323
339
 
@@ -12,9 +12,6 @@ source 'https://rubygems.org'
12
12
  <% end -%>
13
13
  <% end -%>
14
14
 
15
- # Use Puma as the app server
16
- gem 'puma'
17
-
18
15
  # Use ActiveModel has_secure_password
19
16
  # gem 'bcrypt', '~> 3.1.7'
20
17
 
@@ -1,4 +1,4 @@
1
- # Action Cable provides the framework to deal with WebSockets in Rails.
1
+ # Action Cable provides the framework to deal with WebSockets in Rails.
2
2
  # You can generate new channels where WebSocket features live using the rails generate channel command.
3
3
  #
4
4
  # Turn on the cable connection by removing the comments after the require statements (and ensure it's also on in config/routes.rb).
@@ -1,4 +1,4 @@
1
- # Be sure to restart your server when you modify this file. Action Cable runs in an EventMachine loop that does not support auto reloading.
1
+ # Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
2
2
  module ApplicationCable
3
3
  class Channel < ActionCable::Channel::Base
4
4
  end
@@ -1,4 +1,4 @@
1
- # Be sure to restart your server when you modify this file. Action Cable runs in an EventMachine loop that does not support auto reloading.
1
+ # Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
2
2
  module ApplicationCable
3
3
  class Connection < ActionCable::Connection::Base
4
4
  end
@@ -1,11 +1,10 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
3
  require ::File.expand_path('../config/environment', __FILE__)
4
-
5
4
  <%- unless options[:skip_action_cable] -%>
6
- # Action Cable uses EventMachine which requires that all classes are loaded in advance
5
+
6
+ # Action Cable requires that all classes are loaded in advance
7
7
  Rails.application.eager_load!
8
- require 'action_cable/process/logging'
9
8
  <%- end -%>
10
9
 
11
10
  run Rails.application
@@ -0,0 +1,10 @@
1
+ # Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
2
+ production:
3
+ adapter: redis
4
+ url: redis://localhost:6379/1
5
+
6
+ development:
7
+ adapter: async
8
+
9
+ test:
10
+ adapter: async
@@ -54,7 +54,7 @@ Rails.application.configure do
54
54
  config.log_level = :debug
55
55
 
56
56
  # Prepend all log lines with the following tags.
57
- # config.log_tags = [ :subdomain, :request_id ]
57
+ config.log_tags = [ :request_id ]
58
58
 
59
59
  # Use a different logger for distributed setups.
60
60
  # require 'syslog/logger'
@@ -1,5 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Require `belongs_to` associations by default. This is a new Rails 5.0 default,
4
- # so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading.
3
+ # Require `belongs_to` associations by default. This is a new Rails 5.0
4
+ # default, so it is introduced as a configuration option to ensure that apps
5
+ # made on earlier versions of Rails are not affected when upgrading.
5
6
  Rails.application.config.active_record.belongs_to_required_by_default = true
@@ -1,5 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Do not halt callback chains when a callback returns false. This is a new Rails 5.0 default,
4
- # so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading.
3
+ # Do not halt callback chains when a callback returns false. This is a new
4
+ # Rails 5.0 default, so it is introduced as a configuration option to ensure
5
+ # that apps made with earlier versions of Rails are not affected when upgrading.
5
6
  ActiveSupport.halt_callback_chains_on_return_false = false
@@ -1,4 +1,5 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # This is a new Rails 5.0 default, so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading.
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
4
5
  Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Enable per-form CSRF tokens.
4
+ Rails.application.config.action_controller.per_form_csrf_tokens = true
@@ -0,0 +1,44 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum, this matches the default thread size of Active Record.
6
+ #
7
+ threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
8
+ threads threads_count, threads_count
9
+
10
+ # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11
+ #
12
+ port ENV.fetch("PORT") { 3000 }
13
+
14
+ # Specifies the `environment` that Puma will run in.
15
+ #
16
+ environment ENV.fetch("RAILS_ENV") { "development" }
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25
+
26
+ # Use the `preload_app!` method when specifying a `workers` number.
27
+ # This directive tells Puma to first boot the application and load code
28
+ # before forking the application. This takes advantage of Copy On Write
29
+ # process behavior so workers use less memory. If you use this option
30
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
31
+ # block.
32
+ #
33
+ # preload_app!
34
+
35
+ # The code in the `on_worker_boot` will be called if you are using
36
+ # clustered mode by specifying a number of `workers`. After each worker
37
+ # process is booted this block will be run, if you are using `preload_app!`
38
+ # option you will want to use this block to reconnect to any threads
39
+ # or connections that may have been created at application boot, Ruby
40
+ # cannot share connections between processes.
41
+ #
42
+ # on_worker_boot do
43
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
+ # end
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Make sure the secret is at least 30 characters and all random,
7
7
  # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
8
+ # You can use `rails secret` to generate a secure secret key.
9
9
 
10
10
  # Make sure the secrets in this file are kept private
11
11
  # if you're sharing your code publicly.
@@ -1,5 +1,5 @@
1
1
  # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rails db:seed (or created alongside the db with db:setup).
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
3
  #
4
4
  # Examples:
5
5
  #
@@ -8,14 +8,14 @@ Description:
8
8
 
9
9
  As a special case, specifying 'password:digest' will generate a
10
10
  password_digest field of string type, and configure your generated model and
11
- tests for use with ActiveModel has_secure_password (assuming the default ORM
11
+ tests for use with Active Model has_secure_password (assuming the default ORM
12
12
  and test framework are being used).
13
13
 
14
14
  You don't have to think up every attribute up front, but it helps to
15
15
  sketch out a few so you can start working with the model immediately.
16
16
 
17
17
  This generator invokes your configured ORM and test framework, which
18
- defaults to ActiveRecord and TestUnit.
18
+ defaults to Active Record and TestUnit.
19
19
 
20
20
  Finally, if --parent option is given, it's used as superclass of the
21
21
  created model. This allows you create Single Table Inheritance models.
@@ -91,7 +91,7 @@ Available field types:
91
91
  Examples:
92
92
  `rails generate model account`
93
93
 
94
- For ActiveRecord and TestUnit it creates:
94
+ For Active Record and TestUnit it creates:
95
95
 
96
96
  Model: app/models/account.rb
97
97
  Test: test/models/account_test.rb
@@ -104,7 +104,7 @@ Examples:
104
104
 
105
105
  `rails generate model admin/account`
106
106
 
107
- For ActiveRecord and TestUnit it creates:
107
+ For Active Record and TestUnit it creates:
108
108
 
109
109
  Module: app/models/admin.rb
110
110
  Model: app/models/admin/account.rb
@@ -259,6 +259,12 @@ task default: :test
259
259
 
260
260
  public_task :apply_rails_template, :run_bundle
261
261
 
262
+ def run_after_bundle_callbacks
263
+ @after_bundle_callbacks.each do |callback|
264
+ callback.call
265
+ end
266
+ end
267
+
262
268
  def name
263
269
  @name ||= begin
264
270
  # same as ActiveSupport::Inflector#underscore except not replacing '-'
@@ -337,7 +343,7 @@ task default: :test
337
343
  end
338
344
 
339
345
  def wrap_in_modules(unwrapped_code)
340
- unwrapped_code = "#{unwrapped_code}".strip.gsub(/\W$\n/, '')
346
+ unwrapped_code = "#{unwrapped_code}".strip.gsub(/\s$\n/, '')
341
347
  modules.reverse.inject(unwrapped_code) do |content, mod|
342
348
  str = "module #{mod}\n"
343
349
  str += content.lines.map { |line| " #{line}" }.join
@@ -1,3 +1,28 @@
1
1
  # <%= camelized_modules %>
2
+ Short description and motivation.
2
3
 
3
- This project rocks and uses MIT-LICENSE.
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem '<%= name %>'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install <%= name %>
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ rb
7
+ %>
@@ -1,7 +1,7 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require File.expand_path("../../<%= options[:dummy_path] -%>/config/environment.rb", __FILE__)
4
+ require File.expand_path("../../<%= options[:dummy_path] -%>/config/environment.rb", __FILE__)
5
5
  <% unless options[:skip_active_record] -%>
6
6
  ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../<%= options[:dummy_path] -%>/db/migrate", __FILE__)]
7
7
  <% if options[:mountable] -%>
@@ -16,7 +16,7 @@ Description:
16
16
 
17
17
  As a special case, specifying 'password:digest' will generate a
18
18
  password_digest field of string type, and configure your generated model,
19
- controller, views, and test suite for use with ActiveModel
19
+ controller, views, and test suite for use with Active Model
20
20
  has_secure_password (assuming they are using Rails defaults).
21
21
 
22
22
  Timestamps are added by default, so you don't have to specify them by hand
@@ -13,7 +13,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
13
13
  <% else -%>
14
14
  <% actions.each do |action| -%>
15
15
  test "should get <%= action %>" do
16
- get <%= file_name %>_<%= action %>_url
16
+ get <%= url_helper_prefix %>_<%= action %>_url
17
17
  assert_response :success
18
18
  end
19
19
 
@@ -17,7 +17,7 @@
17
17
  <% end -%>
18
18
  <% else -%>
19
19
 
20
- # This model initially had no columns defined. If you add columns to the
20
+ # This model initially had no columns defined. If you add columns to the
21
21
  # model remove the '{}' from the fixture names and add the columns immediately
22
22
  # below each fixture, per the syntax in the comments below
23
23
  #
@@ -25,5 +25,5 @@ one: {}
25
25
  # column: value
26
26
  #
27
27
  two: {}
28
- # column: value
28
+ # column: value
29
29
  <% end -%>
@@ -30,12 +30,6 @@ module Rails
30
30
  protected
31
31
 
32
32
  def call_app(request, env)
33
- # Put some space between requests in development logs.
34
- if development?
35
- logger.debug ''
36
- logger.debug ''
37
- end
38
-
39
33
  instrumenter = ActiveSupport::Notifications.instrumenter
40
34
  instrumenter.start 'request.action_dispatch', request: request
41
35
  logger.info { started_request_message(request) }
@@ -4,8 +4,8 @@ task "load_app" do
4
4
  end
5
5
  task :environment => "app:environment"
6
6
 
7
- if !defined?(ENGINE_PATH) || !ENGINE_PATH
8
- ENGINE_PATH = find_engine_path(APP_RAKEFILE)
7
+ if !defined?(ENGINE_ROOT) || !ENGINE_ROOT
8
+ ENGINE_ROOT = find_engine_path(APP_RAKEFILE)
9
9
  end
10
10
  end
11
11
 
@@ -1,5 +1,12 @@
1
1
  namespace :log do
2
- desc "Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
2
+
3
+ ##
4
+ # Truncates all/specified log files
5
+ # ENV['LOGS']
6
+ # - defaults to standard environment log files i.e. 'development,test,production'
7
+ # - ENV['LOGS']=all truncates all files i.e. log/*.log
8
+ # - ENV['LOGS']='test,development' truncates only specified files
9
+ desc "Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
3
10
  task :clear do
4
11
  log_files.each do |file|
5
12
  clear_log_file(file)
@@ -7,15 +14,21 @@ namespace :log do
7
14
  end
8
15
 
9
16
  def log_files
10
- if ENV['LOGS']
11
- ENV['LOGS'].split(',')
12
- .map { |file| "log/#{file.strip}.log" }
13
- .select { |file| File.exist?(file) }
14
- else
17
+ if ENV['LOGS'] == 'all'
15
18
  FileList["log/*.log"]
19
+ elsif ENV['LOGS']
20
+ log_files_to_truncate(ENV['LOGS'])
21
+ else
22
+ log_files_to_truncate("development,test,production")
16
23
  end
17
24
  end
18
25
 
26
+ def log_files_to_truncate(envs)
27
+ envs.split(',')
28
+ .map { |file| "log/#{file.strip}.log" }
29
+ .select { |file| File.exist?(file) }
30
+ end
31
+
19
32
  def clear_log_file(file)
20
33
  f = File.open(file, "w")
21
34
  f.close