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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -385
  3. data/README.rdoc +1 -1
  4. data/bin/rails +1 -1
  5. data/lib/rails.rb +11 -13
  6. data/lib/rails/all.rb +1 -0
  7. data/lib/rails/api/task.rb +9 -12
  8. data/lib/rails/app_rails_loader.rb +2 -2
  9. data/lib/rails/application.rb +154 -149
  10. data/lib/rails/application/configuration.rb +1 -14
  11. data/lib/rails/application/default_middleware_stack.rb +99 -0
  12. data/lib/rails/application/finisher.rb +2 -0
  13. data/lib/rails/application_controller.rb +16 -0
  14. data/lib/rails/cli.rb +1 -2
  15. data/lib/rails/commands.rb +2 -94
  16. data/lib/rails/commands/application.rb +2 -28
  17. data/lib/rails/commands/commands_tasks.rb +174 -0
  18. data/lib/rails/commands/console.rb +2 -2
  19. data/lib/rails/commands/dbconsole.rb +1 -1
  20. data/lib/rails/commands/plugin.rb +23 -0
  21. data/lib/rails/commands/runner.rb +1 -1
  22. data/lib/rails/commands/server.rb +46 -30
  23. data/lib/rails/configuration.rb +4 -1
  24. data/lib/rails/console/helpers.rb +6 -0
  25. data/lib/rails/engine.rb +29 -18
  26. data/lib/rails/engine/commands.rb +1 -1
  27. data/lib/rails/engine/railties.rb +0 -8
  28. data/lib/rails/generators.rb +4 -3
  29. data/lib/rails/generators/actions.rb +1 -1
  30. data/lib/rails/generators/active_model.rb +0 -8
  31. data/lib/rails/generators/app_base.rb +213 -74
  32. data/lib/rails/generators/base.rb +17 -16
  33. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
  34. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -3
  35. data/lib/rails/generators/migration.rb +18 -26
  36. data/lib/rails/generators/named_base.rb +4 -7
  37. data/lib/rails/generators/rails/app/app_generator.rb +91 -5
  38. data/lib/rails/generators/rails/app/templates/Gemfile +20 -15
  39. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  40. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -0
  41. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -3
  42. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +5 -1
  43. data/lib/rails/generators/rails/app/templates/config/application.rb +2 -0
  44. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +7 -10
  45. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +11 -31
  46. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +25 -29
  47. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +8 -10
  48. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +8 -11
  49. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +6 -3
  50. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -22
  51. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +7 -9
  52. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +9 -12
  53. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +8 -8
  54. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +7 -17
  55. data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
  56. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -5
  57. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -4
  59. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  60. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  61. data/lib/rails/generators/rails/app/templates/config/{initializers/secret_token.rb.tt → secrets.yml} +10 -2
  62. data/lib/rails/generators/rails/app/templates/public/404.html +20 -11
  63. data/lib/rails/generators/rails/app/templates/public/422.html +20 -11
  64. data/lib/rails/generators/rails/app/templates/public/500.html +19 -10
  65. data/lib/rails/generators/rails/controller/USAGE +1 -0
  66. data/lib/rails/generators/rails/controller/controller_generator.rb +35 -1
  67. data/lib/rails/generators/rails/generator/USAGE +1 -0
  68. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
  69. data/lib/rails/generators/rails/model/USAGE +5 -5
  70. data/lib/rails/generators/rails/{plugin_new → plugin}/USAGE +0 -0
  71. data/lib/rails/generators/rails/{plugin_new/plugin_new_generator.rb → plugin/plugin_generator.rb} +10 -4
  72. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/%name%.gemspec +1 -0
  73. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Gemfile +16 -1
  74. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/MIT-LICENSE +0 -0
  75. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/README.rdoc +0 -0
  76. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Rakefile +0 -0
  77. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/controllers/%name%/application_controller.rb.tt +0 -0
  78. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/helpers/%name%/application_helper.rb.tt +0 -0
  79. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory +0 -0
  80. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/models/.empty_directory +0 -0
  81. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/views/layouts/%name%/application.html.erb.tt +0 -0
  82. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/bin/rails.tt +0 -4
  83. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/config/routes.rb +0 -0
  84. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/gitignore +0 -0
  85. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%.rb +0 -0
  86. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/engine.rb +0 -0
  87. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/version.rb +0 -0
  88. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/tasks/%name%_tasks.rake +0 -0
  89. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/application.rb +1 -0
  90. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/boot.rb +0 -0
  91. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/javascripts.js +0 -0
  92. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/routes.rb +0 -0
  93. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/stylesheets.css +5 -3
  94. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/%name%_test.rb +0 -0
  95. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb +0 -0
  96. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/test_helper.rb +0 -0
  97. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
  98. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
  99. data/lib/rails/generators/resource_helpers.rb +20 -5
  100. data/lib/rails/generators/test_unit/generator/generator_generator.rb +26 -0
  101. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb +16 -0
  102. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -1
  103. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +11 -0
  104. data/lib/rails/generators/testing/assertions.rb +1 -1
  105. data/lib/rails/generators/testing/behaviour.rb +3 -13
  106. data/lib/rails/info.rb +5 -3
  107. data/lib/rails/info_controller.rb +5 -15
  108. data/lib/rails/mailers_controller.rb +73 -0
  109. data/lib/rails/paths.rb +13 -18
  110. data/lib/rails/rack/debugger.rb +2 -2
  111. data/lib/rails/rack/logger.rb +1 -1
  112. data/lib/rails/railtie.rb +38 -2
  113. data/lib/rails/source_annotation_extractor.rb +2 -2
  114. data/lib/rails/tasks.rb +0 -2
  115. data/lib/rails/tasks/documentation.rake +0 -5
  116. data/lib/rails/tasks/engine.rake +1 -1
  117. data/lib/rails/tasks/framework.rake +2 -12
  118. data/lib/rails/templates/layouts/application.html.erb +2 -2
  119. data/lib/rails/templates/rails/mailers/email.html.erb +98 -0
  120. data/lib/rails/templates/rails/mailers/index.html.erb +8 -0
  121. data/lib/rails/templates/rails/mailers/mailer.html.erb +6 -0
  122. data/lib/rails/test_help.rb +4 -1
  123. data/lib/rails/test_unit/sub_test_task.rb +44 -3
  124. data/lib/rails/test_unit/testing.rake +9 -111
  125. data/lib/rails/version.rb +3 -3
  126. data/lib/rails/welcome_controller.rb +4 -3
  127. metadata +99 -76
  128. data/lib/rails/commands/plugin_new.rb +0 -9
  129. data/lib/rails/generators/actions/create_migration.rb +0 -68
