From cb02d10df2b892925bfa8b2a9b01223e44f2acb4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 25 Jul 2011 15:10:13 -0700 Subject: [PATCH 001/164] sync the getting started guide with master --- railties/guides/source/getting_started.textile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 0b890213923..6c8aa668b20 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -197,9 +197,10 @@ For example, the following HTTP request: DELETE /photos/17 -refers to a photo resource with an ID of 17 and indicates an action to be taken -upon it: deletion. REST is a natural web application architecture which Rails -abstracts, shielding you from RESTful complexities and browser quirks. +would be understood to refer to a photo resource with the ID of 17, and to +indicate a desired action - deleting that resource. REST is a natural style for +the architecture of web applications, and Rails hooks into this shielding you +from many of the RESTful complexities and browser quirks. If you'd like more details on REST as an architectural style, these resources are more approachable than Fielding's thesis: From fa159d317611d1fe5b483f2542666da00bab2e6c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 26 Jul 2011 19:35:16 +0530 Subject: [PATCH 002/164] move the note after the scaffold files listing --- .../guides/source/getting_started.textile | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6c8aa668b20..3cca383616e 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -536,21 +536,8 @@ command in your terminal: $ rails generate scaffold Post name:string title:string content:text -This will create a new database table called posts (plural of Post). The table -will have three columns, name (type string), title (type string) and content -(type text). It will also hook this new database up to Rails (details below). - -NOTE. While scaffolding will get you up and running quickly, the code it -generates is unlikely to be a perfect fit for your application. You'll most -probably want to customize the generated code. Many experienced Rails developers -avoid scaffolding entirely, preferring to write all or most of their source code -from scratch. Rails, however, makes it really simple to customize templates for -generated models, controllers, views and other source files. You'll find more -information in the "Creating and Customizing Rails Generators & -Templates":generators.html guide. - -The scaffold generator will build 17 files in your application, along with some -folders, and edit one more. Here's a quick overview of what it creates: +The scaffold generator will build several files in your application, along with some +folders, and edit config/routes.rb. Here's a quick overview of what it creates: |_.File |_.Purpose| |db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)| @@ -571,6 +558,15 @@ folders, and edit one more. Here's a quick overview of what it creates: |test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper| |config/routes.rb |Edited to include routing information for posts| +NOTE. While scaffolding will get you up and running quickly, the code it +generates is unlikely to be a perfect fit for your application. You'll most +probably want to customize the generated code. Many experienced Rails developers +avoid scaffolding entirely, preferring to write all or most of their source code +from scratch. Rails, however, makes it really simple to customize templates for +generated models, controllers, views and other source files. You'll find more +information in the "Creating and Customizing Rails Generators & +Templates":generators.html guide. + h4. Running a Migration One of the products of the +rails generate scaffold+ command is a _database From b0a91f2c5e68064514ff406326e63f3fe8abeb65 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Wed, 27 Jul 2011 17:30:35 +0700 Subject: [PATCH 003/164] Fix two spaces between sententes on README.rdoc. --- README.rdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index bca21265592..f87d6e9edbf 100644 --- a/README.rdoc +++ b/README.rdoc @@ -3,11 +3,11 @@ Rails is a web-application framework that includes everything needed to create database-backed web applications according to the {Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller] pattern. -Understanding the MVC pattern is key to understanding Rails. MVC divides your application +Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers, each with a specific responsibility. The View layer is composed of "templates" that are responsible for providing -appropriate representations of your application's resources. Templates +appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (.erb files). @@ -21,7 +21,7 @@ provided by the ActiveModel module. You can read more about Active Record in its {README}[link:blob/master/activerecord/README.rdoc]. The Controller layer is responsible for handling incoming HTTP requests and providing a -suitable response. Usually this means returning HTML, but Rails controllers can also +suitable response. Usually this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers manipulate models and render view templates in order to generate the appropriate HTTP response. From 5a22f05522d4b624463da174576f3663ea2872ac Mon Sep 17 00:00:00 2001 From: Alberto Perdomo Date: Thu, 28 Jul 2011 00:51:14 +0100 Subject: [PATCH 004/164] Association and Callbacks guide: Added section on shortcut syntax 'validates'. --- ...ctive_record_validations_callbacks.textile | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index ce0b5416de7..e2ec8741909 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -612,6 +612,61 @@ class Movie < ActiveRecord::Base end +h3. Shortcut helper + +There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. + +h4. Multiple validations for a single attribue + +In cases where you want multiple validations for a single attribute you can do it with a one-liner. + + +class User < ActiveRecord::Base + validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } +end + + +h4. Combining standard validations with custom validators + +You can also combine standard validations with your own custom validators. + + +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + record.errors[attribute] << (options[:message] || "is not an email") unless + value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + end +end + +class Person + include ActiveModel::Validations + attr_accessor :name, :email + + validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } + validates :email, :presence => true, :email => true +end + + +h4. Validating multiple attributes with the same criteria + +If you have a case where you want to apply the same validations to multiple attributes you can do that as well. + + +class BlogPost < ActiveRecord::Base + validates :title, :body, :presence => true +end + + +h4. Using the standard options + +The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. + + +class User < ActiveRecord::Base + validates :password, :presence => { :if => :password_required? }, :confirmation => true +end + + h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. From 6dc749596c328c44c80f898d5fa860fff6cab783 Mon Sep 17 00:00:00 2001 From: Pete Campbell Date: Thu, 28 Jul 2011 09:44:51 -0400 Subject: [PATCH 005/164] Explicitly included hashes in sentence regarding SQL-injection-safe forms --- activerecord/lib/active_record/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4136868b39c..461df0555fd 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -63,9 +63,9 @@ module ActiveRecord #:nodoc: # == Conditions # # Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement. - # The array form is to be used when the condition input is tainted and requires sanitization. The string form can - # be used for statements that don't involve tainted data. The hash form works much like the array form, except - # only equality and range is possible. Examples: + # The array form is to be used when the condition input is tainted and requires sanitization. The string and hash + # forms can be used for statements that don't involve tainted data. The hash form works much like the array form, + # except only equality and range is possible. Examples: # # class User < ActiveRecord::Base # def self.authenticate_unsafely(user_name, password) From 9e39fd99859a2b5f8a681c1141b4581834c1ebea Mon Sep 17 00:00:00 2001 From: ejy Date: Thu, 28 Jul 2011 18:40:35 +0200 Subject: [PATCH 006/164] Removed trailing slash of 'Download and installation' Github URL as per convention --- activerecord/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc index 822276589bf..8c5c544773f 100644 --- a/activerecord/README.rdoc +++ b/activerecord/README.rdoc @@ -203,7 +203,7 @@ The latest version of Active Record can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/activerecord/ +* https://github.com/rails/rails/tree/master/activerecord == License From b57773c738e2e8f75e92739cf93e402f2a151d5d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 29 Jul 2011 01:13:58 +0530 Subject: [PATCH 007/164] document meta method --- actionpack/lib/action_dispatch/http/request.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index b80574f4977..37d0a3e0b8c 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -29,9 +29,9 @@ module ActionDispatch ENV_METHODS.each do |env| class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{env.sub(/^HTTP_/n, '').downcase} - @env["#{env}"] - end + def #{env.sub(/^HTTP_/n, '').downcase} # def accept_charset + @env["#{env}"] # @env["HTTP_ACCEPT_CHARSET"] + end # end METHOD end From bf3649ab19870c804b81e5d79309d655d054eed2 Mon Sep 17 00:00:00 2001 From: Bratish Goswami Date: Fri, 29 Jul 2011 21:49:43 +0530 Subject: [PATCH 008/164] extra '/' removed from url, which was not linked --- activeresource/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc index b03e8c4c25a..b7cf0292f08 100644 --- a/activeresource/README.rdoc +++ b/activeresource/README.rdoc @@ -28,7 +28,7 @@ The latest version of Active Support can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/activeresource/ +* https://github.com/rails/rails/tree/master/activeresource === Configuration and Usage From 086339a26a88da93554cd84caf02f15219e4c965 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 29 Jul 2011 16:01:20 -0700 Subject: [PATCH 009/164] Superfluous "the". --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index f87d6e9edbf..288a7a3c55e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -27,7 +27,7 @@ and render view templates in order to generate the appropriate HTTP response. In Rails, the Controller and View layers are handled together by Action Pack. These two layers are bundled in a single package due to their heavy interdependence. -This is unlike the relationship between the Active Record and Action Pack which are +This is unlike the relationship between Active Record and Action Pack which are independent. Each of these packages can be used independently outside of Rails. You can read more about Action Pack in its {README}[link:blob/master/actionpack/README.rdoc]. From 186e7dd4ff17a30a80bf99043a4381ff1376def3 Mon Sep 17 00:00:00 2001 From: Bratish Goswami Date: Sat, 30 Jul 2011 12:53:21 +0530 Subject: [PATCH 010/164] '/' was outside of anchor tag. --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 288a7a3c55e..5d1e3f5c5d7 100644 --- a/README.rdoc +++ b/README.rdoc @@ -49,7 +49,7 @@ can read more about Action Pack in its {README}[link:blob/master/actionpack/READ Run with --help for options. -4. Go to http://localhost:3000/ and you'll see: +4. Go to http://localhost:3000 and you'll see: "Welcome aboard: You're riding Ruby on Rails!" From 2177282262195f9decf564b237304a6ff94c3048 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:19:43 +0530 Subject: [PATCH 011/164] Active Resouce guide initial load --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 railties/guides/source/active_resource_basics.textile diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile new file mode 100644 index 00000000000..5df8b6612d7 --- /dev/null +++ b/railties/guides/source/active_resource_basics.textile @@ -0,0 +1,11 @@ +h2. Active Resource Basics + +This guide should provide you with all you need to get started managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics. + +endprologue. + +WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. + +h3. Changelog + +* July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 5da1ddb7506d4dc1b314f6634e4c28e13e6eeaa2 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:21:21 +0530 Subject: [PATCH 012/164] Introduction for active resource --- railties/guides/source/active_resource_basics.textile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5df8b6612d7..5cf22f8e39d 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -6,6 +6,10 @@ endprologue. WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. +h3. Introduction + +Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 95c2230f0577c8f3ef2312fe9268dc9c0ed3bf8a Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:23:05 +0530 Subject: [PATCH 013/164] configuration for active resource --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 5cf22f8e39d..f0cd25bfc21 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -10,6 +10,17 @@ h3. Introduction Active Resource allows you to connect with RESTful web services. So, in Rails, Resource classes inherited from +ActiveResource::Base+ and live in +app/models+. +h3. Configuration and Usage + +Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class +that inherits from ActiveResource::Base and providing a site class variable to it: + + +class Person < ActiveResource::Base + self.site = "http://api.people.com:3000/" +end + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From ad55b1aa86a1d8b7d6e9e35c7cce77b122bca1e1 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sat, 30 Jul 2011 18:24:18 +0530 Subject: [PATCH 014/164] usages of active resouce --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index f0cd25bfc21..64f0949475c 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -21,6 +21,15 @@ class Person < ActiveResource::Base end +Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes +life cycle methods that operate against a persistent store. + + +# Find a person with id = 1 +ryan = Person.find(1) +Person.exists?(1) # => true + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 7372e9ae9a06e6b15e1a20bc69667bf44c79676c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:16:07 +0530 Subject: [PATCH 015/164] make the warning clear about the effect of using validates_associated on both sides on an association. --- .../lib/active_record/validations/associated.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 5df85304a23..7af0352a313 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -17,15 +17,7 @@ module ActiveRecord # validates_associated :pages, :library # end # - # Warning: If, after the above definition, you then wrote: - # - # class Page < ActiveRecord::Base - # belongs_to :book - # - # validates_associated :book - # end - # - # this would specify a circular dependency and cause infinite recursion. + # WARNING: This validation must not be used on both ends of an association. Doing so will lead to a circular dependency and cause infinite recursion. # # NOTE: This validation will not fail if the association hasn't been assigned. If you want to # ensure that the association is both present and guaranteed to be valid, you also need to From 225a2482c19fa3a1acdc05371a44b090c6cb4d7c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:50:31 +0530 Subject: [PATCH 016/164] remove some parts of the section on shortcut helpers, document custom validators --- ...ctive_record_validations_callbacks.textile | 110 ++++++++---------- 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index e2ec8741909..5789d36c6da 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -569,11 +569,50 @@ end All validations inside of +with_options+ block will have automatically passed the condition +:if => :is_admin?+ -h3. Creating Custom Validation Methods +h3. Performing Custom Validations -When the built-in validation helpers are not enough for your needs, you can write your own validation methods. +When the built-in validation helpers are not enough for your needs, you can write your own validators or validation methods as you prefer. -Simply create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. +h4. Custom Validators + +Custom validators are classes that extend ActiveModel::Validator. These classes must implement a +validate+ method which takes a record as an argument and performs the validation on it. The custom validator is called using the +validates_with+ method. + + +class MyValidator < ActiveModel::Validator + def validate(record) + if record.name.starts_with? 'X' + record.errors[:name] << 'Need a name starting with X please!' + end + end +end + +class Person + include ActiveModel::Validations + validates_with MyValidator +end + + +The easiest way to add custom validators for validating individual attributes is with the convenient ActiveModel::EachValidator. In this case, the custom validator class must implement a +validate_each+ method which takes three arguments: record, attribute and value which correspond to the instance, the attribute to be validated and the value of the attribute in the passed instance. + + +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i + record.errors[attribute] << (options[:message] || "is not an email") + end + end +end + +class Person < ActiveRecord::Base + validates :email, :presence => true, :email => true +end + + +As shown in the example, you can also combine standard validations with your own custom validators. + +h4. Custom Methods + +You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. @@ -583,13 +622,15 @@ class Invoice < ActiveRecord::Base :discount_cannot_be_greater_than_total_value def expiration_date_cannot_be_in_the_past - errors.add(:expiration_date, "can't be in the past") if - !expiration_date.blank? and expiration_date < Date.today + if !expiration_date.blank? and expiration_date < Date.today + errors.add(:expiration_date, "can't be in the past") + end end def discount_cannot_be_greater_than_total_value - errors.add(:discount, "can't be greater than total value") if - discount > total_value + if discount > total_value + errors.add(:discount, "can't be greater than total value") + end end end @@ -612,61 +653,6 @@ class Movie < ActiveRecord::Base end -h3. Shortcut helper - -There is a special method +validates+ that is a shortcut to all default validators and any custom validator classes ending in 'Validator'. Note that Rails default validators can be overridden inside specific classes by creating custom validator classes in their place such as +PresenceValidator+. - -h4. Multiple validations for a single attribue - -In cases where you want multiple validations for a single attribute you can do it with a one-liner. - - -class User < ActiveRecord::Base - validates :password, :presence => true, :confirmation => true, :length => { :minimum => 6 } -end - - -h4. Combining standard validations with custom validators - -You can also combine standard validations with your own custom validators. - - -class EmailValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - record.errors[attribute] << (options[:message] || "is not an email") unless - value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i - end -end - -class Person - include ActiveModel::Validations - attr_accessor :name, :email - - validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } - validates :email, :presence => true, :email => true -end - - -h4. Validating multiple attributes with the same criteria - -If you have a case where you want to apply the same validations to multiple attributes you can do that as well. - - -class BlogPost < ActiveRecord::Base - validates :title, :body, :presence => true -end - - -h4. Using the standard options - -The shortcut syntax is also compatible with the standard options +:allow_nil+, +:allow_blank+, etc. as well as the conditional options +:if+ and +unless+. - - -class User < ActiveRecord::Base - validates :password, :presence => { :if => :password_required? }, :confirmation => true -end - - h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. From ad9e52f156575f28949837a3dd0fa433fa824d57 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 30 Jul 2011 23:53:11 +0530 Subject: [PATCH 017/164] prefer to use if..end unless the condition is simple/compact --- .../source/active_record_validations_callbacks.textile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 5789d36c6da..977e736d25d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -1143,8 +1143,9 @@ Here's an example where we create a class with an +after_destroy+ callback for a class PictureFileCallbacks def after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end @@ -1162,8 +1163,9 @@ Note that we needed to instantiate a new +PictureFileCallbacks+ object, since we class PictureFileCallbacks def self.after_destroy(picture_file) - File.delete(picture_file.filepath) - if File.exists?(picture_file.filepath) + if File.exists?(picture_file.filepath) + File.delete(picture_file.filepath) + end end end From ebbf010d4d3f1001ccd6e22e417109135652cafb Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 01:32:20 +0530 Subject: [PATCH 018/164] 3.1 release notes draft --- .../guides/source/3_1_release_notes.textile | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 railties/guides/source/3_1_release_notes.textile diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile new file mode 100644 index 00000000000..03482596685 --- /dev/null +++ b/railties/guides/source/3_1_release_notes.textile @@ -0,0 +1,136 @@ +h2. Ruby on Rails 3.1 Release Notes + +Highlights in Rails 3.1: + +* Streaming +* Reversible Migrations +* Assets Pipeline +* jQuery as the default JavaScript library + +This release notes cover the major changes, but don't include every little bug fix and change. If you want to see everything, check out the "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub. + +endprologue. + +h3. Upgrading to Rails 3.1 + +If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: + +h4. Rails 3.1 requires at least Ruby 1.8.7 + +Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2. + +TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing. + +TODO. What else? + +h3. Creating a Rails 3.1 application + + +# You should have the 'rails' rubygem installed +$ rails new myapp +$ cd myapp + + +h4. Vendoring Gems + +Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. + +More information: - "bundler homepage":http://gembundler.com + +h4. Living on the Edge + ++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: + + +$ rails new myapp --edge + + +If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag: + + +$ ruby /path/to/rails/bin/rails new myapp --dev + + +h3. Rails Architectural Changes + +h4. Assets Pipeline + +h3. Documentation + +The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). + +More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. + +h3. Internationalization + +h3. Railties + +h3. Action Pack + +h4. Abstract Controller + +h4. Action Controller + +h4. Action Dispatch + +h4. Action View + +h3. Active Record + +h3. Active Model + +The major changes in Active Model are: + +* +attr_accessible+ accepts an option +:as+ to specify a role. + +* +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+. + +* Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting. + +* ActiveModel::AttributeMethods allows attributes to be defined on demand. + +h3. Active Resource + +The changes in Active Resource are: + +* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, + + +class User < ActiveResource::Base + self.format = :xml +end + + +h3. Active Support + +The main changes in Active Support are: + +* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. + +* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. + +* Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object. + +* Added Object#in? to test if an object is included in another object. + +* LocalCache strategy is now a real middleware class and no longer an anonymous class. + +* ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. + +* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache. + +* Backports Range#cover? as an alias for Range#include? in Ruby 1.8. + +* Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time. + +* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants! + +Deprecations: + +* ActiveSupport::SecureRandom is deprecated in favor of +SecureRandom+ from the Ruby standard library. + +h3. Credits + +See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. + +Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. From f40723996453470c2b00ff49a25282e0f8bbd691 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 03:05:24 +0530 Subject: [PATCH 019/164] 3.1 release notes - added AP and Railties sections --- .../guides/source/3_1_release_notes.textile | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 03482596685..f520e4dfeaa 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,6 +55,8 @@ h3. Rails Architectural Changes h4. Assets Pipeline +TODO. point to assets guide, talk about rake assets:* tasks + h3. Documentation The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). @@ -65,8 +67,148 @@ h3. Internationalization h3. Railties +* jQuery is the new default JavaScript library. + +* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. + +* The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. + +* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified. + +* The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. + +* Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, --old-style-hash can be passed. + +* Scaffold controller generator creates format block for JSON instead of XML. + +* Active Record logging is directed to STDOUT and shown inline in the console. + +* Added +config.force_ssl+ configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol. + +* Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing. + +* Added Rack::Etag and Rack::ConditionalGet to the default middleware stack. + +* Added Rack::Cache to the default middleware stack. + +* TODO Engine related changes + h3. Action Pack +TODO split items into controller/view sections. + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink + +* Added streaming support, you can enable it with: + + +class PostsController < ActionController::Base + stream :only => :index +end + + +Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. + +* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. + +* Created ActionView::Renderer and specified an API for ActionView::Context. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. + + +class PostsController < ApplicationController + USER_NAME, PASSWORD = "dhh", "secret" + + before_filter :authenticate, :except => [ :index ] + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end + + private + def authenticate + authenticate_or_request_with_http_basic do |user_name, password| + user_name == USER_NAME && password == PASSWORD + end + end +end + + +..can now be written as + + +class PostsController < ApplicationController + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index + + def index + render :text => "Everyone can see me!" + end + + def edit + render :text => "I'm only accessible if you know the password" + end +end + + +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. + +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) + +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. + +* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. + +* URL parameters which return nil for +to_param+ are now removed from the query string. + +* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. + +* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. + +* Added HTML5 button_tag helper. + +* Template lookup now searches further up in the inheritance chain. + +* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version? + +* url_for and named url helpers now accept :subdomain and :domain as options. + +* The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. + +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). + +* Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: + + +tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) +# =>
+ + +Keys are dasherized. Values are JSON-encoded, except for strings and symbols. + +* The old template handler API is deprecated and the new API simply requires a template handler to respond to call. + +* rhtml and rxml are finally removed as template handlers. + +* Moved etag responsibility from ActionDispatch::Response to the middleware stack. + +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. + +* file_field automatically adds :multipart => true to the enclosing form. + +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. + +* Added Rack::Cache to the default stack. + h4. Abstract Controller h4. Action Controller From a98eca8ba501f0370f4ea115bb750b897785215a Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Sat, 30 Jul 2011 18:27:08 -0700 Subject: [PATCH 020/164] "blog" is more common than "weblog" these days. --- actionmailer/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 63e3893316c..de4740b2ed4 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -10,7 +10,7 @@ Mail gem. It provides a way to make emails using templates in the same way that Action Controller renders views using templates. Additionally, an Action Mailer class can be used to process incoming email, -such as allowing a weblog to accept new posts from an email (which could even +such as allowing a blog to accept new posts from an email (which could even have been sent from a phone). == Sending emails From 0e715d0b8ca83fd3053b8a8fa0a5cafbb0cccc79 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 16:56:40 +0530 Subject: [PATCH 021/164] Rack::Sendfile is no more default middleware. --- railties/guides/source/command_line.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index b34506d4d88..627e22f2de8 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -386,7 +386,7 @@ Action Pack version 3.1.0 Active Resource version 3.1.0 Action Mailer version 3.1.0 Active Support version 3.1.0 -Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head +Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development From 8015acf0324f83477e18437a192bcafa11101c93 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 21:58:59 +0530 Subject: [PATCH 022/164] Adding more info as rake about is fixed --- railties/guides/source/command_line.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 627e22f2de8..f48fa96451f 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -389,6 +389,8 @@ Active Support version 3.1.0 Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head Application root /home/foobar/commandsapp Environment development +Database adapter sqlite3 +Database schema version 0 h4. +assets+ From 8f6959d5a4aa933b31fdb53f2687301dc5da0b47 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 23:23:25 +0530 Subject: [PATCH 023/164] 3.1 release notes Active Record changes, Architectural changes and organizing sections. --- .../guides/source/3_1_release_notes.textile | 195 +++++++++++++++--- 1 file changed, 168 insertions(+), 27 deletions(-) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index f520e4dfeaa..7d85d7a6005 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -55,15 +55,23 @@ h3. Rails Architectural Changes h4. Assets Pipeline -TODO. point to assets guide, talk about rake assets:* tasks +The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines. -h3. Documentation +The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide. -The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released). +h4. HTTP Streaming -More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects. +HTTP Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it. -h3. Internationalization +h4. Default JS library is now jQuery + +jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. + +h4. Identity Map + +Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion. + +Rails 3.1 comes with the identity map turned off by default. h3. Railties @@ -95,13 +103,9 @@ h3. Railties h3. Action Pack -TODO split items into controller/view sections. +h4. Abstract Controller -* A warning is given out if the CSRF token authenticity cannot be verified. - -* Allows AM/PM format in datetime selectors. - -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +h4. Action Controller * Added streaming support, you can enable it with: @@ -111,13 +115,25 @@ class PostsController < ActionController::Base end -Please read the docs at ActionController::Streaming for more information. TODO add links to api docs. +Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +h4. Action Dispatch * Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. +h4. Action View + * Created ActionView::Renderer and specified an API for ActionView::Context. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +TODO + +* A warning is given out if the CSRF token authenticity cannot be verified. + +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink * Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. @@ -209,19 +225,148 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * Added Rack::Cache to the default stack. -h4. Abstract Controller - -h4. Action Controller - -h4. Action Dispatch - -h4. Action View - h3. Active Record -h3. Active Model +* Added a class method pluralize_table_names to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. + +class User < ActiveRecord::Base + self.pluralize_table_names = false +end + -The major changes in Active Model are: +* Added block setting of attributes to singular associations. The block will get called after the instance is initialized. + + +class User < ActiveRecord::Base + has_one :account +end + +user.build_account{ |a| a.credit_limit => 100.0 } + + +* Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. + +* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0 + +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: + + +class Post < ActiveRecord::Base + attr_accessible :title + attr_accessible :title, :published_at, :as => :admin +end + +Post.new(params[:post], :as => :admin) + + +* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation: + +* Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. + +* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher. + +* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed. + +* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records. + +* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations. + +* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. + +* limits and offsets are removed from COUNT queries unless both are supplied. + +People.limit(1).count # => 'SELECT COUNT(*) FROM people' +People.offset(1).count # => 'SELECT COUNT(*) FROM people' +People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1' + + +* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. + +* Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. + +* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. + +* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. + +* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. + +* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. + +* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy) + +* Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement. + + +change_table(:users, :bulk => true) do |t| + t.string :company_name + t.change :birthdate, :datetime +end + + +* Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. has_many :through needs to be used. + +* Added a +create_association!+ method for +has_one+ and +belongs_to+ associations. + +* Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method. + +class MyMigration < ActiveRecord::Migration + def change + create_table(:horses) do + t.column :content, :text + t.column :remind_at, :datetime + end + end +end + + +* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. + +* Migrations now use instance methods rather than class methods: + +class FooMigration < ActiveRecord::Migration + def up # Not self.up + ... + end +end + + +* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods. + +* Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used. + + +has_many :things, :conditions => 'foo = #{bar}' # before +has_many :things, :conditions => proc { "foo = #{bar}" } # after + + +Inside the proc, 'self' is the object which is the owner of the association, unless you are eager loading the association, in which case 'self' is the class which the association is within. + +You can have any "normal" conditions inside the proc, so the following will work too: + +has_many :things, :conditions => proc { ["foo = ?", bar] } + + +* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. + +* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. + +# Schema: User(name:string, password_digest:string, password_salt:string) +class User < ActiveRecord::Base + has_secure_password +end + + +* When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns. + +* Setting the id of a belongs_to object will update the reference to the object. + +* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. + +* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. + +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. + +h3. Active Model * +attr_accessible+ accepts an option +:as+ to specify a role. @@ -233,8 +378,6 @@ The major changes in Active Model are: h3. Active Resource -The changes in Active Resource are: - * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, @@ -245,8 +388,6 @@ end h3. Active Support -The main changes in Active Support are: - * ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. * Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. From 55296ec0ea4d65f1eb8a41cdd314ba8bc984b2b4 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Sun, 31 Jul 2011 11:56:47 -0700 Subject: [PATCH 024/164] typo in "wont" --- actionmailer/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index de4740b2ed4..42e612cd074 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -74,7 +74,7 @@ Or you can just chain the methods together like: == Setting defaults -It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method default which you get for free from ActionMailer::Base. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like :from as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you wont need to worry about that. Finally it is also possible to pass in a Proc that will get evaluated when it is needed. +It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method default which you get for free from ActionMailer::Base. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like :from as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally it is also possible to pass in a Proc that will get evaluated when it is needed. Note that every value you set with this method will get over written if you use the same key in your mailer method. From 61899bff17e161dbd706bfb900ac212fe90c3acd Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:37:42 +0530 Subject: [PATCH 025/164] Active Resource - guide for reading and writing data --- railties/guides/source/active_resource_basics.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 64f0949475c..8a366228143 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -24,10 +24,21 @@ end Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes life cycle methods that operate against a persistent store. +h3. Reading and Writing Data + +Active Resource make request over HTTP using a standard JSON format. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol. + +h4. Read + +Read requests use the GET method and expect the JSON form of whatever resource/resources is/are being requested. + # Find a person with id = 1 ryan = Person.find(1) +# Check if a person exists with id = 1 Person.exists?(1) # => true +# Get all resources of Person class +Person.all h3. Changelog From aa9da1fe70a109f86922b4ee83039f1cae1e6584 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:48:45 +0530 Subject: [PATCH 026/164] Active Resource - guide for create --- railties/guides/source/active_resource_basics.textile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 8a366228143..e40ca4fc421 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -34,13 +34,22 @@ Read requests use the GET method and expect the JSON form of whatever resource/r # Find a person with id = 1 -ryan = Person.find(1) +person = Person.find(1) # Check if a person exists with id = 1 Person.exists?(1) # => true # Get all resources of Person class Person.all +h4. Create + +Creating a new resource submits the JSON form of the resource as the body of the request with HTTP POST method and parse the response into Active Resource object. + + +person = Person.create(:name => 'Vishnu') +person.id # => 1 + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 212654be02e28ee97d75819b0f799ccb6f7b9130 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 20:57:57 +0530 Subject: [PATCH 027/164] Active Resource - guide for update/save --- railties/guides/source/active_resource_basics.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index e40ca4fc421..1115b9848f9 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -50,6 +50,16 @@ person = Person.create(:name => 'Vishnu') person.id # => 1 +h4. Update + +To update an existing resource, 'save' method is used. This method make a HTTP PUT request in JSON format. + + +person = Person.find(1) +person.name = 'Atrai' +person.save + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 1ea8d9c38d280e6f55ac3ad1ad4d27d48dcddc15 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Mon, 1 Aug 2011 21:02:48 +0530 Subject: [PATCH 028/164] Active Resource - guide for destroy --- railties/guides/source/active_resource_basics.textile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 1115b9848f9..332d113fa7d 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -60,6 +60,15 @@ person.name = 'Atrai' person.save +h4. Delete + +'destroy' method makes a HTTP DELETE request for an existing resource in JSON format to delete that resource. + + +person = Person.find(1) +person.destroy + + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From ff0b1a3cc65ca8b2af02e62f940aaeffad606b16 Mon Sep 17 00:00:00 2001 From: pbflinn Date: Mon, 1 Aug 2011 12:53:43 -0300 Subject: [PATCH 029/164] Fix typo 'console' -> 'constant' --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 477ee5a3a28..9b92edd250f 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -71,7 +71,7 @@ module Rails end -The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ console, we'll see that when we get to the +in_rails_application?+ method. +The +rails/script_rails_loader+ file uses +RbConfig::Config+ to gather up the +bin_dir+ and +ruby_install_name+ values for the configuration which will result in a path such as +/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby+, which is the default path on Mac OS X. If you're running Windows the path may be something such as +C:/Ruby192/bin/ruby+. Anyway, the path on your system may be different, but the point of this is that it will point at the known ruby executable location for your install. The +RbConfig::CONFIG["EXEEXT"]+ will suffix this path with ".exe" if the script is running on Windows. This constant is used later on in +exec_script_rails!+. As for the +SCRIPT_RAILS+ constant, we'll see that when we get to the +in_rails_application?+ method. Back in +rails/cli+, the next line is this: From 5adb90a14f3fc3441a53476dd75217d1ecb8de97 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:11:22 +0530 Subject: [PATCH 030/164] fixed incorrect tags --- railties/guides/source/migrations.textile | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index e51ee0f5359..7b501807d69 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this: For example, this migration -
+
 class CreateProducts < ActiveRecord::Migration
   def change
     suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
     end
   end
 end
