From ddf27acbc285a892842866cde04951cdad52c5c9 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Sun, 24 Nov 2013 12:52:53 -0500 Subject: Introduce a context for rendering fixtures ERB. Fixture files are passed through an ERB renderer before being read as YAML. The rendering is currently done in the context of the main object, so method definitons leak into other fixtures, and there is no clean place to define fixture helpers. After this commit, the ERB renderer will use a new subclass of ActiveRecord::FixtureSet.context_class each time a fixture is rendered. --- guides/source/upgrading_ruby_on_rails.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index ef5f6ac024..3fbc913d8b 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -27,6 +27,23 @@ Upgrading from Rails 4.0 to Rails 4.1 NOTE: This section is a work in progress. +### Methods defined in Active Record fixtures + +Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods +defined in a fixture will not be available in other fixtures. + +Helper methods that are used in multiple fixtures should be defined on modules +included in the newly introduced `ActiveRecord::FixtureSet.context_class`, in +`test_helper.rb`. + +```ruby +class FixtureFileHelpers + def file_sha(path) + Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path))) + end +end +ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers +``` Upgrading from Rails 3.2 to Rails 4.0 ------------------------------------- -- cgit v1.2.3 From 3fd0bf48963e67199d774bbd04b7893bdb5cf524 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Sat, 30 Nov 2013 01:54:27 -0800 Subject: Added JSON release notes [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 3fbc913d8b..8ad7e62789 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -27,6 +27,60 @@ Upgrading from Rails 4.0 to Rails 4.1 NOTE: This section is a work in progress. +### Changes in JSON handling + +The are a few major changes related to JSON handling in Rails 4.1. + +#### MultiJSON removal + +MultiJSON has reached its [end-of-life](https://github.com/rails/rails/pull/10576) +and has been removed from Rails. + +If your application currently depend on MultiJSON directly, you have a few options: + +1. Add 'multi_json' to your Gemfile. Note that this might cease to work in the future + +2. Migrate away from MultiJSON by using `obj.to_json`, and `JSON.parse(str)` instead. + +WARNING: Do not simply replace `MultiJson.dump` and `MultiJson.load` with +`JSON.dump` and `JSON.load`. These JSON gem APIs are meant for serializing and +deserializing arbitrary Ruby objects and are generally [unsafe](http://www.ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html#method-i-load). + +#### JSON gem compatibility + +Historically, Rails had some compatibility issues with the JSON gem. Using +`JSON.generate` and `JSON.dump` inside a Rails application could produce +unexpected errors. + +Rails 4.1 fixed these issues by isolating its own encoder from the JSON gem. The +JSON gem APIs will function as normal, but they will not have access to any +Rails-specific features. For example: + +```ruby +class FooBar + def as_json(options = nil) + { foo: "bar" } + end +end + +>> FooBar.new.to_json # => "{\"foo\":\"bar\"}" +>> JSON.generate(FooBar.new, quirks_mode: true) # => "\"#\"" +``` + +#### New JSON encoder + +The JSON encoder in Rails 4.1 has been rewritten to take advantage of the JSON +gem. For most applications, this should be a transparent change. However, as +part of the rewrite, the following features have been removed from the encoder: + +1. Circular data structure detection +2. Support for the `encode_json` hook +3. Option to encode `BigDecimal` objects as numbers instead of strings + +If you application depends on one of these features, you can get them back by +adding the [`activesupport-json_encoder`](https://github.com/rails/activesupport-json_encoder) +gem to your Gemfile. + ### Methods defined in Active Record fixtures Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods -- cgit v1.2.3 From 828a8f214535e59d709fd4862605902d1cc21632 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 4 Dec 2013 11:54:34 +0100 Subject: add Spring as major feature in the 4.1 release notes. [ci skip] Follow up to #12958. --- guides/source/upgrading_ruby_on_rails.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 8ad7e62789..f9d5332754 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -27,6 +27,18 @@ Upgrading from Rails 4.0 to Rails 4.1 NOTE: This section is a work in progress. +### Spring + +If you want to use Spring as your application preloader you need to: + +1. add `gem 'spring', group: :development` to your `Gemfile`. +2. install spring using `bundle install`. +3. springify your binstubs with `bundle exec spring binstub --all`. + +NOTE: User defined rake tasks will run in the `development` environment by +default. If you want them to run in other environments consult the +[Spring README](https://github.com/jonleighton/spring#rake). + ### Changes in JSON handling The are a few major changes related to JSON handling in Rails 4.1. -- cgit v1.2.3 From 673a8a8dfe595bf9820a7dad7c83e04bfb23162e Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Thu, 5 Dec 2013 00:08:02 +0530 Subject: update guides to new version of rails 3.2.x[ci skip] --- guides/source/upgrading_ruby_on_rails.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index f9d5332754..596682bb1f 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -433,7 +433,7 @@ Upgrading from Rails 3.1 to Rails 3.2 If your application is currently on any version of Rails older than 3.1.x, you should upgrade to Rails 3.1 before attempting an update to Rails 3.2. -The following changes are meant for upgrading your application to Rails 3.2.15, +The following changes are meant for upgrading your application to Rails 3.2.16, the last 3.2.x version of Rails. ### Gemfile @@ -441,7 +441,7 @@ the last 3.2.x version of Rails. Make the following changes to your `Gemfile`. ```ruby -gem 'rails', '3.2.15' +gem 'rails', '3.2.16' group :assets do gem 'sass-rails', '~> 3.2.6' -- cgit v1.2.3 From 71a7b1f1d4364870905746685d76bbaa3072deb9 Mon Sep 17 00:00:00 2001 From: Prashant Sahni Date: Fri, 6 Dec 2013 11:47:22 +0530 Subject: capitalize words starting after numbered list to maintain consistency [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 596682bb1f..de06ab291f 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -31,9 +31,9 @@ NOTE: This section is a work in progress. If you want to use Spring as your application preloader you need to: -1. add `gem 'spring', group: :development` to your `Gemfile`. -2. install spring using `bundle install`. -3. springify your binstubs with `bundle exec spring binstub --all`. +1. Add `gem 'spring', group: :development` to your `Gemfile`. +2. Install spring using `bundle install`. +3. Springify your binstubs with `bundle exec spring binstub --all`. NOTE: User defined rake tasks will run in the `development` environment by default. If you want them to run in other environments consult the -- cgit v1.2.3 From 68abbac2fc6ef8808e1788be9c4f41581674d17f Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 11 Dec 2013 04:57:39 -0800 Subject: Warn about using `return` inside inline callback blocks [ci skip] Closes #12981 --- guides/source/upgrading_ruby_on_rails.md | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index de06ab291f..9be48acb12 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -93,6 +93,39 @@ If you application depends on one of these features, you can get them back by adding the [`activesupport-json_encoder`](https://github.com/rails/activesupport-json_encoder) gem to your Gemfile. +### Usage of `return` within inline callback blocks + +Previously, Rails allowed you to `return` from an inline callback block: + +```ruby +class ReadOnlyModel < ActiveRecord::Base + before_save { return false } +end +``` + +This behaviour was never intentionally supported. Due to a change in the internals +of `ActiveSupport::Callbacks`, this is no longer allowed in Rails 4.1. Using a +`return` statement in an inline callback block will cause a `LocalJumpError` to +be raised when the callback is executed. If you need to use `return` statements +in your callbacks, it is recommended that you explicitly define them as methods +and pass the method name as a symbol instead: + +```ruby +class ReadOnlyModel < ActiveRecord::Base + before_save :before_save_callback + + private + def before_save_callback + return false + end +end +``` + +This change applies to most places in Rails where callbacks are used, including +Active Record and Active Model callbacks, as well as "filters" in Action +Controller (e.g. `before_action`). See [this pull request](https://github.com/rails/rails/pull/13271) +for more details. + ### Methods defined in Active Record fixtures Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods -- cgit v1.2.3 From 6814c78b6793f4bee4278daa8b6dc5e269b2f06a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 12 Dec 2013 21:20:51 +0100 Subject: copy-edits 68abbac [ci skip] * Rewording to avoid "you"s. * Suggest as first natural alternative to refactor the block to evaluate to the returned value. * Removes the quotes around "filters", since that is a common work in our jargon. --- guides/source/upgrading_ruby_on_rails.md | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 9be48acb12..ca5623bf73 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -95,24 +95,34 @@ gem to your Gemfile. ### Usage of `return` within inline callback blocks -Previously, Rails allowed you to `return` from an inline callback block: +Previously, Rails allowed inline callback blocks to use `return` this way: ```ruby class ReadOnlyModel < ActiveRecord::Base - before_save { return false } + before_save { return false } # BAD end ``` This behaviour was never intentionally supported. Due to a change in the internals of `ActiveSupport::Callbacks`, this is no longer allowed in Rails 4.1. Using a -`return` statement in an inline callback block will cause a `LocalJumpError` to -be raised when the callback is executed. If you need to use `return` statements -in your callbacks, it is recommended that you explicitly define them as methods -and pass the method name as a symbol instead: +`return` statement in an inline callback block causes a `LocalJumpError` to +be raised when the callback is executed. + +Inline callback blocks using `return` can be refactored to evaluate to the +returned value: + +```ruby +class ReadOnlyModel < ActiveRecord::Base + before_save { false } # GOOD +end +``` + +Alternatively, if `return` is preferred it is recommended to explicitly define +a method: ```ruby class ReadOnlyModel < ActiveRecord::Base - before_save :before_save_callback + before_save :before_save_callback # GOOD private def before_save_callback @@ -122,9 +132,11 @@ end ``` This change applies to most places in Rails where callbacks are used, including -Active Record and Active Model callbacks, as well as "filters" in Action -Controller (e.g. `before_action`). See [this pull request](https://github.com/rails/rails/pull/13271) -for more details. +Active Record and Active Model callbacks, as well as filters in Action +Controller (e.g. `before_action`). + +See [this pull request](https://github.com/rails/rails/pull/13271) for more +details. ### Methods defined in Active Record fixtures -- cgit v1.2.3 From 8e21ae37ad9fef6b7393a84f9b5f2e18a831e49a Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 16 Dec 2013 17:12:37 -0200 Subject: Add changelog and upgrading notice related to I18n enforce_available_locales handling --- guides/source/upgrading_ruby_on_rails.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index ca5623bf73..1c233b4d82 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -156,6 +156,23 @@ end ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers ``` +### I18n enforcing available locales + +Rails 4.1 now defaults the I18n option `enforce_available_locales` to `true`, +meaning that it will make sure that all locales passed to it must be declared in +the `available_locales` list. + +To disable it (and allow I18n to accept *any* locale option) add the following +configuration to your application: + +```ruby +config.i18n.enforce_available_locales = false +``` + +Note that this option was added as a security measure, to ensure user input could +not be used as locale information unless previously known, so it's recommended not +to disable this option unless you have a strong reason for doing so. + Upgrading from Rails 3.2 to Rails 4.0 ------------------------------------- -- cgit v1.2.3 From d4ee09cda135da9c36a5ddadd2d8c2d35c116be3 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Fri, 13 Dec 2013 22:11:39 -0200 Subject: Create a blacklist to disallow mutator methods to be delegated to `Array`. This change was necessary because the whitelist wouldn't work. It would be painful for users trying to update their applications. This blacklist intent to prevent odd bugs and confusion in code that call mutator methods directely on the `Relation`. --- guides/source/upgrading_ruby_on_rails.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index ca5623bf73..60b27aa6e5 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -156,6 +156,23 @@ end ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers ``` +### Mutator methods called on Relation + +`Relation` no longer has mutator methods like `#map!` and `#delete_if`. Convert +to an `Array` by calling `#to_a` before using these methods. + +It intends to prevent odd bugs and confusion in code that call mutator +methods directly on the `Relation`. + +```ruby +# Instead of this +Author.where(name: 'Hank Moody').compact! + +# Now you have to do this +authors = Author.where(name: 'Hank Moody').to_a +authors.compact! +``` + Upgrading from Rails 3.2 to Rails 4.0 ------------------------------------- -- cgit v1.2.3 From 2003d0409e357c7be8a9380f479d8094efc47d31 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 16 Dec 2013 22:08:58 -0800 Subject: Some assorted fixes for the 4.1 release notes: * Added release notes for secrets.yml and mentioned it in the highlights * Added release notes for Mailer previews and mentioned it in the highlights * Added release notes for Module#concerning * Removed mention for AV extraction from the highlights * Rearranged the major features to put highlighted features first * Various improvements and typo fixes [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index ca5623bf73..a7946b2120 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -39,6 +39,33 @@ NOTE: User defined rake tasks will run in the `development` environment by default. If you want them to run in other environments consult the [Spring README](https://github.com/jonleighton/spring#rake). +### `config/secrets.yml` + +If you want to use the new `secrets.yml` convention to store your application's +secrets, you need to: + +1. Create a `secrets.yml` file in your `config` folder with the following content: + + ```yaml + development: + secret_key_base: + + test: + secret_key_base: + + production: + secret_key_base: + ``` + +2. Copy the existing `secret_key_base` from the `secret_token.rb` initializer to + `secrets.yml` under the `production` section. + +3. Remove the `secret_token.rb` initializer. + +4. Use `rake secret` to generate new keys for the `development` and `test` sections. + +5. Restart your server. + ### Changes in JSON handling The are a few major changes related to JSON handling in Rails 4.1. -- cgit v1.2.3 From d3fcaba6266d99ef9a5ad6d9154b1257e1300310 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 17 Dec 2013 15:40:11 -0700 Subject: Mention new CSRF protection gotcha in upgrade guide --- guides/source/upgrading_ruby_on_rails.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'guides/source/upgrading_ruby_on_rails.md') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 33e58f892e..2f0f3573fb 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -27,6 +27,31 @@ Upgrading from Rails 4.0 to Rails 4.1 NOTE: This section is a work in progress. +### CSRF protection from remote `