@@ -17,7 +17,7 @@ The latest version of Railties can be installed with RubyGems:
17
17
 
18
18
  Source code can be downloaded as part of the Rails project on GitHub
19
19
 
20
- * https://github.com/rails/rails/tree/4-0-stable/railties
20
+ * https://github.com/rails/rails/tree/master/railties
21
21
 
22
22
  == License
23
23
 
data/bin/rails CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- git_path = File.join(File.expand_path('../../..', __FILE__), '.git')
3
+ git_path = File.expand_path('../../../.git', __FILE__)
4
4
 
5
5
  if File.exist?(git_path)
6
6
  railties_path = File.expand_path('../../lib', __FILE__)
@@ -3,12 +3,13 @@ require 'rails/ruby_version_check'
3
3
  require 'pathname'
4
4
 
5
5
  require 'active_support'
6
+ require 'active_support/dependencies/autoload'
6
7
  require 'active_support/core_ext/kernel/reporting'
8
+ require 'active_support/core_ext/module/delegation'
7
9
  require 'active_support/core_ext/array/extract_options'
8
10
 
9
11
  require 'rails/application'
10
12
  require 'rails/version'
11
- require 'rails/deprecation'
12
13
 
13
14
  require 'active_support/railtie'
14
15
  require 'action_dispatch/railtie'
@@ -20,26 +21,23 @@ silence_warnings do
20
21
  end
21
22
 
22
23
  module Rails
