From 215d41d802637520129cb7551b35faca72873143 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 1 Jul 2012 14:34:47 -0300 Subject: [PATCH] Update 4.0 Release Notes with changelogs [ci skip] Also fix some wrong formatting. Related discussion: https://github.com/rails/rails/commit/ab72040b74f742b6676b2d2a5dd029bfdca25a7a#commitcomment-1525256 --- actionpack/CHANGELOG.md | 6 +- activerecord/CHANGELOG.md | 6 +- activesupport/CHANGELOG.md | 6 +- guides/source/4_0_release_notes.textile | 235 ++++++++++++++++++++++-- 4 files changed, 230 insertions(+), 23 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 3e10310179c6f..7edba84ff62e1 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -14,9 +14,9 @@ * Return proper format on exceptions. *Santiago Pastorino* -* Allow to use mounted_helpers (helpers for accessing mounted engines) in ActionView::TestCase. *Piotr Sarnacki* +* Allow to use `mounted_helpers` (helpers for accessing mounted engines) in `ActionView::TestCase`. *Piotr Sarnacki* -* Include mounted_helpers (helpers for accessing mounted engines) in ActionDispatch::IntegrationTest by default. *Piotr Sarnacki* +* Include `mounted_helpers` (helpers for accessing mounted engines) in `ActionDispatch::IntegrationTest` by default. *Piotr Sarnacki* * Extracted redirect logic from `ActionController::ForceSSL::ClassMethods.force_ssl` into `ActionController::ForceSSL#force_ssl_redirect` @@ -49,7 +49,7 @@ *Piotr Sarnacki* -* `truncate` now always returns an escaped HTMl-safe string. The option `:escape` can be used as +* `truncate` now always returns an escaped HTML-safe string. The option `:escape` can be used as false to not escape the result. *Li Ellis Gallardo + Rafael Mendonça França* diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 84fffb3d17f0e..a965fe04944eb 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -47,7 +47,7 @@ *Tony Schneider* -* Allow ActiveRecord::Relation#pluck to accept multiple columns. Returns an +* Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an array of arrays containing the typecasted values: Person.pluck(:id, :name) @@ -88,7 +88,7 @@ *Andrew White* -* Move HABTM validity checks to ActiveRecord::Reflection. One side effect of +* Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of this is to move when the exceptions are raised from the point of declaration to when the association is built. This is consistant with other association validity checks. @@ -96,7 +96,7 @@ *Andrew White* * Added `stored_attributes` hash which contains the attributes stored using - ActiveRecord::Store. This allows you to retrieve the list of attributes + `ActiveRecord::Store`. This allows you to retrieve the list of attributes you've defined. class User < ActiveRecord::Base diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index d2e07d6762843..df144dd00b236 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,10 +1,10 @@ ## Rails 4.0.0 (unreleased) ## -* Time#change now works with time values with offsets other than UTC or the local time zone. *Andrew White* +* `Time#change` now works with time values with offsets other than UTC or the local time zone. *Andrew White* -* AS::Callbacks: deprecate usage of filter object with `#before` and `#after` methods as `around` callback. *Bogdan Gusiev* +* `ActiveSupport::Callbacks`: deprecate usage of filter object with `#before` and `#after` methods as `around` callback. *Bogdan Gusiev* -* Add `Time#prev_quarter' and 'Time#next_quarter' short-hands for months_ago(3) and months_since(3). *SungHee Kang* +* Add `Time#prev_quarter` and `Time#next_quarter` short-hands for `months_ago(3)` and `months_since(3)`. *SungHee Kang* * Remove obsolete and unused `require_association` method from dependencies. *fxn* diff --git a/guides/source/4_0_release_notes.textile b/guides/source/4_0_release_notes.textile index 23c5220c247b9..e1d6b42e6cc3b 100644 --- a/guides/source/4_0_release_notes.textile +++ b/guides/source/4_0_release_notes.textile @@ -64,6 +64,16 @@ h3. Documentation h3. Railties +* Allow scaffold/model/migration generators to accept a polymorphic modifier for references/belongs_to, for instance + + +rails g model Product supplier:references{polymorphic} + + +will generate the model with belongs_to :supplier, polymorphic: true association and appropriate migration. + +* Set config.active_record.migration_error to :page_load for development. + * Add runner to Rails::Railtie as a hook called just after runner starts. * Add /rails/info/routes path which displays the same information as +rake routes+. @@ -102,12 +112,30 @@ h4(#railties_deprecations). Deprecations h3. Action Mailer -* No changes. +* Raise an ActionView::MissingTemplate exception when no implicit template could be found. + +* Asynchronously send messages via the Rails Queue. h3. Action Pack h4. Action Controller +* Remove Active Model dependency from Action Pack. + +* Support unicode characters in routes. Route will be automatically escaped, so instead of manually escaping: + + +get Rack::Utils.escape('こんにちは') => 'home#index' + + +You just have to write the unicode route: + + +get 'こんにちは' => 'home#index' + + +* Return proper format on exceptions. + * Extracted redirect logic from ActionController::ForceSSL::ClassMethods.force_ssl into ActionController::ForceSSL#force_ssl_redirect. * URL path parameters with invalid encoding now raise ActionController::BadRequest. @@ -156,6 +184,8 @@ h5(#actioncontroller_deprecations). Deprecations h4. Action Dispatch +* Include mounted_helpers (helpers for accessing mounted engines) in ActionDispatch::IntegrationTest by default. + * Added ActionDispatch::SSL middleware that when included force all the requests to be under HTTPS protocol. * Copy literal route constraints to defaults so that url generation know about them. The copied constraints are :protocol, :subdomain, :domain, :host and :port. @@ -179,12 +209,14 @@ If :patch is the default verb for updates, edits are tunneled as PA * Turn off verbose mode of rack-cache, we still have X-Rack-Cache to check that info. -* Include mounted_helpers (helpers for accessing mounted engines) in ActionDispatch::IntegrationTest by default. - h5(#actiondispatch_deprecations). Deprecations h4. Action View +* Remove Active Model dependency from Action Pack. + +* Allow to use mounted_helpers (helpers for accessing mounted engines) in ActionView::TestCase. + * Make current object and counter (when it applies) variables accessible when rendering templates with :object or :collection. * Allow to lazy load +default_form_builder+ by passing a string instead of a constant. @@ -205,8 +237,6 @@ h4. Action View * Removed old +text_helper+ apis for +highlight+, +excerpt+ and +word_wrap+. -* Allow to use mounted_helpers (helpers for accessing mounted engines) in ActionView::TestCase. - * Remove the leading \n added by textarea on +assert_select+. * Changed default value for config.action_view.embed_authenticity_token_in_remote_forms to false. This change breaks remote forms that need to work also without JavaScript, so if you need such behavior, you can either set it to true or explicitly pass :authenticity_token => true in form options. @@ -299,6 +329,127 @@ Moved into a separate gem sprockets-rails. h3. Active Record +* Add :default and :null options to column_exists?. + + +column_exists?(:testings, :taggable_id, :integer, null: false) +column_exists?(:testings, :taggable_type, :string, default: 'Photo') + + +* ActiveRelation#inspect no longer calls #to_a. This means that in places where #inspect is implied (such as in the console), creating a relation will not execute it anymore, you'll have to call #to_a when necessary: + + +User.where(:age => 30) # => returns the relation +User.where(:age => 30).to_a # => executes the query and returns the loaded objects, as before + + +* Add collation and ctype support to PostgreSQL. These are available for PostgreSQL 8.4 or later. + + +development: + adapter: postgresql + host: localhost + database: rails_development + username: foo + password: bar + encoding: UTF8 + collation: ja_JP.UTF8 + ctype: ja_JP.UTF8 + + +* FinderMethods#exists? now returns false with the false argument. + +* Added support for specifying the precision of a timestamp in the postgresql adapter. So, instead of having to incorrectly specify the precision using the :limit option, you may use :precision, as intended. For example, in a migration: + + +def change + create_table :foobars do |t| + t.timestamps :precision => 0 + end +end + + +* Allow ActiveRecord::Relation#pluck to accept multiple columns. Returns an array of arrays containing the typecasted values: + + +Person.pluck(:id, :name) +# SELECT people.id, people.name FROM people +# => [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']] + + +* Improve the derivation of HABTM join table name to take account of nesting. It now takes the table names of the two models, sorts them lexically and then joins them, stripping any common prefix from the second table name. Some examples: + + +Top level models (Category <=> Product) +Old: categories_products +New: categories_products + +Top level models with a global table_name_prefix (Category <=> Product) +Old: site_categories_products +New: site_categories_products + +Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product) +Old: categories_products +New: categories_products + +Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product) +Old: categories_products +New: admin_categories_products + +Nested models in a parent model (Catalog::Category <=> Catalog::Product) +Old: categories_products +New: catalog_categories_products + +Nested models in different parent models (Catalog::Category <=> Content::Page) +Old: categories_pages +New: catalog_categories_content_pages + + +* Move HABTM validity checks to ActiveRecord::Reflection. One side effect of this is to move when the exceptions are raised from the point of declaration to when the association is built. This is consistant with other association validity checks. + +* Added stored_attributes hash which contains the attributes stored using ActiveRecord::Store. This allows you to retrieve the list of attributes you've defined. + + +class User < ActiveRecord::Base + store :settings, accessors: [:color, :homepage] +end + +User.stored_attributes[:settings] # [:color, :homepage] + + +* composed_of was removed. You'll have to write your own accessor and mutator methods if you'd like to use value objects to represent some portion of your models. So, instead of: + + +class Person < ActiveRecord::Base + composed_of :address, :mapping => [ %w(address_street street), %w(address_city city) ] +end + + +you could write something like this: + + +def address + @address ||= Address.new(address_street, address_city) +end + +def address=(address) + self[:address_street] = @address.street + self[:address_city] = @address.city + + @address = address +end + + +* PostgreSQL default log level is now 'warning', to bypass the noisy notice messages. You can change the log level using the min_messages option available in your config/database.yml. + +* Add uuid datatype support to PostgreSQL adapter. + +* update_attribute has been removed. Use update_column if you want to bypass mass-assignment protection, validations, callbacks, and touching of updated_at. Otherwise please use update_attributes. + +* Added ActiveRecord::Migration.check_pending! that raises an error if migrations are pending. + +* Added #destroy! which acts like #destroy but will raise an ActiveRecord::RecordNotDestroyed exception instead of returning false. + * Allow blocks for count with ActiveRecord::Relation, to work similar as Array#count: Person.where("age > 26").count { |person| person.gender == 'female' } * Added support to CollectionAssociation#delete for passing fixnum or string values as record ids. This finds the records responding to the ids and deletes them. @@ -475,27 +626,37 @@ The code to implement the deprecated features has been moved out to the +active_ Don't use this: - scope :red, where(color: 'red') - default_scope where(color: 'red') + +scope :red, where(color: 'red') +default_scope where(color: 'red') + Use this: - scope :red, -> { where(color: 'red') } - default_scope { where(color: 'red') } + +scope :red, -> { where(color: 'red') } +default_scope { where(color: 'red') } + The former has numerous issues. It is a common newbie gotcha to do the following: - scope :recent, where(published_at: Time.now - 2.weeks) + +scope :recent, where(published_at: Time.now - 2.weeks) + Or a more subtle variant: - scope :recent, -> { where(published_at: Time.now - 2.weeks) } - scope :recent_red, recent.where(color: 'red') + +scope :recent, -> { where(published_at: Time.now - 2.weeks) } +scope :recent_red, recent.where(color: 'red') + Eager scopes are also very complex to implement within Active Record, and there are still bugs. For example, the following does not do what you expect: - scope :remove_conditions, except(:where) - where(...).remove_conditions # => still has conditions + +scope :remove_conditions, except(:where) +where(...).remove_conditions # => still has conditions + * Added deprecation for the :dependent => :restrict association option. @@ -507,6 +668,32 @@ The code to implement the deprecated features has been moved out to the +active_ h3. Active Model +* Changed AM::Serializers::JSON.include_root_in_json default value to false. Now, AM Serializers and AR objects have the same default behaviour. + + +class User < ActiveRecord::Base; end + +class Person + include ActiveModel::Model + include ActiveModel::AttributeMethods + include ActiveModel::Serializers::JSON + + attr_accessor :name, :age + + def attributes + instance_values + end +end + +user.as_json +=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true} +# root is not included + +person.as_json +=> {"name"=>"Francesco", "age"=>22} +# root is not included + + * Passing false hash values to +validates+ will no longer enable the corresponding validators. * +ConfirmationValidator+ error messages will attach to :#{attribute}_confirmation instead of +attribute+. @@ -525,6 +712,24 @@ h3. Active Resource h3. Active Support +* Time#change now works with time values with offsets other than UTC or the local time zone. + +* Add Time#prev_quarter and Time#next_quarter short-hands for months_ago(3) and months_since(3). + +* Remove obsolete and unused require_association method from dependencies. + +* Add :instance_accessor option for config_accessor. + + +class User + include ActiveSupport::Configurable + config_accessor :allowed_access, instance_accessor: false +end + +User.new.allowed_access = true # => NoMethodError +User.new.allowed_access # => NoMethodError + + * ActionView::Helpers::NumberHelper methods have been moved to ActiveSupport::NumberHelper and are now available via Numeric#to_s. * Numeric#to_s now accepts the formatting options :phone, :currency, :percentage, :delimited, :rounded, :human, and :human_size. @@ -575,6 +780,8 @@ h3. Active Support h4(#activesupport_deprecations). Deprecations +* ActiveSupport::Callbacks: deprecate usage of filter object with #before and #after methods as around callback. + * BufferedLogger is deprecated. Use ActiveSupport::Logger or the +logger+ from Ruby stdlib. * Deprecates the compatibility method Module#local_constant_names and use Module#local_constants instead (which returns symbols).