-
+ generates the following output @@ -525,7 +525,7 @@ Bob goes on vacation. Alice creates a migration for the +products+ table which adds a new column and initializes it. She also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => 'false') }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
 end
-
+ Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column. -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ -
+
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
   validates_presence_of :fuzz
 end
-
+ Both migrations work for Alice. @@ -575,12 +575,12 @@ Bob comes back from vacation and: The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs. -
+
 rake aborted!
 An error has occurred, this and all later migrations canceled:
 
 undefined method `fuzz' for #
-
+ A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion. @@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat If Alice had done this instead, there would have been no problem: -
+
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => false) }
   end
 end
-
+ -
+
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-
+ h3. Schema Dumping and You From 688b0c318f411a65bb2e27614dd9fe004427a344 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:13:12 +0530 Subject: [PATCH 031/164] minor changes in migrations guide --- railties/guides/source/migrations.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 7b501807d69..4476e067a66 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -540,7 +540,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag + validates :flag, :presence => true end @@ -561,8 +561,7 @@ end # app/model/product.rb class Product < ActiveRecord::Base - validates_presence_of :flag - validates_presence_of :fuzz + validates :flag, :fuzz, :presence => true end @@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem: class AddFlagToProduct < ActiveRecord::Migration class Product < ActiveRecord::Base end + def change add_column :products, :flag, :int - Product.reset_column_information + Product.reset_column_information Product.all.each { |f| f.update_attributes!(:flag => false) } end end From e4d8a95443bbb86cb9a446397469229e85f21867 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Aug 2011 19:34:23 +0530 Subject: [PATCH 032/164] typo fix --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9b92edd250f..6ab2706d6b0 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -33,7 +33,7 @@ end This file will attempt to load +rails/cli+ and if it cannot find it then add the +railties/lib+ path to the load path (+$:+) and will then try to require it again. -h4. +railites/lib/rails/cli.rb+ +h4. +railties/lib/rails/cli.rb+ This file looks like this: From fbd3e38d76e68ea49b5360a174e1a48f3079101e Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Wed, 3 Aug 2011 23:00:24 +0530 Subject: [PATCH 033/164] grammatical changes --- railties/guides/source/form_helpers.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index bf2a7369a78..fa0ca5827a0 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you see on the web is a search form. This form contains: +One of the most basic forms you will see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,3 +807,4 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung + From 0012a9e9d4526c2d7307afb686a0541ba94051a9 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Wed, 3 Aug 2011 21:43:55 -0700 Subject: [PATCH 034/164] The trailing '/' isn't being picked up by Github anyway, and the link works as is. --- actionmailer/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 42e612cd074..937b53a3b2d 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -141,7 +141,7 @@ The latest version of Action Mailer can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/actionmailer/ +* https://github.com/rails/rails/tree/master/actionmailer == License From 111347f0cc7b23efba06d29fc374111f9d160f06 Mon Sep 17 00:00:00 2001 From: Rashmi Yadav Date: Thu, 4 Aug 2011 12:33:56 +0530 Subject: [PATCH 035/164] The trailing '/' isn't being picked up by Github anyway, and the link works as is. --- actionpack/README.rdoc | 2 +- activemodel/README.rdoc | 2 +- activeresource/README.rdoc | 2 +- activesupport/README.rdoc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc index c494d784151..792862cb85a 100644 --- a/actionpack/README.rdoc +++ b/actionpack/README.rdoc @@ -322,7 +322,7 @@ The latest version of Action Pack can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/actionpack/ +* https://github.com/rails/rails/tree/master/actionpack == License diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc index a0e6b4d9b30..5f0d3403079 100644 --- a/activemodel/README.rdoc +++ b/activemodel/README.rdoc @@ -192,7 +192,7 @@ The latest version of Active Model can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/activemodel/ +* https://github.com/rails/rails/tree/master/activemodel == License diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc index b7cf0292f08..6f45fe35983 100644 --- a/activeresource/README.rdoc +++ b/activeresource/README.rdoc @@ -36,7 +36,7 @@ Putting Active Resource to use is very similar to Active Record. It's as simple that inherits from ActiveResource::Base and providing a site class variable to it: class Person < ActiveResource::Base - self.site = "http://api.people.com:3000/" + self.site = "http://api.people.com:3000" end Now the Person class is REST enabled and can invoke REST services very similarly to how Active Record invokes diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc index a38ad76f430..cc3981e74de 100644 --- a/activesupport/README.rdoc +++ b/activesupport/README.rdoc @@ -14,7 +14,7 @@ The latest version of Active Support can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* https://github.com/rails/rails/tree/master/activesupport/ +* https://github.com/rails/rails/tree/master/activesupport == License From 19122e767ca199f6b2b3e8f21d2634eb2f17a8b4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Aug 2011 15:02:13 -0700 Subject: [PATCH 036/164] Revert "grammatical changes" Reason: As discussed in GitHub, it is debatable, and present tense is fine (and simple, and preferred). This reverts commit 54ccda9f0a5e4a5e72a4c159dc8787faaf65e8a2. --- railties/guides/source/form_helpers.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index fa0ca5827a0..bf2a7369a78 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -45,7 +45,7 @@ NOTE: Throughout this guide, the +div+ with the hidden input elements will be ex h4. A Generic Search Form -One of the most basic forms you will see on the web is a search form. This form contains: +One of the most basic forms you see on the web is a search form. This form contains: # a form element with "GET" method, # a label for the input, @@ -807,4 +807,3 @@ h3. Authors * Mislav Marohnić * "Frederick Cheung":credits.html#fcheung - From b537595665527b8ca5ebad97fc053fd102e16d32 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Aug 2011 15:14:06 -0700 Subject: [PATCH 037/164] Revert "Explicitly included hashes in sentence regarding SQL-injection-safe forms" Reason: The hash form is secure, and preferred over the array form if possible. This reverts commit 6dc749596c328c44c80f898d5fa860fff6cab783. --- activerecord/lib/active_record/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 461df0555fd..4136868b39c 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -63,9 +63,9 @@ module ActiveRecord #:nodoc: # == Conditions # # Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement. - # The array form is to be used when the condition input is tainted and requires sanitization. The string and hash - # forms can be used for statements that don't involve tainted data. The hash form works much like the array form, - # except only equality and range is possible. Examples: + # The array form is to be used when the condition input is tainted and requires sanitization. The string form can + # be used for statements that don't involve tainted data. The hash form works much like the array form, except + # only equality and range is possible. Examples: # # class User < ActiveRecord::Base # def self.authenticate_unsafely(user_name, password) From 19ac034bdc9be175eff7cf54208ba14b43d97681 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 25 Jul 2011 18:54:25 -0300 Subject: [PATCH 038/164] Don't use Rack::Sendfile middleware if x_sendfile_header is not present --- railties/lib/rails/application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9e2f1a4b7af..fb60ddd9b5e 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -163,7 +163,9 @@ module Rails middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies - middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header + if config.action_dispatch.x_sendfile_header.present? + middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header + end middleware.use ::ActionDispatch::Reloader unless config.cache_classes middleware.use ::ActionDispatch::Callbacks middleware.use ::ActionDispatch::Cookies From 5b5b22acb5b652a802f2ce36979d452cd1bf52a4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 25 Jul 2011 19:06:30 -0300 Subject: [PATCH 039/164] Remove unused use_sprockets config --- actionpack/lib/abstract_controller/asset_paths.rb | 2 +- actionpack/lib/sprockets/railtie.rb | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index ad14cd6d871..b104d34fb5d 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,7 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir, :use_sprockets + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir end end end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index c8d6af942d4..83799d2b4db 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -11,13 +11,6 @@ module Sprockets load "sprockets/assets.rake" end - # Configure ActionController to use sprockets. - initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app| - ActiveSupport.on_load(:action_controller) do - self.use_sprockets = app.config.assets.enabled - end - end - # We need to configure this after initialization to ensure we collect # paths from all engines. This hook is invoked exactly before routes # are compiled, and so that other Railties have an opportunity to From 710c5eaf2f7766885d7c8f448de8b3b3ff8929f6 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 25 Jul 2011 11:37:25 -0700 Subject: [PATCH 040/164] Allow a route to have :format => true When format is true, it is mandatory (as opposed to :format => false). This is currently not possible with resource routes, which automatically make format optional by default. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 ++ actionpack/test/dispatch/mapper_test.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 1331f67a78d..003bc1dc2c3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -119,6 +119,8 @@ module ActionDispatch path elsif path.include?(":format") || path.end_with?('/') path + elsif @options[:format] == true + "#{path}.:format" else "#{path}(.:format)" end diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index b6c08ffc33d..81f0efb76e4 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -83,6 +83,13 @@ module ActionDispatch assert_equal '/*path', fakeset.conditions.first[:path_info] assert_nil fakeset.requirements.first[:path] end + + def test_map_wildcard_with_format_true + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.match '/*path', :to => 'pages#show', :format => true + assert_equal '/*path.:format', fakeset.conditions.first[:path_info] + end end end end From 6d4f91621871a23576ec6f343f08fd68dda95e0c Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 25 Jul 2011 14:13:26 -0700 Subject: [PATCH 041/164] Add documentation for :format => true --- railties/guides/source/routing.textile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 68fb22f5d85..99dd9a1cd2d 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -569,6 +569,12 @@ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to + match '*pages' => 'pages#show', :format => false +NOTE: If you want to make the format segment mandatory, so it cannot be omitted, you can supply +:format => true+ like this: + + +match '*pages' => 'pages#show', :format => true + + h4. Redirection You can redirect any path to another path using the +redirect+ helper in your router: From cd5f54cfb6ab184659e6e86c6803e4b2915b7271 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 25 Jul 2011 23:02:12 -0300 Subject: [PATCH 042/164] Bump rack up. Closes #2107 --- actionpack/actionpack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 15d104fd822..1766a9322d1 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency('rack-cache', '~> 1.0.2') s.add_dependency('builder', '~> 3.0.0') s.add_dependency('i18n', '~> 0.6') - s.add_dependency('rack', '~> 1.3.1') + s.add_dependency('rack', '~> 1.3.2') s.add_dependency('rack-test', '~> 0.6.0') s.add_dependency('rack-mount', '~> 0.8.1') s.add_dependency('sprockets', '= 2.0.0.beta.10') From 34ca9c122c26dc3e073e52ecdf267cb23885c1df Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 00:18:56 -0300 Subject: [PATCH 043/164] Check that Rack::Sendfile is not included unless config.action_dispatch.x_sendfile_header is set --- railties/test/application/middleware_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 6a0a2720735..bed5ba503f7 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -20,6 +20,8 @@ module ApplicationTests end test "default middleware stack" do + add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'" + boot! assert_equal [ @@ -47,6 +49,12 @@ module ApplicationTests ], middleware end + test "Rack::Sendfile is not included by default" do + boot! + + assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header" + end + test "Rack::Cache is present when action_controller.perform_caching is set" do add_to_config "config.action_controller.perform_caching = true" From 33ee3898ef0aa06bf21ca588b906c7da80886457 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 00:42:31 -0300 Subject: [PATCH 044/164] Bump sprockets up --- actionpack/actionpack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 1766a9322d1..620fdc4a724 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_dependency('rack', '~> 1.3.2') s.add_dependency('rack-test', '~> 0.6.0') s.add_dependency('rack-mount', '~> 0.8.1') - s.add_dependency('sprockets', '= 2.0.0.beta.10') + s.add_dependency('sprockets', '~> 2.0.0.beta.12') s.add_dependency('erubis', '~> 2.7.0') s.add_development_dependency('tzinfo', '~> 0.3.29') From 16e3c40426c470458764dfd62841d647c725ff35 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 01:00:00 -0300 Subject: [PATCH 045/164] use_sprockets is not used anymore --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index 0f8a63901ee..25cc5616083 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -83,11 +83,7 @@ module ActionView # javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr # javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js def javascript_path(source) - if config.use_sprockets - asset_path(source, 'js') - else - asset_paths.compute_public_path(source, 'javascripts', 'js') - end + asset_paths.compute_public_path(source, 'javascripts', 'js') end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route From 5004aaffc1c2bf81dfd23178b8ad691f0cecef26 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Tue, 26 Jul 2011 11:36:18 +0200 Subject: [PATCH 046/164] Simplify the test by using id and name. `id` will be the only real sort criteria in any case as it's unique. --- activerecord/test/cases/relations_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 6363cae3717..821da91f0ab 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -963,6 +963,6 @@ class RelationTest < ActiveRecord::TestCase end def test_ordering_with_extra_spaces - assert_equal authors(:david), Author.order('organization_id ASC , owned_essay_id DESC').last + assert_equal authors(:david), Author.order('id DESC , name DESC').last end end From e7f7439d068f587db91e959ef803606cae9e7cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awosz=20S=C5=82awi=C5=84ski?= Date: Sat, 23 Jul 2011 21:35:16 +0200 Subject: [PATCH 047/164] allow select to have multiple arguments --- activerecord/lib/active_record/relation/query_methods.rb | 9 ++++++--- activerecord/test/cases/base_test.rb | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1654ae1eace..792ffe1c5d8 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -37,12 +37,15 @@ module ActiveRecord relation end - def select(value = Proc.new) + def select(*args, &blk) + if !block_given? && args.blank? + raise ArgumentError + end if block_given? - to_a.select {|*block_args| value.call(*block_args) } + to_a.select {|*block_args| blk.call(*block_args) } else relation = clone - relation.select_values += Array.wrap(value) + relation.select_values += args relation end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index f2f5b736261..84b66fdf49d 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -123,6 +123,11 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.all.map(&:id).sort, topic_ids end + def test_select_symbol_for_many_arguments + topics = Topic.select(:id, :author_name).map{|topic| [topic.id, topic.author_name]}.sort + assert_equal Topic.all.map{|topic| [topic.id,topic.author_name]}.sort, topics + end + def test_table_exists assert !NonExistentTable.table_exists? assert Topic.table_exists? From 182a4284183c63e9cb8fa879620ce01c98e111d3 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 26 Jul 2011 16:12:17 +0200 Subject: [PATCH 048/164] Revert "allow select to have multiple arguments" This reverts commit 04cc446d178653d362510e79a22db5300d463161. I reverted it because apparently we want to use: select([:a, :b]) instead of select(:a, :b), but there was no tests for that form. --- activerecord/lib/active_record/relation/query_methods.rb | 9 +++------ activerecord/test/cases/base_test.rb | 5 ----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 792ffe1c5d8..1654ae1eace 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -37,15 +37,12 @@ module ActiveRecord relation end - def select(*args, &blk) - if !block_given? && args.blank? - raise ArgumentError - end + def select(value = Proc.new) if block_given? - to_a.select {|*block_args| blk.call(*block_args) } + to_a.select {|*block_args| value.call(*block_args) } else relation = clone - relation.select_values += args + relation.select_values += Array.wrap(value) relation end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 84b66fdf49d..f2f5b736261 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -123,11 +123,6 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.all.map(&:id).sort, topic_ids end - def test_select_symbol_for_many_arguments - topics = Topic.select(:id, :author_name).map{|topic| [topic.id, topic.author_name]}.sort - assert_equal Topic.all.map{|topic| [topic.id,topic.author_name]}.sort, topics - end - def test_table_exists assert !NonExistentTable.table_exists? assert Topic.table_exists? From 838ec4b64545ea49817166ba6a4988c846ecf089 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 26 Jul 2011 16:58:24 +0200 Subject: [PATCH 049/164] use sprocket's append_path and assert_match --- .../test/template/sprockets_helper_test.rb | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index 3d7abc7e2a8..b9161b62c54 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -21,9 +21,9 @@ class SprocketsHelperTest < ActionView::TestCase @controller.request = MockRequest.new @assets = Sprockets::Environment.new - @assets.paths << FIXTURES.join("sprockets/app/javascripts") - @assets.paths << FIXTURES.join("sprockets/app/stylesheets") - @assets.paths << FIXTURES.join("sprockets/app/images") + @assets.append_path(FIXTURES.join("sprockets/app/javascripts")) + @assets.append_path(FIXTURES.join("sprockets/app/stylesheets")) + @assets.append_path(FIXTURES.join("sprockets/app/images")) application = Struct.new(:config, :assets).new(config, @assets) Rails.stubs(:application).returns(application) @@ -37,7 +37,7 @@ class SprocketsHelperTest < ActionView::TestCase end test "asset_path" do - assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png", + assert_match %r{/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") end @@ -112,7 +112,7 @@ class SprocketsHelperTest < ActionView::TestCase @config.action_controller.default_asset_host_protocol = :request @config.action_controller.perform_caching = true - assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png", + assert_match %r{/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") end @@ -123,12 +123,12 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript path" do - assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js", + assert_match %r{/assets/application-[0-9a-f]+.js}, asset_path(:application, "js") - assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_match %r{/assets/xmlhr-[0-9a-f]+.js}, asset_path("xmlhr", "js") - assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js", + assert_match %r{/assets/dir/xmlhr-[0-9a-f]+.js}, asset_path("dir/xmlhr.js", "js") assert_equal "/dir/xmlhr.js", @@ -141,28 +141,28 @@ class SprocketsHelperTest < ActionView::TestCase end test "javascript include tag" do - assert_equal '', + assert_match %r{}, javascript_include_tag(:application) - assert_equal '', + assert_match %r{}, javascript_include_tag("xmlhr") - assert_equal '', + assert_match %r{}, javascript_include_tag("xmlhr.js") assert_equal '', javascript_include_tag("http://www.example.com/xmlhr") - assert_equal "\n", + assert_match %r{\n}, javascript_include_tag(:application, :debug => true) - assert_equal "\n", + assert_match %r{\n}, javascript_include_tag("xmlhr", "extra") end test "stylesheet path" do - assert_equal "/assets/application-68b329da9893e34099c7d8ad5cb9c940.css", asset_path(:application, "css") + assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, "css") - assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css") - assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css") + assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", "css") + assert_match %r{/assets/dir/style-[0-9a-f]+.css}, asset_path("dir/style.css", "css") assert_equal "/dir/style.css", asset_path("/dir/style.css", "css") assert_equal "http://www.example.com/css/style", @@ -172,37 +172,37 @@ class SprocketsHelperTest < ActionView::TestCase end test "stylesheet link tag" do - assert_equal '', + assert_match %r{}, stylesheet_link_tag(:application) - assert_equal '', + assert_match %r{}, stylesheet_link_tag("style") - assert_equal '', + assert_match %r{}, stylesheet_link_tag("style.css") assert_equal '', stylesheet_link_tag("http://www.example.com/style.css") - assert_equal '', + assert_match %r{}, stylesheet_link_tag("style", :media => "all") - assert_equal '', + assert_match %r{}, stylesheet_link_tag("style", :media => "print") - assert_equal "\n", + assert_match %r{\n}, stylesheet_link_tag(:application, :debug => true) - assert_equal "\n", + assert_match %r{\n}, stylesheet_link_tag("style", "extra") end test "alternate asset prefix" do stubs(:asset_prefix).returns("/themes/test") - assert_equal "/themes/test/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css") + assert_match %r{/themes/test/style-[0-9a-f]+.css}, asset_path("style", "css") end test "alternate asset environment" do assets = Sprockets::Environment.new - assets.paths << FIXTURES.join("sprockets/alternate/stylesheets") + assets.append_path(FIXTURES.join("sprockets/alternate/stylesheets")) stubs(:asset_environment).returns(assets) - assert_equal "/assets/style-df0b97ad35a8e1f7f61097461f77c19a.css", asset_path("style", "css") + assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", "css") end end From 5a92c6627e02fc2e40a4c4a578e7aab7324af5fe Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Tue, 26 Jul 2011 22:33:23 +0530 Subject: [PATCH 050/164] remove deprication warning for ruby 1.9.3-head for unused variables --- .../lib/active_record/connection_adapters/mysql2_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index d6c167ad367..f9602bbe776 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -577,7 +577,7 @@ module ActiveRecord def quoted_columns_for_index(column_names, options = {}) length = options[:length] if options.is_a?(Hash) - quoted_column_names = case length + case length when Hash column_names.map {|name| length[name] ? "#{quote_column_name(name)}(#{length[name]})" : quote_column_name(name) } when Fixnum From 7934ffe5e9a88236f9fb924d9d4c1f20ff0892c7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 10:58:16 -0700 Subject: [PATCH 051/164] fixing whitespace errors --- activesupport/test/xml_mini_test.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index e2b90ae16e5..4450c1a0ae7 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -50,49 +50,49 @@ module XmlMiniTest def test_rename_key_does_not_dasherize_multiple_trailing_underscores assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") - end + end end class ToTagTest < ActiveSupport::TestCase def assert_xml(xml) assert_equal xml, @options[:builder].target! end - + setup do @xml = ActiveSupport::XmlMini @options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new} end - + test "#to_tag accepts a callable object and passes options with the builder" do @xml.to_tag(:some_tag, lambda {|o| o[:builder].br }, @options) assert_xml "
" end - + test "#to_tag accepts a callable object and passes options and tag name" do @xml.to_tag(:tag, lambda {|o, t| o[:builder].b(t) }, @options) assert_xml "tag" end - + test "#to_tag accepts an object responding to #to_xml and passes the options, where :root is key" do obj = Object.new obj.instance_eval do def to_xml(options) options[:builder].yo(options[:root].to_s) end end - + @xml.to_tag(:tag, obj, @options) assert_xml "tag" end - + test "#to_tag accepts arbitrary objects responding to #to_str" do @xml.to_tag(:b, "Howdy", @options) assert_xml "Howdy" end - + test "#to_tag should dasherize the space when passed a string with spaces as a key" do @xml.to_tag("New York", 33, @options) assert_xml "33" end - + test "#to_tag should dasherize the space when passed a symbol with spaces as a key" do @xml.to_tag(:"New York", 33, @options) assert_xml "33" From 797d2254d7d1a541305526431e7362df5d5dd970 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 11:02:41 -0700 Subject: [PATCH 052/164] fixing tests on ruby trunk --- activesupport/test/xml_mini_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index 4450c1a0ae7..dde17ea4030 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -58,7 +58,7 @@ module XmlMiniTest assert_equal xml, @options[:builder].target! end - setup do + def setup @xml = ActiveSupport::XmlMini @options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new} end From 745d90bde30f34e476cee990bbd07feafb63eba7 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Tue, 26 Jul 2011 23:39:17 +0530 Subject: [PATCH 053/164] remove deprication warning: ambiguous first argument; put parentheses or even spaces --- activerecord/test/cases/base_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index f2f5b736261..12101c16833 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1867,6 +1867,6 @@ class BasicsTest < ActiveRecord::TestCase def test_cache_key_format_for_existing_record_with_nil_updated_at dev = Developer.first dev.update_attribute(:updated_at, nil) - assert_match /\/#{dev.id}$/, dev.cache_key + assert_match(/\/#{dev.id}$/, dev.cache_key) end end From 7b2d5e0d920bc196edd2e579f6108f3d4f9d4b0b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 26 Jul 2011 18:17:58 +0000 Subject: [PATCH 054/164] enable Travis CI irc notifications to #rails-contrib on irc.freenode.org --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d33c6a3c866..596611ecf46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ script: 'ci/travis.rb' -notifications: - disabled: true rvm: - 1.8.7 - 1.9.2 @@ -9,4 +7,8 @@ env: - "GEM=ap,am,amo,ares,as" - "GEM=ar:mysql" - "GEM=ar:mysql2" - - "GEM=ar:sqlite3" \ No newline at end of file + - "GEM=ar:sqlite3" +notifications: + email: false + irc: + - "irc.freenode.org#rails-contrib" \ No newline at end of file From d13b5d4b2aac3bec055933f1769a7becff374742 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Tue, 26 Jul 2011 23:53:54 +0530 Subject: [PATCH 055/164] remove unused variables warnings removed --- activesupport/test/safe_buffer_test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 46bc0d7a34a..7662e9b765b 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -80,14 +80,12 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should escape dirty buffers on add" do - dirty = @buffer clean = "hello".html_safe @buffer.gsub!('', '<>') assert_equal "hello<>", clean + @buffer end test "Should concat as a normal string when dirty" do - dirty = @buffer clean = "hello".html_safe @buffer.gsub!('', '<>') assert_equal "<>hello", @buffer + clean From f87b33daaf0f0a93825a3f022d52fcb5aa4c8320 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Fri, 15 Jul 2011 18:22:31 -0400 Subject: [PATCH 056/164] fixed problem in which options[:html][:remote] would be overridden in form_for() - fixes #2094 --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 974c963d446..52a640abf30 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -365,7 +365,7 @@ module ActionView apply_form_for_options!(record, options) end - options[:html][:remote] = options.delete(:remote) + options[:html][:remote] = options.delete(:remote) if options.has_key?(:remote) options[:html][:method] = options.delete(:method) if options.has_key?(:method) options[:html][:authenticity_token] = options.delete(:authenticity_token) From 28daa8bd4bff2c361c3eb35df5c36a532c6ee259 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Sat, 16 Jul 2011 08:22:43 -0400 Subject: [PATCH 057/164] added test case for fix to issue #2094 --- actionpack/test/template/form_helper_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index cc3d2cddf76..aca2dc9e4d5 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -791,6 +791,23 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_for_with_remote_in_html + form_for(@post, :url => '/', :html => { :remote => true, :id => 'create-post', :method => :put }) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) + end + + expected = whole_form("/", "create-post", "edit_post", :method => "put", :remote => true) do + "" + + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_remote_without_html @post.persisted = false form_for(@post, :remote => true) do |f| From b36a710e713d83436f828e666fd7181e340f7878 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 18:11:03 -0300 Subject: [PATCH 058/164] Remove cruise files --- ci/ci_build.rb | 181 ------------------------------------------ ci/ci_setup_notes.txt | 140 -------------------------------- ci/cruise_config.rb | 9 --- ci/site.css | 13 --- ci/site_config.rb | 72 ----------------- 5 files changed, 415 deletions(-) delete mode 100755 ci/ci_build.rb delete mode 100644 ci/ci_setup_notes.txt delete mode 100644 ci/cruise_config.rb delete mode 100644 ci/site.css delete mode 100644 ci/site_config.rb diff --git a/ci/ci_build.rb b/ci/ci_build.rb deleted file mode 100755 index 50f7f410fad..00000000000 --- a/ci/ci_build.rb +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env ruby -require 'fileutils' -include FileUtils - -def root_dir - @root_dir ||= File.expand_path('../..', __FILE__) -end - -def rake(*tasks) - tasks.each do |task| - cmd = "bundle exec rake #{task}" - puts "Running command: #{cmd}" - return false unless system(cmd) - end - true -end - -puts "[CruiseControl] Rails build" -build_results = {} - -# Install required version of bundler. -bundler_install_cmd = "sudo gem install bundler --no-ri --no-rdoc" -puts "Running command: #{bundler_install_cmd}" -build_results[:install_bundler] = system bundler_install_cmd - -cd root_dir do - puts - puts "[CruiseControl] Bundling gems" - puts - build_results[:bundle] = system 'bundle update' -end - -cd "#{root_dir}/activesupport" do - puts - puts "[CruiseControl] Building Active Support" - puts - build_results[:activesupport] = rake 'test' - build_results[:activesupport_isolated] = rake 'test:isolated' -end - -system "sudo rm -R #{root_dir}/railties/tmp" -cd "#{root_dir}/railties" do - puts - puts "[CruiseControl] Building Railties" - puts - build_results[:railties] = rake 'test' -end - -cd "#{root_dir}/actionpack" do - puts - puts "[CruiseControl] Building Action Pack" - puts - build_results[:actionpack] = rake 'test' - build_results[:actionpack_isolated] = rake 'test:isolated' -end - -cd "#{root_dir}/actionmailer" do - puts - puts "[CruiseControl] Building Action Mailer" - puts - build_results[:actionmailer] = rake 'test' - build_results[:actionmailer_isolated] = rake 'test:isolated' -end - -cd "#{root_dir}/activemodel" do - puts - puts "[CruiseControl] Building Active Model" - puts - build_results[:activemodel] = rake 'test' - build_results[:activemodel_isolated] = rake 'test:isolated' -end - -rm_f "#{root_dir}/activeresource/debug.log" -cd "#{root_dir}/activeresource" do - puts - puts "[CruiseControl] Building Active Resource" - puts - build_results[:activeresource] = rake 'test' - build_results[:activeresource_isolated] = rake 'test:isolated' -end - -rm_f "#{root_dir}/activerecord/debug.log" -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with MySQL IM enabled" - puts - ENV['IM'] = 'true' - build_results[:activerecord_mysql_IM] = rake 'mysql:rebuild_databases', 'mysql:test' - build_results[:activerecord_mysql_isolated_IM] = rake 'mysql:rebuild_databases', 'mysql:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with MySQL IM disabled" - puts - ENV['IM'] = 'false' - build_results[:activerecord_mysql] = rake 'mysql:rebuild_databases', 'mysql:test' - build_results[:activerecord_mysql_isolated] = rake 'mysql:rebuild_databases', 'mysql:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with MySQL2 IM enabled" - puts - ENV['IM'] = 'true' - build_results[:activerecord_mysql2_IM] = rake 'mysql:rebuild_databases', 'mysql2:test' - build_results[:activerecord_mysql2_isolated_IM] = rake 'mysql:rebuild_databases', 'mysql2:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with MySQL2 IM disabled" - puts - ENV['IM'] = 'false' - build_results[:activerecord_mysql2] = rake 'mysql:rebuild_databases', 'mysql2:test' - build_results[:activerecord_mysql2_isolated] = rake 'mysql:rebuild_databases', 'mysql2:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with PostgreSQL IM enabled" - puts - ENV['IM'] = 'true' - build_results[:activerecord_postgresql8_IM] = rake 'postgresql:rebuild_databases', 'postgresql:test' - build_results[:activerecord_postgresql8_isolated_IM] = rake 'postgresql:rebuild_databases', 'postgresql:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with PostgreSQL IM disabled" - puts - ENV['IM'] = 'false' - build_results[:activerecord_postgresql8] = rake 'postgresql:rebuild_databases', 'postgresql:test' - build_results[:activerecord_postgresql8_isolated] = rake 'postgresql:rebuild_databases', 'postgresql:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with SQLite 3 IM enabled" - puts - ENV['IM'] = 'true' - build_results[:activerecord_sqlite3_IM] = rake 'sqlite3:test' - build_results[:activerecord_sqlite3_isolated_IM] = rake 'sqlite3:isolated_test' -end - -cd "#{root_dir}/activerecord" do - puts - puts "[CruiseControl] Building Active Record with SQLite 3 IM disabled" - puts - ENV['IM'] = 'false' - build_results[:activerecord_sqlite3] = rake 'sqlite3:test' - build_results[:activerecord_sqlite3_isolated] = rake 'sqlite3:isolated_test' -end - - -puts -puts "[CruiseControl] Build environment:" -puts "[CruiseControl] #{`cat /etc/issue`}" -puts "[CruiseControl] #{`uname -a`}" -puts "[CruiseControl] #{`ruby -v`}" -puts "[CruiseControl] #{`mysql --version`}" -puts "[CruiseControl] #{`pg_config --version`}" -puts "[CruiseControl] SQLite3: #{`sqlite3 -version`}" -`gem env`.each_line {|line| print "[CruiseControl] #{line}"} -puts "[CruiseControl] Bundled gems:" -`bundle show`.each_line {|line| print "[CruiseControl] #{line}"} -puts "[CruiseControl] Local gems:" -`gem list`.each_line {|line| print "[CruiseControl] #{line}"} - -failures = build_results.select { |key, value| value == false } - -if failures.empty? - puts - puts "[CruiseControl] Rails build finished sucessfully" - exit(0) -else - puts - puts "[CruiseControl] Rails build FAILED" - puts "[CruiseControl] Failed components: #{failures.map { |component| component.first }.join(', ')}" - exit(-1) -end diff --git a/ci/ci_setup_notes.txt b/ci/ci_setup_notes.txt deleted file mode 100644 index 890f9e8ef63..00000000000 --- a/ci/ci_setup_notes.txt +++ /dev/null @@ -1,140 +0,0 @@ -# Rails Continuous Integration Server Setup Notes -# This procedure was used to set up http://ci.rubyonrails.org on Ubuntu 8.04 -# It can be used as a guideline for setting up your own CI server against your local rails branches - -* Set up ci user: -# log in as root -$ adduser ci -enter user info and password -$ visudo -# give ci user same sudo rights as root - -* Disable root login: -# log in as ci -$ sudo vi /etc/shadow -# overwrite and disable encrypted root password to disable root login: -root:*:14001:0:99999:7::: - -* Change Hostname: -$ sudo vi /etc/hostname -change to correct hostname -$ sudo vi /etc/hosts -replace old hostname with the correct hostname -# reboot to use new hostname (and test reboot) -$ sudo shutdown -r now - -* Update aptitude: -$ sudo aptitude update - -* Use cinabox to perform rest of ruby/ccrb setup: -* https://github.com/thewoolleyman/cinabox/tree/master/README.txt - -# This is not yet properly supported by RubyGems... -# * Configure RubyGems to not require root access for gem installation -# $ vi ~/.profile -# # add this line at bottom: -# PATH="$HOME/.gem/ruby/1.8/bin:$PATH" -# $ sudo vi /etc/init.d/cruise -# # edit the start_cruise line to source CRUISE_USER/.profile: -# start_cruise "cd #{CRUISE_HOME} && source /home/#{CRUISE_USER}/.profile && ./cruise start -d" -# $ vi ~/.gemrc -# # add these lines: -# --- -# gemhome: /home/ci/.gem/ruby/1.8 -# gempath: -# - /home/ci/.gem/ruby/1.8 - -* If you did not configure no-root-gem installation via ~/.gemrc as shown above, then allow no-password sudo for gem installation: -$ sudo visudo -# add this line to bottom: -ci ALL=(ALL) NOPASSWD: ALL - -* Start ccrb via init script and check for default homepage at port 3333 - -* Install/setup nginx: -$ sudo aptitude install nginx -$ sudo vi /etc/nginx/sites-available/default -# Add the following entry at the top of the file above the 'server {' line: -upstream mongrel { - server 127.0.0.1:3333; -} - -# Change server_name entry to match server name - -# replace the contents of the root 'location / {}' block with the following entries: - proxy_pass http://mongrel; - proxy_redirect off; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Client-Verify SUCCESS; - proxy_read_timeout 65; - -# also comment default locations for /doc and /images -$ sudo /etc/init.d/nginx start - -* Add project to cruise (It will still fail until everything is set up): -$ cd ~/ccrb -$ ./cruise add rails -s git -r git://github.com/rails/rails.git # or the URI of your branch - -* Copy and configure cruise site config file: -$ cp ~/.cruise/projects/rails/work/ci/site_config.rb ~/.cruise/site_config.rb -# Edit ~/.cruise/site_config.rb as desired, for example: -ActionMailer::Base.smtp_settings = { - :address => "localhost", - :domain => "ci.yourdomain.com", -} -Configuration.dashboard_refresh_interval = 60.seconds -Configuration.dashboard_url = 'http://ci.yourdomain.com/' -Configuration.serialize_builds = true -Configuration.serialized_build_timeout = 1.hours -BuildReaper.number_of_builds_to_keep = 100 - -* Copy and configure cruise project config file -$ cp ~/.cruise/projects/rails/work/ci/cruise_config.rb ~/.cruise/projects/rails -$ vi ~/.cruise/projects/rails/cruise_config.rb: -# Edit ~/.cruise/projects/rails/cruise_config.rb as desired, for example: -Project.configure do |project| - project.build_command = 'ruby ci/ci_build.rb' - project.email_notifier.emails = ['recipient@yourdomain.com'] - project.email_notifier.from = 'sender@yourdomain.com' -end - -* Set up mysql -$ sudo aptitude install mysql-server-5.0 libmysqlclient-dev -# no password for mysql root user - -* setup sqlite 3 -$ sudo aptitude install sqlite3 libsqlite3-dev -# Note: there's some installation bugs with sqlite3-ruby 1.2.2 gem file permissions: -# http://www.icoretech.org/2008/07/06/no-such-file-to-load-sqlite3-database -# cd /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.2 && sudo find . -perm 0662 -exec chmod 664 {} \; - -* setup postgres -$ sudo aptitude install postgresql postgresql-server-dev-8.3 -$ sudo su - postgres -c 'createuser -s ci' - -* Install fcgi libraries -$ sudo apt-get install libfcgi-dev - -* Install memcached and start for first time (should start on reboot automatically) -$ sudo aptitude install memcached -$ sudo /etc/init.d/memcached start - -* Install and run GemInstaller to get all dependency gems -$ sudo gem install geminstaller -$ cd ~/.cruise/projects/rails/work -$ sudo geminstaller --config=ci/geminstaller.yml # turn up debugging with these options: --geminstaller-output=all --rubygems-output=all - -* Create ActiveRecord test databases for mysql -$ mysql -uroot -e 'grant all on *.* to rails@localhost;' -$ mysql -urails -e 'create database activerecord_unittest;' -$ mysql -urails -e 'create database activerecord_unittest2;' - -* Create ActiveRecord test databases for postgres -# cd to rails activerecord dir -$ rake postgresql:build_databases - -* Reboot and make sure everything is working -$ sudo shutdown -r now -$ http://ci.yourdomain.com diff --git a/ci/cruise_config.rb b/ci/cruise_config.rb deleted file mode 100644 index b64cd8aaead..00000000000 --- a/ci/cruise_config.rb +++ /dev/null @@ -1,9 +0,0 @@ -Project.configure do |project| - project.build_command = 'sudo gem update --system && ruby ci/ci_build.rb' - project.email_notifier.from = 'rails-ci@wyeworks.com' - - # project.campfire_notifier.account = 'rails' - # project.campfire_notifier.token = '' - # project.campfire_notifier.room = 'Rails 3' - # project.campfire_notifier.ssl = true -end diff --git a/ci/site.css b/ci/site.css deleted file mode 100644 index e771c5d1fd8..00000000000 --- a/ci/site.css +++ /dev/null @@ -1,13 +0,0 @@ -/* this is a copy of /home/ci/.cruise/site.css, please make any changes to it there */ - -/* this is a copy of /home/ci/.cruise/site.css, please make any changes to it there */ - -/* if you'd like to add custom styles to cruise, add them here */ -/* the following will make successful builds green */ -a.success, a.success:visited { - color: #0A0; -} - -.build_success { - background-image: url(/images/green_gradient.png); -} diff --git a/ci/site_config.rb b/ci/site_config.rb deleted file mode 100644 index f9db39ed57a..00000000000 --- a/ci/site_config.rb +++ /dev/null @@ -1,72 +0,0 @@ -# site_config.rb contains examples of various configuration options for the local installation -# of CruiseControl.rb. - -# YOU MUST RESTART YOUR CRUISE CONTROL SERVER FOR ANY CHANGES MADE HERE TO TAKE EFFECT!!! - -# EMAIL NOTIFICATION -# ------------------ - -# CruiseControl.rb can notify you about build status via email. It uses the Action Mailer component of Ruby on Rails -# framework. Obviously, Action Mailer needs to know how to send out email messages. -# If you have an SMTP server on your network, and it needs no authentication, write this in your site_config.rb: -# -ActionMailer::Base.smtp_settings = { - :address => "localhost", - :domain => "ci.rubyonrails.org", -} -# -# If you have no SMTP server at hand, you can configure email notification to use GMail SMTP server, as follows -# (of course, you'll need to create a GMail account): -# -# ActionMailer::Base.smtp_settings = { -# :address => "smtp.gmail.com", -# :port => 587, -# :domain => "yourdomain.com", -# :authentication => :plain, -# :user_name => "yourgmailaccount", -# :password => "yourgmailpassword" -# } -# -# The same approach works for other SMTP servers thet require authentication. Note that GMail's SMTP server runs on a -# non-standard port 587 (standard port for SMTP is 25). -# -# For further details about configuration of outgoing email, see Ruby On Rails documentation for ActionMailer::Base. - -# Other site-wide options are available through Configuration class: - -# Change how often CC.rb pings Subversion for new requests. Default is 10.seconds, which should be OK for a local -# SVN repository, but probably isn't very polite for a public repository, such as RubyForge. This can also be set for -# each project individually, through project.scheduler.polling_interval option: -# Configuration.default_polling_interval = 1.minute - -# How often the dashboard page refreshes itself. If you have more than 10-20 dashboards open, -# it is advisable to set it to something higher than the default 5 seconds: -Configuration.dashboard_refresh_interval = 60.seconds - -# Site-wide setting for the email "from" field. This can also be set on per-project basis, -# through project.email.notifier.from attribute -Configuration.email_from = 'rails-ci@wyeworks.com' - -# Root URL of the dashboard application. Setting this attribute allows various notifiers to include a link to the -# build page in the notification message. -Configuration.dashboard_url = 'http://rails-ci.wyeworks.com/' - -# If you don't want to allow triggering builds through dashboard Build Now button. Useful when you host CC.rb as a -# public web site (such as http://cruisecontrolrb.thoughtworks.com/projects - try clicking on Build Now button there -# and see what happens): -Configuration.disable_build_now = true - -# If you want to only allow one project to build at a time, uncomment this line -# by default, cruise allows multiple projects to build at a time -Configuration.serialize_builds = true - -# Amount of time a project will wait to build before failing when build serialization is on -Configuration.serialized_build_timeout = 3.hours - -# To delete build when there are more than a certain number present, uncomment this line - it will make the dashboard -# perform better -BuildReaper.number_of_builds_to_keep = 100 - -# any files that you'd like to override in cruise, keep in ~/.cruise, and copy over when this file is loaded like this -site_css = CRUISE_DATA_ROOT + "/site.css" -FileUtils.cp site_css, Rails.root + "/public/stylesheets/site.css" if File.exists? site_css From 39183f4ede48db822044abd8e15e6c7f7e93cdd8 Mon Sep 17 00:00:00 2001 From: thoefer Date: Tue, 26 Jul 2011 11:42:53 +0200 Subject: [PATCH 059/164] refactored 'assert_redirected_to': local call to validate_request! will be called in assert_response already. changed names of local variables in order to recognize the semantics a bit easier. --- .../lib/action_dispatch/testing/assertions/response.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index a2d639cd563..33c6cd52213 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -55,16 +55,15 @@ module ActionDispatch # assert_redirected_to @customer # def assert_redirected_to(options = {}, message=nil) - validate_request! assert_response(:redirect, message) return true if options == @response.location - redirected_to_after_normalization = normalize_argument_to_redirection(@response.location) - options_after_normalization = normalize_argument_to_redirection(options) + redirect_is = normalize_argument_to_redirection(@response.location) + redirect_expected = normalize_argument_to_redirection(options) - if redirected_to_after_normalization != options_after_normalization - flunk "Expected response to be a redirect to <#{options_after_normalization}> but was a redirect to <#{redirected_to_after_normalization}>" + if redirect_is != redirect_expected + flunk "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>" end end From 1d64041d59443ace8840748ec72017442cda4ca2 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 26 Jul 2011 19:20:45 -0300 Subject: [PATCH 060/164] Remove blank line --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 33c6cd52213..7381617dd7d 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -55,7 +55,6 @@ module ActionDispatch # assert_redirected_to @customer # def assert_redirected_to(options = {}, message=nil) - assert_response(:redirect, message) return true if options == @response.location From f1403f930358dcd8c66d8bc276da11874546ed2f Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Tue, 26 Jul 2011 16:10:55 +0100 Subject: [PATCH 061/164] Constantize a regexp in Dependencies#load_missing_constant --- activesupport/lib/active_support/dependencies.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index d1543c4c582..a60697cb12d 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -466,6 +466,7 @@ module ActiveSupport #:nodoc: # Load the constant named +const_name+ which is missing from +from_mod+. If # it is not possible to load the constant into from_mod, try its parent module # using const_missing. + THIS_FILE = %r{#{Regexp.escape(__FILE__)}} def load_missing_constant(from_mod, const_name) log_call from_mod, const_name @@ -478,7 +479,7 @@ module ActiveSupport #:nodoc: qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore - trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}} + trace = caller.reject {|l| l =~ THIS_FILE} name_error = NameError.new("uninitialized constant #{qualified_name}") name_error.set_backtrace(trace) From ab422b04a2fd8144a26d82f2ec1efeeb684b29db Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Wed, 27 Jul 2011 00:06:19 +0100 Subject: [PATCH 062/164] Replace unnecessary regexp in Dependencies#load_missing_constant --- activesupport/lib/active_support/dependencies.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index a60697cb12d..8cd4d15e4c3 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -466,7 +466,6 @@ module ActiveSupport #:nodoc: # Load the constant named +const_name+ which is missing from +from_mod+. If # it is not possible to load the constant into from_mod, try its parent module # using const_missing. - THIS_FILE = %r{#{Regexp.escape(__FILE__)}} def load_missing_constant(from_mod, const_name) log_call from_mod, const_name @@ -479,7 +478,7 @@ module ActiveSupport #:nodoc: qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore - trace = caller.reject {|l| l =~ THIS_FILE} + trace = caller.reject {|l| l.starts_with? __FILE__ } name_error = NameError.new("uninitialized constant #{qualified_name}") name_error.set_backtrace(trace) From f445bb26715406a5718bbf4652bbfa4d8be0b60d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:33:22 -0700 Subject: [PATCH 063/164] fixing wildcard path matching when wildcard is inside parenthesis --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- actionpack/test/dispatch/mapper_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 003bc1dc2c3..ee4d405ce7d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -51,7 +51,7 @@ module ActionDispatch IGNORE_OPTIONS = [:to, :as, :via, :on, :constraints, :defaults, :only, :except, :anchor, :shallow, :shallow_path, :shallow_prefix] ANCHOR_CHARACTERS_REGEX = %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z} SHORTHAND_REGEX = %r{^/[\w/]+$} - WILDCARD_PATH = %r{\*([^/]+)$} + WILDCARD_PATH = %r{\*([^/\)]+)\)?$} def initialize(set, scope, path, options) @set, @scope = set, scope diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 81f0efb76e4..3316dd03aa4 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -35,6 +35,13 @@ module ActionDispatch Mapper.new FakeSet.new end + def test_mapping_requirements + options = { :controller => 'foo', :action => 'bar' } + m = Mapper::Mapping.new FakeSet.new, {}, '/store/:name(*rest)', options + _, _, requirements, _ = m.to_route + assert_equal(/.+?/, requirements[:rest]) + end + def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset From a704fd4ea9b8ac86f57d357bd8e2a555b69edca9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:45:34 -0700 Subject: [PATCH 064/164] use regular ruby rather than clever ruby --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ee4d405ce7d..187e2a8a741 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -105,13 +105,13 @@ module ActionDispatch # controllers with default routes like :controller/:action/:id(.:format), e.g: # GET /admin/products/show/1 # => { :controller => 'admin/products', :action => 'show', :id => '1' } - @options.reverse_merge!(:controller => /.+?/) + @options[:controller] ||= /.+?/ end # Add a constraint for wildcard route to make it non-greedy and match the # optional format part of the route by default if path.match(WILDCARD_PATH) && @options[:format] != false - @options.reverse_merge!(:"#{$1}" => /.+?/) + @options[$1.to_sym] ||= /.+?/ end if @options[:format] == false @@ -264,7 +264,7 @@ module ActionDispatch # because this means it will be matched first. As this is the most popular route # of most Rails applications, this is beneficial. def root(options = {}) - match '/', options.reverse_merge(:as => :root) + match '/', { :as => :root }.merge(options) end # Matches a url pattern to one or more routes. Any symbols in a pattern From ed09aef1a3566ac987f883d743ad1ef773a87ac2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jul 2011 17:49:19 -0700 Subject: [PATCH 065/164] simplify conditionals by assuming hash values will never be `false` --- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 187e2a8a741..53374949ae2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -224,19 +224,11 @@ module ActionDispatch end def default_controller - if @options[:controller] - @options[:controller] - elsif @scope[:controller] - @scope[:controller] - end + @options[:controller] || @scope[:controller] end def default_action - if @options[:action] - @options[:action] - elsif @scope[:action] - @scope[:action] - end + @options[:action] || @scope[:action] end end From 924975a34aa3337cdf7a68f76bcae205815778f1 Mon Sep 17 00:00:00 2001 From: Lachlan Sylvester Date: Wed, 27 Jul 2011 16:59:11 +1000 Subject: [PATCH 066/164] fix some types in schema_test.rb --- activeresource/test/cases/base/schema_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/activeresource/test/cases/base/schema_test.rb b/activeresource/test/cases/base/schema_test.rb index 48fdeb13df1..d29eaf5fb60 100644 --- a/activeresource/test/cases/base/schema_test.rb +++ b/activeresource/test/cases/base/schema_test.rb @@ -139,7 +139,7 @@ class SchemaTest < ActiveModel::TestCase assert_nothing_raised { Person.schema = new_schema assert_equal new_schema, Person.schema, "should have saved the schema on the class" - assert_equal new_schema, Person.new.schema, "should have mde the schema available to every instance" + assert_equal new_schema, Person.new.schema, "should have made the schema available to every instance" } end @@ -283,8 +283,8 @@ class SchemaTest < ActiveModel::TestCase new_attr_name_two = :another_new_schema_attribute assert Person.schema.blank?, "sanity check - should have a blank class schema" - assert !Person.new.respond_do?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet" - assert !Person.new.respond_do?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet" + assert !Person.new.respond_to?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet" + assert !Person.new.respond_to?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet" assert_nothing_raised do Person.schema = {new_attr_name.to_s => 'string'} @@ -301,8 +301,8 @@ class SchemaTest < ActiveModel::TestCase assert Person.schema.blank?, "sanity check - should have a blank class schema" - assert !Person.new.respond_do?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet" - assert !Person.new.respond_do?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet" + assert !Person.new.respond_to?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet" + assert !Person.new.respond_to?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet" assert_nothing_raised do Person.schema { string new_attr_name_two } From 05f1a9bcc3c9223768187e2379b508638dfa19b6 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 27 Jul 2011 12:36:00 +0100 Subject: [PATCH 067/164] Add a proxy_association method to association proxies, which can be called by association extensions to access information about the association. This replaces proxy_owner etc with proxy_association.owner. --- activerecord/CHANGELOG | 6 ++++++ activerecord/lib/active_record/associations.rb | 6 ++++++ .../associations/collection_proxy.rb | 16 ++++++++++------ activerecord/test/cases/associations_test.rb | 5 +++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e448609cf48..e8d4b9c04e3 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -24,6 +24,12 @@ a URI that specifies the connection configuration. For example: *Rails 3.1.0 (unreleased)* +* Add a proxy_association method to association proxies, which can be called by association + extensions to access information about the association. This replaces proxy_owner etc with + proxy_association.owner. + + [Jon Leighton] + * ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature. Before: def build_association(*options) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 029d7a9b153..2605a54cb62 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -460,6 +460,12 @@ module ActiveRecord # * record.association(:items).target - Returns the associated object for +belongs_to+ and +has_one+, or # the collection of associated objects for +has_many+ and +has_and_belongs_to_many+. # + # However, inside the actual extension code, you will not have access to the record as + # above. In this case, you can access proxy_association. For example, + # record.association(:items) and record.items.proxy_association will return + # the same object, allowing you to make calls like proxy_association.owner inside + # association extensions. + # # === Association Join Models # # Has Many associations can be configured with the :through option to use an diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 827dfb7ccb2..6ba3d45affe 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -58,23 +58,27 @@ module ActiveRecord alias_method :new, :build + def proxy_association + @association + end + def respond_to?(name, include_private = false) super || (load_target && target.respond_to?(name, include_private)) || - @association.klass.respond_to?(name, include_private) + proxy_association.klass.respond_to?(name, include_private) end def method_missing(method, *args, &block) match = DynamicFinderMatch.match(method) if match && match.instantiator? send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r| - @association.send :set_owner_attributes, r - @association.send :add_to_target, r + proxy_association.send :set_owner_attributes, r + proxy_association.send :add_to_target, r yield(r) if block_given? end end - if target.respond_to?(method) || (!@association.klass.respond_to?(method) && Class.respond_to?(method)) + if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method)) if load_target if target.respond_to?(method) target.send(method, *args, &block) @@ -104,7 +108,7 @@ module ActiveRecord alias_method :to_a, :to_ary def <<(*records) - @association.concat(records) && self + proxy_association.concat(records) && self end alias_method :push, :<< @@ -114,7 +118,7 @@ module ActiveRecord end def reload - @association.reload + proxy_association.reload self end end diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 49d82ba2dfa..ffe2993e0f9 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -203,6 +203,11 @@ class AssociationProxyTest < ActiveRecord::TestCase assert_equal david.projects, david.projects.reload.reload end end + + def test_proxy_association_accessor + david = developers(:david) + assert_equal david.association(:projects), david.projects.proxy_association + end end class OverridingAssociationsTest < ActiveRecord::TestCase From 4c873cbf367d82538dbac914e7eee05b3582b6f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Kiriyenko Date: Tue, 5 Jul 2011 13:17:39 +0300 Subject: [PATCH 068/164] Fixed failing query when performing calculation with having based on select. --- activerecord/lib/active_record/relation/calculations.rb | 1 + activerecord/test/cases/calculations_test.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 0ac821b2d7d..9a7ff87e889 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -250,6 +250,7 @@ module ActiveRecord operation, distinct).as(aggregate_alias) ] + select_values += @select_values unless @having_values.empty? select_values.concat group_fields.zip(group_aliases).map { |field,aliaz| "#{field} AS #{aliaz}" diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 224b3f3d1f6..42f98b3d427 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -170,6 +170,13 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 60, c[2] end + def test_should_group_by_summed_field_having_condition_from_select + c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("min_credit_limit > 50").sum(:credit_limit) + assert_nil c[1] + assert_equal 60, c[2] + assert_equal 53, c[9] + end + def test_should_group_by_summed_association c = Account.sum(:credit_limit, :group => :firm) assert_equal 50, c[companies(:first_firm)] From 035d31bd93d68724912d656e03cba7c6b503d25a Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Wed, 27 Jul 2011 16:12:22 +0200 Subject: [PATCH 069/164] Improve performance and memory usage for options_for_select with Ruby 1.8.7 --- actionpack/lib/action_view/helpers/form_options_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 7c43dc04e05..c677257d600 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -323,12 +323,12 @@ module ActionView return container if String === container selected, disabled = extract_selected_and_disabled(selected).map do | r | - Array.wrap(r).map(&:to_s) + Array.wrap(r).map { |item| item.to_s } end container.map do |element| html_attributes = option_html_attributes(element) - text, value = option_text_and_value(element).map(&:to_s) + text, value = option_text_and_value(element).map { |item| item.to_s } selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled) %() From 45f9c2b3619d96867f9c6af7c16d2f5d53f1a17e Mon Sep 17 00:00:00 2001 From: thedarkone Date: Wed, 27 Jul 2011 18:07:47 +0200 Subject: [PATCH 070/164] Handle the empty array correctly. --- activemodel/lib/active_model/errors.rb | 2 +- activemodel/test/cases/errors_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 71ece15b71a..1cf8144e98c 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -86,7 +86,7 @@ module ActiveModel # Do the error messages include an error with key +error+? def include?(error) - messages.include? error + (v = messages[error]) && v.any? end # Get messages for +key+ diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index a24cac40ad3..85ca8ca835a 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -38,6 +38,7 @@ class ErrorsTest < ActiveModel::TestCase person.errors[:foo] assert person.errors.empty? assert person.errors.blank? + assert !person.errors.include?(:foo) end test "method validate! should work" do From c751bb1ac25c1b563cb55da2a25284f430e5e40e Mon Sep 17 00:00:00 2001 From: Samer Masry Date: Wed, 27 Jul 2011 10:17:25 -0700 Subject: [PATCH 071/164] Reverse order fix when using function for ActiveRecord::QueryMethods Fixes #1697 --- activerecord/lib/active_record/relation/query_methods.rb | 2 +- activerecord/test/cases/relations_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1654ae1eace..3a7b245c51e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -312,7 +312,7 @@ module ActiveRecord when String, Symbol o.to_s.split(',').collect do |s| s.strip! - s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') + (s if s =~ /\(/) || s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') end else o diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 821da91f0ab..8a2cf0ef851 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -911,6 +911,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name end + def test_order_with_function_and_last + authors = Author.scoped + assert_equal authors(:bob), authors.order( "id asc, MAX( organization_id, owned_essay_id)" ).last + end + def test_order_using_scoping car1 = CoolCar.order('id DESC').scoping do CoolCar.find(:first, :order => 'id asc') From f76e689f0019c0af6dafc2fc67e5b3793e606742 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 27 Jul 2011 13:21:59 -0700 Subject: [PATCH 072/164] contrib app minor tweak --- actionpack/CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 9888be07a92..3b323b3899b 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -2270,7 +2270,7 @@ superclass' view_paths. [Rick Olson] * Update documentation for erb trim syntax. #5651 [matt@mattmargolis.net] -* Pass :id => nil or :class => nil to error_messages_for to supress that html attribute. #3586 [olivier_ansaldi@yahoo.com, sebastien@goetzilla.info] +* Pass :id => nil or :class => nil to error_messages_for to supress that html attribute. #3586 [olivier_ansaldi@yahoo.com] * Reset @html_document between requests so assert_tag works. #4810 [Jarkko Laine, easleydp@gmail.com] @@ -2867,7 +2867,7 @@ superclass' view_paths. [Rick Olson] * Provide support for decimal columns to form helpers. Closes #5672. [Dave Thomas] -* Pass :id => nil or :class => nil to error_messages_for to supress that html attribute. #3586 [olivier_ansaldi@yahoo.com, sebastien@goetzilla.info] +* Pass :id => nil or :class => nil to error_messages_for to supress that html attribute. #3586 [olivier_ansaldi@yahoo.com] * Reset @html_document between requests so assert_tag works. #4810 [Jarkko Laine, easleydp@gmail.com] From a636a9358e184bd1a3e2d2522584247be7045cdf Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 27 Jul 2011 15:09:42 -0500 Subject: [PATCH 073/164] Make Rails.application.assets available in initializers --- actionpack/lib/sprockets/railtie.rb | 82 +++++++++++++---------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 83799d2b4db..c8438e60433 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -11,15 +11,20 @@ module Sprockets load "sprockets/assets.rake" end - # We need to configure this after initialization to ensure we collect - # paths from all engines. This hook is invoked exactly before routes - # are compiled, and so that other Railties have an opportunity to - # register compressors. - config.after_initialize do |app| - assets = app.config.assets - next unless assets.enabled + initializer "sprockets.environment" do |app| + config = app.config + next unless config.assets.enabled - app.assets = asset_environment(app) + require 'sprockets' + + app.assets = Sprockets::Environment.new(app.root.to_s) do |env| + env.static_root = File.join(app.root.join('public'), config.assets.prefix) + env.logger = ::Rails.logger + + if config.assets.cache_store != false + env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache + end + end ActiveSupport.on_load(:action_view) do include ::Sprockets::Helpers::RailsHelper @@ -28,9 +33,32 @@ module Sprockets include ::Sprockets::Helpers::RailsHelper end end + end + + # We need to configure this after initialization to ensure we collect + # paths from all engines. This hook is invoked exactly before routes + # are compiled, and so that other Railties have an opportunity to + # register compressors. + config.after_initialize do |app| + next unless app.assets + config = app.config + + config.assets.paths.each { |path| app.assets.append_path(path) } + + if config.assets.compress + # temporarily hardcode default JS compressor to uglify. Soon, it will work + # the same as SCSS, where a default plugin sets the default. + unless config.assets.js_compressor == false + app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) } + end + + unless config.assets.css_compressor == false + app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) } + end + end app.routes.prepend do - mount app.assets => assets.prefix + mount app.assets => config.assets.prefix end if config.action_controller.perform_caching @@ -39,42 +67,6 @@ module Sprockets end protected - def asset_environment(app) - require "sprockets" - - assets = app.config.assets - - env = Sprockets::Environment.new(app.root.to_s) - - env.static_root = File.join(app.root.join("public"), assets.prefix) - - if env.respond_to?(:append_path) - assets.paths.each { |path| env.append_path(path) } - else - env.paths.concat assets.paths - end - - env.logger = ::Rails.logger - - if env.respond_to?(:cache) && assets.cache_store != false - env.cache = ActiveSupport::Cache.lookup_store(assets.cache_store) || ::Rails.cache - end - - if assets.compress - # temporarily hardcode default JS compressor to uglify. Soon, it will work - # the same as SCSS, where a default plugin sets the default. - unless assets.js_compressor == false - env.js_compressor = LazyCompressor.new { expand_js_compressor(assets.js_compressor || :uglifier) } - end - - unless assets.css_compressor == false - env.css_compressor = LazyCompressor.new { expand_css_compressor(assets.css_compressor) } - end - end - - env - end - def expand_js_compressor(sym) case sym when :closure From 6e671a8536f17b6f23b5251652015ce8c1557f1f Mon Sep 17 00:00:00 2001 From: Grant Hutchins & Peter Jaros Date: Fri, 8 Jul 2011 17:54:15 -0400 Subject: [PATCH 074/164] Let ActiveModel instances define partial paths. Deprecate ActiveModel::Name#partial_path. Now you should call #to_path directly on ActiveModel instances. --- .../lib/action_view/helpers/form_helper.rb | 8 +++- .../action_view/renderer/partial_renderer.rb | 43 ++++++++++--------- actionpack/test/template/form_helper_test.rb | 11 +++++ actionpack/test/template/render_test.rb | 30 +++++++++++++ activemodel/lib/active_model/conversion.rb | 26 ++++++++++- activemodel/lib/active_model/lint.rb | 15 +++++-- activemodel/lib/active_model/naming.rb | 3 ++ activemodel/test/cases/conversion_test.rb | 9 +++- activemodel/test/cases/naming_test.rb | 16 +++++-- activemodel/test/models/helicopter.rb | 3 ++ 10 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 activemodel/test/models/helicopter.rb diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 52a640abf30..7ea2ea2d5a4 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,8 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self.model_name - @model_name ||= Struct.new(:partial_path).new(name.demodulize.underscore.sub!(/_builder$/, '')) + def self.to_path + @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') + end + + def to_path + self.class.to_path end def to_model diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index c0ac332c4e8..fc8a6b3107d 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -206,13 +206,6 @@ module ActionView # <%- end -%> # <% end %> class PartialRenderer < AbstractRenderer #:nodoc: - PARTIAL_NAMES = Hash.new {|h,k| h[k] = {} } - - def initialize(*) - super - @partial_names = PARTIAL_NAMES[@lookup_context.prefixes.first] - end - def render(context, options, block) setup(context, options, block) @@ -359,28 +352,36 @@ module ActionView segments end + PARTIAL_PATHS = {} + def partial_path(object = @object) - @partial_names[object.class.name] ||= begin - object = object.to_model if object.respond_to?(:to_model) - object.class.model_name.partial_path.dup.tap do |partial| - path = @lookup_context.prefixes.first - merge_path_into_partial(path, partial) - end + object = object.to_model if object.respond_to?(:to_model) + + path = if object.respond_to?(:to_path) + object.to_path + else + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + object.class.model_name.partial_path + end + + prefix = @lookup_context.prefixes.first + PARTIAL_PATHS[ [path, prefix] ] ||= path.dup.tap do |object_path| + merge_prefix_into_object_path(prefix, object_path) end end - def merge_path_into_partial(path, partial) - if path.include?(?/) && partial.include?(?/) + def merge_prefix_into_object_path(prefix, object_path) + if prefix.include?(?/) && object_path.include?(?/) overlap = [] - path_array = File.dirname(path).split('/') - partial_array = partial.split('/')[0..-3] # skip model dir & partial + prefix_array = File.dirname(prefix).split('/') + object_path_array = object_path.split('/')[0..-3] # skip model dir & partial - path_array.each_with_index do |dir, index| - overlap << dir if dir == partial_array[index] + prefix_array.each_with_index do |dir, index| + overlap << dir if dir == object_path_array[index] end - partial.gsub!(/^#{overlap.join('/')}\//,'') - partial.insert(0, "#{File.dirname(path)}/") + object_path.gsub!(/^#{overlap.join('/')}\//,'') + object_path.insert(0, "#{File.dirname(prefix)}/") end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index aca2dc9e4d5..71a2c46d92d 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1891,6 +1891,17 @@ class FormHelperTest < ActionView::TestCase assert_equal LabelledFormBuilder, klass end + def test_form_for_with_labelled_builder_path + path = nil + + form_for(@post, :builder => LabelledFormBuilder) do |f| + path = f.to_path + '' + end + + assert_equal 'labelled_form', path + end + class LabelledFormBuilderSubclass < LabelledFormBuilder; end def test_form_for_with_labelled_builder_with_nested_fields_for_with_custom_builder diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 68b2ed45d1f..0b91e550914 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -201,6 +201,36 @@ module RenderTestCases @controller_view.render(customers, :greeting => "Hello") end + class CustomerWithDeprecatedPartialPath + attr_reader :name + + def self.model_name + Struct.new(:partial_path).new("customers/customer") + end + + def initialize(name) + @name = name + end + end + + def test_render_partial_using_object_with_deprecated_partial_path + assert_deprecated(/#model_name.*#partial_path.*#to_path/) do + assert_equal "Hello: nertzy", + @controller_view.render(CustomerWithDeprecatedPartialPath.new("nertzy"), :greeting => "Hello") + end + end + + def test_render_partial_using_collection_with_deprecated_partial_path + assert_deprecated(/#model_name.*#partial_path.*#to_path/) do + customers = [ + CustomerWithDeprecatedPartialPath.new("nertzy"), + CustomerWithDeprecatedPartialPath.new("peeja") + ] + assert_equal "Hello: nertzyHello: peeja", + @controller_view.render(customers, :greeting => "Hello") + end + end + # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 1405b1bfe34..dca1c1aa444 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -1,9 +1,12 @@ +require 'active_support/concern' +require 'active_support/inflector' + module ActiveModel # == Active Model Conversions # - # Handles default conversions: to_model, to_key and to_param. + # Handles default conversions: to_model, to_key, to_param, and to_path. # - # Let's take for example this non persisted object. + # Let's take for example this non-persisted object. # # class ContactMessage # include ActiveModel::Conversion @@ -18,8 +21,11 @@ module ActiveModel # cm.to_model == self # => true # cm.to_key # => nil # cm.to_param # => nil + # cm.to_path # => "contact_messages/contact_message" # module Conversion + extend ActiveSupport::Concern + # If your object is already designed to implement all of the Active Model # you can use the default :to_model implementation, which simply # returns self. @@ -45,5 +51,21 @@ module ActiveModel def to_param persisted? ? to_key.join('-') : nil end + + # Returns a string identifying the path associated with the object. + # ActionPack uses this to find a suitable partial to represent the object. + def to_path + self.class.to_path + end + + module ClassMethods + def to_path + @_to_path ||= begin + element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)) + collection = ActiveSupport::Inflector.tableize(self) + "#{collection}/#{element}".freeze + end + end + end end end diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index b71ef4b22e3..08c2e5fcf35 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -43,6 +43,16 @@ module ActiveModel assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end + # == Responds to to_path + # + # Returns a string giving a relative path. This is used for looking up + # partials. For example, a BlogPost model might return "blog_posts/blog_post" + # + def test_to_path + assert model.respond_to?(:to_path), "The model should respond to to_path" + assert_kind_of String, model.to_path + end + # == Responds to valid? # # Returns a boolean that specifies whether the object is in a valid or invalid @@ -66,15 +76,14 @@ module ActiveModel # == Naming # - # Model.model_name must return a string with some convenience methods as - # :human and :partial_path. Check ActiveModel::Naming for more information. + # Model.model_name must return a string with some convenience methods: + # :human, :singular, and :plural. Check ActiveModel::Naming for more information. # def test_model_naming assert model.class.respond_to?(:model_name), "The model should respond to model_name" model_name = model.class.model_name assert_kind_of String, model_name assert_kind_of String, model_name.human - assert_kind_of String, model_name.partial_path assert_kind_of String, model_name.singular assert_kind_of String, model_name.plural end diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 4c1a82f4133..26fa3062eb6 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -1,12 +1,15 @@ require 'active_support/inflector' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/module/introspection' +require 'active_support/core_ext/module/deprecation' module ActiveModel class Name < String attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key alias_method :cache_key, :collection + deprecate :partial_path => "ActiveModel::Name#partial_path is deprecated. Call #to_path on model instances directly instead." + def initialize(klass, namespace = nil, name = nil) name ||= klass.name super(name) diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb index 7669bf5f65c..2eccc4e56db 100644 --- a/activemodel/test/cases/conversion_test.rb +++ b/activemodel/test/cases/conversion_test.rb @@ -1,5 +1,6 @@ require 'cases/helper' require 'models/contact' +require 'models/helicopter' class ConversionTest < ActiveModel::TestCase test "to_model default implementation returns self" do @@ -22,4 +23,10 @@ class ConversionTest < ActiveModel::TestCase test "to_param default implementation returns a string of ids for persisted records" do assert_equal "1", Contact.new(:id => 1).to_param end -end \ No newline at end of file + + test "to_path default implementation returns a string giving a relative path" do + assert_equal "contacts/contact", Contact.new.to_path + assert_equal "helicopters/helicopter", Helicopter.new.to_path, + "ActiveModel::Conversion#to_path caching should be class-specific" + end +end diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb index f814fcc56c9..bafe4f3c0ca 100644 --- a/activemodel/test/cases/naming_test.rb +++ b/activemodel/test/cases/naming_test.rb @@ -26,7 +26,9 @@ class NamingTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'post/track_backs/track_back', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'post/track_backs/track_back', @model_name.partial_path + end end def test_human @@ -56,7 +58,9 @@ class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'blog/posts/post', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'blog/posts/post', @model_name.partial_path + end end def test_human @@ -98,7 +102,9 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'blog/posts/post', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'blog/posts/post', @model_name.partial_path + end end def test_human @@ -136,7 +142,9 @@ class NamingWithSuppliedModelNameTest < ActiveModel::TestCase end def test_partial_path - assert_equal 'articles/article', @model_name.partial_path + assert_deprecated(/#partial_path.*#to_path/) do + assert_equal 'articles/article', @model_name.partial_path + end end def test_human diff --git a/activemodel/test/models/helicopter.rb b/activemodel/test/models/helicopter.rb new file mode 100644 index 00000000000..a52b6fb4ddb --- /dev/null +++ b/activemodel/test/models/helicopter.rb @@ -0,0 +1,3 @@ +class Helicopter + include ActiveModel::Conversion +end From 91ca214ca0aa431f3cbe90d660c22129b3584bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 28 Jul 2011 09:56:42 +0200 Subject: [PATCH 075/164] Rename class method to_path to _to_path and make it explicit that it is an internal method. --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- activemodel/lib/active_model/conversion.rb | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7ea2ea2d5a4..85dea96bbb7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,12 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self.to_path + def self._to_path @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') end def to_path - self.class.to_path + self.class._to_path end def to_model diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index dca1c1aa444..39977f12c37 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -55,11 +55,13 @@ module ActiveModel # Returns a string identifying the path associated with the object. # ActionPack uses this to find a suitable partial to represent the object. def to_path - self.class.to_path + self.class._to_path end - module ClassMethods - def to_path + module ClassMethods #:nodoc: + # Provide a class level cache for the to_path. This is an + # internal method and should not be accessed directly. + def _to_path #:nodoc: @_to_path ||= begin element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)) collection = ActiveSupport::Inflector.tableize(self) From 554ea3c37b21be56f7f82c1179f2553dc445dc37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 28 Jul 2011 10:01:55 +0200 Subject: [PATCH 076/164] Move the cache to a nested hash which performs better than a hash with array as keys. --- .../action_view/renderer/partial_renderer.rb | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index fc8a6b3107d..f67388b8cfd 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -206,6 +206,14 @@ module ActionView # <%- end -%> # <% end %> class PartialRenderer < AbstractRenderer #:nodoc: + PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} } + + def initialize(*) + super + @context_prefix = @lookup_context.prefixes.first + @partial_names = PARTIAL_NAMES[@context_prefix] + end + def render(context, options, block) setup(context, options, block) @@ -284,6 +292,7 @@ module ActionView else paths.map! { |path| retrieve_variable(path).unshift(path) } end + if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/ raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " + "make sure your partial name starts with a letter or underscore, " + @@ -352,21 +361,18 @@ module ActionView segments end - PARTIAL_PATHS = {} - def partial_path(object = @object) object = object.to_model if object.respond_to?(:to_model) path = if object.respond_to?(:to_path) - object.to_path - else - ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." - object.class.model_name.partial_path - end + object.to_path + else + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + object.class.model_name.partial_path + end - prefix = @lookup_context.prefixes.first - PARTIAL_PATHS[ [path, prefix] ] ||= path.dup.tap do |object_path| - merge_prefix_into_object_path(prefix, object_path) + @partial_names[path] ||= path.dup.tap do |object_path| + merge_prefix_into_object_path(@context_prefix, object_path) end end From 66fdfbc2d590672b2234358a8ab8bba608a192ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 28 Jul 2011 10:05:17 +0200 Subject: [PATCH 077/164] Update CHANGELOG. --- activemodel/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG index c38349b95e9..81386667c2c 100644 --- a/activemodel/CHANGELOG +++ b/activemodel/CHANGELOG @@ -1,3 +1,5 @@ +* Deprecate "Model.model_name.partial_path" in favor of "model.to_path" [Grant Hutchins] + * Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior [Bogdan Gusiev] *Rails 3.1.0 (unreleased)* From bec59779326daa35aab483fa8b95c0f87440fede Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 28 Jul 2011 13:14:11 +0100 Subject: [PATCH 078/164] Revert "Merge pull request #2309 from smasry/master" This reverts commit 9d396ee8195e31f646e0b89158ed96f4db4ab38f, reversing changes made to fa2bfd832c1d1e997d93c2269a485cc74782c86d. Reason: the change broke the build. --- activerecord/lib/active_record/relation/query_methods.rb | 2 +- activerecord/test/cases/relations_test.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 3a7b245c51e..1654ae1eace 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -312,7 +312,7 @@ module ActiveRecord when String, Symbol o.to_s.split(',').collect do |s| s.strip! - (s if s =~ /\(/) || s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') + s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') end else o diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 8a2cf0ef851..821da91f0ab 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -911,11 +911,6 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name end - def test_order_with_function_and_last - authors = Author.scoped - assert_equal authors(:bob), authors.order( "id asc, MAX( organization_id, owned_essay_id)" ).last - end - def test_order_using_scoping car1 = CoolCar.order('id DESC').scoping do CoolCar.find(:first, :order => 'id asc') From b82e226b7fb2e4dd443a4016f586ce06516d3d85 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 17:25:32 -0400 Subject: [PATCH 079/164] Expanded meta-data in gemspec to include author, email, etc.; Defaults include "TODO" to prevent gems from being built without review. --- .../rails/plugin_new/templates/%name%.gemspec | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index eb1a1e5054c..b469edd7728 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,12 +1,16 @@ # Provide a simple gemspec so you can easily use your # project in your rails apps through git. Gem::Specification.new do |s| - s.name = "<%= name %>" - s.summary = "Insert <%= camelized %> summary." - s.description = "Insert <%= camelized %> description." + s.name = "<%= name %>" + s.version = "0.0.1" + s.authors = ["TODO: Your name"] + s.email = ["TODO: Your email"] + s.homepage = "TODO" + s.summary = "TODO: Summary of <%= camelized %>." + s.description = "TODO: Description of <%= camelized %>." + s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> - s.version = "0.0.1" end From f9eadb8b432f220865c5205a81e6dd5af90f35b5 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 18:51:44 -0400 Subject: [PATCH 080/164] Extracted version from gemspec and placed it in its own file. This is consistent with the approach taken by "bundle gem", and is expected by gems such as svenfuchs/gem-release which can be used to bump / tag versions of gems. --- .../rails/plugin_new/plugin_new_generator.rb | 1 + .../rails/plugin_new/templates/%name%.gemspec | 10 +++++++--- .../rails/plugin_new/templates/lib/%name%/version.rb | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 7c0a2b9cf42..56b15877600 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -46,6 +46,7 @@ module Rails def lib template "lib/%name%.rb" template "lib/tasks/%name%_tasks.rake" + template "lib/%name%/version.rb" if full? template "lib/%name%/engine.rb" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b469edd7728..736d114901b 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -1,8 +1,12 @@ -# Provide a simple gemspec so you can easily use your -# project in your rails apps through git. +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "<%= name %>/version" + +# Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "<%= name %>" - s.version = "0.0.1" + s.version = <%= camelized %>::VERSION s.authors = ["TODO: Your name"] s.email = ["TODO: Your email"] s.homepage = "TODO" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb new file mode 100644 index 00000000000..ef07ef2e196 --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb @@ -0,0 +1,3 @@ +module <%= camelized %> + VERSION = "0.0.1" +end From 47cc214600b9f099140a1df34bc68432ad1d2b23 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 21:54:45 -0400 Subject: [PATCH 081/164] Moved dependencies from Gemfile to gemspec to eliminate redundant declarations. --- .../rails/plugin_new/templates/%name%.gemspec | 11 ++++++++++ .../rails/plugin_new/templates/Gemfile | 20 ++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index 736d114901b..b8d68ad0bc8 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -17,4 +17,15 @@ Gem::Specification.new do |s| <% unless options.skip_test_unit? -%> s.test_files = Dir["test/**/*"] <% end -%> + + # If your gem is dependent on a specific version (or higher) of Rails: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" + +<% unless options[:skip_javascript] || !full? -%> + # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" + +<% end -%> + # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 7e6eb183411..160baa69065 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -1,14 +1,20 @@ source "http://rubygems.org" +# Declare your gem's dependencies in <%= name %>.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +<% if options.dev? || options.edge? -%> +# Your gem is dependent on dev or edge Rails. Once you can lock this +# dependency down to a specific version, move it to your gemspec. <%= rails_gemfile_entry -%> -<% if full? -%> -<%= database_gemfile_entry -%> <% end -%> - -<% if mountable? -%> -<%= javascript_gemfile_entry -%> -<% end -%> - # To use debugger # <%= ruby_debugger_gemfile_entry %> \ No newline at end of file From 60f593dc548e5a62cd1a6de7512eaf344beff788 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 11:48:21 -0300 Subject: [PATCH 082/164] Tidy up a bit plugin new gemspec --- .../rails/plugin_new/templates/%name%.gemspec | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index b8d68ad0bc8..8588e880770 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -18,14 +18,10 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] <% end -%> - # If your gem is dependent on a specific version (or higher) of Rails: - <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", ">= <%= Rails::VERSION::STRING %>" - -<% unless options[:skip_javascript] || !full? -%> - # If your gem contains any <%= "#{options[:javascript]}-specific" %> javascript: + <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>" +<% if full? && !options[:skip_javascript] -%> # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" - <% end -%> - # Declare development-specific dependencies: + s.add_development_dependency "<%= gem_for_database %>" end From b50dfce6018bb5d380a6faa18d93cec41cf458ca Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Thu, 28 Jul 2011 21:14:29 +0530 Subject: [PATCH 083/164] pluging generator test fix --- .../test/generators/plugin_new_generator_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 0ccb2ae9dad..e6ea1cbc33b 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -69,13 +69,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode run_generator([destination_root, "--full"]) assert_file "test/dummy/config/database.yml", /sqlite/ - assert_file "Gemfile", /^gem\s+["']sqlite3["']$/ + assert_file "bukkits.gemspec", /sqlite3/ end def test_config_another_database run_generator([destination_root, "-d", "mysql", "--full"]) assert_file "test/dummy/config/database.yml", /mysql/ - assert_file "Gemfile", /^gem\s+["']mysql2["']$/ + assert_file "bukkits.gemspec", /mysql/ end def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given @@ -117,8 +117,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'jquery-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/jquery-rails/, contents) end end @@ -128,8 +128,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match %r{^//= require prototype}, contents assert_match %r{^//= require prototype_ujs}, contents end - assert_file 'Gemfile' do |contents| - assert_match(/^gem 'prototype-rails'/, contents) + assert_file 'bukkits.gemspec' do |contents| + assert_match(/prototype-rails/, contents) end end @@ -205,10 +205,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_gemspec run_generator - assert_file "bukkits.gemspec", /s.name = "bukkits"/ + assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/ assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*"\]/ assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/ - assert_file "bukkits.gemspec", /s.version = "0.0.1"/ + assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/ end def test_usage_of_engine_commands From c4cf9073a15c7185ee7da345c41e341009a7a690 Mon Sep 17 00:00:00 2001 From: Grant Hutchins Date: Thu, 28 Jul 2011 13:38:28 -0300 Subject: [PATCH 084/164] Give attribution to Peter Jaros for the patch we paired on. --- activemodel/CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG index 81386667c2c..597f5ab3956 100644 --- a/activemodel/CHANGELOG +++ b/activemodel/CHANGELOG @@ -1,4 +1,4 @@ -* Deprecate "Model.model_name.partial_path" in favor of "model.to_path" [Grant Hutchins] +* Deprecate "Model.model_name.partial_path" in favor of "model.to_path" [Grant Hutchins, Peter Jaros] * Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior [Bogdan Gusiev] From 37b30d4b4eb983579f083627b3faa065be527a61 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 28 Jul 2011 20:00:48 +0200 Subject: [PATCH 085/164] There is no need to be destructive with the passed-in options. This fixes a bug that is caused by Resource/SingletonResource mangling resource options when using inline "multi"-resource declarations. --- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++++++------ actionpack/test/controller/resources_test.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 53374949ae2..a53a2d98d34 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -872,9 +872,9 @@ module ActionDispatch def initialize(entities, options = {}) @name = entities.to_s - @path = (options.delete(:path) || @name).to_s - @controller = (options.delete(:controller) || @name).to_s - @as = options.delete(:as) + @path = (options[:path] || @name).to_s + @controller = (options[:controller] || @name).to_s + @as = options[:as] @options = options end @@ -938,9 +938,9 @@ module ActionDispatch def initialize(entities, options) @as = nil @name = entities.to_s - @path = (options.delete(:path) || @name).to_s - @controller = (options.delete(:controller) || plural).to_s - @as = options.delete(:as) + @path = (options[:path] || @name).to_s + @controller = (options[:controller] || plural).to_s + @as = options[:as] @options = options end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 6ea492cf8b6..3b1b5fc3ec5 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -91,6 +91,15 @@ class ResourcesTest < ActionController::TestCase end end + def test_multiple_resources_with_options + expected_options = {:controller => 'threads', :action => 'index'} + + with_restful_routing :messages, :comments, expected_options.slice(:controller) do + assert_recognizes(expected_options, :path => 'comments') + assert_recognizes(expected_options, :path => 'messages') + end + end + def test_with_custom_conditions with_restful_routing :messages, :conditions => { :subdomain => 'app' } do assert @routes.recognize_path("/messages", :method => :get, :subdomain => 'app') From a53ef972066503e601e023748949b6668fce51e3 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 28 Jul 2011 20:02:21 +0200 Subject: [PATCH 086/164] Make use of the inherited initializer. --- actionpack/lib/action_dispatch/routing/mapper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a53a2d98d34..bd04f48c007 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -936,12 +936,11 @@ module ActionDispatch DEFAULT_ACTIONS = [:show, :create, :update, :destroy, :new, :edit] def initialize(entities, options) + super + @as = nil - @name = entities.to_s - @path = (options[:path] || @name).to_s @controller = (options[:controller] || plural).to_s @as = options[:as] - @options = options end def plural From 018b1315b561d9c2e6c95151f8145f21cac6eb91 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Thu, 28 Jul 2011 18:45:43 +0300 Subject: [PATCH 087/164] We don't need to require erb here. --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index bd04f48c007..a5c1501f614 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,4 +1,3 @@ -require 'erb' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/inclusion' From 651a9c93be23651bf33b53813f1124aa69ae53de Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 28 Jul 2011 16:46:39 -0300 Subject: [PATCH 088/164] Tidy up --- railties/lib/rails/generators/app_base.rb | 6 ++++-- railties/lib/rails/generators/rails/app/templates/Gemfile | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index bbdd000ad9f..21a2ae4e28f 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -200,9 +200,11 @@ module Rails def assets_gemfile_entry <<-GEMFILE.strip_heredoc + # Gems used only for assets and not required + # in production environments by default. group :assets do - gem 'sass-rails', :git => 'git://github.com/rails/sass-rails' - gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails' + gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git' + gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git' gem 'uglifier' end GEMFILE diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 88eea40b1bf..c83e7ddf808 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -7,10 +7,7 @@ source 'http://rubygems.org' <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%> <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> -# Gems used only for assets and not required -# in production environments by default. <%= assets_gemfile_entry %> - <%= javascript_gemfile_entry %> # Use unicorn as the web server From bfde0636dd1b1252436ea3c42ddae2eecd2e554b Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 26 Jul 2011 15:41:08 -0400 Subject: [PATCH 089/164] Include empty app/mailers directory in mountable and full plugins --- .../rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + .../rails/plugin_new/templates/app/mailers/.empty_directory | 0 2 files changed, 1 insertion(+) create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 56b15877600..c46422437d3 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -19,6 +19,7 @@ module Rails empty_directory_with_gitkeep "app/controllers" empty_directory_with_gitkeep "app/views" empty_directory_with_gitkeep "app/helpers" + empty_directory_with_gitkeep "app/mailers" empty_directory_with_gitkeep "app/assets/images/#{name}" end end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory b/railties/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory new file mode 100644 index 00000000000..e69de29bb2d From 1deb0253aee8ea96eaa118dba7cf8eaa42dcbeba Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 29 Jul 2011 22:06:36 +0530 Subject: [PATCH 090/164] Test add for plugin new generator generate mailer --- railties/test/generators/plugin_new_generator_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index e6ea1cbc33b..19e80eee896 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -25,10 +25,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase # brings setup, teardown, and some tests include SharedGeneratorTests - def default_files - ::DEFAULT_PLUGIN_FILES - end - def test_invalid_plugin_name_raises_an_error content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] } assert_equal "Invalid plugin name 43-things. Please give a name which does not start with numbers.\n", content @@ -176,6 +172,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers" assert_file "app/views" assert_file "app/helpers" + assert_file "app/mailers" assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ @@ -257,6 +254,10 @@ protected silence(:stdout){ generator.send(*args, &block) } end +protected + def default_files + ::DEFAULT_PLUGIN_FILES + end end class CustomPluginGeneratorTest < Rails::Generators::TestCase From 9d5340e7094444a35c48035d9f111617806d519c Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Fri, 29 Jul 2011 13:06:45 -0400 Subject: [PATCH 091/164] Reset @dirty to false when slicing an instance of SafeBuffer --- .../lib/active_support/core_ext/string/output_safety.rb | 6 ++++++ activesupport/test/safe_buffer_test.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 3bf4edbdef1..6d6c4912bb9 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -86,6 +86,12 @@ module ActiveSupport #:nodoc: end end + def[](*args) + new_safe_buffer = super + new_safe_buffer.instance_eval { @dirty = false } + new_safe_buffer + end + def safe_concat(value) raise SafeConcatError if dirty? original_concat(value) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 7662e9b765b..8f77999d251 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -106,4 +106,10 @@ class SafeBufferTest < ActiveSupport::TestCase test "should not fail if the returned object is not a string" do assert_kind_of NilClass, @buffer.slice("chipchop") end + + test "Should initialize @dirty to false for new instance when sliced" do + dirty = @buffer[0,0].send(:dirty?) + assert_not_nil dirty + assert !dirty + end end From 55fb1780a0695bc60ba7ab91084026d45c36b43e Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Fri, 29 Jul 2011 12:08:35 -0400 Subject: [PATCH 092/164] Instead of removing the instance variable just set it to nil, resolves the warnings because of a missing instance variable --- actionpack/test/template/sprockets_helper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index b9161b62c54..f4b5344d63f 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -97,7 +97,7 @@ class SprocketsHelperTest < ActionView::TestCase end test "stylesheets served without a controller in scope cannot access the request" do - remove_instance_variable("@controller") + @controller = nil @config.action_controller.asset_host = Proc.new do |asset, request| fail "This should not have been called." end @@ -107,7 +107,7 @@ class SprocketsHelperTest < ActionView::TestCase end test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do - remove_instance_variable("@controller") + @controller = nil @config.action_controller.asset_host = "assets-%d.example.com" @config.action_controller.default_asset_host_protocol = :request @config.action_controller.perform_caching = true From 17a66a8ddc5a2ee8263d1dcc86a032322cb8e615 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 29 Jul 2011 12:23:37 -0700 Subject: [PATCH 093/164] dump IO encoding value along with schema.rb so the file can be reloaded. fixes #1592 --- activerecord/lib/active_record/schema_dumper.rb | 4 ++++ activerecord/test/cases/schema_dumper_test.rb | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 19585f6214b..6fe305f8431 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -40,6 +40,10 @@ module ActiveRecord def header(stream) define_params = @version ? ":version => #{@version}" : "" + if stream.respond_to?(:external_encoding) + stream.puts "# encoding: #{stream.external_encoding.name}" + end + stream.puts <
Date: Fri, 29 Jul 2011 12:28:12 -0700 Subject: [PATCH 094/164] default writing the schema file as utf-8 --- activerecord/lib/active_record/railties/databases.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 0ee7e20cf1b..ec00f7faad6 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -341,7 +341,8 @@ db_namespace = namespace :db do desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR' task :dump => :load_config do require 'active_record/schema_dumper' - File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file| + filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb" + File.open(filename, "w:utf-8") do |file| ActiveRecord::Base.establish_connection(Rails.env) ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end From f85b9662699d7b77fd9ad4e1303565fdaaed0379 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 29 Jul 2011 14:38:57 -0700 Subject: [PATCH 095/164] delay backtrace scrubbing until we actually raise an exception. fixes #1936 --- activesupport/lib/active_support/dependencies.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 8cd4d15e4c3..3f6c93e860e 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -478,10 +478,6 @@ module ActiveSupport #:nodoc: qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore - trace = caller.reject {|l| l.starts_with? __FILE__ } - name_error = NameError.new("uninitialized constant #{qualified_name}") - name_error.set_backtrace(trace) - file_path = search_for_file(path_suffix) if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load @@ -500,11 +496,12 @@ module ActiveSupport #:nodoc: return parent.const_missing(const_name) rescue NameError => e raise unless e.missing_name? qualified_name_for(parent, const_name) - raise name_error end - else - raise name_error end + + raise NameError, + "uninitialized constant #{qualified_name}", + caller.reject {|l| l.starts_with? __FILE__ } end # Remove the constants that have been autoloaded, and those that have been From 48fce08bb3606b989a20f5e60f9243e627099339 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Fri, 29 Jul 2011 17:27:45 -0500 Subject: [PATCH 096/164] Change ActiveSupport::Cache behavior to always return duplicate objects instead of frozen objects. --- activesupport/lib/active_support/cache.rb | 27 +++++++++-------------- activesupport/test/caching_test.rb | 17 ++++++++------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ac88c82709c..2d2264e58a0 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -557,15 +557,14 @@ module ActiveSupport @expires_in = options[:expires_in] @expires_in = @expires_in.to_f if @expires_in @created_at = Time.now.to_f - if defined?(value) - if should_compress?(value, options) - @value = Zlib::Deflate.deflate(Marshal.dump(value)) - @compressed = true - else - @value = value - end - else + if value.nil? @value = nil + else + @value = Marshal.dump(value) + if should_compress?(value, options) + @value = Zlib::Deflate.deflate(@value) + @compressed = true + end end end @@ -576,12 +575,8 @@ module ActiveSupport # Get the value stored in the cache. def value - if defined?(@value) - val = compressed? ? Marshal.load(Zlib::Inflate.inflate(@value)) : @value - unless val.frozen? - val.freeze rescue nil - end - val + if @value + Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value) end end @@ -614,10 +609,8 @@ module ActiveSupport def size if @value.nil? 0 - elsif @value.respond_to?(:bytesize) - @value.bytesize else - Marshal.dump(@value).bytesize + @value.bytesize end end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 402c6695aaa..dff3d6ef0d7 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -204,7 +204,7 @@ module CacheStoreBehavior @cache.write('foo', 'bar', :compress => true) raw_value = @cache.send(:read_entry, 'foo', {}).raw_value assert_equal 'bar', @cache.read('foo') - assert_equal 'bar', raw_value + assert_equal 'bar', Marshal.load(raw_value) end def test_read_and_write_compressed_large_data @@ -270,10 +270,12 @@ module CacheStoreBehavior assert !@cache.exist?('foo') end - def test_store_objects_should_be_immutable + def test_read_should_return_a_different_object_id_each_time_it_is_called @cache.write('foo', 'bar') - assert_raise(ActiveSupport::FrozenObjectError) { @cache.read('foo').gsub!(/.*/, 'baz') } - assert_equal 'bar', @cache.read('foo') + assert_not_equal @cache.read('foo').object_id, @cache.read('foo').object_id + value = @cache.read('foo') + value << 'bingo' + assert_not_equal value, @cache.read('foo') end def test_original_store_objects_should_not_be_immutable @@ -551,7 +553,8 @@ end class MemoryStoreTest < ActiveSupport::TestCase def setup - @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => 100) + @record_size = Marshal.dump("aaaaaaaaaa").bytesize + @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10) end include CacheStoreBehavior @@ -566,7 +569,7 @@ class MemoryStoreTest < ActiveSupport::TestCase @cache.write(5, "eeeeeeeeee") && sleep(0.001) @cache.read(2) && sleep(0.001) @cache.read(4) - @cache.prune(30) + @cache.prune(@record_size * 3) assert_equal true, @cache.exist?(5) assert_equal true, @cache.exist?(4) assert_equal false, @cache.exist?(3) @@ -719,7 +722,7 @@ class CacheEntryTest < ActiveSupport::TestCase def test_non_compress_values entry = ActiveSupport::Cache::Entry.new("value") assert_equal "value", entry.value - assert_equal "value", entry.raw_value + assert_equal "value", Marshal.load(entry.raw_value) assert_equal false, entry.compressed? end end From 759815547bf85167e97b3cdbff2f1e8d33e218e4 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 29 Jul 2011 17:07:27 -0700 Subject: [PATCH 097/164] remove redundant calls to stringify_keys --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 822686b09d0..79f07400b28 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -417,7 +417,7 @@ module ActionView options["data-confirm"] = confirm end - tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys) + tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options) end # Creates a button element that defines a submit button, @@ -503,7 +503,7 @@ module ActionView options["data-confirm"] = confirm end - tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys) + tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options) end # Creates a field set for grouping HTML form elements. From 3d87d01dad08f0ff84d38b1211ba8de0364e0efb Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Sat, 30 Jul 2011 12:08:26 -0400 Subject: [PATCH 098/164] Resolve warnings by instantizing @attrubtes as nil --- activerecord/test/cases/attribute_methods_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index b0896fb236e..dbf5a1ba76e 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -113,6 +113,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase # by inspecting it. def test_allocated_object_can_be_inspected topic = Topic.allocate + topic.instance_eval { @attributes = nil } assert_nothing_raised { topic.inspect } assert topic.inspect, "#" end From 67d76f43a047a24c3bfcdde7a81257e5cdfa65be Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 29 Jul 2011 23:05:40 +0530 Subject: [PATCH 099/164] Covering more files in test for plugin new generator. --- railties/test/generators/plugin_new_generator_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 19e80eee896..b49945f153d 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -7,11 +7,13 @@ DEFAULT_PLUGIN_FILES = %w( .gitignore Gemfile Rakefile + README.rdoc bukkits.gemspec MIT-LICENSE lib lib/bukkits.rb lib/tasks/bukkits_tasks.rake + lib/bukkits/version.rb test/bukkits_test.rb test/test_helper.rb test/dummy From 3d2bda9601d3a45f62ad5b7930e453bd1eb01583 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 30 Jul 2011 09:19:58 +0530 Subject: [PATCH 100/164] magic comment test only if encoding_aware?. --- activerecord/test/cases/schema_dumper_test.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 5da3f59a1f3..99e7ef6c039 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -14,9 +14,10 @@ class SchemaDumperTest < ActiveRecord::TestCase @stream.string end - def test_magic_comment - skip "only test magic comments on 1.9" if RUBY_VERSION < '1.9' - assert_match "# encoding: #{@stream.external_encoding.name}", standard_dump + if "string".encoding_aware? + def test_magic_comment + assert_match "# encoding: #{@stream.external_encoding.name}", standard_dump + end end def test_schema_dump From e1b546464ecf20466fb38a93eea9769945774eee Mon Sep 17 00:00:00 2001 From: Brad Ediger Date: Sun, 31 Jul 2011 07:38:38 -0500 Subject: [PATCH 101/164] remove_possible_method: test if method exists This speeds up remove_possible_method substantially since it doesn't have to rescue a NameError in the common case. Closes #2346. --- .../lib/active_support/core_ext/module/remove_method.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb index 07d7c9b0183..b76bc16ee11 100644 --- a/activesupport/lib/active_support/core_ext/module/remove_method.rb +++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb @@ -1,11 +1,16 @@ class Module def remove_possible_method(method) - remove_method(method) + if method_defined?(method) || private_method_defined?(method) + remove_method(method) + end rescue NameError + # If the requested method is defined on a superclass or included module, + # method_defined? returns true but remove_method throws a NameError. + # Ignore this. end def redefine_method(method, &block) remove_possible_method(method) define_method(method, &block) end -end \ No newline at end of file +end From 076afd0e22caaa307f5fddeca8a5749586654852 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 31 Jul 2011 21:39:10 +0530 Subject: [PATCH 102/164] fixes #2368. rake about not showing the middleware, db adapter and db schema version --- railties/lib/rails/tasks/misc.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index 833fcb6f72b..8b4775d1d3b 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -14,7 +14,7 @@ task :secret do end desc 'List versions of all Rails frameworks and the environment' -task :about do +task :about => :environment do puts Rails::Info end From 665a89ed4f2b6024d36183b9442f9e55568611ba Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sun, 31 Jul 2011 18:05:05 +0530 Subject: [PATCH 103/164] remove extra require for 'stringio' as it is required in helper.rb --- activerecord/test/cases/schema_dumper_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 99e7ef6c039..71ff727b7f9 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -1,5 +1,4 @@ require "cases/helper" -require 'stringio' class SchemaDumperTest < ActiveRecord::TestCase From 9d0b376bbf44c5515ab0f1e72d4f4e466f315ef2 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Sun, 31 Jul 2011 23:12:28 +0530 Subject: [PATCH 104/164] remove extra require for 'active_support/dependencies' as it is required in abstract_unit.rb --- actionpack/test/controller/routing_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index aa9d1934363..b693fbec2b7 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1,7 +1,6 @@ # encoding: utf-8 require 'abstract_unit' require 'controller/fake_controllers' -require 'active_support/dependencies' require 'active_support/core_ext/object/with_options' class MilestonesController < ActionController::Base From 30ef55de66decbbcf6475917c741c42fb738718b Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sun, 31 Jul 2011 23:36:21 +0530 Subject: [PATCH 105/164] Removing extra requires from the test. Already loaded in abstract_unit. --- actionpack/test/controller/helper_test.rb | 1 - activesupport/test/core_ext/string_ext_test.rb | 1 - activesupport/test/dependencies_test.rb | 1 - activesupport/test/json/decoding_test.rb | 1 - activesupport/test/multibyte_utils_test.rb | 1 - activesupport/test/test_test.rb | 1 - 6 files changed, 6 deletions(-) diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 584d73668a6..35a87c1aaed 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'active_support/core_ext/kernel/reporting' ActionController::Base.helpers_path = File.expand_path('../../fixtures/helpers', __FILE__) diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 18a86e08f5d..a4bba056df3 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -6,7 +6,6 @@ require 'inflector_test_cases' require 'active_support/inflector' require 'active_support/core_ext/string' require 'active_support/time' -require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/string/strip' class StringInflectionsTest < Test::Unit::TestCase diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index b4edf0f51d0..b0e96731cc8 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' require 'pp' require 'active_support/dependencies' -require 'active_support/core_ext/kernel/reporting' module ModuleWithMissing mattr_accessor :missing_count diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 201729a6c23..d1454902e58 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -2,7 +2,6 @@ require 'abstract_unit' require 'active_support/json' require 'active_support/time' -require 'active_support/core_ext/kernel/reporting' class TestJSONDecoding < ActiveSupport::TestCase TESTS = { diff --git a/activesupport/test/multibyte_utils_test.rb b/activesupport/test/multibyte_utils_test.rb index 1dff944922b..0a2f20d2821 100644 --- a/activesupport/test/multibyte_utils_test.rb +++ b/activesupport/test/multibyte_utils_test.rb @@ -2,7 +2,6 @@ require 'abstract_unit' require 'multibyte_test_helpers' -require 'active_support/core_ext/kernel/reporting' class MultibyteUtilsTest < ActiveSupport::TestCase include MultibyteTestHelpers diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 5bd995aa327..f880052786b 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'active_support/core_ext/kernel/reporting' class AssertDifferenceTest < ActiveSupport::TestCase def setup From b6b6e81a5c29d4adb3007659ca30e02444ad0c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 1 Aug 2011 11:42:00 +0200 Subject: [PATCH 106/164] Rename new method to_path to to_partial_path to avoid conflicts with File#to_path and similar. --- actionpack/lib/action_view/helpers/form_helper.rb | 8 ++++---- .../lib/action_view/renderer/partial_renderer.rb | 6 +++--- actionpack/test/template/form_helper_test.rb | 2 +- actionpack/test/template/render_test.rb | 4 ++-- activemodel/CHANGELOG | 2 +- activemodel/lib/active_model/conversion.rb | 10 +++++----- activemodel/lib/active_model/lint.rb | 8 ++++---- activemodel/lib/active_model/naming.rb | 2 +- activemodel/test/cases/conversion_test.rb | 6 +++--- activemodel/test/cases/naming_test.rb | 8 ++++---- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 85dea96bbb7..f22c4666669 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1227,12 +1227,12 @@ module ActionView parent_builder.multipart = multipart if parent_builder end - def self._to_path - @_to_path ||= name.demodulize.underscore.sub!(/_builder$/, '') + def self._to_partial_path + @_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, '') end - def to_path - self.class._to_path + def to_partial_path + self.class._to_partial_path end def to_model diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index f67388b8cfd..cd0f7054a9a 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -364,10 +364,10 @@ module ActionView def partial_path(object = @object) object = object.to_model if object.respond_to?(:to_model) - path = if object.respond_to?(:to_path) - object.to_path + path = if object.respond_to?(:to_partial_path) + object.to_partial_path else - ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead." + ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead." object.class.model_name.partial_path end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 71a2c46d92d..f898c22e1ec 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1895,7 +1895,7 @@ class FormHelperTest < ActionView::TestCase path = nil form_for(@post, :builder => LabelledFormBuilder) do |f| - path = f.to_path + path = f.to_partial_path '' end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 0b91e550914..6f02f8662dc 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -214,14 +214,14 @@ module RenderTestCases end def test_render_partial_using_object_with_deprecated_partial_path - assert_deprecated(/#model_name.*#partial_path.*#to_path/) do + assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do assert_equal "Hello: nertzy", @controller_view.render(CustomerWithDeprecatedPartialPath.new("nertzy"), :greeting => "Hello") end end def test_render_partial_using_collection_with_deprecated_partial_path - assert_deprecated(/#model_name.*#partial_path.*#to_path/) do + assert_deprecated(/#model_name.*#partial_path.*#to_partial_path/) do customers = [ CustomerWithDeprecatedPartialPath.new("nertzy"), CustomerWithDeprecatedPartialPath.new("peeja") diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG index 597f5ab3956..9b7d2d026d6 100644 --- a/activemodel/CHANGELOG +++ b/activemodel/CHANGELOG @@ -1,4 +1,4 @@ -* Deprecate "Model.model_name.partial_path" in favor of "model.to_path" [Grant Hutchins, Peter Jaros] +* Deprecate "Model.model_name.partial_path" in favor of "model.to_partial_path" [Grant Hutchins, Peter Jaros] * Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior [Bogdan Gusiev] diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 39977f12c37..80a3ba51c35 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -4,7 +4,7 @@ require 'active_support/inflector' module ActiveModel # == Active Model Conversions # - # Handles default conversions: to_model, to_key, to_param, and to_path. + # Handles default conversions: to_model, to_key, to_param, and to_partial_path. # # Let's take for example this non-persisted object. # @@ -54,15 +54,15 @@ module ActiveModel # Returns a string identifying the path associated with the object. # ActionPack uses this to find a suitable partial to represent the object. - def to_path - self.class._to_path + def to_partial_path + self.class._to_partial_path end module ClassMethods #:nodoc: # Provide a class level cache for the to_path. This is an # internal method and should not be accessed directly. - def _to_path #:nodoc: - @_to_path ||= begin + def _to_partial_path #:nodoc: + @_to_partial_path ||= begin element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)) collection = ActiveSupport::Inflector.tableize(self) "#{collection}/#{element}".freeze diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 08c2e5fcf35..bfe7ea1869f 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -43,14 +43,14 @@ module ActiveModel assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end - # == Responds to to_path + # == Responds to to_partial_path # # Returns a string giving a relative path. This is used for looking up # partials. For example, a BlogPost model might return "blog_posts/blog_post" # - def test_to_path - assert model.respond_to?(:to_path), "The model should respond to to_path" - assert_kind_of String, model.to_path + def test_to_partial_path + assert model.respond_to?(:to_partial_path), "The model should respond to to_partial_path" + assert_kind_of String, model.to_partial_path end # == Responds to valid? diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 26fa3062eb6..f16459ede2a 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -8,7 +8,7 @@ module ActiveModel attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key alias_method :cache_key, :collection - deprecate :partial_path => "ActiveModel::Name#partial_path is deprecated. Call #to_path on model instances directly instead." + deprecate :partial_path => "ActiveModel::Name#partial_path is deprecated. Call #to_partial_path on model instances directly instead." def initialize(klass, namespace = nil, name = nil) name ||= klass.name diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb index 2eccc4e56db..24552bcaf20 100644 --- a/activemodel/test/cases/conversion_test.rb +++ b/activemodel/test/cases/conversion_test.rb @@ -25,8 +25,8 @@ class ConversionTest < ActiveModel::TestCase end test "to_path default implementation returns a string giving a relative path" do - assert_equal "contacts/contact", Contact.new.to_path - assert_equal "helicopters/helicopter", Helicopter.new.to_path, - "ActiveModel::Conversion#to_path caching should be class-specific" + assert_equal "contacts/contact", Contact.new.to_partial_path + assert_equal "helicopters/helicopter", Helicopter.new.to_partial_path, + "ActiveModel::Conversion#to_partial_path caching should be class-specific" end end diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb index bafe4f3c0ca..1777ce2aaef 100644 --- a/activemodel/test/cases/naming_test.rb +++ b/activemodel/test/cases/naming_test.rb @@ -26,7 +26,7 @@ class NamingTest < ActiveModel::TestCase end def test_partial_path - assert_deprecated(/#partial_path.*#to_path/) do + assert_deprecated(/#partial_path.*#to_partial_path/) do assert_equal 'post/track_backs/track_back', @model_name.partial_path end end @@ -58,7 +58,7 @@ class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_deprecated(/#partial_path.*#to_path/) do + assert_deprecated(/#partial_path.*#to_partial_path/) do assert_equal 'blog/posts/post', @model_name.partial_path end end @@ -102,7 +102,7 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase end def test_partial_path - assert_deprecated(/#partial_path.*#to_path/) do + assert_deprecated(/#partial_path.*#to_partial_path/) do assert_equal 'blog/posts/post', @model_name.partial_path end end @@ -142,7 +142,7 @@ class NamingWithSuppliedModelNameTest < ActiveModel::TestCase end def test_partial_path - assert_deprecated(/#partial_path.*#to_path/) do + assert_deprecated(/#partial_path.*#to_partial_path/) do assert_equal 'articles/article', @model_name.partial_path end end From 5f3265c4714efd697cb71015489a9c59d1129440 Mon Sep 17 00:00:00 2001 From: thoefer Date: Mon, 1 Aug 2011 11:28:31 +0200 Subject: [PATCH 107/164] Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/action_controller/metal/testing.rb | 5 ++++ actionpack/lib/action_controller/test_case.rb | 1 + .../default_url_options_with_filter_test.rb | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 actionpack/test/controller/default_url_options_with_filter_test.rb diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index f4efeb33ba8..d1813ee7457 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -4,6 +4,11 @@ module ActionController include RackDelegation + def recycle! + @_url_options = nil + end + + # TODO: Clean this up def process_with_new_base_test(request, response) @_request = request diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 45bb641aee5..c8cf04bb69e 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -450,6 +450,7 @@ module ActionController @controller.params.merge!(parameters) build_request_uri(action, parameters) @controller.class.class_eval { include Testing } + @controller.recycle! @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? diff --git a/actionpack/test/controller/default_url_options_with_filter_test.rb b/actionpack/test/controller/default_url_options_with_filter_test.rb new file mode 100644 index 00000000000..3bbb981040e --- /dev/null +++ b/actionpack/test/controller/default_url_options_with_filter_test.rb @@ -0,0 +1,29 @@ +require 'abstract_unit' + + +class ControllerWithBeforeFilterAndDefaultUrlOptions < ActionController::Base + + before_filter { I18n.locale = params[:locale] } + after_filter { I18n.locale = "en" } + + def target + render :text => "final response" + end + + def redirect + redirect_to :action => "target" + end + + def default_url_options + {:locale => "de"} + end +end + +class ControllerWithBeforeFilterAndDefaultUrlOptionsTest < ActionController::TestCase + + # This test has it´s roots in issue #1872 + test "should redirect with correct locale :de" do + get :redirect, :locale => "de" + assert_redirected_to "/controller_with_before_filter_and_default_url_options/target?locale=de" + end +end From f86f7702507f477eb8f0a8e914bdb53219fac953 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 28 Jul 2011 11:56:08 +0300 Subject: [PATCH 108/164] MassAssignmentProtection: consider 'id' insensetive in StrictSanitizer In order to use StrictSanitizer in test mode Consider :id as not sensetive attribute that can be filtered from mass assignement without exception. --- .../active_model/mass_assignment_security/sanitizer.rb | 5 +++++ .../cases/mass_assignment_security/sanitizer_test.rb | 10 +++++++++- .../rails/app/templates/config/environments/test.rb.tt | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb index bb0526adc3d..bbdddfb50dd 100644 --- a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb +++ b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb @@ -44,8 +44,13 @@ module ActiveModel class StrictSanitizer < Sanitizer def process_removed_attributes(attrs) + return if (attrs - insensitive_attributes).empty? raise ActiveModel::MassAssignmentSecurity::Error, "Can't mass-assign protected attributes: #{attrs.join(', ')}" end + + def insensitive_attributes + ['id'] + end end class Error < StandardError diff --git a/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb b/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb index 62a6ec9c9b7..676937b5e19 100644 --- a/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb +++ b/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb @@ -7,7 +7,7 @@ class SanitizerTest < ActiveModel::TestCase class Authorizer < ActiveModel::MassAssignmentSecurity::PermissionSet def deny?(key) - key.in?(['admin']) + ['admin', 'id'].include?(key) end end @@ -40,4 +40,12 @@ class SanitizerTest < ActiveModel::TestCase end end + test "mass assignment insensitive attributes" do + original_attributes = {'id' => 1, 'first_name' => 'allowed'} + + assert_nothing_raised do + @strict_sanitizer.sanitize(original_attributes, @authorizer) + end + end + end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index ee068b02020..80198cc21e9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -34,6 +34,11 @@ # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql + <%- unless options.skip_active_record? -%> + # Raise exception on mass assignment protection for ActiveRecord models + config.active_record.mass_assignment_sanitizer = :strict + <%- end -%> + # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end From cc78a8f04cb8a4ced280e73de6337cec25070a8e Mon Sep 17 00:00:00 2001 From: Dmitriy Kiriyenko Date: Mon, 1 Aug 2011 18:00:41 +0300 Subject: [PATCH 109/164] Remove unnecessary require (happened after fcbde454f6) --- activesupport/lib/active_support/core_ext/module/delegation.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 41f9a76b131..149b849b12e 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,5 +1,3 @@ -require "active_support/core_ext/module/remove_method" - class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) From 05d4b9d2fdb0aceb9082303301ecaf77605288a0 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Mon, 1 Aug 2011 12:05:29 -0500 Subject: [PATCH 110/164] Pass options in ActiveSupport::Cache::CacheStore#read_multi through to the delete_entry call. --- activesupport/lib/active_support/cache.rb | 2 +- activesupport/test/caching_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 2d2264e58a0..95d936b32fb 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -347,7 +347,7 @@ module ActiveSupport entry = read_entry(key, options) if entry if entry.expired? - delete_entry(key) + delete_entry(key, options) else results[name] = entry.value end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index dff3d6ef0d7..6bb13ec9b85 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -199,6 +199,14 @@ module CacheStoreBehavior @cache.write('fud', 'biz') assert_equal({"foo" => "bar", "fu" => "baz"}, @cache.read_multi('foo', 'fu')) end + + def test_read_multi_with_expires + @cache.write('foo', 'bar', :expires_in => 0.001) + @cache.write('fu', 'baz') + @cache.write('fud', 'biz') + sleep(0.002) + assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu')) + end def test_read_and_write_compressed_small_data @cache.write('foo', 'bar', :compress => true) From f9a69e8744546602b567dc5787f7d8ee23073bec Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 1 Aug 2011 12:32:17 -0700 Subject: [PATCH 111/164] Merge pull request #2324 from zenapsis/3-1-stable Rails 3.1 throws a Errno::ENOTDIR if files are put in assets directories --- railties/lib/rails/engine.rb | 6 +++--- railties/lib/rails/paths.rb | 4 ++++ railties/test/application/assets_test.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index c41f7d7c2e8..2c3f61f4042 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -542,9 +542,9 @@ module Rails end initializer :append_assets_path do |app| - app.config.assets.paths.unshift(*paths["vendor/assets"].existent) - app.config.assets.paths.unshift(*paths["lib/assets"].existent) - app.config.assets.paths.unshift(*paths["app/assets"].existent) + app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories) + app.config.assets.paths.unshift(*paths["app/assets"].existent_directories) end initializer :prepend_helpers_path do |app| diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index de3d0b6fc56..55b820b12ed 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,6 +171,10 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end + + def existent_directories + expanded.select {|d| Dir.exists?(d) } + end alias to_a expanded end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 7fb930bd999..802b7374837 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -109,5 +109,19 @@ module ApplicationTests assert_match "alert()", last_response.body assert_equal nil, last_response.headers["Set-Cookie"] end + + test "files in any assets/ directories are not added to Sprockets" do + %w[app lib vendor].each do |dir| + app_file "#{dir}/assets/#{dir}_test.erb", "testing" + end + + app_file "app/assets/javascripts/demo.js", "alert();" + + require "#{app_path}/config/environment" + + get "/assets/demo.js" + assert_match "alert();", last_response.body + assert_equal 200, last_response.status + end end end From 8293b10425bfe621b4bed85bf3db57cccd70e43b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 1 Aug 2011 17:29:03 -0700 Subject: [PATCH 112/164] use File.directory? as Dir.exists? is only 1.9.2+ --- railties/lib/rails/paths.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 55b820b12ed..b37421c09c5 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -171,9 +171,9 @@ module Rails def existent expanded.select { |f| File.exists?(f) } end - + def existent_directories - expanded.select {|d| Dir.exists?(d) } + expanded.select { |d| File.directory?(d) } end alias to_a expanded From 9d19bae233d7a2ce9adac39b6b6e91de85729def Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Fri, 29 Jul 2011 21:26:21 -0400 Subject: [PATCH 113/164] Support backwards compatible interface for migration down/up with rails 3.0.x. --- activerecord/lib/active_record/migration.rb | 1 + .../test/cases/invertible_migration_test.rb | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 507f345ef5d..9307d7ef24d 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -329,6 +329,7 @@ module ActiveRecord end def self.method_missing(name, *args, &block) # :nodoc: + self.delegate = self.new (delegate || superclass.delegate).send(name, *args, &block) end diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index afec64750e8..acba4a134ec 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -27,6 +27,19 @@ module ActiveRecord end end + class LegacyMigration < ActiveRecord::Migration + def self.up + create_table("horses") do |t| + t.column :content, :text + t.column :remind_at, :datetime + end + end + + def self.down + drop_table("horses") + end + end + def teardown if ActiveRecord::Base.connection.table_exists?("horses") ActiveRecord::Base.connection.drop_table("horses") @@ -53,5 +66,16 @@ module ActiveRecord migration.migrate :down assert !migration.connection.table_exists?("horses") end + + def test_legacy_up + LegacyMigration.migrate :up + assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist" + end + + def test_legacy_down + LegacyMigration.migrate :up + LegacyMigration.migrate :down + assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist" + end end end From 9d31acf8b9e8c106f5cac2348a55de0f553458c1 Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Fri, 29 Jul 2011 23:17:12 -0400 Subject: [PATCH 114/164] Ensure that .up and .down work as well. --- .../test/cases/invertible_migration_test.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index acba4a134ec..3ae7b63dffb 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -54,13 +54,13 @@ module ActiveRecord end end - def test_up + def test_migrate_up migration = InvertibleMigration.new migration.migrate(:up) assert migration.connection.table_exists?("horses"), "horses should exist" end - def test_down + def test_migrate_down migration = InvertibleMigration.new migration.migrate :up migration.migrate :down @@ -77,5 +77,16 @@ module ActiveRecord LegacyMigration.migrate :down assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist" end + + def test_up + LegacyMigration.up + assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist" + end + + def test_down + LegacyMigration.up + LegacyMigration.down + assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist" + end end end From d6af6fc0c03860f677e8fc85fa7eb4bab181215a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 2 Aug 2011 20:01:38 -0700 Subject: [PATCH 115/164] add a migrate class method and delegate to the new instance --- activerecord/lib/active_record/migration.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 9307d7ef24d..fa1b303fc7a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -329,10 +329,13 @@ module ActiveRecord end def self.method_missing(name, *args, &block) # :nodoc: - self.delegate = self.new (delegate || superclass.delegate).send(name, *args, &block) end + def self.migrate(direction) + new.migrate direction + end + cattr_accessor :verbose attr_accessor :name, :version From 1ff52cbe818f9f7bad2a9ff6ae0e515f82b1ab06 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 3 Aug 2011 08:57:52 -0700 Subject: [PATCH 116/164] initializing @open_transactions in the initialize method --- .../active_record/connection_adapters/abstract_adapter.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 65024d76f87..bde31d1cdaa 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -43,6 +43,7 @@ module ActiveRecord @connection, @logger = connection, logger @query_cache_enabled = false @query_cache = Hash.new { |h,sql| h[sql] = {} } + @open_transactions = 0 @instrumenter = ActiveSupport::Notifications.instrumenter end @@ -177,12 +178,9 @@ module ActiveRecord @connection end - def open_transactions - @open_transactions ||= 0 - end + attr_reader :open_transactions def increment_open_transactions - @open_transactions ||= 0 @open_transactions += 1 end From a9b2634a3c31a8c2d15cf63147aa663aea851b06 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 18:14:11 -0300 Subject: [PATCH 117/164] This dep is already defined in activerecord.gemspec --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index ec064bbda87..f6caa1ee651 100644 --- a/Gemfile +++ b/Gemfile @@ -4,8 +4,6 @@ gemspec if ENV['AREL'] gem "arel", :path => ENV['AREL'] -else - gem "arel", '~> 2.1.3' end gem "jquery-rails" From ab6b61e34c046da944d9b517876a032fe3d0a8a1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 19:18:34 -0300 Subject: [PATCH 118/164] Don't require assets group in production by default, you can change this default in the application.rb anyways --- .../rails/app/templates/config/application.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 7687b1beac8..dd0cf64650f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -13,9 +13,13 @@ require "active_resource/railtie" <% end -%> # If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if in development -# or test environments. -Bundler.require *Rails.groups(:assets) if defined?(Bundler) +# current environment and also include :assets gems if you ... +if defined?(Bundler) + # ... precompile your assets + Bundler.require *Rails.groups(:assets => %w(development test)) + # ... want your assets to be lazily compiled also in production + # Bundler.require(:default, :assets, Rails.env) +end module <%= app_const_base %> class Application < Rails::Application From bb72183bca60c105c901f6c38cf81dae3a104102 Mon Sep 17 00:00:00 2001 From: artemk Date: Thu, 4 Aug 2011 00:34:13 +0300 Subject: [PATCH 119/164] accept option for recreate db for postgres (same as mysql now) --- .../active_record/connection_adapters/postgresql_adapter.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a84f73c73f5..aefe69f8ed9 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -614,9 +614,11 @@ module ActiveRecord # SCHEMA STATEMENTS ======================================== - def recreate_database(name) #:nodoc: + # Drops the database specified on the +name+ attribute + # and creates it again using the provided +options+. + def recreate_database(name, options = {}) #:nodoc: drop_database(name) - create_database(name) + create_database(name, options) end # Create a new PostgreSQL database. Options include :owner, :template, From eaee18dd9abe6a72e83743009931f7765a005f24 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 3 Aug 2011 16:55:00 -0700 Subject: [PATCH 120/164] make assert_difference error message not suck --- .../lib/active_support/testing/assertions.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 3864b1f5a63..ba34e9853c7 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -46,16 +46,17 @@ module ActiveSupport # end def assert_difference(expression, difference = 1, message = nil, &block) exps = Array.wrap(expression).map { |e| - e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } + callee = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } + [e, callee] } - before = exps.map { |e| e.call } + before = exps.map { |_, block| block.call } yield - exps.each_with_index do |e, i| - error = "#{e.inspect} didn't change by #{difference}" + exps.each_with_index do |(code, block), i| + error = "#{code.inspect} didn't change by #{difference}" error = "#{message}.\n#{error}" if message - assert_equal(before[i] + difference, e.call, error) + assert_equal(before[i] + difference, block.call, error) end end From f2ea1ddc278d5466f3d3b7c8feb73aa9c78d2628 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 3 Aug 2011 21:04:32 -0300 Subject: [PATCH 121/164] Fix a bit precompile and lazy compile comments --- .../generators/rails/app/templates/config/application.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index dd0cf64650f..86c9bd2d1d9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -12,12 +12,10 @@ require "active_resource/railtie" <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie" <% end -%> -# If you have a Gemfile, require the default gems, the ones in the -# current environment and also include :assets gems if you ... if defined?(Bundler) - # ... precompile your assets + # If you precompile assets before deploying to production, use this line Bundler.require *Rails.groups(:assets => %w(development test)) - # ... want your assets to be lazily compiled also in production + # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end From 66e114cd0c0fada80fb3487262a1f578ac910437 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 4 Aug 2011 00:23:58 +0100 Subject: [PATCH 122/164] Quote these dates to prevent intermittent test failure. Suppose local time is 00:50 GMT+1. Without the quoting, the YAML parser would parse this as 00:50 UTC, into the local time of 01:50 GMT+1. Then, it would get written into the database in local time as 01:50. When it came back out the UTC date from the database and the UTC date of two weeks ago would be compared. The former would be 23:50, and the latter would be 00:50, so the two dates would differ, causing the assertion to fail. Quoting it prevents the YAML parser from getting involved. --- activerecord/test/cases/fixtures_test.rb | 4 ++-- activerecord/test/fixtures/pirates.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 842e8a0049c..913f6a33405 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -587,8 +587,8 @@ class FoxyFixturesTest < ActiveRecord::TestCase end def test_preserves_existing_fixture_data - assert_equal(2.weeks.ago.utc.to_date, pirates(:redbeard).created_on.utc.to_date) - assert_equal(2.weeks.ago.utc.to_date, pirates(:redbeard).updated_on.utc.to_date) + assert_equal(2.weeks.ago.to_date, pirates(:redbeard).created_on.to_date) + assert_equal(2.weeks.ago.to_date, pirates(:redbeard).updated_on.to_date) end def test_generates_unique_ids diff --git a/activerecord/test/fixtures/pirates.yml b/activerecord/test/fixtures/pirates.yml index abb91101da0..6004f390a49 100644 --- a/activerecord/test/fixtures/pirates.yml +++ b/activerecord/test/fixtures/pirates.yml @@ -5,5 +5,5 @@ blackbeard: redbeard: catchphrase: "Avast!" parrot: louis - created_on: <%= 2.weeks.ago.to_s(:db) %> - updated_on: <%= 2.weeks.ago.to_s(:db) %> + created_on: "<%= 2.weeks.ago.to_s(:db) %>" + updated_on: "<%= 2.weeks.ago.to_s(:db) %>" From 68c4b66015dd17e1a91a8ddc90b634d5cfc0f9ff Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 29 Jul 2011 17:43:05 -0700 Subject: [PATCH 123/164] fix stringify_keys destructive behavior for most FormTagHelper functions add four new tests to verify that the other three methods that called stringify_keys! are fixed. verified that the tests break in master without the code patch. Closes #2355 --- .../action_view/helpers/form_tag_helper.rb | 8 +++---- .../test/template/form_tag_helper_test.rb | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 79f07400b28..2bbe0c175f6 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -304,7 +304,7 @@ module ActionView # text_area_tag 'comment', nil, :class => 'comment_input' # # => def text_area_tag(name, content = nil, options = {}) - options.stringify_keys! + options = options.stringify_keys if size = options.delete("size") options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split) @@ -407,7 +407,7 @@ module ActionView # data-confirm="Are you sure?" /> # def submit_tag(value = "Save changes", options = {}) - options.stringify_keys! + options = options.stringify_keys if disable_with = options.delete("disable_with") options["data-disable-with"] = disable_with @@ -458,7 +458,7 @@ module ActionView def button_tag(content_or_options = nil, options = nil, &block) options = content_or_options if block_given? && content_or_options.is_a?(Hash) options ||= {} - options.stringify_keys! + options = options.stringify_keys if disable_with = options.delete("disable_with") options["data-disable-with"] = disable_with @@ -497,7 +497,7 @@ module ActionView # image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button") # # => def image_submit_tag(source, options = {}) - options.stringify_keys! + options = options.stringify_keys if confirm = options.delete("confirm") options["data-confirm"] = confirm diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 979251bfd10..ad31812273c 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -505,6 +505,30 @@ class FormTagHelperTest < ActionView::TestCase expected = %(
Hello world!
) assert_dom_equal expected, output_buffer end + + def test_text_area_tag_options_symbolize_keys_side_effects + options = { :option => "random_option" } + actual = text_area_tag "body", "hello world", options + assert_equal options, { :option => "random_option" } + end + + def test_submit_tag_options_symbolize_keys_side_effects + options = { :option => "random_option" } + actual = submit_tag "submit value", options + assert_equal options, { :option => "random_option" } + end + + def test_button_tag_options_symbolize_keys_side_effects + options = { :option => "random_option" } + actual = button_tag "button value", options + assert_equal options, { :option => "random_option" } + end + + def test_image_submit_tag_options_symbolize_keys_side_effects + options = { :option => "random_option" } + actual = image_submit_tag "submit source", options + assert_equal options, { :option => "random_option" } + end def protect_against_forgery? false From 6b8091731445dcd0a1843c59b84cd4e2b5b8b66c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 11:27:26 -0700 Subject: [PATCH 124/164] adding my brain dump of the release process --- RELEASING_RAILS.rdoc | 163 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 RELEASING_RAILS.rdoc diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc new file mode 100644 index 00000000000..2d8d8c5f956 --- /dev/null +++ b/RELEASING_RAILS.rdoc @@ -0,0 +1,163 @@ += Releasing Rails + +In this document, we'll cover the steps necessary to release Rails. Each +section contains steps to take during that time before the release. The times +suggested in each header are just that: suggestions. However, they should +really be considered as minimums. + +== 10 Days before release + +Today is mostly coordination tasks. Here are the things you must do today: + +=== Contact the security team (either Koz or tenderlove) + +Let them know of your plans to release. There may be security issues to be +addressed, and that can impact your release date. + +=== Is the CI green? If not, make it green. (See "Fixing the CI") + +Do not release with a Red CI. You can find the CI status here: + + http://travis-ci.org/#!/rails/rails + +=== Is Sam Ruby happy? If not, make him happy. + +Sam Ruby keeps a test suite that makes sure the code samples in his book (Agile +Web Development with Rails) all work. These are valuable integration tests +for Rails. You can check the status of his tests here: + + http://intertwingly.net/projects/dashboard.html + +Do not release with Red AWDwR tests. + +=== Do we have any git dependencies? If so, contact those authors. + +Having git dependencies indicates that we depend on unreleased code. +Obviously rails cannot be released when it depends on unreleased code. +Contact the authors of those particular gems and work out a release date that +suites them. + +== 3 Days before release + +This is when you should release the release candidate. Here are your tasks +for today: + +=== Is the CI green? If not, make it green. + +=== Is Sam Ruby happy? If not, make him happy. + +=== Contact the security team. CVE emails must be sent on this day. + +=== Create a release branch. + +From the stable branch, create a release branch. For example, if you're +releasing Rails 3.0.10, do this: + + [aaron@higgins rails (3-0-stable)]$ git checkout -b 3-0-10 + Switched to a new branch '3-0-10' + [aaron@higgins rails (3-0-10)]$ + +=== Update each CHANGELOG. + +Many times commits are made without the CHANGELOG being updated. You should +review the commits since the last release, and fill in any missing information +for each CHANGELOG. + +You can review the commits for the 3.0.10 release like this: + + [aaron@higgins rails (3-0-10)]$ git log v3.0.9.. + +=== Update the RAILS_VERSION file to include the RC. + +=== Release the gem. + +IMPORTANT: Due to YAML parse problems on the rubygems.org server, it is safest +to use Ruby 1.8 when releasing. + +Run `rake release`. This will populate the gemspecs with data from +RAILS_VERSION, commit the changes, tag it, and push the gems to rubygems.org. +Here are the commands that `rake release` should use, so you can understand +what to do in case anything goes wrong: + + $ rake all:build + $ git commit -am'updating RAILS_VERSION' + $ git tag -m'tagging rc release' v3.0.10.rc1 + $ for i in $(ls dist); do gem push $i; done + +=== Send Rails release announcements + +Write a release announcement that includes the version, changes, and links to +github where people can find the specific commit list. Here are the mailing +lists where you should announce: + +* rubyonrails-core@googlegroups.com +* rubyonrails-talk@googlegroups.com +* ruby-talk@ruby-lang.org + +Use markdown format for your announcement. Remember to ask people to report +issues with the release candidate to the rails-core mailing list. + +IMPORTANT: If anything users experience regressions when using the release +candidate, you *must* postpone the release. Bugfix releases *should not* +break existing applications. + +=== Post the announcement to the Rails blog. + +If you used markdown format for your email, you can just paste it in to the +blog. + +* http://weblog.rubyonrails.org + +=== Post the announcement to the Rails twitter account. + +== Time between release candidate and actual release + +Check the rails-core mailing list and the github issue list for regressions in +the RC. + +If any regressions are found, fix the regressions and repeat the release +candidate process. We will not release the final until 72 hours after the +last release candidate has been pushed. This means that if users find +regressions, the scheduled release date must be postponed. + +When you fix the regressions, do not create a new branch. Fix them on the +stable branch, then cherry pick the commit to your release branch. No other +commits should be added to the release branch besides regression fixing commits. + +== Day of release + +Many of these steps are the same as for the release candidate, so if you need +more explanation on a particular step, so the RC steps. + +=== Email the rails security announce list, once for each vulnerability fixed. + +You can do this, or ask the security team to do it. + +FIXME: I can't remember the email addresses, but we should list them here. +FIXME: Possibly we should do this the day of the RC? + +* Apply security patches to the release branch +* Update CHANGELOG with security fixes. +* Update RAILS_VERSION to remove the rc +* Release the gems +* Email announcement + +Be sure to note the security fixes in your announcement along with CVE numbers +and links to each patch. Some people may not be able to upgrade right away, +so we need to give them the security fixes in patch form. + +* Blog announcements +* Twitter announcements +* Merge the release branch to the stable branch. +* Drink beer (or other cocktail) + +== Misc + +=== Fixing the CI + +There are two simple steps for fixing the CI: + +1. Identify the problem +2. Fix it + +Repeat these steps until the CI is green. From ebfca248f9084f8176f6b5b993d9c3c99d06737b Mon Sep 17 00:00:00 2001 From: Casebook Developer Date: Thu, 4 Aug 2011 13:34:47 -0400 Subject: [PATCH 125/164] ActionView::Helpers::TextHelper#simple_format should not change the text in place. Now it duplicates it. --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- actionpack/test/template/text_helper_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index ae71ade5887..21074efe863 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -256,7 +256,7 @@ module ActionView # # => "

I'm allowed! It's true.

" def simple_format(text, html_options={}, options={}) text = '' if text.nil? - text = text.dup if text.frozen? + text = text.dup start_tag = tag('p', html_options, true) text = sanitize(text) unless options[:sanitize] == false text = text.to_str diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index f7c3986bb18..02f9609483f 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -48,10 +48,10 @@ class TextHelperTest < ActionView::TestCase assert_equal "

test with unsafe string

", simple_format(" test with unsafe string ", {}, :sanitize => false) end - def test_simple_format_should_not_change_the_frozen_text_passed + def test_simple_format_should_not_change_the_text_passed text = "Ok" text_clone = text.dup - simple_format(text.freeze) + simple_format(text) assert_equal text_clone, text end From 886d0115dc766865eada9308839ee827d9f13cad Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 12:00:06 -0700 Subject: [PATCH 126/164] fixing wrong words. thanks @jbrown --- RELEASING_RAILS.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc index 2d8d8c5f956..98453db549a 100644 --- a/RELEASING_RAILS.rdoc +++ b/RELEASING_RAILS.rdoc @@ -97,7 +97,7 @@ lists where you should announce: Use markdown format for your announcement. Remember to ask people to report issues with the release candidate to the rails-core mailing list. -IMPORTANT: If anything users experience regressions when using the release +IMPORTANT: If any users experience regressions when using the release candidate, you *must* postpone the release. Bugfix releases *should not* break existing applications. From a7a3169cc33aa06b6d3b70889c577d067a6c41ae Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 14:07:23 -0700 Subject: [PATCH 127/164] fixing assert_difference issues on ruby 1.8 --- .../lib/active_support/testing/assertions.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index ba34e9853c7..f3629ada5b8 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -45,18 +45,19 @@ module ActiveSupport # post :delete, :id => ... # end def assert_difference(expression, difference = 1, message = nil, &block) - exps = Array.wrap(expression).map { |e| - callee = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } - [e, callee] + expressions = Array.wrap expression + + exps = expressions.map { |e| + e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } } - before = exps.map { |_, block| block.call } + before = exps.map { |e| e.call } yield - exps.each_with_index do |(code, block), i| + expressions.zip(exps).each_with_index do |(code, e), i| error = "#{code.inspect} didn't change by #{difference}" error = "#{message}.\n#{error}" if message - assert_equal(before[i] + difference, block.call, error) + assert_equal(before[i] + difference, e.call, error) end end From bf0b6e4b8b1df8114ab0208686bc4cffb0851877 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 14:13:41 -0700 Subject: [PATCH 128/164] add section about notifying implementors --- RELEASING_RAILS.rdoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc index 98453db549a..f780f58f2f1 100644 --- a/RELEASING_RAILS.rdoc +++ b/RELEASING_RAILS.rdoc @@ -14,6 +14,20 @@ Today is mostly coordination tasks. Here are the things you must do today: Let them know of your plans to release. There may be security issues to be addressed, and that can impact your release date. +=== Notify implementors. + +Ruby implementors have high stakes in making sure Rails works. Be kind and +give them a heads up that Rails will be released soonish. + +Send an email just giving a heads up about the upcoming release to these +lists: + +* team@jruby.org +* community@rubini.us +* rubyonrails-core@googlegroups.com + +Implementors will love you and help you. + === Is the CI green? If not, make it green. (See "Fixing the CI") Do not release with a Red CI. You can find the CI status here: From 5399b2028712e0fc3bb768ee3c0a836ea4859909 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 14:15:45 -0700 Subject: [PATCH 129/164] moving CI and Sam Ruby to the top of the list. I :heart: CI and Sam --- RELEASING_RAILS.rdoc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc index f780f58f2f1..22fc58516e8 100644 --- a/RELEASING_RAILS.rdoc +++ b/RELEASING_RAILS.rdoc @@ -9,25 +9,6 @@ really be considered as minimums. Today is mostly coordination tasks. Here are the things you must do today: -=== Contact the security team (either Koz or tenderlove) - -Let them know of your plans to release. There may be security issues to be -addressed, and that can impact your release date. - -=== Notify implementors. - -Ruby implementors have high stakes in making sure Rails works. Be kind and -give them a heads up that Rails will be released soonish. - -Send an email just giving a heads up about the upcoming release to these -lists: - -* team@jruby.org -* community@rubini.us -* rubyonrails-core@googlegroups.com - -Implementors will love you and help you. - === Is the CI green? If not, make it green. (See "Fixing the CI") Do not release with a Red CI. You can find the CI status here: @@ -51,6 +32,25 @@ Obviously rails cannot be released when it depends on unreleased code. Contact the authors of those particular gems and work out a release date that suites them. +=== Contact the security team (either Koz or tenderlove) + +Let them know of your plans to release. There may be security issues to be +addressed, and that can impact your release date. + +=== Notify implementors. + +Ruby implementors have high stakes in making sure Rails works. Be kind and +give them a heads up that Rails will be released soonish. + +Send an email just giving a heads up about the upcoming release to these +lists: + +* team@jruby.org +* community@rubini.us +* rubyonrails-core@googlegroups.com + +Implementors will love you and help you. + == 3 Days before release This is when you should release the release candidate. Here are your tasks From 5852fcfb118156abcd8912de5279f7dac91c4b3d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 4 Aug 2011 18:43:13 -0300 Subject: [PATCH 130/164] Add git push and git push --tags to RELEASING_RAILS.rdoc --- RELEASING_RAILS.rdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc index 22fc58516e8..e3d3f67237e 100644 --- a/RELEASING_RAILS.rdoc +++ b/RELEASING_RAILS.rdoc @@ -96,6 +96,8 @@ what to do in case anything goes wrong: $ rake all:build $ git commit -am'updating RAILS_VERSION' $ git tag -m'tagging rc release' v3.0.10.rc1 + $ git push + $ git push --tags $ for i in $(ls dist); do gem push $i; done === Send Rails release announcements From c8e5c0d2b98570693dada92ce23fa4b611a5a7bf Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 4 Aug 2011 16:31:57 -0700 Subject: [PATCH 131/164] we should not ignore all gems in here --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index be764143aaa..2d3c39d8858 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.gem pkg .bundle Gemfile.lock @@ -22,4 +21,4 @@ railties/doc railties/guides/output railties/tmp .rvmrc -RDOC_MAIN.rdoc \ No newline at end of file +RDOC_MAIN.rdoc From ac287b2aa04c8376bf7d1f95c99047796442406e Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 5 Aug 2011 12:16:53 +0530 Subject: [PATCH 132/164] Adding Basic file for ActiveModel. @vatrai and @sukeerthiadiga is going to take care other detailed stuff. --- .../guides/source/active_model_basics.textile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 railties/guides/source/active_model_basics.textile diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile new file mode 100644 index 00000000000..5e41d394472 --- /dev/null +++ b/railties/guides/source/active_model_basics.textile @@ -0,0 +1,16 @@ +h2. Active Model Basics + +This guide should provide you with all you need to get started using model classes. Active Model allow for Action Pack helpers to interact with non-ActiveRecord models. Active Model also helps building custom ORMs for use outside of the Rails framework. + +endprologue. + +WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in earlier versions of Rails. + +h3. Introduction + +Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. + + +h3. Changelog + +* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file From 4bde1b0041d73accf75525697461ac6b9fad5404 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 13:13:22 +0530 Subject: [PATCH 133/164] ActiveModel::AttributeMethods basic guide --- .../guides/source/active_model_basics.textile | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 5e41d394472..c76469f62c2 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -8,8 +8,33 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not h3. Introduction -Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. +Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. Some of modules are explained below - +h4. AttributeMethods + +AttributeMethods module can add custom prefixes and suffixes on methods of a class. It is used by defining the prefixes and suffixes, which methods on the object will use them. + + +class Person + include ActiveModel::AttributeMethods + + attribute_method_prefix 'reset_' + attribute_method_suffix '_highest?' + define_attribute_methods ['age'] + + attr_accessor :age + +private + def reset_attribute(attribute) + send("#{attribute}=", 0) + end + + def attribute_highest?(attribute) + attribute > 100 ? true : false + end + +end + h3. Changelog From 7963099b904031fef7d593d5be7e2061d1bcbfe8 Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga G Date: Fri, 5 Aug 2011 13:13:31 +0530 Subject: [PATCH 134/164] ActiveResource::Validations module basics updated --- .../source/active_resource_basics.textile | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 332d113fa7d..3294227f7bf 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -69,6 +69,56 @@ person = Person.find(1) person.destroy +h3. Validations + +Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveRecord::Errors. + +h4. Validating client side resources by overriding validation methods in base class + + +class Person < ActiveResource::Base + self.site = "http://api.people.com:3000/" + + protected + + def validate + errors.add("last", "has invalid characters") unless last =~ /[a-zA-Z]*/ + end +end + + +h4. Validating client side resources + +Consider a Person resource on the server requiring both a first_name and a last_name with a validates_presence_of :first_name, :last_name declaration in the model: + + +person = Person.new(:first_name => "Jim", :last_name => "") +person.save # => false (server returns an HTTP 422 status code and errors) +person.valid? # => false +person.errors.empty? # => false +person.errors.count # => 1 +person.errors.full_messages # => ["Last name can't be empty"] +person.errors[:last_name] # => ["can't be empty"] +person.last_name = "Halpert" +person.save # => true (and person is now saved to the remote service) + + +h4. Public instance methods + +ActiveResource::Validations have three public instance methods + +h5. errors() + +This will return errors object that holds all information about attribute error messages + +h5. save_with_validation(options=nil) + +This validates the resource with any local validations written in base class and then it will try to POST if there are no errors. + +h5. valid? + +Runs all the local validations and will return true if no errors. + h3. Changelog * July 30, 2011: Initial version by "Vishnu Atrai":http://github.com/vatrai \ No newline at end of file From 9eb3e637fb7ffa7a35847b5dd577c3a2736e5101 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 13:34:28 +0530 Subject: [PATCH 135/164] AttributeMethods refector suffix method added some usages --- railties/guides/source/active_model_basics.textile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index c76469f62c2..87a9658a946 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -30,12 +30,23 @@ private end def attribute_highest?(attribute) - attribute > 100 ? true : false + send(attribute) > 100 ? true : false end end + +person = Person.new +person.age = 110 +person.age_highest? # true +person.reset_age # 0 +person.age_highest? # false + +h4. Callbacks + + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file From a7b2867061b884f8a8f18db61902874ef56c906c Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 5 Aug 2011 01:08:53 -0700 Subject: [PATCH 136/164] rephrase "like to be" --- actionpack/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc index 792862cb85a..0abfc8f81dd 100644 --- a/actionpack/README.rdoc +++ b/actionpack/README.rdoc @@ -283,7 +283,7 @@ methods: The last two lines are responsible for telling ActionController where the template files are located and actually running the controller on a new -request from the web-server (like to be Apache). +request from the web-server (e.g., Apache). And the templates look like this: From 2579d8840507155988f39d36c265b65b94fc4d0f Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 5 Aug 2011 01:17:09 -0700 Subject: [PATCH 137/164] capitalize RubyGems properl --- activemodel/README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc index 5f0d3403079..67701bc4228 100644 --- a/activemodel/README.rdoc +++ b/activemodel/README.rdoc @@ -186,7 +186,7 @@ modules: == Download and installation -The latest version of Active Model can be installed with Rubygems: +The latest version of Active Model can be installed with RubyGems: % [sudo] gem install activemodel From b905f8c96326c86caafc20bec7e3722cf4813d2c Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga Date: Fri, 5 Aug 2011 14:04:43 +0530 Subject: [PATCH 138/164] Rubygems => RubyGems --- actionmailer/README.rdoc | 2 +- actionpack/README.rdoc | 2 +- activerecord/README.rdoc | 2 +- activeresource/README.rdoc | 2 +- activesupport/README.rdoc | 2 +- railties/README.rdoc | 2 +- railties/guides/source/performance_testing.textile | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 937b53a3b2d..f48e77b4c7f 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -135,7 +135,7 @@ The Base class has the full list of configuration options. Here's an example: == Download and installation -The latest version of Action Mailer can be installed with Rubygems: +The latest version of Action Mailer can be installed with RubyGems: % [sudo] gem install actionmailer diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc index 0abfc8f81dd..95301c21ee5 100644 --- a/actionpack/README.rdoc +++ b/actionpack/README.rdoc @@ -316,7 +316,7 @@ an URL such as /weblog/5 (where 5 is the id of the post). == Download and installation -The latest version of Action Pack can be installed with Rubygems: +The latest version of Action Pack can be installed with RubyGems: % [sudo] gem install actionpack diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc index 8c5c544773f..b5db57569cd 100644 --- a/activerecord/README.rdoc +++ b/activerecord/README.rdoc @@ -197,7 +197,7 @@ Admit the Database: == Download and installation -The latest version of Active Record can be installed with Rubygems: +The latest version of Active Record can be installed with RubyGems: % [sudo] gem install activerecord diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc index 6f45fe35983..0f10bfc1a7a 100644 --- a/activeresource/README.rdoc +++ b/activeresource/README.rdoc @@ -22,7 +22,7 @@ received and serialized into a usable Ruby object. == Download and installation -The latest version of Active Support can be installed with Rubygems: +The latest version of Active Support can be installed with RubyGems: % [sudo] gem install activeresource diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc index cc3981e74de..1ab8e006080 100644 --- a/activesupport/README.rdoc +++ b/activesupport/README.rdoc @@ -8,7 +8,7 @@ outside of Rails. == Download and installation -The latest version of Active Support can be installed with Rubygems: +The latest version of Active Support can be installed with RubyGems: % [sudo] gem install activesupport diff --git a/railties/README.rdoc b/railties/README.rdoc index 04572274737..eb7ed961e37 100644 --- a/railties/README.rdoc +++ b/railties/README.rdoc @@ -11,7 +11,7 @@ Railties is responsible to glue all frameworks together. Overall, it: == Download -The latest version of Railties can be installed with Rubygems: +The latest version of Railties can be installed with RubyGems: * gem install railties diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index dbe6f97f5ce..75f81cf13d3 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -438,9 +438,9 @@ alias gcrails='~/rubygc/bin/rails' Don't forget to use your aliases from now on. -h6. Install Rubygems (1.8 only!) +h6. Install RubyGems (1.8 only!) -Download "Rubygems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above. +Download "RubyGems":http://rubyforge.org/projects/rubygems and install it from source. Rubygem's README file should have necessary installation instructions. Please note that this step isn't necessary if you've installed Ruby 1.9 and above. h4. Using Ruby-Prof on MRI and REE From bc49d6d1eb075900657b0f94d03c51d18a95a54d Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Fri, 5 Aug 2011 20:46:20 +1200 Subject: [PATCH 139/164] [asset pipeline] fixed example Changed << to += because we are _concatenating_ this new array to the end of config array, NOT pushing this array in it. --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 51cb332e381..13e28a25ba5 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -297,7 +297,7 @@ The default matcher for compiling files will include +application.js+, +applicat If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array: -config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js'] +config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js'] Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them. From 33d7a6bc55a983ea690961d3a434096fe80d0fca Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 14:35:04 +0530 Subject: [PATCH 140/164] ActiveModel::Callbacks basic guide --- .../guides/source/active_model_basics.textile | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 87a9658a946..e4c84365d35 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -45,7 +45,31 @@ person.age_highest? # false h4. Callbacks +Callbacks gives Active Record style callbacks. This provides the ability to define the callbacks and those will run at appropriate time. After defining a callbacks you can wrap with before, after and around custom methods. + +class Person + extend ActiveModel::Callbacks + + define_model_callbacks :update + + before_update :reset_me + + def update + _run_update_callbacks do + puts 'saving...' + end + end + + def reset_me + puts 'before saving...' + end +end + +person = Person.new +person.update # before saving... + # saving... + h3. Changelog From d5adaf2d38f81429e21d9670b6a852668edb3757 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 14:48:00 +0530 Subject: [PATCH 141/164] ActiveModel::Callbacks basic guide --- railties/guides/source/active_model_basics.textile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index e4c84365d35..92fa5bc8f4a 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -57,18 +57,14 @@ class Person def update _run_update_callbacks do - puts 'saving...' + # This will call when we are trying to call update on object. end end def reset_me - puts 'before saving...' + # This method will call when you are calling update on object as a before_update callback as defined. end end - -person = Person.new -person.update # before saving... - # saving... h3. Changelog From a3cf68291df3e9f5b23f56a90929c601ffc26ebd Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 15:28:01 +0530 Subject: [PATCH 142/164] ActiveModel::Conversion basic guide --- .../guides/source/active_model_basics.textile | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 92fa5bc8f4a..daf41d2296d 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -67,6 +67,29 @@ class Person end +h4. Conversion + +If a class defines persisted? and id methods then you can include Conversion module in that class and you can able to call Rails conversion methods to objects of that class. + + +class Person + include ActiveModel::Conversion + + def persisted? + false + end + + def id + nil + end +end + +person = Person.new +person.to_model == person #=> true +person.to_key #=> nil +person.to_param #=> nil + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file From 86ae14df4733cac1748513994caec2f9775ae224 Mon Sep 17 00:00:00 2001 From: Sukeerthi Adiga G Date: Fri, 5 Aug 2011 15:21:12 +0530 Subject: [PATCH 143/164] Dirty object methods added to active model basics --- .../guides/source/active_model_basics.textile | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index daf41d2296d..404cc71c50f 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -90,6 +90,92 @@ person.to_key #=> nil person.to_param #=> nil +h4. Dirty + +An object becomes dirty when an object is gone through one or more changes to its attributes and not yet saved. This gives the ability to check whether an object has been changed or not. It also has attribute based accessor methods. Lets consider a Person class with attributes first_name and last_name + + +require 'rubygems' +require 'active_model' + +class Person + include ActiveModel::Dirty + define_attribute_methods [:first_name, :last_name] + + def first_name + @first_name + end + + def first_name=(value) + first_name_will_change! + @first_name = value + end + + def last_name + @last_name + end + + def last_name=(value) + last_name_will_change! + @last_name = value + end + + def save + @previously_changed = changes + end + +end + + +h5. Querying object directly for its list of all changed attributes. + + +person = Person.new +person.first_name = "First Name" + +person.first_name #=> "First Name" +person.first_name = "First Name Changed" + +person.changed? #=> true + +#returns an list of fields arry which all has been changed before saved. +person.changed #=> ["first_name"] + +#returns a hash of the fields that have changed with their original values. +person.changed_attributes #=> {"first_name" => "First Name Changed"} + +#returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field. +person.changes #=> {"first_name" => ["First Name","First Name Changed"]} + + +h5. Attribute based accessor methods + +Track whether the particular attribute has been changed or not. + + +#attr_name_changed? +person.first_name #=> "First Name" + +#assign some other value to first_name attribute +person.first_name = "First Name 1" + +person.first_name_changed? #=> true + + +Track what was the previous value of the attribute. + +#attr_name_was accessor +person.first_name_was #=> "First Name" + + + +Track both previous and current value of the changed attribute. Returns an array if changed else returns nil + +#attr_name_change +person.first_name_change #=> ["First Name", "First Name 1"] +person.last_name_change #=> nil + + h3. Changelog -* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw \ No newline at end of file +* August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw From bc9eaf422d9731bb4deb599f7b1e2e9014b870a0 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 01:01:54 +0530 Subject: [PATCH 144/164] indentation fixes --- railties/guides/source/initialization.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 6ab2706d6b0..154df51cdc3 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -348,10 +348,10 @@ The class *is* defined in +Rack::Server+, but is overwritten in +Rails::Server+ def parse!(args) args, options = args.dup, {} - opt_parser = OptionParser.new do |opts| - opts.banner = "Usage: rails server [mongrel, thin, etc] [options]" - opts.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } + opt_parser = OptionParser.new do |opts| + opts.banner = "Usage: rails server [mongrel, thin, etc] [options]" + opts.on("-p", "--port=port", Integer, + "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } ... From 31b820eef92e218349a4a7f033868fc387a92e5b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 01:39:05 +0530 Subject: [PATCH 145/164] expand tmp:* tasks, and a few more additions in the command line guide --- railties/guides/source/command_line.textile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index f48fa96451f..6d5132a1bf6 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -381,6 +381,7 @@ Ruby version 1.8.7 (x86_64-linux) RubyGems version 1.3.6 Rack version 1.1 Rails version 3.1.0 +JavaScript Runtime Node.js (V8) Active Record version 3.1.0 Action Pack version 3.1.0 Active Resource version 3.1.0 @@ -390,12 +391,12 @@ Middleware ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rai Application root /home/foobar/commandsapp Environment development Database adapter sqlite3 -Database schema version 0 +Database schema version 20110805173523 h4. +assets+ -You can precompile the assets in app/assets using rake assets:precompile and remove compiled assets using rake assets:clean. +You can precompile the assets in app/assets using rake assets:precompile and remove those compiled assets using rake assets:clean. h4. +db+ @@ -460,13 +461,18 @@ h4. +test+ INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html -Rails comes with a test suite called Test::Unit. It is through the use of tests that Rails itself is so stable, and the slew of people working on Rails can prove that everything works as it should. - -The +test:+ namespace helps in running the different tests you will (hopefully!) write. +Rails comes with a test suite called Test::Unit. Rails owes its stability to the use of tests. The tasks available in the +test:+ namespace helps in running the different tests you will hopefully write. h4. +tmp+ -The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. The +tmp:+ namespace tasks will help you clear them if you need to if they've become overgrown, or create them in case of deletions gone awry. +The Rails.root/tmp directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions. + +The +tmp:+ namespaced tasks will help you clear the Rails.root/tmp directory: + +* +rake tmp:cache:clear+ clears tmp/cache. +* +rake tmp:sessions:clear+ clears tmp/sessions. +* +rake tmp:sockets:clear+ clears tmp/sockets. +* +rake tmp:clear+ clears all the three: cache, sessions and sockets. h4. Miscellaneous From 8320fbb3b01be05d133de445ecf0bbc172225dc5 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Sat, 6 Aug 2011 05:21:27 +0530 Subject: [PATCH 146/164] prototype switch --- railties/guides/source/3_1_release_notes.textile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 7d85d7a6005..b1eaca1ef9f 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -67,6 +67,10 @@ h4. Default JS library is now jQuery jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. + +$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev + + h4. Identity Map Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion. @@ -417,3 +421,4 @@ h3. Credits See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. + From dbf22560c627c9b639d201887c137e822e4464be Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 6 Aug 2011 23:53:53 +0530 Subject: [PATCH 147/164] 3.1 release notes: organize action_pack notes --- .../guides/source/3_1_release_notes.textile | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index b1eaca1ef9f..eb4f775ff0a 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -21,8 +21,6 @@ Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby ve TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing. -TODO. What else? - h3. Creating a Rails 3.1 application @@ -68,7 +66,7 @@ h4. Default JS library is now jQuery jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch. -$ ruby /path/to/rails/bin/rails new myapp -j prototype --dev +$ rails new myapp -j prototype h4. Identity Map @@ -103,41 +101,25 @@ h3. Railties * Added Rack::Cache to the default middleware stack. -* TODO Engine related changes +* Engines received a major update - You can mount them at any path, enable assets, run generators etc. h3. Action Pack -h4. Abstract Controller - h4. Action Controller -* Added streaming support, you can enable it with: - - -class PostsController < ActionController::Base - stream :only => :index -end - - -Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. - -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. - -h4. Action Dispatch - -* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. - -h4. Action View - -* Created ActionView::Renderer and specified an API for ActionView::Context. - -TODO - * A warning is given out if the CSRF token authenticity cannot be verified. -* Allows AM/PM format in datetime selectors. +* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. + +* URL parameters which return nil for +to_param+ are now removed from the query string. + +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. + +* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). + +* +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options. * Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. @@ -180,31 +162,43 @@ class PostsController < ApplicationController end -* Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, :only or :except can be used. +* Added streaming support, you can enable it with: -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) + +class PostsController < ActionController::Base + stream :only => :index +end + -* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. - -* Sensitive query string parameters specified in config.filter_parameters will now be filtered out from the request paths in the log. - -* URL parameters which return nil for +to_param+ are now removed from the query string. - -* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. - -* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. - -* Added HTML5 button_tag helper. - -* Template lookup now searches further up in the inheritance chain. - -* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. TODO from which version? - -* url_for and named url helpers now accept :subdomain and :domain as options. +Please read the docs at "ActionController::Streaming":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information. * The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused. -* Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). +h4. Action Dispatch + +* ActionDispatch::MiddlewareStack now uses composition over inheritance and is no longer an array. + +* Added ActionDispatch::Request.ignore_accept_header to ignore accept headers. + +* Added Rack::Cache to the default stack. + +* Moved etag responsibility from ActionDispatch::Response to the middleware stack. + +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. + +* Template lookup now searches further up in the inheritance chain. + +h4. Action View + +* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. + +* Created ActionView::Renderer and specified an API for ActionView::Context. + +* In place SafeBuffer mutation is prohibited in Rails 3.1. + +* Added HTML5 button_tag helper. + +* +file_field+ automatically adds :multipart => true to the enclosing form. * Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a :data hash of options: @@ -215,19 +209,23 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) Keys are dasherized. Values are JSON-encoded, except for strings and symbols. +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. + * The old template handler API is deprecated and the new API simply requires a template handler to respond to call. * rhtml and rxml are finally removed as template handlers. -* Moved etag responsibility from ActionDispatch::Response to the middleware stack. +* config.action_view.cache_template_loading is brought back which allows to decide whether templates should be cached or not. -* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. +* The submit form helper does not generate an id "object_name_id" anymore. -* file_field automatically adds :multipart => true to the enclosing form. +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) -* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. -* Added Rack::Cache to the default stack. +* Allows AM/PM format in datetime selectors. + +* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink h3. Active Record @@ -380,6 +378,8 @@ h3. Active Model * ActiveModel::AttributeMethods allows attributes to be defined on demand. +* Added support for selectively enabling and disabling observers. + h3. Active Resource * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. For example, From b840d71bfb702b121b48832f984090e202793f10 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 7 Aug 2011 09:37:39 +1200 Subject: [PATCH 148/164] [asset pipeline] Update Capistrano info v2.8.0 of Capistrano has a recipe to handle precompile and symlinking. --- railties/guides/source/asset_pipeline.textile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 13e28a25ba5..3a87c905166 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -276,17 +276,15 @@ The rake task is: rake assets:precompile -You can run this as part of a Capistrano deployment: +Capistrano (v2.8.0+) has a recipe to to handle this in deployment. Add the following line to +Capfile+: -before 'deploy:symlink' do - run "cd #{release_path}; RAILS_ENV=#{rails_env} rake assets:precompile" -end +load 'deploy/assets' -If you are not precompiling your assets, and you are using the default cache file store (which is the file system), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure in order to persist the cached file between deployments. +This links the folder specified in +config.assets.prefix+ to +shared/assets+. If you already use this folder you'll need to write your own deployment task. -TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35). +It is important for this folder is shared between deployments so that remotely cached pages that reference the old compiled assets still work for the life of the cached page. The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+: From 8c133fc4c0c04ddfe6f964062c4dcfc65ceb0222 Mon Sep 17 00:00:00 2001 From: ov3y Date: Sun, 7 Aug 2011 07:55:59 -0300 Subject: [PATCH 149/164] Point to current, official upgrade plugin --- railties/guides/source/3_0_release_notes.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index fbb684978a5..d22c76dd81f 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a + h4. Upgrade Process -To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it. +To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it. Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following: -$ ruby script/plugin install git://github.com/jm/rails_upgrade.git +$ ruby script/plugin install git://github.com/rails/rails_upgrade.git You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin From 93ec7bb59a62702051377e9beb43501ccd9d0f2a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 7 Aug 2011 21:45:12 +0530 Subject: [PATCH 150/164] 3.1 release notes: fixed font changes --- .../guides/source/3_1_release_notes.textile | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index eb4f775ff0a..5f09d8fd2b6 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -121,7 +121,7 @@ h4. Action Controller * +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options. -* Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call. +* Added +Base.http_basic_authenticate_with+ to do simple http basic authentication with a single class method call. class PostsController < ApplicationController @@ -190,13 +190,13 @@ h4. Action Dispatch h4. Action View -* Added an :authenticity_token option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. +* Added an +:authenticity_token+ option to +form_tag+ for custom handling or to omit the token by passing :authenticity_token => false. * Created ActionView::Renderer and specified an API for ActionView::Context. -* In place SafeBuffer mutation is prohibited in Rails 3.1. +* In place +SafeBuffer+ mutation is prohibited in Rails 3.1. -* Added HTML5 button_tag helper. +* Added HTML5 +button_tag+ helper. * +file_field+ automatically adds :multipart => true to the enclosing form. @@ -248,9 +248,9 @@ user.build_account{ |a| a.credit_limit => 100.0 } * Added ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist. -* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0 +* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0. -* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: +* ActiveRecord#new, ActiveRecord#create and ActiveRecord#update_attributes all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of ActiveModel's new mass assignment capabilities: class Post < ActiveRecord::Base @@ -261,19 +261,19 @@ end Post.new(params[:post], :as => :admin) -* default_scope can now take a block, lambda, or any other object which responds to call for lazy evaluation: +* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation: * Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. * PostgreSQL adapter only supports PostgreSQL version 8.2 and higher. -* ConnectionManagement middleware is changed to clean up the connection pool after the rack body has been flushed. +* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed. -* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of the updated_at column. It should not be called on new records. +* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records. -* Associations with a :through option can now use any association as the through or source association, including other associations which have a :through option and has_and_belongs_to_many associations. +* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations. -* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. +* The configuration for the current database connection is now accessible via ActiveRecord::Base.connection_config. * limits and offsets are removed from COUNT queries unless both are supplied. @@ -286,9 +286,9 @@ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET * Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. -* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. +* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. -* The behavior of association.destroy for has_and_belongs_to_many and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. +* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. * Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. @@ -332,7 +332,7 @@ class FooMigration < ActiveRecord::Migration end -* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's change method instead of the ordinary up and down methods. +* Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's +change+ method instead of the ordinary +up+ and +down+ methods. * Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used. @@ -348,7 +348,7 @@ You can have any "normal" conditions inside the proc, so the following will work has_many :things, :conditions => proc { ["foo = ?", bar] } -* Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. +* Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc. * Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting. @@ -360,13 +360,13 @@ end * When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns. -* Setting the id of a belongs_to object will update the reference to the object. +* Setting the id of a +belongs_to+ object will update the reference to the object. -* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. +* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics. -* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. +* Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called. -* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. +* Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable. h3. Active Model @@ -394,13 +394,13 @@ h3. Active Support * ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. -* Added a new reporting method Kernel#quietly which silences both STDOUT and STDERR. +* Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+. * Added String#inquiry as a convenience method for turning a String into a +StringInquirer+ object. * Added Object#in? to test if an object is included in another object. -* LocalCache strategy is now a real middleware class and no longer an anonymous class. +* +LocalCache+ strategy is now a real middleware class and no longer an anonymous class. * ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. @@ -421,4 +421,3 @@ h3. Credits See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them. Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev. - From 32da2f864eb9e1f626f25e5d46a38d0c0d214d15 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 8 Aug 2011 18:02:19 +1200 Subject: [PATCH 151/164] [asset pipeline] update to reflect new sendfile header default X-Sendfile headers are now set to nil and are off by default. See commit eff7fddeb26eaa346827 --- railties/guides/source/asset_pipeline.textile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 3a87c905166..3eede315725 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -385,16 +385,14 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr h4. X-Sendfile Headers -The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the web server to do the file serving, which is usually faster. Both Apache and nginx support this option. +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. This option is off be default, but can be enabled if your server supports it. When enabled, this passes responsibility for serving the file to the web server, which is faster. -The configuration is available in config/environments/production.rb. +Apache and nginx support this option which is enabled in config/environments/production.rb. config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx -You should check that your server or hosting service actually supports this, otherwise comment it out. - WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior. h3. How Caching Works From 49e81f21a3e6facac06c49739644dbb36c94f794 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 8 Aug 2011 22:21:25 +1200 Subject: [PATCH 152/164] [asset pipeline] update snippet to reflect patch Two commented lines in example to match the commit (8845ae683e2688) --- railties/guides/source/asset_pipeline.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 3eede315725..8a4d61dc3a2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -390,7 +390,8 @@ The X-Sendfile header is a directive to the server to ignore the response from t Apache and nginx support this option which is enabled in config/environments/production.rb. -config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx +# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache +# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behavior. From 239e6153167c9babceaec2e3ca0e286166e0cea5 Mon Sep 17 00:00:00 2001 From: Tate Johnson Date: Tue, 9 Aug 2011 20:01:06 +1000 Subject: [PATCH 153/164] Fixed typo --- activemodel/lib/active_model/errors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 1cf8144e98c..d5665de561f 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -49,7 +49,7 @@ module ActiveModel # # The last three methods are required in your object for Errors to be # able to generate error messages correctly and also handle multiple - # languages. Of course, if you extend your object with ActiveModel::Translations + # languages. Of course, if you extend your object with ActiveModel::Translation # you will not need to implement the last two. Likewise, using # ActiveModel::Validations will handle the validation related methods # for you. From 9cf56c709b6ec2ab0479f664761596f6c64f8887 Mon Sep 17 00:00:00 2001 From: Floris Huetink Date: Tue, 9 Aug 2011 15:48:34 +0200 Subject: [PATCH 154/164] Fixed typo (attachments method name was missing an s) in Action Mailer basics guide --- railties/guides/source/action_mailer_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index f05d9dcf1c4..5b2212d9cbc 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -404,7 +404,7 @@ Will put the HTML part first, and the plain text part second. h4. Sending Emails with Attachments -Attachments can be added by using the +attachment+ method: +Attachments can be added by using the +attachments+ method: class UserMailer < ActionMailer::Base From 76158146eb6c7a95bb65848fac1ae23147f07325 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Tue, 9 Aug 2011 11:37:13 -0700 Subject: [PATCH 155/164] comma is more appropriate here --- activeresource/README.rdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc index 0f10bfc1a7a..c86289c5fe8 100644 --- a/activeresource/README.rdoc +++ b/activeresource/README.rdoc @@ -135,8 +135,8 @@ as the id of the ARes object. ==== Update -'save' is also used to update an existing resource - and follows the same protocol as creating a resource -with the exception that no response headers are needed - just an empty response when the update on the +'save' is also used to update an existing resource and follows the same protocol as creating a resource +with the exception that no response headers are needed -- just an empty response when the update on the server side was successful. # Ryan From 3b4e7c9f8e38bdc7517e85c413f48f5aadf17eec Mon Sep 17 00:00:00 2001 From: "Mr. Wolfe" Date: Wed, 10 Aug 2011 23:22:16 +0200 Subject: [PATCH 156/164] update rails on rack guide, section 2 needs to be changed or maybe deleted --- railties/guides/source/rails_on_rack.textile | 33 +++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 8d5985dba8a..ea26334ba0a 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,23 +89,32 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: +use ActionDispatch::Static use Rack::Lock -use ActionController::Failsafe -use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} -use Rails::Rack::Metal -use ActionDispatch::RewindableInput -use ActionController::ParamsParser -use Rack::MethodOverride -use Rack::Head +use ActiveSupport::Cache::Strategy::LocalCache +use Rack::Runtime +use Rails::Rack::Logger +use ActionDispatch::ShowExceptions +use ActionDispatch::RemoteIp +use Rack::Sendfile +use ActionDispatch::Callbacks +use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache -run ActionController::Dispatcher.new +use ActionDispatch::Cookies +use ActionDispatch::Session::CookieStore +use ActionDispatch::Flash +use ActionDispatch::ParamsParser +use Rack::MethodOverride +use ActionDispatch::Head +use ActionDispatch::BestStandardsSupport +run Blog::Application.routes Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/environment.rb +# config/application.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -133,7 +142,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/environment.rb +# config/application.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# environment.rb +# application.rb config.middleware.clear From 635c1ca007a4e86f277508ec5b116ebcbe71a7f2 Mon Sep 17 00:00:00 2001 From: "Mr. Wolfe" Date: Wed, 10 Aug 2011 23:27:00 +0200 Subject: [PATCH 157/164] Revert "update rails on rack guide, section 2 needs to be changed or maybe deleted" This reverts commit 7a4e545eccf834cb620df0f909ef3f4bec4e6608. --- railties/guides/source/rails_on_rack.textile | 33 +++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index ea26334ba0a..8d5985dba8a 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,32 +89,23 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: -use ActionDispatch::Static use Rack::Lock -use ActiveSupport::Cache::Strategy::LocalCache -use Rack::Runtime -use Rails::Rack::Logger -use ActionDispatch::ShowExceptions -use ActionDispatch::RemoteIp -use Rack::Sendfile -use ActionDispatch::Callbacks -use ActiveRecord::ConnectionAdapters::ConnectionManagement -use ActiveRecord::QueryCache -use ActionDispatch::Cookies -use ActionDispatch::Session::CookieStore -use ActionDispatch::Flash -use ActionDispatch::ParamsParser +use ActionController::Failsafe +use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} +use Rails::Rack::Metal +use ActionDispatch::RewindableInput +use ActionController::ParamsParser use Rack::MethodOverride -use ActionDispatch::Head -use ActionDispatch::BestStandardsSupport -run Blog::Application.routes +use Rack::Head +use ActiveRecord::QueryCache +run ActionController::Dispatcher.new Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -127,7 +118,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/application.rb +# config/environment.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -142,7 +133,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/application.rb +# config/environment.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -207,7 +198,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# application.rb +# environment.rb config.middleware.clear From 1b0d03b5db04f19d9428959844624a47f6ba1a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emili=20Parre=C3=B1o?= Date: Wed, 10 Aug 2011 23:32:11 +0200 Subject: [PATCH 158/164] update rails on rack guide, section 2 needs to be changed or maybe deleted --- railties/guides/source/rails_on_rack.textile | 33 +++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index 8d5985dba8a..818df0ffafd 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -89,23 +89,32 @@ $ rake middleware For a freshly generated Rails application, this might produce something like: +use ActionDispatch::Static use Rack::Lock -use ActionController::Failsafe -use ActionController::Session::CookieStore, , {:secret=>"", :session_key=>"__session"} -use Rails::Rack::Metal -use ActionDispatch::RewindableInput -use ActionController::ParamsParser -use Rack::MethodOverride -use Rack::Head +use ActiveSupport::Cache::Strategy::LocalCache +use Rack::Runtime +use Rails::Rack::Logger +use ActionDispatch::ShowExceptions +use ActionDispatch::RemoteIp +use Rack::Sendfile +use ActionDispatch::Callbacks +use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache -run ActionController::Dispatcher.new +use ActionDispatch::Cookies +use ActionDispatch::Session::CookieStore +use ActionDispatch::Flash +use ActionDispatch::ParamsParser +use Rack::MethodOverride +use ActionDispatch::Head +use ActionDispatch::BestStandardsSupport +run Blog::Application.routes Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. h4. Configuring Middleware Stack -Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +environment.rb+ or the environment specific configuration file environments/<environment>.rb. +Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file environments/<environment>.rb. h5. Adding a Middleware @@ -118,7 +127,7 @@ You can add a new middleware to the middleware stack using any of the following * config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack. -# config/environment.rb +# config/application.rb # Push Rack::BounceFavicon at the bottom config.middleware.use Rack::BounceFavicon @@ -133,7 +142,7 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -# config/environment.rb +# config/application.rb # Replace ActionController::Failsafe with Lifo::Failsafe config.middleware.swap ActionController::Failsafe, Lifo::Failsafe @@ -198,7 +207,7 @@ The following shows how to replace use +Rack::Builder+ instead of the Rails supp Clear the existing Rails middleware stack -# environment.rb +# config/application.rb config.middleware.clear From 56efdbc6260f49fdf8d82d8557f233a7df3beafa Mon Sep 17 00:00:00 2001 From: Florent Guilleux Date: Mon, 8 Aug 2011 19:31:03 -0500 Subject: [PATCH 159/164] Document exclamation point on dynamic finders --- activerecord/lib/active_record/base.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4136868b39c..b3a02672762 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -177,6 +177,10 @@ module ActiveRecord #:nodoc: # And instead of writing Person.where(:last_name => last_name).all, you just do # Person.find_all_by_last_name(last_name). # + # It's possible to add an exclamation point (!) on the end of the dynamic finders to get them to raise an + # ActiveRecord::RecordNotFound error if they do not return any records, + # like Person.find_by_last_name!. + # # It's also possible to use multiple attributes in the same find by separating them with "_and_". # # Person.where(:user_name => user_name, :password => password).first From 54cd73e20d5fe2c4168e04f9525b8793e9e3c64c Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 5 Aug 2011 20:15:48 +0530 Subject: [PATCH 160/164] ActiveModel::Validations basic guide --- .../guides/source/active_model_basics.textile | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile index 404cc71c50f..f3a2b2edbcd 100644 --- a/railties/guides/source/active_model_basics.textile +++ b/railties/guides/source/active_model_basics.textile @@ -176,6 +176,30 @@ person.first_name_change #=> ["First Name", "First Name 1"] person.last_name_change #=> nil +h4. Validations + +Validations module adds the ability to class objects to validate them in Active Record style. + + +class Person + include ActiveModel::Validations + + attr_accessor :name, :email + + validates :name, :presence => true + validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i + +end + +person = Person.new +person.valid? #=> false +person.name = 'vishnu' +person.email = 'me' +person.valid? #=> false +person.email = 'me@vishnuatrai.com' +person.valid? #=> true + + h3. Changelog * August 5, 2011: Initial version by "Arun Agrawal":http://github.com/arunagw From 53e1a9d411b2a8720de6958662e9f8f2dd7af2be Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 11 Aug 2011 14:43:48 -0500 Subject: [PATCH 161/164] update abstract_controller callbacks to document meta-programmed filters --- .../lib/abstract_controller/callbacks.rb | 120 +++++++++++++++--- 1 file changed, 102 insertions(+), 18 deletions(-) diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index e8426bc52b5..14c984e41fb 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -75,38 +75,122 @@ module AbstractController end end + ## + # :method: before_filter + # + # :call-seq: before_filter(names, block) + # + # Append a before filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_before_filter + # + # :call-seq: prepend_before_filter(names, block) + # + # Prepend a before filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_before_filter + # + # :call-seq: skip_before_filter(names, block) + # + # Skip a before filter. See _insert_callbacks for parameter details. + + ## + # :method: append_before_filter + # + # :call-seq: append_before_filter(names, block) + # + # Append a before filter. See _insert_callbacks for parameter details. + + ## + # :method: after_filter + # + # :call-seq: after_filter(names, block) + # + # Append an after filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_after_filter + # + # :call-seq: prepend_after_filter(names, block) + # + # Prepend an after filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_after_filter + # + # :call-seq: skip_after_filter(names, block) + # + # Skip an after filter. See _insert_callbacks for parameter details. + + ## + # :method: append_after_filter + # + # :call-seq: append_after_filter(names, block) + # + # Append an after filter. See _insert_callbacks for parameter details. + + ## + # :method: around_filter + # + # :call-seq: around_filter(names, block) + # + # Append an around filter. See _insert_callbacks for parameter details. + + ## + # :method: prepend_around_filter + # + # :call-seq: prepend_around_filter(names, block) + # + # Prepend an around filter. See _insert_callbacks for parameter details. + + ## + # :method: skip_around_filter + # + # :call-seq: skip_around_filter(names, block) + # + # Skip an around filter. See _insert_callbacks for parameter details. + + ## + # :method: append_around_filter + # + # :call-seq: append_around_filter(names, block) + # + # Append an around filter. See _insert_callbacks for parameter details. + # set up before_filter, prepend_before_filter, skip_before_filter, etc. # for each of before, after, and around. [:before, :after, :around].each do |filter| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 # Append a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def #{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} - set_callback(:process_action, :#{filter}, name, options) - end - end + def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} # options[:if] = (Array.wrap(options[:if]) << "!halted") if false + set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options) + end # end + end # end # Prepend a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def prepend_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} - set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) - end - end + def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + options[:if] = (Array.wrap(options[:if]) << "!halted") if #{filter == :after} # options[:if] = (Array.wrap(options[:if]) << "!halted") if false + set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) + end # end + end # end # Skip a before, after or around filter. See _insert_callbacks # for details on the allowed parameters. - def skip_#{filter}_filter(*names, &blk) - _insert_callbacks(names, blk) do |name, options| - skip_callback(:process_action, :#{filter}, name, options) - end - end + def skip_#{filter}_filter(*names, &blk) # def skip_before_filter(*names, &blk) + _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options| + skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :#{filter}, name, options) + end # end + end # end # *_filter is the same as append_*_filter - alias_method :append_#{filter}_filter, :#{filter}_filter + alias_method :append_#{filter}_filter, :#{filter}_filter # alias_method :append_before_filter, :before_filter RUBY_EVAL end end From 0196f0feb12d6a093f7ffa95de9f878be17adea7 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 11 Aug 2011 21:28:57 -0300 Subject: [PATCH 162/164] Some fixes on the 3_1_release_notes guide. --- .../guides/source/3_1_release_notes.textile | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/railties/guides/source/3_1_release_notes.textile b/railties/guides/source/3_1_release_notes.textile index 5f09d8fd2b6..c1585c707ee 100644 --- a/railties/guides/source/3_1_release_notes.textile +++ b/railties/guides/source/3_1_release_notes.textile @@ -13,7 +13,7 @@ endprologue. h3. Upgrading to Rails 3.1 -If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: +If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 in case you haven't and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes: h4. Rails 3.1 requires at least Ruby 1.8.7 @@ -31,13 +31,13 @@ $ cd myapp h4. Vendoring Gems -Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. +Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems. More information: - "bundler homepage":http://gembundler.com h4. Living on the Edge -+Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated bundle command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: ++Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated +bundle+ command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag: $ rails new myapp --edge @@ -79,11 +79,11 @@ h3. Railties * jQuery is the new default JavaScript library. -* jQuery and prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. +* jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems. * The application generator accepts an option -j which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". Currently only "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. -* Generating an application or a plugin runs bundle install unless --skip-gemfile or --skip-bundle is specified. +* Generating an application or a plugin runs +bundle install+ unless --skip-gemfile or --skip-bundle is specified. * The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use CoffeeScript and Sass, if those libraries are available. @@ -115,7 +115,7 @@ h4. Action Controller * URL parameters which return nil for +to_param+ are now removed from the query string. -* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. +* Added ActionController::ParamsWrapper to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting ActionController::Base.wrap_parameters in config/initializer/wrap_parameters.rb. * Added config.action_controller.include_all_helpers. By default helper :all is done in ActionController::Base, which includes all the helpers by default. Setting +include_all_helpers+ to false will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller). @@ -184,7 +184,7 @@ h4. Action Dispatch * Moved etag responsibility from ActionDispatch::Response to the middleware stack. -* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. +* Rely on Rack::Session stores API for more compatibility across the Ruby world. This is backwards incompatible since Rack::Session expects #get_session to accept four arguments and requires #destroy_session instead of simply #destroy. * Template lookup now searches further up in the inheritance chain. @@ -209,7 +209,7 @@ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)}) Keys are dasherized. Values are JSON-encoded, except for strings and symbols. -* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases csrf_meta_tag for backwards compatibility. +* +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases +csrf_meta_tag+ for backwards compatibility. * The old template handler API is deprecated and the new API simply requires a template handler to respond to call. @@ -219,13 +219,13 @@ Keys are dasherized. Values are JSON-encoded, except for strings and symbols. * The submit form helper does not generate an id "object_name_id" anymore. -* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }) +* Allows FormHelper#form_for to specify the :method as a direct option instead of through the :html hash. form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete }). -* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. +* Provided JavaScriptHelper#j() as an alias for JavaScriptHelper#escape_javascript(). This supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper. * Allows AM/PM format in datetime selectors. -* auto_link has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink +* +auto_link+ has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink h3. Active Record @@ -261,7 +261,7 @@ end Post.new(params[:post], :as => :admin) -* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation: +* +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation. * Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped. @@ -282,19 +282,19 @@ People.offset(1).count # => 'SELECT COUNT(*) FROM people' People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1' -* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper +called+ CollectionProxy, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. +* ActiveRecord::Associations::AssociationProxy has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings. * Singular associations (has_one, belongs_to) no longer have a proxy and simply returns the associated record or nil. This means that you should not use undocumented methods such as bob.mother.create - use bob.create_mother instead. -* Support the :dependent option on has_many :through associations. For historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. +* Support the :dependent option on has_many :through associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is +:nullify+ for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association. -* The behavior of association.destroy for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. +* The behavior of +association.destroy+ for +has_and_belongs_to_many+ and has_many :through is changed. From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link', not (necessarily) 'get rid of the associated records'. -* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. +* Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table. -* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. +* Previously, has_many_through.destroy(*records) would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table. -* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy) +* Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to 'deprecate' it before changing it. The change is being made in order to have consistency as to the meaning of 'destroy' or 'delete' across the different types of associations. If you wish to destroy the records themselves, you can do records.association.each(&:destroy). * Add :bulk => true option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement. @@ -321,7 +321,7 @@ class MyMigration < ActiveRecord::Migration end -* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define 'up' and 'down' in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. +* Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define +up+ and +down+ in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down. * Migrations now use instance methods rather than class methods: @@ -392,7 +392,7 @@ end h3. Active Support -* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in load_missing_constant. +* ActiveSupport::Dependencies now raises +NameError+ if it finds an existing constant in +load_missing_constant+. * Added a new reporting method Kernel#quietly which silences both +STDOUT+ and +STDERR+. @@ -404,13 +404,13 @@ h3. Active Support * ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes. -* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new ClassCache. +* ActiveSupport::Dependencies::Reference has been refactored to take direct advantage of the new +ClassCache+. * Backports Range#cover? as an alias for Range#include? in Ruby 1.8. * Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time. -* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants! +* Added +before_remove_const+ callback to ActiveSupport::Dependencies.remove_unloadable_constants!. Deprecations: From aa0d3cece80f6181bbd664596c46fc0f65b4abbe Mon Sep 17 00:00:00 2001 From: Oge Nnadi Date: Fri, 12 Aug 2011 12:00:32 -0300 Subject: [PATCH 163/164] Typo fix --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 667ba15cc91..0031d2701f0 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -38,7 +38,7 @@ module ActionController #:nodoc: # :action => 'lists' is not the same as # :action => 'list', :format => :xml. # - # You can set modify the default action cache path by passing a + # You can modify the default action cache path by passing a # :cache_path option. This will be passed directly to # ActionCachePath.path_for. This is handy for actions with # multiple possible routes that should be cached differently. If a From f566fb32c49a81636ca341f376f99ef230d71d99 Mon Sep 17 00:00:00 2001 From: Waynn Lue Date: Fri, 12 Aug 2011 17:23:16 -0700 Subject: [PATCH 164/164] "suits" is correct here, not "suites" --- RELEASING_RAILS.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASING_RAILS.rdoc b/RELEASING_RAILS.rdoc index e3d3f67237e..4a9a875bfa9 100644 --- a/RELEASING_RAILS.rdoc +++ b/RELEASING_RAILS.rdoc @@ -30,7 +30,7 @@ Do not release with Red AWDwR tests. Having git dependencies indicates that we depend on unreleased code. Obviously rails cannot be released when it depends on unreleased code. Contact the authors of those particular gems and work out a release date that -suites them. +suits them. === Contact the security team (either Koz or tenderlove)