23
- autoload :Info, 'rails/info'
24
- autoload :InfoController, 'rails/info_controller'
25
- autoload :WelcomeController, 'rails/welcome_controller'
24
+ extend ActiveSupport::Autoload
25
+
26
+ autoload :Info
27
+ autoload :InfoController
28
+ autoload :MailersController
29
+ autoload :WelcomeController
26
30
 
27
31
  class << self
28
32
  attr_accessor :application, :cache, :logger
29
33
 
34
+ delegate :initialize!, :initialized?, to: :application
35
+
30
36
  # The Configuration instance used to configure the Rails environment
31
37
  def configuration
32
38
  application.config
33
39
  end
34
40
 
35
- def initialize!
36
- application.initialize!
37
- end
38
-
39
- def initialized?
40
- application.initialized?
41
- end
42
-
43
41
  def backtrace_cleaner
44
42
  @backtrace_cleaner ||= begin
45
43
  # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded
@@ -76,7 +74,7 @@ module Rails
76
74
  env = Rails.env
77
75
  groups.unshift(:default, env)
78
76
  groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
79
- groups.concat hash.map { |k,v| k if v.map(&:to_s).include?(env) }
77
+ groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) }
80
78
  groups.compact!
81
79
  groups.uniq!
82
80
  groups
@@ -3,6 +3,7 @@ require "rails"
3
3
  %w(
4
4
  active_record
5
5
  action_controller
6
+ action_view
6
7
  action_mailer
7
8
  rails/test_unit
8
9
  sprockets
@@ -7,7 +7,6 @@ module Rails
7
7
  'activesupport' => {
8
8
  :include => %w(
9
9
  README.rdoc
10
- CHANGELOG.md
11
10
  lib/active_support/**/*.rb
12
11
  ),
13
12
  :exclude => 'lib/active_support/vendor/*'
@@ -16,16 +15,13 @@ module Rails
16
15
  'activerecord' => {
17
16
  :include => %w(
18
17
  README.rdoc
19
- CHANGELOG.md
20
18
  lib/active_record/**/*.rb
21
- ),
22
- :exclude => 'lib/active_record/vendor/*'
19
+ )
23
20
  },
24
21
 
25
22
  'activemodel' => {
26
23
  :include => %w(
27
24
  README.rdoc
28
- CHANGELOG.md
29
25
  lib/active_model/**/*.rb
30
26
  )
31
27
  },
@@ -33,29 +29,30 @@ module Rails
33
29
  'actionpack' => {
34
30
  :include => %w(
35
31
  README.rdoc
36
- CHANGELOG.md
37
32
  lib/abstract_controller/**/*.rb
38
33
  lib/action_controller/**/*.rb
39
34
  lib/action_dispatch/**/*.rb
35
+ )
36
+ },
37
+
38
+ 'actionview' => {
39
+ :include => %w(
40
+ README.rdoc
40
41
  lib/action_view/**/*.rb
41
42
  ),
42
- :exclude => 'lib/action_controller/vendor/*'
43
+ :exclude => 'lib/action_view/vendor/*'
43
44
  },
44
45
 
45
46
  'actionmailer' => {
46
47
  :include => %w(
47
48
  README.rdoc
48
- CHANGELOG.md
49
49
  lib/action_mailer/**/*.rb
50
- ),
51
- :exclude => 'lib/action_mailer/vendor/*'
50
+ )
52
51
  },
53
52
 
