aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md378
-rwxr-xr-xrailties/bin/rails4
-rw-r--r--railties/lib/rails/all.rb4
-rw-r--r--railties/lib/rails/engine.rb16
-rw-r--r--railties/lib/rails/generators/actions.rb2
-rw-r--r--railties/lib/rails/generators/app_base.rb46
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb6
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/index.html.erb14
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environment.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/routes.rb2
-rw-r--r--railties/lib/rails/railtie.rb40
-rw-r--r--railties/lib/rails/tasks/documentation.rake4
-rw-r--r--railties/lib/rails/test_unit/railtie.rb4
-rw-r--r--railties/lib/rails/version.rb2
-rw-r--r--railties/test/application/routing_test.rb24
-rw-r--r--railties/test/generators/actions_test.rb2
-rw-r--r--railties/test/generators/app_generator_test.rb6
-rw-r--r--railties/test/railties/engine_test.rb5
-rw-r--r--railties/test/railties/generators_test.rb2
-rw-r--r--railties/test/railties/railtie_test.rb11
27 files changed, 136 insertions, 458 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index f67177a047..e1b98eda55 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,375 +1,7 @@
-## Rails 4.0.0 (unreleased) ##
+* Rails::Railtie no longer forces the Rails::Configurable module on everything
+ that subclassess it. Instead, the methods from Rails::Configurable have been
+ moved to class methods in Railtie and the Railtie has been made abstract.
-* Move rails.png into a data-uri. One less file to get generated into a new
- application. This is also consistent with the removal of index.html.
+ *John Wang*
- *Steve Klabnik*
-
-* The application rake task `doc:rails` generates now an API like the
- official one (except for the links to GitHub).
-
- *Xavier Noria*
-
-* Allow vanilla apps to render CoffeeScript templates in production
-
- Vanilla apps already render CoffeeScript templates in development and test
- environments. With this change, the production behavior matches that of
- the other environments.
-
- Effectively, this meant moving coffee-rails (and the JavaScript runtime on
- which it is dependent) from the :assets group to the top-level of the
- generated Gemfile.
-
- *Gabe Kopley*
-
-* Don't generate a scaffold.css when --no-assets is specified
-
- *Kevin Glowacz*
-
-* Add support for generate scaffold password:digest
-
- * adds password_digest attribute to the migration
- * adds has_secure_password to the model
- * adds password and password_confirmation password_fields to _form.html
- * omits password from index.html and show.html
- * adds password and password_confirmation to the controller
- * adds unencrypted password and password_confirmation to the controller test
- * adds encrypted password_digest to the fixture
-
- *Sam Ruby*
-
-* Improved `rake test` command for running tests
-
- To run all tests:
-
- $ rake test
-
- To run a test suite
-
- $ rake test:[models,helpers,units,controllers,mailers,...]
-
- To run a selected test file(s):
-
- $ rake test test/unit/foo_test.rb [test/unit/bar_test.rb ...]
-
- To run a single test from a test file
-
- $ rake test test/unit/foo_test.rb TESTOPTS='-n test_the_truth'
-
-* Improve service pages with new layout (404, etc).
-
- *Stanislav Sobolev*
-
-
-## Rails 4.0.0.beta1 (February 25, 2013) ##
-
-* Improve `rake stats` for JavaScript and CoffeeScript: ignore block comments
- and calculates number of functions.
-
- *Hendy Tanata*
-
-* Ability to use a custom builder by passing `--builder` (or `-b`) has been removed.
- Consider using application template instead. See this guide for more detail:
- http://guides.rubyonrails.org/rails_application_templates.html
-
- *Prem Sichanugrist*
-
-* Fix `rake db:*` tasks to work with `DATABASE_URL` and without `config/database.yml`.
-
- *Terence Lee*
-
-* Add notice message for destroy action in scaffold generator.
-
- *Rahul P. Chaudhari*
-
-* Add two new test rake tasks to speed up full test runs.
-
- * `test:all`: run tests quickly by merging all types and not resetting db.
- * `test:all:db`: run tests quickly, but also reset db.
-
- *Ryan Davis*
-
-* Add `--rc` option to support the load of a custom rc file during the generation of a new app.
-
- *Amparo Luna*
-
-* Add `--no-rc` option to skip the loading of railsrc file during the generation of a new app.
-
- *Amparo Luna*
-
-* Fixes database.yml when creating a new rails application with '.'
- Fixes #8304.
-
- *Jeremy W. Rowe*
-
-* Restore Rails::Engine::Railties#engines with deprecation to ensure
- compatibility with gems such as Thinking Sphinx
- Fixes #8551.
-
- *Tim Raymond*
-
-* Specify which logs to clear when using the `rake log:clear` task.
- (e.g. rake log:clear LOGS=test,staging)
-
- *Matt Bridges*
-
-* Allow a `:dirs` key in the `SourceAnnotationExtractor.enumerate` options
- to explicitly set the directories to be traversed so it's easier to define
- custom rake tasks.
-
- *Brian D. Burns*
-
-* Deprecate `Rails::Generators::ActiveModel#update_attributes` in favor of `#update`.
-
- ORMs that implement `Generators::ActiveModel#update_attributes` should change
- to `#update`. Scaffold controller generators should change calls like:
-
- @orm_instance.update_attributes(...)
-
- to:
-
- @orm_instance.update(...)
-
- This goes along with the addition of `ActiveRecord::Base#update`.
-
- *Carlos Antonio da Silva*
-
-* Include `jbuilder` by default and rely on its scaffold generator to show json API.
- Check https://github.com/rails/jbuilder for more info and examples.
-
- *DHH*
-
-* Scaffold now generates HTML-only controller by default.
-
- *DHH + Pavel Pravosud*
-
-* The generated `README.rdoc` for new applications invites the user to
- document the necessary steps to get the application up and running.
-
- *Xavier Noria*
-
-* Generated applications no longer get `doc/README_FOR_APP`. In consequence,
- the `doc` directory is created on demand by documentation tasks rather than
- generated by default.
-
- *Xavier Noria*
-
-* App executables now live in the `bin/` directory: `bin/bundle`,
- `bin/rails`, `bin/rake`. Run `rake rails:update:bin` to add these
- executables to your own app. `script/rails` is gone from new apps.
-
- Running executables within your app ensures they use your app's Ruby
- version and its bundled gems, and it ensures your production deployment
- tools only need to execute a single script. No more having to carefully
- `cd` to the app dir and run `bundle exec ...`.
-
- Rather than treating `bin/` as a junk drawer for generated "binstubs",
- bundler 1.3 adds support for generating stubs for just the executables
- you actually use: `bundle binstubs unicorn` generates `bin/unicorn`.
- Add that executable to git and version it just like any other app code.
-
- *Jeremy Kemper*
-
-* `config.assets.enabled` is now true by default. If you're upgrading from a Rails 3.x app
- that does not use the asset pipeline, you'll be required to add `config.assets.enabled = false`
- to your application.rb. If you don't want the asset pipeline on a new app use `--skip-sprockets`
-
- *DHH*
-
-* Environment name can be a start substring of the default environment names
- (production, development, test). For example: tes, pro, prod, dev, devel.
- Fixes #8628.
-
- *Mykola Kyryk*
-
-* Add `-B` alias for `--skip-bundle` option in the rails new generators.
-
- *Jiri Pospisil*
-
-* Quote column names in generates fixture files. This prevents
- conflicts with reserved YAML keywords such as 'yes' and 'no'
- Fixes #8612.
-
- *Yves Senn*
-
-* Explicit options have precedence over `~/.railsrc` on the `rails new` command.
-
- *Rafael Mendonça França*
-
-* Generated migrations now always use the `change` method.
-
- *Marc-André Lafortune*
-
-* Add `app/models/concerns` and `app/controllers/concerns` to the default directory structure and load path.
- See http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns for usage instructions.
-
- *DHH*
-
-* The `rails/info/routes` now correctly formats routing output as an html table.
-
- *Richard Schneeman*
-
-* The `public/index.html` is no longer generated for new projects.
- Page is replaced by internal `welcome_controller` inside of railties.
-
- *Richard Schneeman*
-
-* Add `ENV['RACK_ENV']` support to `rails runner/console/server`.
-
- *kennyj*
-
-* Add `db` to list of folders included by `rake notes` and `rake notes:custom`. *Antonio Cangiano*
-
-* Engines with a dummy app include the rake tasks of dependencies in the app namespace.
- Fixes #8229.
-
- *Yves Senn*
-
-* Add `sqlserver.yml` template file to satisfy `-d sqlserver` being passed to `rails new`.
- Fixes #6882.
-
- *Robert Nesius*
-
-* Rake test:uncommitted finds git directory in ancestors *Nicolas Despres*
-
-* Add dummy app Rake tasks when `--skip-test-unit` and `--dummy-path` is passed to the plugin generator.
- Fixes #8121.
-
- *Yves Senn*
-
-* Add `.rake` to list of file extensions included by `rake notes` and `rake notes:custom`. *Brent J. Nordquist*
-
-* New test locations `test/models`, `test/helpers`, `test/controllers`, and
- `test/mailers`. Corresponding rake tasks added as well. *Mike Moore*
-
-* Set a different cache per environment for assets pipeline
- through `config.assets.cache`.
-
- *Guillermo Iguaran*
-
-* `Rails.public_path` now returns a Pathname object. *Prem Sichanugrist*
-
-* Remove highly uncommon `config.assets.manifest` option for moving the manifest path.
- This option is now unsupported in sprockets-rails.
-
- *Guillermo Iguaran & Dmitry Vorotilin*
-
-* Add `config.action_controller.permit_all_parameters` to disable
- StrongParameters protection, it's false by default.
-
- *Guillermo Iguaran*
-
-* Remove `config.active_record.whitelist_attributes` and
- `config.active_record.mass_assignment_sanitizer` from new applications since
- MassAssignmentSecurity has been extracted from Rails.
-
- *Guillermo Iguaran*
-
-* Change `rails new` and `rails plugin new` generators to name the `.gitkeep` files
- as `.keep` in a more SCM-agnostic way.
-
- Change `--skip-git` option to only skip the `.gitignore` file and still generate
- the `.keep` files.
-
- Add `--skip-keeps` option to skip the `.keep` files.
-
- *Derek Prior & Francesco Rodriguez*
-
-* Fixed support for `DATABASE_URL` environment variable for rake db tasks.
-
- *Grace Liu*
-
-* `rails dbconsole` now can use SSL for MySQL. The `database.yml` options sslca, sslcert, sslcapath, sslcipher
- and sslkey now affect `rails dbconsole`.
-
- *Jim Kingdon and Lars Petrus*
-
-* Correctly handle SCRIPT_NAME when generating routes to engine in application
- that's mounted at a sub-uri. With this behavior, you *should not* use
- `default_url_options[:script_name]` to set proper application's mount point by
- yourself.
-
- *Piotr Sarnacki*
-
-* `config.threadsafe!` is deprecated in favor of `config.eager_load` which provides a more fine grained control on what is eager loaded .
-
- *José Valim*
-
-* The migration generator will now produce AddXXXToYYY/RemoveXXXFromYYY migrations with references statements, for instance
-
- rails g migration AddReferencesToProducts user:references supplier:references{polymorphic}
-
- will generate the migration with:
-
- add_reference :products, :user, index: true
- add_reference :products, :supplier, polymorphic: true, index: true
-
- *Aleksey Magusev*
-
-* Allow scaffold/model/migration generators to accept a `polymorphic` modifier
- for `references`/`belongs_to`, for instance
-
- rails g model Product supplier:references{polymorphic}
-
- will generate the model with `belongs_to :supplier, polymorphic: true`
- association and appropriate migration.
-
- *Aleksey Magusev*
-
-* Set `config.active_record.migration_error` to `:page_load` for development.
-
- *Richard Schneeman*
-
-* Add runner to `Rails::Railtie` as a hook called just after runner starts.
-
- *José Valim & kennyj*
-
-* Add `/rails/info/routes` path, displays same information as `rake routes` .
-
- *Richard Schneeman & Andrew White*
-
-* Improved `rake routes` output for redirects.
-
- *Łukasz Strzałkowski & Andrew White*
-
-* Load all environments available in `config.paths["config/environments"]`.
-
- *Piotr Sarnacki*
-
-* Remove `Rack::SSL` in favour of `ActionDispatch::SSL`.
-
- *Rafael Mendonça França*
-
-* Remove Active Resource from Rails framework.
-
- *Prem Sichangrist*
-
-* Allow to set class that will be used to run as a console, other than IRB, with `Rails.application.config.console=`. It's best to add it to `console` block.
-
- Example:
-
- # it can be added to config/application.rb
- console do
- # this block is called only when running console,
- # so we can safely require pry here
- require "pry"
- config.console = Pry
- end
-
- *Piotr Sarnacki*
-
-* Add convenience `hide!` method to Rails generators to hide current generator
- namespace from showing when running `rails generate`.
-
- *Carlos Antonio da Silva*
-
-* Rails::Plugin has gone. Instead of adding plugins to vendor/plugins use gems or bundler with path or git dependencies.
-
- *Santiago Pastorino*
-
-* Set config.action_mailer.async = true to turn on asynchronous
- message delivery.
-
- *Brian Cardarella*
-
-Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/railties/CHANGELOG.md) for previous changes.
+Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md) for previous changes.
diff --git a/railties/bin/rails b/railties/bin/rails
index a1c4faaa73..b3026e8a93 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
-if File.exists?(File.join(File.expand_path('../../..', __FILE__), '.git'))
+git_path = File.join(File.expand_path('../../..', __FILE__), '.git')
+
+if File.exists?(git_path)
railties_path = File.expand_path('../../lib', __FILE__)
$:.unshift(railties_path)
end
diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb
index 1493815c30..6c9c53fc69 100644
--- a/railties/lib/rails/all.rb
+++ b/railties/lib/rails/all.rb
@@ -1,9 +1,5 @@
require "rails"
-if defined?(Rake) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any?
- ENV['RAILS_ENV'] ||= 'test'
-end
-
%w(
active_record
action_controller
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 86f62dfb40..bfb9b456db 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -124,7 +124,7 @@ module Rails
#
# Now you can mount your engine in application's routes just like that:
#
- # MyRailsApp::Application.routes.draw do
+ # Rails.application.routes.draw do
# mount MyEngine::Engine => "/engine"
# end
#
@@ -154,7 +154,7 @@ module Rails
# Note that now there can be more than one router in your application, and it's better to avoid
# passing requests through many routers. Consider this situation:
#
- # MyRailsApp::Application.routes.draw do
+ # Rails.application.routes.draw do
# mount MyEngine::Engine => "/blog"
# get "/blog/omg" => "main#omg"
# end
@@ -164,7 +164,7 @@ module Rails
# and if there is no such route in +Engine+'s routes, it will be dispatched to <tt>main#omg</tt>.
# It's much better to swap that:
#
- # MyRailsApp::Application.routes.draw do
+ # Rails.application.routes.draw do
# get "/blog/omg" => "main#omg"
# mount MyEngine::Engine => "/blog"
# end
@@ -251,7 +251,7 @@ module Rails
# created to allow you to do that. Consider such a scenario:
#
# # config/routes.rb
- # MyApplication::Application.routes.draw do
+ # Rails.application.routes.draw do
# mount MyEngine::Engine => "/my_engine", as: "my_engine"
# get "/foo" => "foo#index"
# end
@@ -634,6 +634,10 @@ module Rails
end
end
+ def routes? #:nodoc:
+ @routes
+ end
+
protected
def run_tasks_blocks(*) #:nodoc:
@@ -641,10 +645,6 @@ module Rails
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end
- def routes? #:nodoc:
- @routes
- end
-
def has_migrations? #:nodoc:
paths["db/migrate"].existent.any?
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 28593c5907..366c72ebaa 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -86,7 +86,7 @@ module Rails
# end
def environment(data=nil, options={}, &block)
sentinel = /class [a-z_:]+ < Rails::Application/i
- env_file_sentinel = /::Application\.configure do/
+ env_file_sentinel = /Rails\.application\.configure do/
data = block.call if !data && block_given?
in_root do
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index b62d1fff14..853d6fa4b9 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -115,9 +115,9 @@ module Rails
end
def database_gemfile_entry
- options[:skip_active_record] ? "" :
- <<-GEMFILE.gsub(/^ {12}/, '').strip
- # Use #{options[:database]} as the database for ActiveRecord
+ options[:skip_active_record] ? "" :
+ <<-GEMFILE.strip_heredoc.chomp
+ # Use #{options[:database]} as the database for Active Record
gem '#{gem_for_database}'
GEMFILE
end
@@ -135,13 +135,11 @@ module Rails
<<-GEMFILE.strip_heredoc
gem 'rails', path: '#{Rails::Generators::RAILS_DEV_PATH}'
gem 'arel', github: 'rails/arel'
- gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
GEMFILE
elsif options.edge?
<<-GEMFILE.strip_heredoc
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
- gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
GEMFILE
else
<<-GEMFILE.strip_heredoc
@@ -182,55 +180,53 @@ module Rails
return if options[:skip_sprockets]
gemfile = if options.dev? || options.edge?
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE.strip_heredoc
# Use edge version of sprockets-rails
gem 'sprockets-rails', github: 'rails/sprockets-rails'
# Use SCSS for stylesheets
- gem 'sass-rails', github: 'rails/sass-rails'
-
- # Use Uglifier as compressor for JavaScript assets
- gem 'uglifier', '~> 1.3'
+ gem 'sass-rails', github: 'rails/sass-rails'
GEMFILE
else
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE.strip_heredoc
# Use SCSS for stylesheets
- gem 'sass-rails', '~> 4.0.0.beta1'
-
- # Use Uglifier as compressor for JavaScript assets
- gem 'uglifier', '~> 1.3'
+ gem 'sass-rails', '~> 4.0.0.rc1'
GEMFILE
end
+ gemfile += <<-GEMFILE.strip_heredoc
+
+ # Use Uglifier as compressor for JavaScript assets
+ gem 'uglifier', '>= 1.3.0'
+ GEMFILE
+
if options[:skip_javascript]
- gemfile += <<-GEMFILE.gsub(/^ {12}/, '')
+ gemfile += <<-GEMFILE
#{coffee_gemfile_entry}
#{javascript_runtime_gemfile_entry}
GEMFILE
end
- gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
+ gemfile.gsub(/^[ \t]+/, '')
end
def coffee_gemfile_entry
- gemfile = if options.dev? || options.edge?
- <<-GEMFILE.gsub(/^ {12}/, '')
+ if options.dev? || options.edge?
+ <<-GEMFILE
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', github: 'rails/coffee-rails'
GEMFILE
else
- <<-GEMFILE.gsub(/^ {12}/, '')
+ <<-GEMFILE
# Use CoffeeScript for .js.coffee assets and views
- gem 'coffee-rails', '~> 4.0.0.beta1'
+ gem 'coffee-rails', '~> 4.0.0'
GEMFILE
end
-
- gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
end
def javascript_gemfile_entry
unless options[:skip_javascript]
- <<-GEMFILE.gsub(/^ {12}/, '').strip_heredoc
+ <<-GEMFILE.gsub(/^[ \t]+/, '')
#{coffee_gemfile_entry}
#{javascript_runtime_gemfile_entry}
# Use #{options[:javascript]} as the JavaScript library
@@ -248,7 +244,7 @@ module Rails
else
"# gem 'therubyracer', platforms: :ruby"
end
- <<-GEMFILE.gsub(/^ {10}/, '')
+ <<-GEMFILE
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#{runtime}
GEMFILE
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
index 85a1b01cc6..1799e823b6 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
@@ -14,14 +14,14 @@
<% attributes.each do |attribute| -%>
<div class="field">
<% if attribute.password_digest? -%>
- <%%= f.label :password %><br />
+ <%%= f.label :password %><br>
<%%= f.password_field :password %>
</div>
<div>
- <%%= f.label :password_confirmation %><br />
+ <%%= f.label :password_confirmation %><br>
<%%= f.password_field :password_confirmation %>
<% else -%>
- <%%= f.label :<%= attribute.name %> %><br />
+ <%%= f.label :<%= attribute.name %> %><br>
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
<% end -%>
</div>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
index d2fd99fdcb..9d778642f2 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
@@ -14,18 +14,18 @@
<tbody>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
- <tr>
+ <tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
- <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
- <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
- <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
- <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
- </tr>
+ <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
<%% end %>
</tbody>
</table>
-<br />
+<br>
<%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 1842e09bae..ace804ffe6 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -9,14 +9,14 @@ source 'https://rubygems.org'
<%= assets_gemfile_entry %>
<%= javascript_gemfile_entry -%>
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder', '~> 1.0.1'
+
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
-# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
-gem 'jbuilder', '~> 1.0.1'
-
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile
index 6eb23f68a3..ba6b733dd2 100644
--- a/railties/lib/rails/generators/rails/app/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/app/templates/Rakefile
@@ -3,4 +3,4 @@
require File.expand_path('../config/application', __FILE__)
-<%= app_const %>.load_tasks
+Rails.application.load_tasks
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
index e080ebd74e..00a613ff04 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
@@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application.
-<%= app_const %>.initialize!
+Rails.application.initialize!
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 8b64881dbc..91253d1508 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -1,4 +1,4 @@
-<%= app_const %>.configure do
+Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index c40eef145f..1dfc9f136b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -1,4 +1,4 @@
-<%= app_const %>.configure do
+Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
index 3c9c787948..ba0742f97f 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
@@ -1,4 +1,4 @@
-<%= app_const %>.configure do
+Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
@@ -13,7 +13,7 @@
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
- config.serve_static_assets = true
+ config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Show full error reports and disable caching.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt
index efccf72d3d..f3cc6098a3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt
@@ -9,4 +9,4 @@
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
-<%= app_const %>.config.secret_key_base = '<%= app_secret %>'
+Rails.application.config.secret_key_base = '<%= app_secret %>'
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt
index 4a099a4ce2..2bb9b82c61 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt
@@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.
-<%= app_const %>.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>
+Rails.application.config.session_store :cookie_store, key: <%= "'_#{app_name}_session'" %>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
index 1794ffa833..3dfb724164 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
@@ -1,4 +1,4 @@
-<%= app_const %>.routes.draw do
+Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index 9437e9c406..89ca8cbe11 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -112,7 +112,6 @@ module Rails
# Be sure to look at the documentation of those specific classes for more information.
#
class Railtie
- autoload :Configurable, "rails/railtie/configurable"
autoload :Configuration, "rails/railtie/configuration"
include Initializable
@@ -121,6 +120,7 @@ module Rails
class << self
private :new
+ delegate :config, to: :instance
def subclasses
@subclasses ||= []
@@ -128,7 +128,6 @@ module Rails
def inherited(base)
unless base.abstract_railtie?
- base.send(:include, Railtie::Configurable)
subclasses << base
end
end
@@ -166,14 +165,51 @@ module Rails
@railtie_name ||= generate_railtie_name(self.name)
end
+ # Since Rails::Railtie cannot be instantiated, any methods that call
+ # +instance+ are intended to be called only on subclasses of a Railtie.
+ def instance
+ @instance ||= new
+ end
+
+ def respond_to_missing?(*args)
+ instance.respond_to?(*args) || super
+ end
+
+ # Allows you to configure the railtie. This is the same method seen in
+ # Railtie::Configurable, but this module is no longer required for all
+ # subclasses of Railtie so we provide the class method here.
+ def configure(&block)
+ instance.configure(&block)
+ end
+
protected
def generate_railtie_name(class_or_module)
ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_")
end
+
+ # If the class method does not have a method, then send the method call
+ # to the Railtie instance.
+ def method_missing(name, *args, &block)
+ if instance.respond_to?(name)
+ instance.public_send(name, *args, &block)
+ else
+ super
+ end
+ end
end
delegate :railtie_name, to: :class
+ def initialize
+ if self.class.abstract_railtie?
+ raise "#{self.class.name} is abstract, you cannot instantiate it directly."
+ end
+ end
+
+ def configure(&block)
+ instance_eval(&block)
+ end
+
def config
@config ||= Railtie::Configuration.new
end
diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake
index 1c3426028d..f89d6b12e1 100644
--- a/railties/lib/rails/tasks/documentation.rake
+++ b/railties/lib/rails/tasks/documentation.rake
@@ -57,8 +57,8 @@ namespace :doc do
# desc "Generate Rails Guides"
task :guides do
- # FIXME: Reaching outside lib directory is a bad idea
- require File.expand_path('../../../../../guides/rails_guides', __FILE__)
+ rails_gem_dir = Gem::Specification.find_by_name("rails").gem_dir
+ require File.expand_path(File.join(rails_gem_dir, "/guides/rails_guides"))
RailsGuides::Generator.new(Rails.root.join("doc/guides")).generate
end
end
diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb
index f52c4c44b7..ab1ebe1f8c 100644
--- a/railties/lib/rails/test_unit/railtie.rb
+++ b/railties/lib/rails/test_unit/railtie.rb
@@ -1,3 +1,7 @@
+if defined?(Rake) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any?
+ ENV['RAILS_ENV'] ||= 'test'
+end
+
module Rails
class TestUnitRailtie < Rails::Railtie
config.app_generators do |c|
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index fee352db5a..dcbf57a4df 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -3,7 +3,7 @@ module Rails
MAJOR = 4
MINOR = 0
TINY = 0
- PRE = "beta1"
+ PRE = "rc1"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 22de640236..25372d0a50 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -277,6 +277,30 @@ module ApplicationTests
end
end
+ def test_root_path
+ app('development')
+
+ controller :foo, <<-RUBY
+ class FooController < ApplicationController
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do
+ get 'foo', :to => 'foo#index'
+ root :to => 'foo#index'
+ end
+ RUBY
+
+ remove_file 'public/index.html'
+
+ get '/'
+ assert_equal 'foo', last_response.body
+ end
+
test 'routes are added and removed when reloading' do
app('development')
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index f8fa8ee153..0db40c1d32 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -103,7 +103,7 @@ class ActionsTest < Rails::Generators::TestCase
run_generator
autoload_paths = 'config.autoload_paths += %w["#{Rails.root}/app/extras"]'
action :environment, autoload_paths, env: 'development'
- assert_file "config/environments/development.rb", /Application\.configure do\n #{Regexp.escape(autoload_paths)}/
+ assert_file "config/environments/development.rb", /Rails\.application\.configure do\n #{Regexp.escape(autoload_paths)}/
end
def test_environment_with_block_should_include_block_contents_in_environment_initializer_block
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 5fdf58c8ee..f70c90bffa 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -65,7 +65,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_invalid_application_name_is_fixed
run_generator [File.join(destination_root, "things-43")]
- assert_file "things-43/config/environment.rb", /Things43::Application\.initialize!/
+ assert_file "things-43/config/environment.rb", /Rails\.application\.initialize!/
assert_file "things-43/config/application.rb", /^module Things43$/
end
@@ -111,7 +111,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
destination_root: app_moved_root, shell: @shell
generator.send(:app_const)
quietly { generator.send(:create_config_files) }
- assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/
+ assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
end
@@ -131,7 +131,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_application_names_are_not_singularized
run_generator [File.join(destination_root, "hats")]
- assert_file "hats/config/environment.rb", /Hats::Application\.initialize!/
+ assert_file "hats/config/environment.rb", /Rails\.application\.initialize!/
end
def test_gemfile_has_no_whitespace_errors
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 01fa2c6864..0948ae59c0 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -416,11 +416,6 @@ YAML
boot_rails
end
- test "Rails::Engine itself does not respond to config" do
- boot_rails
- assert !Rails::Engine.respond_to?(:config)
- end
-
test "initializers are executed after application configuration initializers" do
@plugin.write "lib/bukkits.rb", <<-RUBY
module Bukkits
diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb
index 0abb2b7578..7348d70c56 100644
--- a/railties/test/railties/generators_test.rb
+++ b/railties/test/railties/generators_test.rb
@@ -44,7 +44,7 @@ module RailtiesTests
Dir.chdir(engine_path) do
File.open("Gemfile", "w") do |f|
f.write <<-GEMFILE.gsub(/^ {12}/, '')
- source "http://rubygems.org"
+ source "https://rubygems.org"
gem 'rails', path: '#{RAILS_FRAMEWORK_ROOT}'
gem 'sqlite3'
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index 0786b8f8c7..520a855c90 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -19,8 +19,8 @@ module RailtiesTest
@app ||= Rails.application
end
- test "Rails::Railtie itself does not respond to config" do
- assert !Rails::Railtie.respond_to?(:config)
+ test "cannot instantiate a Railtie object" do
+ assert_raise(RuntimeError) { Rails::Railtie.new }
end
test "Railtie provides railtie_name" do
@@ -39,13 +39,6 @@ module RailtiesTest
assert_equal "bar", Foo.railtie_name
end
- test "cannot inherit from a railtie" do
- class Foo < Rails::Railtie ; end
- assert_raise RuntimeError do
- class Bar < Foo; end
- end
- end
-
test "config is available to railtie" do
class Foo < Rails::Railtie ; end
assert_nil Foo.config.action_controller.foo