aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile5
-rw-r--r--Gemfile.lock43
-rw-r--r--actioncable/lib/action_cable/channel/periodic_timers.rb4
-rw-r--r--actioncable/lib/action_cable/server/worker.rb12
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--activesupport/lib/active_support/key_generator.rb12
-rw-r--r--activesupport/test/key_generator_test.rb17
-rw-r--r--guides/assets/images/getting_started/template_is_missing_articles_new.pngbin6174 -> 587962 bytes
-rw-r--r--guides/source/5_0_release_notes.md85
-rw-r--r--guides/source/configuring.md2
-rw-r--r--guides/source/documents.yaml4
-rw-r--r--guides/source/getting_started.md22
-rw-r--r--guides/source/testing.md144
-rw-r--r--guides/source/upgrading_ruby_on_rails.md141
-rw-r--r--railties/lib/rails/generators/app_base.rb4
-rw-r--r--railties/test/application/assets_test.rb2
16 files changed, 357 insertions, 142 deletions
diff --git a/Gemfile b/Gemfile
index 5650147099..1d58c413ed 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,8 +11,9 @@ gem 'mocha', '~> 0.14', require: false
gem 'rack-cache', '~> 1.2'
gem 'jquery-rails'
-gem 'coffee-rails', github: 'rails/coffee-rails'
-gem 'turbolinks', github: 'turbolinks/turbolinks-rails'
+gem 'coffee-rails'
+gem 'sass-rails'
+gem 'turbolinks', '~> 5'
# require: false so bcrypt is loaded only when has_secure_password is used.
# This is to avoid Active Model (and by extension the entire framework)
diff --git a/Gemfile.lock b/Gemfile.lock
index 71f4302a5b..a62a71521e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -22,27 +22,12 @@ GIT
delayed_job (>= 3.0, < 5)
GIT
- remote: git://github.com/rails/coffee-rails.git
- revision: aa2e623cbda4f3c789a0a15d1f707239e68f5736
- specs:
- coffee-rails (4.1.1)
- coffee-script (>= 2.2.0)
- railties (>= 4.0.0, < 5.2.x)
-
-GIT
remote: git://github.com/sass/sass.git
revision: 3fda1cbe70d615e7ef96e28db4fd1f8a3ebb5505
branch: stable
specs:
sass (3.4.22)
-GIT
- remote: git://github.com/turbolinks/turbolinks-rails.git
- revision: 65884729016dbb4d032f12bb01b7e7c1ddeb68ac
- specs:
- turbolinks (5.0.0.beta2)
- turbolinks-source
-
PATH
remote: .
specs:
@@ -59,7 +44,7 @@ PATH
actionpack (5.1.0.alpha)
actionview (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
- rack (~> 2.x)
+ rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
@@ -140,6 +125,9 @@ GEM
byebug (8.2.5)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
+ coffee-rails (4.2.1)
+ coffee-script (>= 2.2.0)
+ railties (>= 4.0.0, < 5.2.x)
coffee-script (2.4.1)
coffee-script-source
execjs
@@ -233,7 +221,7 @@ GEM
pg (0.18.4-x64-mingw32)
pg (0.18.4-x86-mingw32)
pkg-config (1.1.7)
- psych (2.0.17)
+ psych (2.1.0)
puma (3.4.0)
qu (0.2.0)
multi_json
@@ -243,8 +231,7 @@ GEM
simple_uuid
que (0.11.4)
racc (1.4.14)
- rack (2.0.0.rc1)
- json
+ rack (2.0.1)
rack-cache (1.6.1)
rack (>= 0.4)
rack-test (0.6.3)
@@ -277,6 +264,12 @@ GEM
rufus-scheduler (~> 3.2)
rubyzip (1.2.0)
rufus-scheduler (3.2.1)
+ sass-rails (5.0.5)
+ railties (>= 4.0.0, < 6)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
@@ -304,7 +297,7 @@ GEM
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-export (0.9.1)
- sprockets-rails (3.0.4)
+ sprockets-rails (3.1.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
@@ -321,7 +314,10 @@ GEM
thor (0.19.1)
thread (0.1.7)
thread_safe (0.3.5)
- turbolinks-source (5.0.0.beta4)
+ tilt (2.0.5)
+ turbolinks (5.0.0)
+ turbolinks-source (~> 5)
+ turbolinks-source (5.0.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2016.4)
@@ -355,7 +351,7 @@ DEPENDENCIES
blade
blade-sauce_labs_plugin
byebug
- coffee-rails!
+ coffee-rails
dalli (>= 2.2.1)
delayed_job!
delayed_job_active_record!
@@ -385,6 +381,7 @@ DEPENDENCIES
resque (< 1.26)
resque-scheduler
sass!
+ sass-rails
sdoc (~> 0.4.0)
sequel
sidekiq
@@ -392,7 +389,7 @@ DEPENDENCIES
sqlite3 (~> 1.3.6)
stackprof
sucker_punch
- turbolinks!
+ turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
w3c_validators
diff --git a/actioncable/lib/action_cable/channel/periodic_timers.rb b/actioncable/lib/action_cable/channel/periodic_timers.rb
index dab604440f..41511312fc 100644
--- a/actioncable/lib/action_cable/channel/periodic_timers.rb
+++ b/actioncable/lib/action_cable/channel/periodic_timers.rb
@@ -64,9 +64,7 @@ module ActionCable
def start_periodic_timer(callback, every:)
connection.server.event_loop.timer every do
- connection.worker_pool.async_invoke connection do
- instance_exec(&callback)
- end
+ connection.worker_pool.async_exec self, connection: connection, &callback
end
end
diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb
index a638ff72e7..f3a4fc5a5b 100644
--- a/actioncable/lib/action_cable/server/worker.rb
+++ b/actioncable/lib/action_cable/server/worker.rb
@@ -42,16 +42,20 @@ module ActionCable
self.connection = nil
end
- def async_invoke(receiver, method, *args, connection: receiver)
+ def async_exec(receiver, *args, connection:, &block)
+ async_invoke receiver, :instance_exec, *args, connection: connection, &block
+ end
+
+ def async_invoke(receiver, method, *args, connection: receiver, &block)
@executor.post do
- invoke(receiver, method, *args, connection: connection)
+ invoke(receiver, method, *args, connection: connection, &block)
end
end
- def invoke(receiver, method, *args, connection:)
+ def invoke(receiver, method, *args, connection:, &block)
work(connection) do
begin
- receiver.send method, *args
+ receiver.send method, *args, &block
rescue Exception => e
logger.error "There was an exception - #{e.class}(#{e.message})"
logger.error e.backtrace.join("\n")
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 965fafff5f..f912a72efe 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport', version
- s.add_dependency 'rack', '~> 2.x'
+ s.add_dependency 'rack', '~> 2.0'
s.add_dependency 'rack-test', '~> 0.6.3'
s.add_dependency 'rails-html-sanitizer', '~> 1.0', '>= 1.0.2'
s.add_dependency 'rails-dom-testing', '~> 2.0'
diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb
index 7eafbb571f..0f0e931c06 100644
--- a/activesupport/lib/active_support/key_generator.rb
+++ b/activesupport/lib/active_support/key_generator.rb
@@ -15,8 +15,9 @@ module ActiveSupport
end
# Returns a derived key suitable for use. The default key_size is chosen
- # to be compatible with the acceptable key length of aes-256-cbc, the default cipher.
- def generate_key(salt, key_size=32)
+ # to be compatible with the default settings of ActiveSupport::MessageVerifier.
+ # i.e. OpenSSL::Digest::SHA1#block_length
+ def generate_key(salt, key_size=64)
OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
end
end
@@ -30,10 +31,9 @@ module ActiveSupport
@cache_keys = Concurrent::Map.new
end
- # Returns a derived key suitable for use. The default key_size is chosen
- # to be compatible with the acceptable key length of aes-256-cbc, the default cipher.
- def generate_key(salt, key_size=32)
- @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
+ # Returns a derived key suitable for use.
+ def generate_key(*args)
+ @cache_keys[args.join] ||= @key_generator.generate_key(*args)
end
end
diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb
index 6cf72f1fec..b60077460e 100644
--- a/activesupport/test/key_generator_test.rb
+++ b/activesupport/test/key_generator_test.rb
@@ -19,7 +19,7 @@ class KeyGeneratorTest < ActiveSupport::TestCase
test "Generating a key of the default length" do
derived_key = @generator.generate_key("some_salt")
assert_kind_of String, derived_key
- assert_equal OpenSSL::Cipher.new('aes-256-cbc').key_len, derived_key.length, "Should have generated a key of the default size"
+ assert_equal 64, derived_key.length, "Should have generated a key of the default size"
end
test "Generating a key of an alternative length" do
@@ -27,6 +27,21 @@ class KeyGeneratorTest < ActiveSupport::TestCase
assert_kind_of String, derived_key
assert_equal 32, derived_key.length, "Should have generated a key of the right size"
end
+
+ test "Expected results" do
+ # For any given set of inputs, this method must continue to return
+ # the same output: if it changes, any existing values relying on a
+ # key would break.
+
+ expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055739be5cc6956345d5ae38e7e1daa66f1de587dc8da2bf9e8b965af4b3918a122"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt").unpack('H*').first
+
+ expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt", 32).unpack('H*').first
+
+ expected = "cbea7f7f47df705967dc508f4e446fd99e7797b1d70011c6899cd39bbe62907b8508337d678505a7dc8184e037f1003ba3d19fc5d829454668e91d2518692eae"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64, iterations: 2).generate_key("some_salt").unpack('H*').first
+ end
end
class CachingKeyGeneratorTest < ActiveSupport::TestCase
diff --git a/guides/assets/images/getting_started/template_is_missing_articles_new.png b/guides/assets/images/getting_started/template_is_missing_articles_new.png
index 4e636d09ff..f4f054f3c6 100644
--- a/guides/assets/images/getting_started/template_is_missing_articles_new.png
+++ b/guides/assets/images/getting_started/template_is_missing_articles_new.png
Binary files differ
diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md
index f0c7f03bf2..e90a205d0f 100644
--- a/guides/source/5_0_release_notes.md
+++ b/guides/source/5_0_release_notes.md
@@ -154,10 +154,23 @@ for a detailed write up.
### Test Runner
-[Pull Request](https://github.com/rails/rails/pull/19216)
-ToDo...
+A new test runner has been introduced to enhance the capabilities of running tests from Rails.
+To use this test runner simply type `bin/rails test`.
+Test Runner is inspired from `RSpec`, `minitest-reporters`, `maxitest` and others.
+It includes some of these notable advancements:
+
+- Run a single test using line number of test.
+- Run multiple tests pinpointing to line number of tests.
+- Improved failure messages, which also add ease of re-running failed tests.
+- Fail fast using `-f` option, to stop tests immediately on occurrence of failure,
+instead of waiting for the suite to complete.
+- Defer test output until the end of a full test run using the `-d` option.
+- Complete exception backtrace output using `-b` option.
+- Integration with `Minitest` to allow options like `-s` for test seed data,
+`-n` for running specific test by name, `-v` for better verbose output and so forth.
+- Colored test output
Railties
--------
@@ -244,7 +257,6 @@ Please refer to the [Changelog][railties] for detailed changes.
Spring to watch additional common files.
([commit](https://github.com/rails/rails/commit/b04d07337fd7bc17e88500e9d6bcd361885a45f8))
-
* Added `--skip-action-mailer` to skip Action Mailer while generating new app.
([Pull Request](https://github.com/rails/rails/pull/18288))
@@ -254,6 +266,9 @@ Please refer to the [Changelog][railties] for detailed changes.
* Changed `_form.html.erb` generated by scaffold generator to use local variables.
([Pull Request](https://github.com/rails/rails/pull/13434))
+* Disabled autoloading of classes in production environment.
+ ([commit](https://github.com/rails/rails/commit/a71350cae0082193ad8c66d65ab62e8bb0b7853b))
+
Action Pack
-----------
@@ -345,6 +360,15 @@ Please refer to the [Changelog][action-pack] for detailed changes.
* Deprecated `:controller` and `:action` path parameters.
([Pull Request](https://github.com/rails/rails/pull/23980))
+* Deprecated env method on controller instances.
+ ([commit](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be))
+
+* `ActionDispatch::ParamsParser` is deprecated and was removed from the
+ middleware stack. To configure the parameter parsers use
+ `ActionDispatch::Request.parameter_parsers=`.
+ ([commit](https://github.com/rails/rails/commit/38d2bf5fd1f3e014f2397898d371c339baa627b1),
+ [commit](https://github.com/rails/rails/commit/5ed38014811d4ce6d6f957510b9153938370173b))
+
### Notable changes
* Added `ActionController::Renderer` to render arbitrary templates
@@ -419,6 +443,21 @@ Please refer to the [Changelog][action-pack] for detailed changes.
* Discarded flash messages get removed before storing into session.
([Pull Request](https://github.com/rails/rails/pull/18721))
+* Added support for passing collection of records to `fresh_when` and
+ `stale?`.
+ ([Pull Request](https://github.com/rails/rails/pull/18374))
+
+* `ActionController::Live` became an `ActiveSupport::Concern`. That
+ means it can't be just included in other modules without extending
+ them with `ActiveSupport::Concern` or `ActionController::Live`
+ won't take effect in production. Some people may be using another
+ module to include some special `Warden`/`Devise` authentication
+ failure handling code as well since the middleware can't catch a
+ `:warden` thrown by a spawned thread which is the case when using
+ `ActionController::Live`.
+ ([More details in this issue](https://github.com/rails/rails/issues/25581))
+
+
Action View
-------------
@@ -438,13 +477,6 @@ Please refer to the [Changelog][action-view] for detailed changes.
supported by I18n.
([Pull Request](https://github.com/rails/rails/pull/20019))
-### Deprecations
-
-* Deprecated `datetime_field` and `datetime_field_tag` helpers.
- Datetime input type was removed from HTML specification.
- One can use `datetime_local_field` and `datetime_local_field_tag` instead.
- ([Pull Request](https://github.com/rails/rails/pull/24385))
-
### Notable Changes
* Changed the default template handler from `ERB` to `Raw`.
@@ -464,6 +496,10 @@ Please refer to the [Changelog][action-view] for detailed changes.
* Partial template name no longer has to be a valid Ruby identifier.
([commit](https://github.com/rails/rails/commit/da9038e))
+* The `datetime_tag` helper now generates an input tag with the type of
+ `datetime-local`.
+ ([Pull Request](https://github.com/rails/rails/pull/25469))
+
Action Mailer
-------------
@@ -624,6 +660,18 @@ Please refer to the [Changelog][active-record] for detailed changes.
`use_transactional_tests` for more clarity.
([Pull Request](https://github.com/rails/rails/pull/19282))
+* Deprecated passing a column to `ActiveRecord::Connection#quote`.
+ ([commit](https://github.com/rails/rails/commit/7bb620869725ad6de603f6a5393ee17df13aa96c))
+
+* Deprecated passing of `start` value to `find_in_batches` and `find_each`
+ in favour of `begin_at`.
+ ([Pull Request](https://github.com/rails/rails/pull/18961))
+
+* Added an option `end` to `find_in_batches` that complements the `start`
+ parameter to specify where to stop batch processing.
+ ([Pull Request](https://github.com/rails/rails/pull/12257))
+
+
### Notable changes
* Added a `foreign_key` option to `references` while creating the table.
@@ -746,6 +794,20 @@ Please refer to the [Changelog][active-record] for detailed changes.
* Added `:index_errors` option to add indexes to errors of nested attributes.
([Pull Request](https://github.com/rails/rails/pull/19686))
+* Added support for bidirectional destroy dependencies.
+ ([Pull Request](https://github.com/rails/rails/pull/18548))
+
+* Added support for `after_commit` callbacks in transactional tests.
+ ([Pull Request](https://github.com/rails/rails/pull/18458))
+
+* Added `foreign_key_exists?` method to see if a foreign key exists on a table
+ or not.
+ ([Pull Request](https://github.com/rails/rails/pull/18662))
+
+* Added `:time` option to `touch` method to touch records with different time
+ than the current time.
+ ([Pull Request](https://github.com/rails/rails/pull/18956))
+
Active Model
------------
@@ -799,6 +861,9 @@ Please refer to the [Changelog][active-model] for detailed changes.
* Validate multiple contexts on `valid?` and `invalid?` at once.
([Pull Request](https://github.com/rails/rails/pull/21069))
+* Change `validates_acceptance_of` to accept `true` as default value
+ apart from `1`.
+ ([Pull Request](https://github.com/rails/rails/pull/18439))
Active Job
-----------
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index 1f7e9cc61f..59cf412c5f 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -94,7 +94,7 @@ application. Accepts a valid week day symbol (e.g. `:monday`).
* `config.eager_load_paths` accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the `app` directory of the application.
-* `config.enable_dependency_loading`: when true, enables autoload loading, even if the application is eager loaded and `config.cache_classes` is set as true. Defaults to false.
+* `config.enable_dependency_loading`: when true, enables autoloading, even if the application is eager loaded and `config.cache_classes` is set as true. Defaults to false.
* `config.encoding` sets up the application-wide encoding. Defaults to UTF-8.
diff --git a/guides/source/documents.yaml b/guides/source/documents.yaml
index a06a53b250..627e23422d 100644
--- a/guides/source/documents.yaml
+++ b/guides/source/documents.yaml
@@ -85,9 +85,8 @@
description: This guide provides you with all you need to get started creating, enqueuing, and executing background jobs.
-
name: Testing Rails Applications
- work_in_progress: true
url: testing.html
- description: This is a rather comprehensive guide to the various testing facilities in Rails. It covers everything from 'What is a test?' to the testing APIs. Enjoy.
+ description: This is a rather comprehensive guide to the various testing facilities in Rails. It covers everything from 'What is a test?' to Integration Testing. Enjoy.
-
name: Securing Rails Applications
url: security.html
@@ -198,7 +197,6 @@
name: Ruby on Rails 5.0 Release Notes
url: 5_0_release_notes.html
description: Release notes for Rails 5.0.
- work_in_progress: true
-
name: Ruby on Rails 4.2 Release Notes
url: 4_2_release_notes.html
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index e0832a32a6..b0d3953cbd 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -313,8 +313,6 @@ It should look something like the following:
Rails.application.routes.draw do
get 'welcome/index'
- # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
-
root 'welcome#index'
end
```
@@ -457,7 +455,7 @@ available, Rails will raise an exception.
In the above image, the bottom line has been truncated. Let's see what the full
error message looks like:
->Missing template articles/new, application/new with {locale:[:en], formats:[:html], handlers:[:erb, :builder, :coffee]}. Searched in: * "/path/to/blog/app/views"
+>ArticlesController#new is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not… nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
That's quite a lot of text! Let's quickly go through and understand what each
part of it means.
@@ -476,9 +474,9 @@ us what _template handlers_ could be used to render our template. `:erb` is most
commonly used for HTML templates, `:builder` is used for XML templates, and
`:coffee` uses CoffeeScript to build JavaScript templates.
-The final part of this message tells us where Rails has looked for the templates.
-Templates within a basic Rails application like this are kept in a single
-location, but in more complex applications it could be many different paths.
+The message also contains `request.formats` which specifies the format of template to be
+served in response. It is set to `text/html` as we requested this page via browser, so Rails
+is looking for an HTML template.
The simplest template that would work in this case would be one located at
`app/views/articles/new.html.erb`. The extension of this file name is important:
@@ -486,7 +484,9 @@ the first extension is the _format_ of the template, and the second extension
is the _handler_ that will be used. Rails is attempting to find a template
called `articles/new` within `app/views` for the application. The format for
this template can only be `html` and the handler must be one of `erb`,
-`builder` or `coffee`. Because you want to create a new HTML form, you will be
+`builder` or `coffee`. `:erb` is most commonly used for HTML templates, `:builder` is
+used for XML templates, and `:coffee` uses CoffeeScript to build JavaScript templates.
+Because you want to create a new HTML form, you will be
using the `ERB` language which is designed to embed Ruby in HTML.
Therefore the file should be called `articles/new.html.erb` and needs to be
@@ -606,9 +606,11 @@ class ArticlesController < ApplicationController
end
```
-If you re-submit the form now, you'll see another familiar error: a template is
-missing. That's ok, we can ignore that for now. What the `create` action should
-be doing is saving our new article to the database.
+If you re-submit the form now, you may not see any change on the page. Don't worry!
+This is because Rails by default returns `204 No Content` response for an action if
+we don't specify what the response should be. We just added the `create` action
+but didn't specify anything about how the response should be. In this case, the
+`create` action should save our new article to the database.
When a form is submitted, the fields of the form are sent to Rails as
_parameters_. These parameters can then be referenced inside the controller
diff --git a/guides/source/testing.md b/guides/source/testing.md
index d4a826cee5..e8dc6ffe2a 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -146,18 +146,28 @@ Let us run this newly added test (where `6` is the number of line where the test
```bash
$ bin/rails test test/models/article_test.rb:6
+Run options: --seed 44656
+
+# Running:
+
F
-Finished tests in 0.044632s, 22.4054 tests/s, 22.4054 assertions/s.
+Failure:
+ArticleTest#test_should_not_save_article_without_title [/path/to/blog/test/models/article_test.rb:6]:
+Expected true to be nil or false
- 1) Failure:
-test_should_not_save_article_without_title(ArticleTest) [test/models/article_test.rb:6]:
-Failed assertion, no message given.
-1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
+bin/rails test test/models/article_test.rb:6
+
+
+
+Finished in 0.023918s, 41.8090 runs/s, 41.8090 assertions/s.
+
+1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
+
```
-In the output, `F` denotes a failure. You can see the corresponding trace shown under `1)` along with the name of the failing test. The next few lines contain the stack trace followed by a message that mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable, every assertion provides an optional message parameter, as shown here:
+In the output, `F` denotes a failure. You can see the corresponding trace shown under `Failure` along with the name of the failing test. The next few lines contain the stack trace followed by a message that mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable, every assertion provides an optional message parameter, as shown here:
```ruby
test "should not save article without title" do
@@ -169,8 +179,8 @@ end
Running this test shows the friendlier assertion message:
```bash
- 1) Failure:
-test_should_not_save_article_without_title(ArticleTest) [test/models/article_test.rb:6]:
+Failure:
+ArticleTest#test_should_not_save_article_without_title [/path/to/blog/test/models/article_test.rb:6]:
Saved the article without a title
```
@@ -186,11 +196,15 @@ Now the test should pass. Let us verify by running the test again:
```bash
$ bin/rails test test/models/article_test.rb:6
+Run options: --seed 31252
+
+# Running:
+
.
-Finished tests in 0.047721s, 20.9551 tests/s, 20.9551 assertions/s.
+Finished in 0.027476s, 36.3952 runs/s, 36.3952 assertions/s.
-1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
```
Now, if you noticed, we first wrote a test which fails for a desired
@@ -215,16 +229,25 @@ Now you can see even more output in the console from running the tests:
```bash
$ bin/rails test test/models/article_test.rb
-E
+Run options: --seed 1808
+
+# Running:
+
+.E
+
+Error:
+ArticleTest#test_should_report_error:
+NameError: undefined local variable or method `some_undefined_variable' for #<ArticleTest:0x007fee3aa71798>
+ test/models/article_test.rb:11:in `block in <class:ArticleTest>'
+
+
+bin/rails test test/models/article_test.rb:9
-Finished tests in 0.030974s, 32.2851 tests/s, 0.0000 assertions/s.
- 1) Error:
-test_should_report_error(ArticleTest):
-NameError: undefined local variable or method `some_undefined_variable' for #<ArticleTest:0x007fe32e24afe0>
- test/models/article_test.rb:10:in `block in <class:ArticleTest>'
-1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
+Finished in 0.040609s, 49.2500 runs/s, 24.6250 assertions/s.
+
+2 runs, 1 assertions, 0 failures, 1 errors, 0 skips
```
Notice the 'E' in the output. It denotes a test with error.
@@ -342,17 +365,21 @@ documentation](http://docs.seattlerb.org/minitest).
### The Rails Test Runner
-We can run all of our tests at once by using the `rails test` command.
+We can run all of our tests at once by using the `bin/rails test` command.
-Or we can run a single test by passing the `rails test` command the filename containing the test cases.
+Or we can run a single test by passing the `bin/rails test` command the filename containing the test cases.
```bash
$ bin/rails test test/models/article_test.rb
-.
+Run options: --seed 1559
-Finished tests in 0.009262s, 107.9680 tests/s, 107.9680 assertions/s.
+# Running:
-1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+..
+
+Finished in 0.027034s, 73.9810 runs/s, 110.9715 assertions/s.
+
+2 runs, 3 assertions, 0 failures, 0 errors, 0 skips
```
This will run all test methods from the test case.
@@ -362,6 +389,10 @@ You can also run a particular test method from the test case by providing the
```bash
$ bin/rails test test/models/article_test.rb -n test_the_truth
+Run options: -n test_the_truth --seed 43583
+
+# Running:
+
.
Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s.
@@ -372,7 +403,7 @@ Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s.
You can also run a test at a specific line by providing the line number.
```bash
-$ bin/rails test test/models/post_test.rb:44 # run specific test and line
+$ bin/rails test test/models/article_test.rb:6 # run specific test and line
```
You can also run an entire directory of tests by providing the path to the directory.
@@ -381,6 +412,38 @@ You can also run an entire directory of tests by providing the path to the direc
$ bin/rails test test/controllers # run all tests from specific directory
```
+The test runner provides lot of other features too like failing fast, deferring test output
+at the end of test run and so on. Check the documentation of the test runner as follows:
+
+```bash
+$ bin/rails test -h
+minitest options:
+ -h, --help Display this help.
+ -s, --seed SEED Sets random seed. Also via env. Eg: SEED=n rake
+ -v, --verbose Verbose. Show progress processing files.
+ -n, --name PATTERN Filter run on /regexp/ or string.
+ --exclude PATTERN Exclude /regexp/ or string from run.
+
+Known extensions: rails, pride
+
+Usage: bin/rails test [options] [files or directories]
+You can run a single test by appending a line number to a filename:
+
+ bin/rails test test/models/user_test.rb:27
+
+You can run multiple files and directories at the same time:
+
+ bin/rails test test/controllers test/integration/login_test.rb
+
+By default test failures and errors are reported inline during a run.
+
+Rails options:
+ -e, --environment ENV Run tests in the ENV environment
+ -b, --backtrace Show the complete backtrace
+ -d, --defer-output Output test failures and errors after the test run
+ -f, --fail-fast Abort test run on first failure or error
+ -c, --[no-]color Enable color in the output
+```
The Test Database
-----------------
@@ -529,7 +592,7 @@ Integration Testing
Integration tests are used to test how various parts of your application interact. They are generally used to test important workflows within our application.
-For creating Rails integration tests, we use the 'test/integration' directory for our application. Rails provides a generator to create an integration test skeleton for us.
+For creating Rails integration tests, we use the `test/integration` directory for our application. Rails provides a generator to create an integration test skeleton for us.
```bash
$ bin/rails generate integration_test user_flows
@@ -685,9 +748,8 @@ Let's take a look at one such test, `test_should_get_index` from the file `artic
# articles_controller_test.rb
class ArticlesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
- get '/articles'
+ get articles_url
assert_response :success
- assert_includes @response.body, 'Articles'
end
end
```
@@ -732,7 +794,7 @@ Let us modify `test_should_create_article` test in `articles_controller_test.rb`
```ruby
test "should create article" do
assert_difference('Article.count') do
- post '/article', params: { article: { title: 'Some title' } }
+ post articles_url, params: { article: { body: 'Rails is awesome!', title: 'Hello Rails' } }
end
assert_redirected_to article_path(Article.last)
@@ -763,7 +825,7 @@ To test AJAX requests, you can specify the `xhr: true` option to `get`, `post`,
```ruby
test "ajax request" do
- article = articles(:first)
+ article = articles(:one)
get article_url(article), xhr: true
assert_equal 'hello world', @response.body
@@ -800,16 +862,14 @@ You also have access to three instance variables in your functional tests:
[HTTP headers](http://tools.ietf.org/search/rfc2616#section-5.3)
and
[CGI variables](http://tools.ietf.org/search/rfc3875#section-4.1)
-can be set directly on the `@request` instance variable:
+can be passed as headers:
```ruby
# setting an HTTP Header
-@request.headers["Accept"] = "text/plain, text/html"
-get articles_url # simulate the request with custom header
+get articles_url, headers: "Content-Type" => "text/plain" # simulate the request with custom header
# setting a CGI variable
-@request.headers["HTTP_REFERER"] = "http://example.com/home"
-post article_url # simulate the request with custom env variable
+get articles_url, headers: "HTTP_REFERER" => "http://example.com/home" # simulate the request with custom env variable
```
### Testing `flash` notices
@@ -845,7 +905,7 @@ F
Finished in 0.114870s, 8.7055 runs/s, 34.8220 assertions/s.
1) Failure:
-ArticlesControllerTest#test_should_create_article [/Users/zzak/code/bench/sharedapp/test/controllers/articles_controller_test.rb:16]:
+ArticlesControllerTest#test_should_create_article [/test/controllers/articles_controller_test.rb:16]:
--- expected
+++ actual
@@ -1 +1 @@
@@ -894,7 +954,7 @@ Let's write a test for the `:show` action:
```ruby
test "should show article" do
article = articles(:one)
- get '/article', params: { id: article.id }
+ get article_url(article)
assert_response :success
end
```
@@ -920,7 +980,7 @@ We can also add a test for updating an existing Article.
test "should update article" do
article = articles(:one)
- patch '/article', params: { id: article.id, article: { title: "updated" } }
+ patch article_url(article), params: { article: { title: "updated" } }
assert_redirected_to article_path(article)
# Reload association to fetch updated data and assert that title is updated.
@@ -963,7 +1023,7 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest
end
test "should update article" do
- patch '/article', params: { id: @article.id, article: { title: "updated" } }
+ patch article_url(@article), params: { article: { title: "updated" } }
assert_redirected_to article_path(@article)
# Reload association to fetch updated data and assert that title is updated.
@@ -984,8 +1044,8 @@ Sign in helper can be a good example:
#test/test_helper.rb
module SignInHelper
- def sign_in(user)
- session[:user_id] = user.id
+ def sign_in_as(user)
+ post sign_in_url(email: user.email, password: user.password)
end
end
@@ -1001,7 +1061,7 @@ class ProfileControllerTest < ActionDispatch::IntegrationTest
test "should show profile" do
# helper is now reusable from any controller test case
- sign_in users(:david)
+ sign_in_as users(:david)
get profile_url
assert_response :success
@@ -1247,8 +1307,8 @@ end
This test is pretty simple and only asserts that the job get the work done
as expected.
-By default, `ActiveJob::TestCase` will set the queue adapter to `:test` so that
-your jobs are performed inline. It will also ensure that all previously performed
+By default, `ActiveJob::TestCase` will set the queue adapter to `:async` so that
+your jobs are performed in an async fashion. It will also ensure that all previously performed
and enqueued jobs are cleared before any test run so you can safely assume that
no jobs have already been executed in the scope of each test.
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index cbe46d6c0d..c41876cd28 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -75,9 +75,9 @@ For more information on changes made to Rails 5.0 please see the [release notes]
From Ruby on Rails 5.0 onwards, Ruby 2.2.2+ is the only supported Ruby version.
Make sure you are on Ruby 2.2.2 version or greater, before you proceed.
-### Active Record models now inherit from ApplicationRecord by default
+### Active Record Models Now Inherit from ApplicationRecord by Default
-In Rails 4.2 an Active Record model inherits from `ActiveRecord::Base`. In Rails 5.0,
+In Rails 4.2, an Active Record model inherits from `ActiveRecord::Base`. In Rails 5.0,
all models inherit from `ApplicationRecord`.
`ApplicationRecord` is a new superclass for all app models, analogous to app
@@ -85,7 +85,7 @@ controllers subclassing `ApplicationController` instead of
`ActionController::Base`. This gives apps a single spot to configure app-wide
model behavior.
-When upgrading from Rails 4.2 to Rails 5.0 you need to create an
+When upgrading from Rails 4.2 to Rails 5.0, you need to create an
`application_record.rb` file in `app/models/` and add the following content:
```
@@ -94,7 +94,7 @@ class ApplicationRecord < ActiveRecord::Base
end
```
-### Halting callback chains via `throw(:abort)`
+### Halting Callback Chains via `throw(:abort)`
In Rails 4.2, when a 'before' callback returns `false` in Active Record
and Active Model, then the entire callback chain is halted. In other words,
@@ -119,12 +119,12 @@ halted the chain when any value was returned.
See [#17227](https://github.com/rails/rails/pull/17227) for more details.
-### ActiveJob jobs now inherit from ApplicationJob by default
+### ActiveJob Now Inherits from ApplicationJob by Default
-In Rails 4.2 an Active Job inherits from `ActiveJob::Base`. In Rails 5.0 this
+In Rails 4.2, an Active Job inherits from `ActiveJob::Base`. In Rails 5.0, this
behavior has changed to now inherit from `ApplicationJob`.
-When upgrading from Rails 4.2 to Rails 5.0 you need to create an
+When upgrading from Rails 4.2 to Rails 5.0, you need to create an
`application_job.rb` file in `app/jobs/` and add the following content:
```
@@ -139,25 +139,41 @@ See [#19034](https://github.com/rails/rails/pull/19034) for more details.
### Rails Controller Testing
`assigns` and `assert_template` have been extracted to the `rails-controller-testing` gem. To
-continue using these methods in your controller tests add `gem 'rails-controller-testing'` to
+continue using these methods in your controller tests, add `gem 'rails-controller-testing'` to
your Gemfile.
-If you are using Rspec for testing please see the extra configuration required in the gem's
+If you are using Rspec for testing, please see the extra configuration required in the gem's
documentation.
+### Autoloading is Disabled After Booting in the Production Environment
+
+Autoloading is now disabled after booting in the production environment by
+default.
+
+Eager loading the application is part of the boot process, so top-level
+constants are fine and are still autoloaded, no need to require their files.
+
+Constants in deeper places only executed at runtime, like regular method bodies,
+are also fine because the file defining them will have been eager loaded while booting.
+
+For the vast majority of applications this change needs no action. But in the
+very rare event that your application needs autoloading while running in
+production mode, set `Rails.application.config.enable_dependency_loading` to
+true.
+
### XML Serialization
`ActiveModel::Serializers::Xml` has been extracted from Rails to the `activemodel-serializers-xml`
-gem. To continue using XML serialization in your application add `gem 'activemodel-serializers-xml'`
+gem. To continue using XML serialization in your application, add `gem 'activemodel-serializers-xml'`
to your Gemfile.
-### Removed support for legacy MySQL
+### Removed Support for Legacy `mysql` Database Adapter
Rails 5 removes support for the legacy `mysql` database adapter. Most users should be able to
use `mysql2` instead. It will be converted to a separate gem when we find someone to maintain
it.
-### Removed support for debugger
+### Removed Support for Debugger
`debugger` is not supported by Ruby 2.2 which is required by Rails 5. Use `byebug` instead.
@@ -168,27 +184,27 @@ these changes are in parallel with rake, but some were ported over altogether.
To use the new test runner simply type `bin/rails test`.
- rake dev:cache` is now `rails dev:cache
+`rake dev:cache` is now `rails dev:cache`.
Run `bin/rails` to see the list of commands available.
-### `ActionController::Parameters` no longer inherits from `HashWithIndifferentAccess`
+### `ActionController::Parameters` No Longer Inherits from `HashWithIndifferentAccess`
Calling `params` in your application will now return an object instead of a hash. If your
-parameters are already permitted you will not need to make any changes. If you are using slice
+parameters are already permitted, then you will not need to make any changes. If you are using `slice`
and other methods that depend on being able to read the hash regardless of `permitted?` you will
need to upgrade your application to first permit and then convert to a hash.
params.permit([:proceed_to, :return_to]).to_h
-### `protect_from_forgery` now defaults to `prepend: false`
+### `protect_from_forgery` Now Defaults to `prepend: false`
`protect_from_forgery` defaults to `prepend: false` which means that it will be inserted into
the callback chain at the point in which you call it in your application. If you want
-`protect_from_forgery` to always run first you should change your application to use
+`protect_from_forgery` to always run first, then you should change your application to use
`protect_from_forgery prepend: true`.
-### Default template handler is now RAW
+### Default Template Handler is Now RAW
Files without a template handler in their extension will be rendered using the raw handler.
Previously Rails would render files using the ERB template handler.
@@ -196,9 +212,9 @@ Previously Rails would render files using the ERB template handler.
If you do not want your file to be handled via the raw handler, you should add an extension
to your file that can be parsed by the appropriate template handler.
-### Add wildcard matching for template dependencies
+### Added Wildcard Matching for Template Dependencies
-You can now use wildcard matching for your template dependencies. For example if you were
+You can now use wildcard matching for your template dependencies. For example, if you were
defining your templates as such:
```erb
@@ -213,17 +229,17 @@ You can now just call the dependency once with a wildcard.
<% # Template Dependency: recordings/threads/events/* %>
```
-### Remove support for `protected_attributes` gem
+### Removed Support for `protected_attributes` Gem
The `protected_attributes` gem is no longer supported in Rails 5.
-### Remove support for `activerecord-deprecated_finders` gem
+### Removed support for `activerecord-deprecated_finders` gem
The `activerecord-deprecated_finders` gem is no longer supported in Rails 5.
-### `ActiveSupport::TestCase` default test order is now random
+### `ActiveSupport::TestCase` Default Test Order is Now Random
-When tests are run in your application the default order is now `:random`
+When tests are run in your application, the default order is now `:random`
instead of `:sorted`. Use the following config option to set it back to `:sorted`.
```ruby
@@ -233,38 +249,97 @@ Rails.application.configure do
end
```
-### New config options
+### `ActionController::Live` became a `Concern`
+
+If you include `ActionController::Live` in another module that is included in your controller, then you
+should also extend the module with `ActiveSupport::Concern`. Alternatively, you can use the `self.included` hook
+to include `ActionController::Live` directly to the controller once the `StreamingSupport` is included.
+
+This means that if your application used to have its own streaming module, the following code
+would break in production mode:
+
+```ruby
+# This is a work-around for streamed controllers performing authentication with Warden/Devise.
+# See https://github.com/plataformatec/devise/issues/2332
+# Authenticating in the router is another solution as suggested in that issue
+class StreamingSupport
+ include ActionController::Live # this won't work in production for Rails 5
+ # extend ActiveSupport::Concern # unless you uncomment this line.
+
+ def process(name)
+ super(name)
+ rescue ArgumentError => e
+ if e.message == 'uncaught throw :warden'
+ throw :warden
+ else
+ raise e
+ end
+ end
+end
+```
+
+### New Framework Defaults
-## Active Record `belongs_to` Required by Default Option
+#### Active Record `belongs_to` Required by Default Option
`belongs_to` will now trigger a validation error by default if the association is not present.
This can be turned off per-association with `optional: true`.
-This default will will be automatically configured in new applications. If existing application
+This default will be automatically configured in new applications. If existing application
want to add this feature it will need to be turned on in an initializer.
config.active_record.belongs_to_required_by_default = true
-## Allow configuration of Action Mailer queue name
+#### Per-form CSRF Tokens
+
+Rails 5 now supports per-form CSRF tokens to mitigate against code-injection attacks with forms
+created by JavaScript. With this option turned on, forms in your application will each have their
+own CSRF token that is specified to the action and method for that form.
+
+ config.action_controller.per_form_csrf_tokens = true
+
+#### Forgery Protection with Origin Check
+
+You can now configure your application to check if the HTTP `Origin` header should be checked
+against the site's origin as an additional CSRF defense. Set the following in your config to
+true:
+
+ config.action_controller.forgery_protection_origin_check = true
+
+#### Allow Configuration of Action Mailer Queue Name
The default mailer queue name is `mailers`. This configuration option allows you to globally change
-the queue name. Set the following in your config.
+the queue name. Set the following in your config:
- config.action_mailer.deliver_later_queue_name
+ config.action_mailer.deliver_later_queue_name = :new_queue_name
-## Support fragment caching in Action Mailer views
+#### Support Fragment Caching in Action Mailer Views
Set `config.action_mailer.perform_caching` in your config to determine whether your Action Mailer views
should support caching.
-## Configure the output of `db:structure:dump`
+ config.action_mailer.perform_caching = true
+
+#### Configure the Output of `db:structure:dump`
If you're using `schema_search_path` or other PostgreSQL extentions, you can control how the schema is
-dumped. Set to `:all` to generate all dumps, or `:schema_search_path` to generate from schema search path.
+dumped. Set to `:all` to generate all dumps, or to `:schema_search_path` to generate from schema search path.
config.active_record.dump_schemas = :all
+#### Configure SSL Options to Enable HSTS with Subdomains
+
+Set the following in your config to enable HSTS when using subdomains:
+
+ config.ssl_options = { hsts: { subdomains: true } }
+
+#### Preserve Timezone of the Receiver
+
+When using Ruby 2.4, you can preserve the timezone of the receiver when calling `to_time`.
+
+ ActiveSupport.to_time_preserves_timezone = false
+
Upgrading from Rails 4.1 to Rails 4.2
-------------------------------------
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index f0a3289563..0835c09323 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -312,7 +312,7 @@ module Rails
end
def coffee_gemfile_entry
- GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', nil, 'Use CoffeeScript for .coffee assets and views'
+ GemfileEntry.version 'coffee-rails', '~> 4.2', 'Use CoffeeScript for .coffee assets and views'
end
def javascript_gemfile_entry
@@ -324,7 +324,7 @@ module Rails
"Use #{options[:javascript]} as the JavaScript library")
unless options[:skip_turbolinks]
- gems << GemfileEntry.version("turbolinks", "~> 5.x",
+ gems << GemfileEntry.version("turbolinks", "~> 5",
"Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks")
end
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 9e8531b482..12bdbcf23e 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -188,7 +188,7 @@ module ApplicationTests
test 'sprockets cache is not shared between environments' do
app_file "app/assets/images/rails.png", "notactuallyapng"
- app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+ app_file "app/assets/stylesheets/application.css.erb", "body { background: '<%= asset_path('rails.png') %>'; }"
add_to_env_config 'production', 'config.assets.prefix = "production_assets"'
precompile!