aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile5
-rw-r--r--Gemfile.lock43
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--actionpack/lib/action_controller/base.rb8
-rw-r--r--actionview/lib/action_view/helpers/tag_helper.rb23
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb32
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb2
-rw-r--r--activerecord/test/cases/adapters/mysql2/schema_test.rb21
-rw-r--r--activerecord/test/cases/migration/foreign_key_test.rb13
-rw-r--r--activerecord/test/cases/primary_keys_test.rb12
-rw-r--r--activerecord/test/schema/schema.rb15
-rw-r--r--activesupport/lib/active_support/key_generator.rb12
-rw-r--r--activesupport/test/key_generator_test.rb17
-rw-r--r--guides/source/5_0_release_notes.md44
-rw-r--r--guides/source/configuring.md2
-rw-r--r--guides/source/documents.yaml4
-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/lib/rails/generators/rails/app/app_generator.rb5
-rw-r--r--railties/lib/rails/tasks/framework.rake6
-rw-r--r--railties/test/application/assets_test.rb2
-rw-r--r--tasks/release.rb40
23 files changed, 406 insertions, 191 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/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/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index d546d7260c..251289d4bb 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -32,7 +32,7 @@ module ActionController
# new post), it initiates a redirect instead. This redirect works by returning an external
# "302 Moved" HTTP response that takes the user to the index action.
#
- # These two methods represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
+ # These two methods represent the two basic action archetypes used in Action Controllers: Get-and-show and do-and-redirect.
# Most actions are variations on these themes.
#
# == Requests
@@ -51,8 +51,8 @@ module ActionController
# == Parameters
#
# All request parameters, whether they come from a query string in the URL or form data submitted through a POST request are
- # available through the params method which returns a hash. For example, an action that was performed through
- # <tt>/posts?category=All&limit=5</tt> will include <tt>{ "category" => "All", "limit" => "5" }</tt> in params.
+ # available through the <tt>params</tt> method which returns a hash. For example, an action that was performed through
+ # <tt>/posts?category=All&limit=5</tt> will include <tt>{ "category" => "All", "limit" => "5" }</tt> in <tt>params</tt>.
#
# It's also possible to construct multi-dimensional parameter hashes by specifying keys using brackets, such as:
#
@@ -60,7 +60,7 @@ module ActionController
# <input type="text" name="post[address]" value="hyacintvej">
#
# A request stemming from a form holding these inputs will include <tt>{ "post" => { "name" => "david", "address" => "hyacintvej" } }</tt>.
- # If the address input had been named <tt>post[address][street]</tt>, the params would have included
+ # If the address input had been named <tt>post[address][street]</tt>, the <tt>params</tt> would have included
# <tt>{ "post" => { "address" => { "street" => "hyacintvej" } } }</tt>. There's no limit to the depth of the nesting.
#
# == Sessions
diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb
index 48dea8f214..0633cfc2b4 100644
--- a/actionview/lib/action_view/helpers/tag_helper.rb
+++ b/actionview/lib/action_view/helpers/tag_helper.rb
@@ -124,11 +124,11 @@ module ActionView
# ==== Passing content
# Tags can pass content to embed within it:
#
- # tag.h1 'All shit fit to print' # => <h1>All shit fit to print</h1>
+ # tag.h1 'All titles fit to print' # => <h1>All titles fit to print</h1>
#
# tag.div tag.p('Hello world!') # => <div><p>Hello world!</p></div>
#
- # Content can also be captured with a block. Great for ERB templates:
+ # Content can also be captured with a block, which is useful in templates:
#
# <%= tag.p do %>
# The next great American novel starts here.
@@ -136,7 +136,7 @@ module ActionView
# # => <p>The next great American novel starts here.</p>
#
# ==== Options
- # Any passed options becomes attributes on the generated tag.
+ # Any passed options become attributes on the generated tag.
#
# tag.section class: %w( kitties puppies )
# # => <section class="kitties puppies"></section>
@@ -144,7 +144,7 @@ module ActionView
# tag.section id: dom_id(@post)
# # => <section id="<generated dom id>"></section>
#
- # Pass true for any attributes that can render with no values like +disabled+.
+ # Pass +true+ for any attributes that can render with no values, like +disabled+ and +readonly+.
#
# tag.input type: 'text', disabled: true
# # => <input type="text" disabled="disabled">
@@ -152,7 +152,7 @@ module ActionView
# HTML5 <tt>data-*</tt> attributes can be set with a single +data+ key
# pointing to a hash of sub-attributes.
#
- # To play nicely with JavaScript conventions sub-attributes are dasherized.
+ # To play nicely with JavaScript conventions, sub-attributes are dasherized.
#
# tag.article data: { user_id: 123 }
# # => <article data-user-id="123"></article>
@@ -167,7 +167,7 @@ module ActionView
# tag.div data: { city_state: %w( Chigaco IL ) }
# # => <div data-city-state="[&quot;Chicago&quot;,&quot;IL&quot;]"></div>
#
- # The generated attributes are escaped by default, but it can be turned off with
+ # The generated attributes are escaped by default. This can be disabled using
# +escape_attributes+.
#
# tag.img src: 'open & shut.png'
@@ -187,7 +187,7 @@ module ActionView
# tag.br # => <br>
#
# === Legacy syntax
- # Following format is legacy syntax. It will be deprecated in future versions of rails.
+ # The following format is for legacy syntax support. It will be deprecated in future versions of Rails.
#
# tag(tag_name, options)
#
@@ -207,15 +207,6 @@ module ActionView
# HTML5 <tt>data-*</tt> attributes can be set with a single +data+ key
# pointing to a hash of sub-attributes.
#
- # To play nicely with JavaScript conventions sub-attributes are dasherized.
- # For example, a key +user_id+ would render as <tt>data-user-id</tt> and
- # thus accessed as <tt>dataset.userId</tt>.
- #
- # Values are encoded to JSON, with the exception of strings, symbols and
- # BigDecimals.
- # This may come in handy when using jQuery's HTML5-aware <tt>.data()</tt>
- # from 1.4.3.
- #
# ==== Examples
# tag("br")
# # => <br />
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 718a6c5b91..c7881a6c6c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -515,19 +515,21 @@ module ActiveRecord
schema, name = extract_schema_qualified_name(table_name)
- fk_info = select_all <<-SQL.strip_heredoc
- SELECT fk.referenced_table_name as 'to_table'
- ,fk.referenced_column_name as 'primary_key'
- ,fk.column_name as 'column'
- ,fk.constraint_name as 'name'
+ fk_info = select_all(<<-SQL.strip_heredoc, 'SCHEMA')
+ SELECT fk.referenced_table_name AS 'to_table',
+ fk.referenced_column_name AS 'primary_key',
+ fk.column_name AS 'column',
+ fk.constraint_name AS 'name',
+ rc.update_rule AS 'on_update',
+ rc.delete_rule AS 'on_delete'
FROM information_schema.key_column_usage fk
- WHERE fk.referenced_column_name is not null
+ JOIN information_schema.referential_constraints rc
+ USING (constraint_schema, constraint_name)
+ WHERE fk.referenced_column_name IS NOT NULL
AND fk.table_schema = #{quote(schema)}
AND fk.table_name = #{quote(name)}
SQL
- create_table_info = create_table_info(table_name)
-
fk_info.map do |row|
options = {
column: row['column'],
@@ -535,8 +537,8 @@ module ActiveRecord
primary_key: row['primary_key']
}
- options[:on_update] = extract_foreign_key_action(create_table_info, row['name'], "UPDATE")
- options[:on_delete] = extract_foreign_key_action(create_table_info, row['name'], "DELETE")
+ options[:on_update] = extract_foreign_key_action(row['on_update'])
+ options[:on_delete] = extract_foreign_key_action(row['on_delete'])
ForeignKeyDefinition.new(table_name, row['to_table'], options)
end
@@ -891,12 +893,10 @@ module ActiveRecord
end
end
- def extract_foreign_key_action(structure, name, action) # :nodoc:
- if structure =~ /CONSTRAINT #{quote_column_name(name)} FOREIGN KEY .* REFERENCES .* ON #{action} (CASCADE|SET NULL|RESTRICT)/
- case $1
- when 'CASCADE'; :cascade
- when 'SET NULL'; :nullify
- end
+ def extract_foreign_key_action(specifier) # :nodoc:
+ case specifier
+ when 'CASCADE'; :cascade
+ when 'SET NULL'; :nullify
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index f6860b9aba..45507e206a 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -579,7 +579,7 @@ module ActiveRecord
end
def foreign_keys(table_name)
- fk_info = select_all <<-SQL.strip_heredoc
+ fk_info = select_all(<<-SQL.strip_heredoc, 'SCHEMA')
SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid
diff --git a/activerecord/test/cases/adapters/mysql2/schema_test.rb b/activerecord/test/cases/adapters/mysql2/schema_test.rb
index 43957791b1..57ea8258d1 100644
--- a/activerecord/test/cases/adapters/mysql2/schema_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/schema_test.rb
@@ -103,3 +103,24 @@ module ActiveRecord
end
end
end
+
+class Mysql2AnsiQuotesTest < ActiveRecord::Mysql2TestCase
+ def setup
+ @connection = ActiveRecord::Base.connection
+ @connection.execute("SET SESSION sql_mode='ANSI_QUOTES'")
+ end
+
+ def teardown
+ @connection.reconnect!
+ end
+
+ def test_primary_key_method_with_ansi_quotes
+ assert_equal "id", @connection.primary_key("topics")
+ end
+
+ def test_foreign_keys_method_with_ansi_quotes
+ fks = @connection.foreign_keys("lessons_students")
+ assert_equal([["lessons_students", "students", :cascade]],
+ fks.map {|fk| [fk.from_table, fk.to_table, fk.on_delete] })
+ end
+end
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb
index 01162dcefe..49a8fa241f 100644
--- a/activerecord/test/cases/migration/foreign_key_test.rb
+++ b/activerecord/test/cases/migration/foreign_key_test.rb
@@ -232,6 +232,10 @@ module ActiveRecord
t.column :city_id, :integer
end
add_foreign_key :houses, :cities, column: "city_id"
+
+ # remove and re-add to test that schema is updated and not accidently cached
+ remove_foreign_key :houses, :cities
+ add_foreign_key :houses, :cities, column: "city_id", on_delete: :cascade
end
end
@@ -243,6 +247,15 @@ module ActiveRecord
silence_stream($stdout) { migration.migrate(:down) }
end
+ def test_foreign_key_constraint_is_not_cached_incorrectly
+ migration = CreateCitiesAndHousesMigration.new
+ silence_stream($stdout) { migration.migrate(:up) }
+ output = dump_table_schema "houses"
+ assert_match %r{\s+add_foreign_key "houses",.+on_delete: :cascade$}, output
+ ensure
+ silence_stream($stdout) { migration.migrate(:down) }
+ end
+
class CreateSchoolsAndClassesMigration < ActiveRecord::Migration::Current
def change
create_table(:schools)
diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb
index 52eac4a124..6c8532cf00 100644
--- a/activerecord/test/cases/primary_keys_test.rb
+++ b/activerecord/test/cases/primary_keys_test.rb
@@ -275,18 +275,6 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase
end
if current_adapter?(:Mysql2Adapter)
- class PrimaryKeyWithAnsiQuotesTest < ActiveRecord::TestCase
- self.use_transactional_tests = false
-
- def test_primary_key_method_with_ansi_quotes
- con = ActiveRecord::Base.connection
- con.execute("SET SESSION sql_mode='ANSI_QUOTES'")
- assert_equal "id", con.primary_key("topics")
- ensure
- con.reconnect!
- end
- end
-
class PrimaryKeyBigintNilDefaultTest < ActiveRecord::TestCase
include SchemaDumpingHelper
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 628a59c2e3..2f2993ce18 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -409,6 +409,14 @@ ActiveRecord::Schema.define do
t.references :student
end
+ create_table :students, force: true do |t|
+ t.string :name
+ t.boolean :active
+ t.integer :college_id
+ end
+
+ add_foreign_key :lessons_students, :students, on_delete: :cascade
+
create_table :lint_models, force: true
create_table :line_items, force: true do |t|
@@ -777,12 +785,6 @@ ActiveRecord::Schema.define do
t.integer :lock_version, null: false, default: 0
end
- create_table :students, force: true do |t|
- t.string :name
- t.boolean :active
- t.integer :college_id
- end
-
create_table :subscribers, force: true, id: false do |t|
t.string :nick, null: false
t.string :name
@@ -1002,7 +1004,6 @@ ActiveRecord::Schema.define do
end
add_foreign_key :fk_test_has_fk, :fk_test_has_pk, column: "fk_id", name: "fk_name", primary_key: "pk_id"
- add_foreign_key :lessons_students, :students
end
create_table :overloaded_types, force: true do |t|
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/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md
index 7b5c6cf345..bdd1c2cc4e 100644
--- a/guides/source/5_0_release_notes.md
+++ b/guides/source/5_0_release_notes.md
@@ -257,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))
@@ -267,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
-----------
@@ -441,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
-------------
@@ -643,6 +660,14 @@ 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))
+
+* 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.
@@ -765,6 +790,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
------------
@@ -818,6 +857,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/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/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 448dce06af..afa76aae44 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -226,6 +226,11 @@ module Rails
end
remove_task :update_config_files
+ def display_upgrade_guide_info
+ say "\nAfter this, check Rails upgrade guide at http://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
+ end
+ remove_task :display_upgrade_info
+
def create_boot_file
template "config/boot.rb"
end
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 51d9daaaa9..255312493f 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -2,7 +2,7 @@ require 'active_support/deprecation'
namespace :app do
desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
- task update: [ "update:configs", "update:bin" ]
+ task update: [ "update:configs", "update:bin", "update:upgrade_guide_info" ]
desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
task template: :environment do
@@ -67,6 +67,10 @@ namespace :app do
task :bin do
RailsUpdate.invoke_from_app_generator :create_bin_files
end
+
+ task :upgrade_guide_info do
+ RailsUpdate.invoke_from_app_generator :display_upgrade_guide_info
+ end
end
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!
diff --git a/tasks/release.rb b/tasks/release.rb
index 4a1ed04478..045bcc5b5f 100644
--- a/tasks/release.rb
+++ b/tasks/release.rb
@@ -43,7 +43,28 @@ directory "pkg"
raise "Could not insert PRE in #{file}" unless $1
File.open(file, 'w') { |f| f.write ruby }
+ end
+
+ task gem => %w(update_versions pkg) do
+ cmd = ""
+ cmd << "cd #{framework} && " unless framework == "rails"
+ cmd << "bundle exec rake package && " unless framework == "rails"
+ cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
+ sh cmd
+ end
+
+ task :build => [:clean, gem]
+ task :install => :build do
+ sh "gem install --pre #{gem}"
+ end
+
+ task :push => :build do
+ sh "gem push #{gem}"
+ # When running the release task we usually run build first to check that the gem works properly.
+ # NPM will refuse to publish or rebuild the gem if the version is changed when the Rails gem
+ # versions are changed. This then causes the gem push to fail. Because of this we need to update
+ # the version and publish at the same time.
if File.exist?("#{framework}/package.json")
Dir.chdir("#{framework}") do
# This "npm-ifies" the current version
@@ -68,30 +89,13 @@ directory "pkg"
# Check if npm is installed, and raise an error if not
if sh 'which npm'
sh "npm version #{version} --no-git-tag-version"
+ sh "npm publish"
else
raise 'You must have npm installed to release Rails.'
end
end
end
end
-
- task gem => %w(update_versions pkg) do
- cmd = ""
- cmd << "cd #{framework} && " unless framework == "rails"
- cmd << "bundle exec rake package && " unless framework == "rails"
- cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
- sh cmd
- end
-
- task :build => [:clean, gem]
- task :install => :build do
- sh "gem install --pre #{gem}"
- end
-
- task :push => :build do
- sh "gem push #{gem}"
- sh "npm publish" if File.exist?("#{framework}/package.json")
- end
end
end