54
53
  'railties' => {
55
54
  :include => %w(
56
55
  README.rdoc
57
- CHANGELOG.md
58
- MIT-LICENSE
59
56
  lib/**/*.rb
60
57
  ),
61
58
  :exclude => 'lib/rails/generators/rails/**/templates/**/*.rb'
@@ -2,7 +2,7 @@ require 'pathname'
2
2
 
3
3
  module Rails
4
4
  module AppRailsLoader
5
- RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
5
+ RUBY = Gem.ruby
6
6
  EXECUTABLES = ['bin/rails', 'script/rails']
7
7
  BUNDLER_WARNING = <<EOS
8
8
  Looks like your app's ./bin/rails is a stub that was generated by Bundler.
@@ -49,7 +49,7 @@ EOS
49
49
  # call to generate a new application, so restore the original cwd.
50
50
  Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root?
51
51
 
52
- # Otherwise keep moving upwards in search of a executable.
52
+ # Otherwise keep moving upwards in search of an executable.
53
53
  Dir.chdir('..')
54
54
  end
55
55
  end
@@ -1,6 +1,8 @@
1
1
  require 'fileutils'
2
+ require 'active_support/core_ext/hash/keys'
2
3
  require 'active_support/core_ext/object/blank'
3
4
  require 'active_support/key_generator'
5
+ require 'active_support/message_verifier'
4
6
  require 'rails/engine'
5
7
 
6
8
  module Rails
@@ -51,21 +53,49 @@ module Rails
51
53
  # 10) Run config.before_eager_load and eager_load! if eager_load is true
52
54
  # 11) Run config.after_initialize callbacks
53
55
  #
56
+ # == Multiple Applications
57
+ #
58
+ # If you decide to define multiple applications, then the first application
59
+ # that is initialized will be set to +Rails.application+, unless you override
60
+ # it with a different application.
61
+ #
62
+ # To create a new application, you can instantiate a new instance of a class
63
+ # that has already been created:
64
+ #
65
+ # class Application < Rails::Application
66
+ # end
67
+ #
68
+ # first_application = Application.new
69
+ # second_application = Application.new(config: first_application.config)
70
+ #
71
+ # In the above example, the configuration from the first application was used
72
+ # to initialize the second application. You can also use the +initialize_copy+
73
+ # on one of the applications to create a copy of the application which shares
74
+ # the configuration.
75
+ #
76
+ # If you decide to define rake tasks, runners, or initializers in an
77
+ # application other than +Rails.application+, then you must run those
78
+ # these manually.
54
79
  class Application < Engine
55
- autoload :Bootstrap, 'rails/application/bootstrap'
56
- autoload :Configuration, 'rails/application/configuration'
57
- autoload :Finisher, 'rails/application/finisher'
58
- autoload :Railties, 'rails/engine/railties'
59
- autoload :RoutesReloader, 'rails/application/routes_reloader'
80
+ autoload :Bootstrap, 'rails/application/bootstrap'
81
+ autoload :Configuration, 'rails/application/configuration'
82
+ autoload :DefaultMiddlewareStack, 'rails/application/default_middleware_stack'
83
+ autoload :Finisher, 'rails/application/finisher'
84
+ autoload :Railties, 'rails/engine/railties'
85
+ autoload :RoutesReloader, 'rails/application/routes_reloader'
60
86
 
61
87
  class << self
62
88
  def inherited(base)
63
- raise "You cannot have more than one Rails::Application" if Rails.application
64
89
  super
65
- Rails.application = base.instance
66
- Rails.application.add_lib_to_load_path!
67
- ActiveSupport.run_load_hooks(:before_configuration, base.instance)
90
+ Rails.application ||= base.instance
68
91
  end
92
+
93
+ # Makes the +new+ method public.
94
+ #
95
+ # Note that Rails::Application inherits from Rails::Engine, which
96
+ # inherits from Rails::Railtie and the +new+ method on Rails::Railtie is
97
+ # private
98
+ public :new
69
99
  end
70
100
 
71
101
  attr_accessor :assets, :sandbox
@@ -74,14 +104,29 @@ module Rails
74
104
 
75
105
  delegate :default_url_options, :default_url_options=, to: :routes
76
106
 
77
- def initialize
78
- super
79
- @initialized = false
80
- @reloaders = []
81
- @routes_reloader = nil
82
- @app_env_config = nil
83
- @ordered_railties = nil
84
- @railties = nil
107
+ INITIAL_VARIABLES = [:config, :railties, :routes_reloader, :reloaders,
108
+ :routes, :helpers, :app_env_config, :secrets] # :nodoc:
109
+
110
+ def initialize(initial_variable_values = {}, &block)
111
+ super()
112
+ @initialized = false
113
+ @reloaders = []
114
+ @routes_reloader = nil
115
+ @app_env_config = nil
116
+ @ordered_railties = nil
117
+ @railties = nil
118
+ @message_verifiers = {}
119
+
120
+ add_lib_to_load_path!
121
+ ActiveSupport.run_load_hooks(:before_configuration, self)
122
+
123
+ initial_variable_values.each do |variable_name, value|
124
+ if INITIAL_VARIABLES.include?(variable_name)
125
+ instance_variable_set("@#{variable_name}", value)
126
+ end
127
+ end
128
+
129
+ instance_eval(&block) if block_given?
85
130
  end
86
131
 
87
132
  # Returns true if the application is initialized.
@@ -102,14 +147,13 @@ module Rails
102
147
  routes_reloader.reload!
103
148
  end
104
149
 
105
-
106
150
  # Return the application's KeyGenerator
107
151
  def key_generator
108
152
  # number of iterations selected based on consultation with the google security
109
153
  # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
110
154
  @caching_key_generator ||= begin
111
- if config.secret_key_base
112
- key_generator = ActiveSupport::KeyGenerator.new(config.secret_key_base, iterations: 1000)
155
+ if secrets.secret_key_base
156
+ key_generator = ActiveSupport::KeyGenerator.new(secrets.secret_key_base, iterations: 1000)
113
157
  ActiveSupport::CachingKeyGenerator.new(key_generator)
114
158
  else
115
159
  ActiveSupport::LegacyKeyGenerator.new(config.secret_token)
@@ -117,40 +161,42 @@ module Rails
117
161
  end
118
162
  end
119
163
 
120
- # Stores some of the Rails initial environment parameters which
121
- # will be used by middlewares and engines to configure themselves.
122
- # Currently stores:
164
+ # Returns a message verifier object.
165
+ #
166
+ # This verifier can be used to generate and verify signed messages in the application.
167
+ #
168
+ # It is recommended not to use the same verifier for different things, so you can get different
169
+ # verifiers passing the +verifier_name+ argument.
123
170
  #
124
- # * "action_dispatch.parameter_filter" => config.filter_parameters
125
- # * "action_dispatch.redirect_filter" => config.filter_redirect
126
- # * "action_dispatch.secret_token" => config.secret_token
127
- # * "action_dispatch.secret_key_base" => config.secret_key_base
128
- # * "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions
129
- # * "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local
130
- # * "action_dispatch.logger" => Rails.logger
131
- # * "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
132
- # * "action_dispatch.key_generator" => key_generator
133
- # * "action_dispatch.http_auth_salt" => config.action_dispatch.http_auth_salt
134
- # * "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt
135
- # * "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt
136
- # * "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt
171
+ # ==== Parameters
137
172
  #
173
+ # * +salt+ - the salt that will be used to generate the secret key of the verifier.
174
+ #
175
+ # ==== Examples
176
+ #
177
+ # message = Rails.application.message_verifier('salt').generate('my sensible data')
178
+ # Rails.application.message_verifier('salt').verify(message)
179
+ # # => 'my sensible data'
180
+ #
181
+ # See the +ActiveSupport::MessageVerifier+ documentation for more information.
182
+ def message_verifier(salt)
183
+ @message_verifiers[salt] ||= begin
184
+ secret = key_generator.generate_key(salt)
185
+ ActiveSupport::MessageVerifier.new(secret)
186
+ end
187
+ end
188
+
189
+ # Stores some of the Rails initial environment parameters which
190
+ # will be used by middlewares and engines to configure themselves.
138
191
  def env_config
139
192
  @app_env_config ||= begin
140
- if config.secret_key_base.blank?
141
- ActiveSupport::Deprecation.warn "You didn't set config.secret_key_base. " +
142
- "Read the upgrade documentation to learn more about this new config option."
143
-
144
- if config.secret_token.blank?
145
- raise "You must set config.secret_key_base in your app's config."
146
- end
147
- end
193
+ validate_secret_key_config!
148
194
 
149
195
  super.merge({
150
196
  "action_dispatch.parameter_filter" => config.filter_parameters,
151
197
  "action_dispatch.redirect_filter" => config.filter_redirect,
152
198
  "action_dispatch.secret_token" => config.secret_token,
153
- "action_dispatch.secret_key_base" => config.secret_key_base,
199
+ "action_dispatch.secret_key_base" => secrets.secret_key_base,
154
200
  "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
155
201
  "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
156
202
  "action_dispatch.logger" => Rails.logger,
@@ -164,6 +210,30 @@ module Rails
164
210
  end
165
211
  end
166
212
 
213
+ # If you try to define a set of rake tasks on the instance, these will get
214
+ # passed up to the rake tasks defined on the application's class.
215
+ def rake_tasks(&block)
216
+ self.class.rake_tasks(&block)
217
+ end
218
+
219
+ # Sends the initializers to the +initializer+ method defined in the
220
+ # Rails::Initializable module. Each Rails::Application class has its own
221
+ # set of initializers, as defined by the Initializable module.
222
+ def initializer(name, opts={}, &block)
223
+ self.class.initializer(name, opts, &block)
224
+ end
225
+
226
+ # Sends any runner called in the instance of a new application up
227
+ # to the +runner+ method defined in Rails::Railtie.
228
+ def runner(&blk)
229
+ self.class.runner(&blk)
230
+ end
231
+
232
+ # Sends the +isolate_namespace+ method up to the class method.
233
+ def isolate_namespace(mod)
234
+ self.class.isolate_namespace(mod)
235
+ end
236
+
167
237
  ## Rails internal API
168
238
 
169
239
  # This method is called just after an application inherits from Rails::Application,
@@ -181,7 +251,9 @@ module Rails
181
251
  # you need to load files in lib/ during the application configuration as well.
182
252
  def add_lib_to_load_path! #:nodoc:
183
253
  path = File.join config.root, 'lib'
184
- $LOAD_PATH.unshift(path) if File.exist?(path)
254
+ if File.exist?(path) && !$LOAD_PATH.include?(path)
255
+ $LOAD_PATH.unshift(path)
256
+ end
185
257
  end
186
258
 
187
259
  def require_environment! #:nodoc:
@@ -207,9 +279,7 @@ module Rails
207
279
  end
208
280
 
209
281
  # Initialize the application passing the given group. By default, the
210
- # group is :default but sprockets precompilation passes group equals
211
- # to assets if initialize_on_precompile is false to avoid booting the
212
- # whole app.
282
+ # group is :default
213
283
  def initialize!(group=:default) #:nodoc:
214
284
  raise "Application has been already initialized." if @initialized
215
285
  run_initializers(group, self)
@@ -227,6 +297,31 @@ module Rails
227
297
  @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
228
298
  end
229
299
 
300
+ def config=(configuration) #:nodoc:
301
+ @config = configuration
302
+ end
303
+
304
+ def secrets #:nodoc:
305
+ @secrets ||= begin
306
+ secrets = ActiveSupport::OrderedOptions.new
307
+ yaml = config.paths["config/secrets"].first
308
+ if File.exist?(yaml)
309
+ require "erb"
310
+ env_secrets = YAML.load(ERB.new(IO.read(yaml)).result)[Rails.env]
311
+ secrets.merge!(env_secrets.symbolize_keys) if env_secrets
312
+ end
313
+
314
+ # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
315
+ secrets.secret_key_base ||= config.secret_key_base
316
+
317
+ secrets
318
+ end
319
+ end
320
+
321
+ def secrets=(secrets) #:nodoc:
322
+ @secrets = secrets
323
+ end
324
+
230
325
  def to_app #:nodoc:
231
326
  self
232
327
  end
@@ -235,16 +330,6 @@ module Rails
235
330
  config.helpers_paths
236
331
  end
237
332
 
238
- # Return an array of railties respecting the order they're loaded
239
- # and the order specified by the +railties_order+ config.
240
- #
241
- # While when running initializers we need engines in reverse
242
- # order here when copying migrations from railties we need then in the same
243
- # order as given by +railties_order+
244
- def migration_railties # :nodoc:
245
- ordered_railties.flatten - [self]
246
- end
247
-
248
333
  protected
249
334
 
250
335
  alias :build_middleware_stack :app
@@ -253,7 +338,6 @@ module Rails
253
338
  railties.each { |r| r.run_tasks_blocks(app) }
254
339
  super
255
340
  require "rails/tasks"
256
- config = self.config
257
341
  task :environment do
258
342
  ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
259
343
 
@@ -295,13 +379,13 @@ module Rails
295
379
 
296
380
  index = order.index(:all)
297
381
  order[index] = all
298
- order
382
+ order.reverse.flatten
299
383
  end
300
384
  end
301
385
 
302
386
  def railties_initializers(current) #:nodoc:
303
387
  initializers = []
304
- ordered_railties.reverse.flatten.each do |r|
388
+ ordered_railties.each do |r|
305
389
  if r == self
306
390
  initializers += current
307
391
  else
@@ -311,94 +395,9 @@ module Rails
311
395
  initializers
312
396
  end
313
397
 
314
- def reload_dependencies? #:nodoc:
315
- config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
316
- end
317
-
318
398
  def default_middleware_stack #:nodoc:
319
- ActionDispatch::MiddlewareStack.new.tap do |middleware|
320
- app = self
321
-
322
- if rack_cache = load_rack_cache
323
- require "action_dispatch/http/rack_cache"
324
- middleware.use ::Rack::Cache, rack_cache
325
- end
326
-
327
- if config.force_ssl
328
- middleware.use ::ActionDispatch::SSL, config.ssl_options
329
- end
330
-
331
- middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
332
-
333
- if config.serve_static_assets
334
- middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
335
- end
336
-
337
- middleware.use ::Rack::Lock unless allow_concurrency?
338
- middleware.use ::Rack::Runtime
339
- middleware.use ::Rack::MethodOverride
340
- middleware.use ::ActionDispatch::RequestId
341
-
342
- # Must come after Rack::MethodOverride to properly log overridden methods
343
- middleware.use ::Rails::Rack::Logger, config.log_tags
344
- middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
345
- middleware.use ::ActionDispatch::DebugExceptions, app
346
- middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
347
-
348
- unless config.cache_classes
349
- middleware.use ::ActionDispatch::Reloader, lambda { app.reload_dependencies? }
350
- end
351
-
352
- middleware.use ::ActionDispatch::Callbacks
353
- middleware.use ::ActionDispatch::Cookies
354
-
355
- if config.session_store
356
- if config.force_ssl && !config.session_options.key?(:secure)
357
- config.session_options[:secure] = true
358
- end
359
- middleware.use config.session_store, config.session_options
360
- middleware.use ::ActionDispatch::Flash
361
- end
362
-
363
- middleware.use ::ActionDispatch::ParamsParser
364
- middleware.use ::Rack::Head
365
- middleware.use ::Rack::ConditionalGet
366
- middleware.use ::Rack::ETag, "no-cache"
367
- end
368
- end
369
-
370
- def allow_concurrency?
371
- if config.allow_concurrency.nil?
372
- config.cache_classes
373
- else
374
- config.allow_concurrency
375
- end
376
- end
377
-
378
- def load_rack_cache
379
- rack_cache = config.action_dispatch.rack_cache
380
- return unless rack_cache
381
-
382
- begin
383
- require 'rack/cache'
384
- rescue LoadError => error
385
- error.message << ' Be sure to add rack-cache to your Gemfile'
386
- raise
387
- end
388
-
389
- if rack_cache == true
390
- {
391
- metastore: "rails:/",
392
- entitystore: "rails:/",
393
- verbose: false
394
- }
395
- else
396
- rack_cache
397
- end
398
- end
399
-
400
- def show_exceptions_app
401
- config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
399
+ default_stack = DefaultMiddlewareStack.new(self, config, paths)
400
+ default_stack.build_stack
402
401
  end
403
402
 
404
403
  def build_original_fullpath(env) #:nodoc:
@@ -412,5 +411,11 @@ module Rails
412
411
  "#{script_name}#{path_info}"
413
412
  end
414
413
  end
414
+
415
+ def validate_secret_key_config! #:nodoc:
416
+ if secrets.secret_key_base.blank? && config.secret_token.blank?
417
+ raise "You must set secret_key_base in your app's config"
418
+ end
419
+ end
415
420
  end
416
421
  end