From d790b50db4b0e605a915b4a4af5f81acae7b6094 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Sun, 12 May 2013 22:27:40 -0400 Subject: Document ActionMailer::Base#set_content_type --- actionmailer/lib/action_mailer/base.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d2e01cfd4c..d68182c0ff 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -720,6 +720,15 @@ module ActionMailer protected + # Used by #mail to set the content type of the message. + # + # It will use the given +user_content_type+, or multipart if the mail + # message has any attachments. If the attachments are inline, the content + # type will be "multipart/related", otherwise "multipart/mixed". + # + # If there is no content type passed in via headers, and there are no + # attachments, or the message is multipart, then the default content type is + # used. def set_content_type(m, user_content_type, class_default) params = m.content_type_parameters || {} case -- cgit v1.2.3 From f173c8c533f01548ca3da588de025c50a92cd745 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 13 May 2013 15:28:12 +0100 Subject: Adding notes on PATCH to the upgrade guide. Discusses compatibility between PATCH and PUT, as well as how to add support for JSON PATCH to your application. Fixes #10439. --- guides/source/upgrading_ruby_on_rails.md | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 1d14656f79..694592a9de 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -22,6 +22,59 @@ Rails generally stays close to the latest released Ruby version when it's releas TIP: Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition has these fixed since the release of 1.8.7-2010.02. 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 straight to 1.9.3 for smooth sailing. +### HTTP PATCH + +Rails 4 now uses `PATCH` as the primary HTTP verb for updates. When a resource +is declared in `config/routes.rb`: + +```ruby +resources :users +``` + +the action in `UsersController` to update a user is still `update`. + +`PUT` requests to `/users/:id` in Rails 4 get routed to `update` as they are +today. So, if you have an API that gets real PUT requests it is going to work. +The router also routes `PATCH` requests to `/users/:id` to the `update` action. + +So, in Rails 4 both `PUT` and `PATCH` are routed to update. We recommend +switching to `PATCH` as part of your upgrade process if possible, as it's more +likely what you want. + +For more on PATCH and why this change was made, see [this post](http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/) +on the Rails blog. + +#### A note about media types + +The erratta for the `PATCH` verb [specifies that a 'diff' media type should be +used with `PATCH`](http://www.rfc-editor.org/errata_search.php?rfc=5789). One +such format is [JSON Patch](http://tools.ietf.org/html/rfc6902). While Rails +does not support JSON Patch natively, it's easy enough to add support: + +``` +# in your controller +def update + respond_to do |format| + format.json do + # perform a partial update + @post.update params[:post] + end + + format.json_patch do + # perform sophisticated change + end + end +end + +# In config/initializers/json_patch.rb: +Mime::Type.register 'application/json-patch+json', :json_patch +``` + +As JSON Patch was only recently made into an RFC, there aren't a lot of great +Ruby libraries yet. Aaron Patterson's +[hana](https://github.com/tenderlove/hana) is one such gem, but doesn't have +full support for the last few changes in the specification. + Upgrading from Rails 3.2 to Rails 4.0 ------------------------------------- -- cgit v1.2.3 From 7b24cf0391ed8916bf12781a179b4ac5995e1690 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 13 May 2013 11:39:09 -0400 Subject: emphasize that callbacks are called in destroy_all Cleaned up rdoc a bit emphasizing that callbacks are called. Also removed the stress on the fact that records are always removed. If callbacks return false then records will not be deleted. --- .../lib/active_record/associations/collection_association.rb | 8 ++++---- activerecord/lib/active_record/associations/collection_proxy.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 2a00ac1386..efd7ecb97c 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -237,11 +237,11 @@ module ActiveRecord end end - # Destroy +records+ and remove them from this association calling - # +before_remove+ and +after_remove+ callbacks. + # Deletes the +records+ and removes them from this association calling + # +before_remove+ , +after_remove+ , +before_destroy+ and +after_destroy+ callbacks. # - # Note that this method will _always_ remove records from the database - # ignoring the +:dependent+ option. + # Note that this method removes records from the database ignoring the + # +:dependent+ option. def destroy(*records) records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) } delete_or_destroy(records, :destroy) diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 71b64de5ea..e82c195335 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -422,9 +422,9 @@ module ActiveRecord @association.delete_all end - # Deletes the records of the collection directly from the database. - # This will _always_ remove the records ignoring the +:dependent+ - # option. + # Deletes the records of the collection directly from the database + # ignoring the +:dependent+ option. It invokes +before_remove+, + # +after_remove+ , +before_destroy+ and +after_destroy+ callbacks. # # class Person < ActiveRecord::Base # has_many :pets -- cgit v1.2.3 From d6bf62c3c6be07dd4208214f86b8b122b4f3d16a Mon Sep 17 00:00:00 2001 From: Adam Konner Date: Mon, 13 May 2013 13:14:46 -0400 Subject: fix grammar --- guides/source/migrations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/source/migrations.md b/guides/source/migrations.md index fcfc54a3d7..ceb1859c2f 100644 --- a/guides/source/migrations.md +++ b/guides/source/migrations.md @@ -1065,8 +1065,8 @@ with foreign key constraints in the database. Although Active Record does not provide any tools for working directly with such features, the `execute` method can be used to execute arbitrary SQL. You -could also use some gem like -[foreigner](https://github.com/matthuhiggins/foreigner) which add foreign key +can also use a gem like +[foreigner](https://github.com/matthuhiggins/foreigner) which adds foreign key support to Active Record (including support for dumping foreign keys in `db/schema.rb`). -- cgit v1.2.3 From af2d212b63d5af09044d30e3dfbaec8b31f26fd7 Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Tue, 14 May 2013 00:22:59 +0530 Subject: Added documentation for Rails::Generators::NamedBase.template --- railties/lib/rails/generators/named_base.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index d891ba1215..fbb747970d 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -18,6 +18,10 @@ module Rails parse_attributes! if respond_to?(:attributes) end + # Defines the template that would be used for the migration file. + # The source defines the source template file that would be used in creating the migration + # The args is an array containing any other options and the name of the file which would be saved on the filesystem + no_tasks do def template(source, *args, &block) inside_template do -- cgit v1.2.3 From 87d71b02b85a44ce461e533666ef5f0e43a46531 Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Tue, 14 May 2013 00:27:52 +0530 Subject: Added documentation for model migration generation --- .../lib/rails/generators/active_record/model/model_generator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index 40e134e626..821df0e0d6 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -12,6 +12,9 @@ module ActiveRecord class_option :parent, :type => :string, :desc => "The parent class for the generated model" class_option :indexes, :type => :boolean, :default => true, :desc => "Add indexes for references and belongs_to columns" + + # creates the migration file for the model first followed by the model file itself + def create_migration_file return unless options[:migration] && options[:parent].nil? attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false @@ -39,6 +42,7 @@ module ActiveRecord protected + # Used by the migration template to determine the parent name of the model def parent_class_name options[:parent] || "ActiveRecord::Base" end -- cgit v1.2.3 From ddf07d21834f4ad88c25334829348f5e4000fea0 Mon Sep 17 00:00:00 2001 From: Anton Kalyaev Date: Tue, 14 May 2013 10:15:32 +0400 Subject: improved doc for ActiveRecord#find_by_sql method (Refs #10599) [ci skip] --- activerecord/lib/active_record/querying.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb index f78ccb01aa..3d85898c41 100644 --- a/activerecord/lib/active_record/querying.rb +++ b/activerecord/lib/active_record/querying.rb @@ -14,7 +14,7 @@ module ActiveRecord # Executes a custom SQL query against your database and returns all the results. The results will # be returned as an array with columns requested encapsulated as attributes of the model you call # this method from. If you call Product.find_by_sql then the results will be returned in - # a Product object with the attributes you specified in the SQL query. + # a +Product+ object with the attributes you specified in the SQL query. # # If you call a complicated SQL query which spans multiple tables the columns specified by the # SELECT will be attributes of the model, whether or not they are columns of the corresponding @@ -29,9 +29,10 @@ module ActiveRecord # Post.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id" # # => [#"Ruby Meetup", "first_name"=>"Quentin"}>, ...] # - # # You can use the same string replacement techniques as you can with ActiveRecord#find + # You can use the same string replacement techniques as you can with ActiveRecord::QueryMethods#where: + # # Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date] - # # => [#"The Cheap Man Buys Twice"}>, ...] + # Post.find_by_sql ["SELECT body FROM comments WHERE author = :user_id OR approved_by = :user_id", { :user_id => user_id }] def find_by_sql(sql, binds = []) result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds) column_types = {} -- cgit v1.2.3 From 4d88e85d98639b4ea6ec7e67b8c5a52422199b0f Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Tue, 14 May 2013 21:04:32 +0300 Subject: Use new hash syntax --- guides/source/migrations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/source/migrations.md b/guides/source/migrations.md index ceb1859c2f..550f8fdc3c 100644 --- a/guides/source/migrations.md +++ b/guides/source/migrations.md @@ -852,7 +852,7 @@ end # app/models/product.rb class Product < ActiveRecord::Base - validates :flag, :inclusion => { :in => [true, false] } + validates :flag, inclusion: { in: [true, false] } end ``` @@ -877,7 +877,7 @@ end # app/models/product.rb class Product < ActiveRecord::Base - validates :flag, :inclusion => { :in => [true, false] } + validates :flag, inclusion: { in: [true, false] } validates :fuzz, presence: true end ``` -- cgit v1.2.3 From e47c85c696de1c4137c222bedc846b2cdbb0893f Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 15 May 2013 00:17:37 -0400 Subject: ActionMailer::Collector should be nodoc'd --- actionmailer/lib/action_mailer/collector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index e8883a8235..a44195ae98 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/array/extract_options' module ActionMailer - class Collector + class Collector # :nodoc: all include AbstractController::Collector attr_reader :responses -- cgit v1.2.3 From 41c3670fab23f3eb1acbd415d47cbf36dbc36bca Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 15 May 2013 00:19:38 -0400 Subject: Document ActionMailer::LogSubscriber and ActionMailer::DeliveryMethods::ClassMethods --- actionmailer/lib/action_mailer/delivery_methods.rb | 1 + actionmailer/lib/action_mailer/log_subscriber.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index caea3d7535..9a1a27c8ed 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -38,6 +38,7 @@ module ActionMailer add_delivery_method :test, Mail::TestMailer end + # Helpers for creating and wrapping delivery behavior, used by DeliveryMethods. module ClassMethods # Provides a list of emails that have been delivered by Mail::TestMailer delegate :deliveries, :deliveries=, to: Mail::TestMailer diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 3fe64759ac..c108156792 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -1,5 +1,8 @@ module ActionMailer + # Implements the ActiveSupport::LogSubscriber for logging notifications when + # email is delivered and received. class LogSubscriber < ActiveSupport::LogSubscriber + # An email was delivered. def deliver(event) return unless logger.info? recipients = Array(event.payload[:to]).join(', ') @@ -7,12 +10,14 @@ module ActionMailer debug(event.payload[:mail]) end + # An email was received. def receive(event) return unless logger.info? info("\nReceived mail (#{event.duration.round(1)}ms)") debug(event.payload[:mail]) end + # Use the logger configured for ActionMailer::Base def logger ActionMailer::Base.logger end -- cgit v1.2.3 From 98d81def34c3a7c6d47f11d324702321480e210c Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 15 May 2013 00:36:07 -0400 Subject: Document ActionMailer::MailHelper --- actionmailer/lib/action_mailer/mail_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index ec84256491..892eb2472f 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,4 +1,7 @@ module ActionMailer + # Provides helper methods for ActionMailer::Base that can be used for easily + # formatting messages, accessing mailer or message instances, and the + # attachments list. module MailHelper # Take the text and format it, indented two spaces for each line, and # wrapped at 72 columns. -- cgit v1.2.3 From 328e876a1569058e47eaf7ea3f4f045a83b585fa Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 15 May 2013 00:38:51 -0400 Subject: nodoc ActionMailer module from lib/action_mailer/*.rb --- actionmailer/lib/action_mailer/base.rb | 2 +- actionmailer/lib/action_mailer/collector.rb | 2 +- actionmailer/lib/action_mailer/delivery_methods.rb | 2 +- actionmailer/lib/action_mailer/log_subscriber.rb | 2 +- actionmailer/lib/action_mailer/mail_helper.rb | 2 +- actionmailer/lib/action_mailer/railtie.rb | 2 +- actionmailer/lib/action_mailer/test_case.rb | 2 +- actionmailer/lib/action_mailer/test_helper.rb | 2 +- actionmailer/lib/action_mailer/version.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d68182c0ff..6da0064148 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -5,7 +5,7 @@ require 'active_support/core_ext/hash/except' require 'active_support/core_ext/module/anonymous' require 'action_mailer/log_subscriber' -module ActionMailer +module ActionMailer # :nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. # # = Mailer Models diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index a44195ae98..b2b4957369 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -2,7 +2,7 @@ require 'abstract_controller/collector' require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/array/extract_options' -module ActionMailer +module ActionMailer # :nodoc: class Collector # :nodoc: all include AbstractController::Collector attr_reader :responses diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index 9a1a27c8ed..5a7c4d8bfb 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -1,6 +1,6 @@ require 'tmpdir' -module ActionMailer +module ActionMailer # :nodoc: # This module handles everything related to mail delivery, from registering # new delivery methods to configuring the mail object to be sent. module DeliveryMethods diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index c108156792..f2ee1d3ec4 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -1,4 +1,4 @@ -module ActionMailer +module ActionMailer # :nodoc: # Implements the ActiveSupport::LogSubscriber for logging notifications when # email is delivered and received. class LogSubscriber < ActiveSupport::LogSubscriber diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 892eb2472f..642f90bd3e 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,4 +1,4 @@ -module ActionMailer +module ActionMailer # :nodoc: # Provides helper methods for ActionMailer::Base that can be used for easily # formatting messages, accessing mailer or message instances, and the # attachments list. diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 7677ff3a7c..9f2e5abed5 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -2,7 +2,7 @@ require "action_mailer" require "rails" require "abstract_controller/railties/routes_helpers" -module ActionMailer +module ActionMailer # :nodoc: class Railtie < Rails::Railtie # :nodoc: config.action_mailer = ActiveSupport::OrderedOptions.new config.eager_load_namespaces << ActionMailer diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 207f949fe2..2f5c4b268c 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,6 +1,6 @@ require 'active_support/test_case' -module ActionMailer +module ActionMailer # :nodoc: class NonInferrableMailerError < ::StandardError def initialize(name) super "Unable to determine the mailer to test from #{name}. " + diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 6452bf616c..58e46a7af2 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -1,4 +1,4 @@ -module ActionMailer +module ActionMailer # :nodoc: module TestHelper # Asserts that the number of emails sent matches the given number. # diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 9d00091972..19bf7a8c51 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,4 +1,4 @@ -module ActionMailer +module ActionMailer # :nodoc: # Returns the version of the currently loaded ActionMailer as a Gem::Version def self.version Gem::Version.new "4.1.0.beta" -- cgit v1.2.3 From dfb69f2b8a85586ad70071baba416747cbb07364 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Wed, 15 May 2013 00:48:31 -0400 Subject: Document Rails::Generators::MailerGenerator --- actionmailer/lib/rails/generators/mailer/mailer_generator.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb index d5bf864595..c77cb6ab5e 100644 --- a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb +++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb @@ -1,11 +1,13 @@ -module Rails - module Generators +module Rails # :nodoc: + module Generators # :nodoc: + # Implements the Rails::Generators for creating new mailers. class MailerGenerator < NamedBase source_root File.expand_path("../templates", __FILE__) argument :actions, type: :array, default: [], banner: "method method" check_class_collision + # Generates the mailer file for the application. def create_mailer_file template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb") end -- cgit v1.2.3 From 0fbf31b2000e467f18ebba90efb3a88fa1a4a7c9 Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Wed, 15 May 2013 12:28:08 +0530 Subject: Added documentation for ActiveRecord::Associations::Builder::Association class --- activerecord/lib/active_record/associations/builder/association.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 5c37f42794..34684fd71a 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -1,3 +1,7 @@ +# This is the parent Association class which defines certain class variables (valid_options) and +# instance variables (model, name, scope, options, reflection) which would be common across all the associations that we known today in Rails.. +# Every association need to have the values of these variables set and they are used at multiple places + module ActiveRecord::Associations::Builder class Association #:nodoc: class << self -- cgit v1.2.3 From da8fff528ddcf3ea92f5c6cc402105e0403bb74a Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Wed, 15 May 2013 15:07:55 +0530 Subject: Added some more documentation for ActiveRecord::Associations::Builder::Association class --- .../lib/active_record/associations/builder/association.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 34684fd71a..456041cce8 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -1,6 +1,17 @@ # This is the parent Association class which defines certain class variables (valid_options) and # instance variables (model, name, scope, options, reflection) which would be common across all the associations that we known today in Rails.. # Every association need to have the values of these variables set and they are used at multiple places +# The heirarchy is defined as follows: +# Association +# - SingularAssociation +# - BelongsTo +# - HasOne +# - CollectionAssociation +# - HasMany +# - HasAndBelongsToMany +# +# The HasMany :Through association is a special case of HasMany association with the :through option set for it +# module ActiveRecord::Associations::Builder class Association #:nodoc: -- cgit v1.2.3 From 90e60aa4694be408b299085cad8b8a6be64df0ac Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Wed, 15 May 2013 15:31:53 +0530 Subject: Added some more documentation for define_readers and define_writer of the Association and its inherited classes --- activerecord/lib/active_record/associations/builder/association.rb | 7 +++++++ .../active_record/associations/builder/collection_association.rb | 4 ++++ .../lib/active_record/associations/builder/singular_association.rb | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 456041cce8..4b72846ef6 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -73,6 +73,13 @@ module ActiveRecord::Associations::Builder def validate_options options.assert_valid_keys(valid_options) end + + # Defines the setter and getter methods for the association + # class Post < ActiveRecord::Base + # has_many :comments + # end + # + # Post.first.comments and Post.first.comments= methods are defined by this method... def define_accessors define_readers diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index fdead16761..9c6690b721 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -1,3 +1,5 @@ +# This class is inherited by the has_many and has_many_and_belongs_to_many association classes + require 'active_record/associations' module ActiveRecord::Associations::Builder @@ -66,6 +68,8 @@ module ActiveRecord::Associations::Builder model.send("#{full_callback_name}=", Array(options[callback_name.to_sym])) end + # Defines the setter and getter methods for the collection_singular_ids. + def define_readers super diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index f06426a09d..96ccbeb8a3 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -1,3 +1,5 @@ +# This class is inherited by the has_one and belongs_to association classes + module ActiveRecord::Associations::Builder class SingularAssociation < Association #:nodoc: def valid_options @@ -13,6 +15,8 @@ module ActiveRecord::Associations::Builder define_constructors if constructable? end + # Defines the (build|create)_association methods for belongs_to or has_one association + def define_constructors mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def build_#{name}(*args, &block) -- cgit v1.2.3 From 8f901dee9e2072dd20e0a252a89dd501d783d85b Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Thu, 16 May 2013 01:54:54 +0530 Subject: Corrected documentation and added some more for the classify method in inflectors --- activesupport/lib/active_support/inflector/methods.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 39648727fd..3c46cd9690 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -138,16 +138,25 @@ module ActiveSupport pluralize(underscore(class_name)) end - # Create a class name from a plural table name like Rails does for table - # names to models. Note that this returns a string and not a Class (To - # convert to an actual class follow +classify+ with +constantize+). + # Create a class name from a plural table name like Rails does for table names to models. + # Note that this returns a string and not a class. (To convert to an actual class + # follow +classify+ with +constantize+.) # # 'egg_and_hams'.classify # => "EggAndHam" # 'posts'.classify # => "Post" # - # Singular names are not handled correctly: + # Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly such as + # for "business", "address" the classify function would return "busines" and "addres" respectively.. but now + # this has been resolved and corrected in Rails 4 + # + # 'business'.classify # => "Business" + # 'address'.classify # => "Address" # - # 'business'.classify # => "Busines" + # Yet some singular names are not handled correctly and I guess we would work upon it to improve upon these shortcomings + # + # "radius".classify #=> "Radiu" it should be "Radius" + # "feet".classify #=> "Foot", it should be "Feet" + # "abacus".classify #=> "Abacu" it should be "Abacus" def classify(table_name) # strip out any leading schema name camelize(singularize(table_name.to_s.sub(/.*\./, ''))) -- cgit v1.2.3 From 5554775980b27b64a5ae5810cabc4886776b9206 Mon Sep 17 00:00:00 2001 From: Radu Busuioc Date: Thu, 16 May 2013 18:46:00 +0100 Subject: Corrected documentation regarding validation errors --- guides/source/active_record_validations.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index dfc951f10e..621d2222ff 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -162,8 +162,8 @@ Person.create(name: nil).valid? # => false ``` After Active Record has performed validations, any errors found can be accessed -through the `errors` instance method, which returns a collection of errors. By -definition, an object is valid if this collection is empty after running +through the `errors.messages` instance method, which returns a collection of errors. +By definition, an object is valid if this collection is empty after running validations. Note that an object instantiated with `new` will not report errors even if it's @@ -176,17 +176,17 @@ end >> p = Person.new #=> # ->> p.errors +>> p.errors.messages #=> {} >> p.valid? #=> false ->> p.errors +>> p.errors.messages #=> {name:["can't be blank"]} >> p = Person.create #=> # ->> p.errors +>> p.errors.messages #=> {name:["can't be blank"]} >> p.save @@ -993,12 +993,12 @@ end person = Person.new person.valid? # => false -person.errors +person.errors.messages # => {:name=>["can't be blank", "is too short (minimum is 3 characters)"]} person = Person.new(name: "John Doe") person.valid? # => true -person.errors # => [] +person.errors.messages # => {} ``` ### `errors[]` -- cgit v1.2.3 From 98849c71acb8623546a22898497baa4d9b435b12 Mon Sep 17 00:00:00 2001 From: kennyj Date: Fri, 17 May 2013 00:56:31 +0900 Subject: Fix AM testcase break with mail 2.5.4. It seems that AM's testcase was wrong. --- actionmailer/CHANGELOG.md | 5 ++++- actionmailer/test/mailers/base_mailer.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 9e9d07b386..41436de526 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,6 @@ -* No changes. +* Fix ActionMailer testcase break with mail 2.5.4. + ActionMailer's testcase was wrong, because :transfer_encoding option was ignored in mail 2.5.3. + + *kennyj* Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md) for previous changes. diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index 20b6671283..6584bf5195 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -38,7 +38,7 @@ class BaseMailer < ActionMailer::Base end def attachment_with_hash - attachments['invoice.jpg'] = { data: "\312\213\254\232)b", + attachments['invoice.jpg'] = { data: ::Base64.encode64("\312\213\254\232)b"), mime_type: "image/x-jpg", transfer_encoding: "base64" } mail -- cgit v1.2.3 From 872e2a8184c3ba79d4fc5862bbfb09e12bb61ca1 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Fri, 17 May 2013 09:04:44 +0530 Subject: "normalize_callback_params" doesn't require name param --- activesupport/lib/active_support/callbacks.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index bbfa74f98d..85b7669353 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -537,7 +537,7 @@ module ActiveSupport module ClassMethods - def normalize_callback_params(name, filters, block) # :nodoc: + def normalize_callback_params(filters, block) # :nodoc: type = CALLBACK_FILTER_TYPES.include?(filters.first) ? filters.shift : :before options = filters.last.is_a?(Hash) ? filters.pop : {} filters.unshift(block) if block @@ -589,7 +589,7 @@ module ActiveSupport # * :prepend - If +true+, the callback will be prepended to the # existing chain rather than appended. def set_callback(name, *filter_list, &block) - type, filters, options = normalize_callback_params(name, filter_list, block) + type, filters, options = normalize_callback_params(filter_list, block) self_chain = get_callbacks name mapped = filters.map do |filter| Callback.build(self_chain, filter, type, options) @@ -609,7 +609,7 @@ module ActiveSupport # skip_callback :validate, :before, :check_membership, if: -> { self.age > 18 } # end def skip_callback(name, *filter_list, &block) - type, filters, options = normalize_callback_params(name, filter_list, block) + type, filters, options = normalize_callback_params(filter_list, block) __update_callbacks(name) do |target, chain| filters.each do |filter| -- cgit v1.2.3 From 94b97f6154e3a86fe4520dc685d010a533105650 Mon Sep 17 00:00:00 2001 From: Megan Bowra-Dean Date: Fri, 17 May 2013 17:48:25 +1200 Subject: Fix documentation for ActionMailer template names. ActionMailer templates that are not plain text do not require *.text.* in the name and will fail to be picked up automatically if it is included in the name. --- actionmailer/lib/action_mailer/base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 6da0064148..c363eca8ea 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -151,9 +151,9 @@ module ActionMailer # :nodoc: # # For example, if the following templates exist: # * signup_notification.text.erb - # * signup_notification.text.html.erb - # * signup_notification.text.xml.builder - # * signup_notification.text.yaml.erb + # * signup_notification.html.erb + # * signup_notification.xml.builder + # * signup_notification.yaml.erb # # Each would be rendered and added as a separate part to the message, with the corresponding content # type. The content type for the entire message is automatically set to multipart/alternative, @@ -175,7 +175,7 @@ module ActionMailer # :nodoc: # end # end # - # Which will (if it had both a welcome.text.erb and welcome.text.html.erb + # Which will (if it had both a welcome.text.erb and welcome.html.erb # template in the view directory), send a complete multipart/mixed email with two parts, # the first part being a multipart/alternative with the text and HTML email parts inside, # and the second being a application/pdf with a Base64 encoded copy of the file.pdf book -- cgit v1.2.3 From 2b66b32a4cddfe37006f8e457d329f26aab477b0 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 18 May 2013 13:11:17 +0530 Subject: Don't autorequire mocha to avoid deprecation warnings - https://travis-ci.org/rails/rails/jobs/7264822 contains deprecated warnings given by Mocha version 0.14 - 632f215da added Mocha 0.14 to Gemfile - But with the version, require: false was removed - So Mocha started giving deprecation warnings - Acc.to Mocha documentation(https://github.com/freerange/mocha#bundler) it should not be auto required. --- Gemfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index d1fa0c2a1d..b0f91c6dac 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,11 @@ source 'https://rubygems.org' gemspec -gem 'mocha', '~> 0.14' +# This needs to be with require false as it is +# loaded after loading the test library to +# ensure correct loading order +gem 'mocha', '~> 0.14', require: false + gem 'rack-cache', '~> 1.2' gem 'bcrypt-ruby', '~> 3.0.0' gem 'jquery-rails', '~> 2.2.0' -- cgit v1.2.3 From 0123c39f41e2062311b2197e6e230ef8ad67e20e Mon Sep 17 00:00:00 2001 From: Takehiro Adachi Date: Sat, 18 May 2013 17:12:46 +0900 Subject: Add test to AR's counter_cache_test.rb According to https://github.com/rails/rails/blob/b601399b72ab56cc01368f02615af99f45d1 4f02/activerecord/lib/active_record/counter_cache.rb#L14, u can pass more then one association to the `reset_counters` method. --- activerecord/test/cases/counter_cache_test.rb | 12 ++++++++++++ activerecord/test/models/reply.rb | 1 + activerecord/test/schema/schema.rb | 1 + 3 files changed, 14 insertions(+) diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index ac093251a5..61f9d4cdae 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -51,6 +51,18 @@ class CounterCacheTest < ActiveRecord::TestCase end end + test 'reset multiple association counters' do + Topic.increment_counter(:replies_count, @topic.id) + assert_difference '@topic.reload.replies_count', -1 do + Topic.reset_counters(@topic.id, :replies, :unique_replies) + end + + Topic.increment_counter(:unique_replies_count, @topic.id) + assert_difference '@topic.reload.unique_replies_count', -1 do + Topic.reset_counters(@topic.id, :replies, :unique_replies) + end + end + test "reset counters with string argument" do Topic.increment_counter('replies_count', @topic.id) diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index c88262580e..3e82e55d89 100644 --- a/activerecord/test/models/reply.rb +++ b/activerecord/test/models/reply.rb @@ -7,6 +7,7 @@ class Reply < Topic end class UniqueReply < Reply + belongs_to :topic, :foreign_key => 'parent_id', :counter_cache => true validates_uniqueness_of :content, :scope => 'parent_id' end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 8beb58f3fc..188a3f0164 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -675,6 +675,7 @@ ActiveRecord::Schema.define do end t.boolean :approved, :default => true t.integer :replies_count, :default => 0 + t.integer :unique_replies_count, :default => 0 t.integer :parent_id t.string :parent_title t.string :type -- cgit v1.2.3 From 2dbb346ffe1be19e3480564391edb34cce7c8dde Mon Sep 17 00:00:00 2001 From: Takehiro Adachi Date: Sat, 18 May 2013 18:22:21 +0900 Subject: Fix tests which started to fail due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e Due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e, column topic.unique_replies_count has been added, and these test started to fail since the tests depends on the topic tables column info. --- activerecord/test/cases/base_test.rb | 2 +- activerecord/test/cases/reflection_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index d20ccaa5ca..15d536daf5 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1236,7 +1236,7 @@ class BasicsTest < ActiveRecord::TestCase def test_inspect_instance topic = topics(:first) - assert_equal %(#), topic.inspect + assert_equal %(#), topic.inspect end def test_inspect_new_instance diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index a9d46f4fba..b5314bc9be 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -35,18 +35,18 @@ class ReflectionTest < ActiveRecord::TestCase def test_read_attribute_names assert_equal( - %w( id title author_name author_email_address bonus_time written_on last_read content important group approved replies_count parent_id parent_title type created_at updated_at ).sort, + %w( id title author_name author_email_address bonus_time written_on last_read content important group approved replies_count unique_replies_count parent_id parent_title type created_at updated_at ).sort, @first.attribute_names.sort ) end def test_columns - assert_equal 17, Topic.columns.length + assert_equal 18, Topic.columns.length end def test_columns_are_returned_in_the_order_they_were_declared column_names = Topic.columns.map { |column| column.name } - assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content important approved replies_count parent_id parent_title type group created_at updated_at), column_names + assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content important approved replies_count unique_replies_count parent_id parent_title type group created_at updated_at), column_names end def test_content_columns -- cgit v1.2.3 From f8a3dda6ce268ac428a8624d788bf16dc4264d55 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 18 May 2013 19:22:46 +0530 Subject: Fxied some typos --- activerecord/CHANGELOG.md | 2 +- railties/CHANGELOG.md | 2 +- railties/lib/rails/tasks.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 858c33c4e5..19d2195bca 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,4 +1,4 @@ -* Also support extentions in PostgreSQL 9.1. This feature has been supported since 9.1. +* Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1. *kennyj* diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 04cdbec428..d11b0b7e85 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -4,7 +4,7 @@ *Arun Agrawal* * Rails::Railtie no longer forces the Rails::Configurable module on everything - that subclassess it. Instead, the methods from Rails::Configurable have been + that subclasses it. Instead, the methods from Rails::Configurable have been moved to class methods in Railtie and the Railtie has been made abstract. *John Wang* diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index 9807000578..142af2d792 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -1,6 +1,6 @@ $VERBOSE = nil -# Load Rails rakefile extensions +# Load Rails Rakefile extensions %w( annotations documentation -- cgit v1.2.3 From 8d5fcb691e7496900f1c77dff8d6e729c1b56201 Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Sun, 19 May 2013 10:45:58 +0530 Subject: Changed the CHANGELOG for active_support and improved the doc for inflector method classify --- activesupport/CHANGELOG.md | 8 ++++++++ activesupport/lib/active_support/inflector/methods.rb | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 7c666a9b83..df584eb643 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -23,4 +23,12 @@ *Daniel Schierbeck* +* Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly + such as for "business", "address" the classify function would return "busines" and "addres" respectively.. but now this has been resolved and corrected in Rails 4 + + # 'business'.classify # => "Business" + # 'address'.classify # => "Address" + + *Aditya Kapoor* + Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activesupport/CHANGELOG.md) for previous changes. diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 3c46cd9690..0a24e5afb8 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -145,14 +145,7 @@ module ActiveSupport # 'egg_and_hams'.classify # => "EggAndHam" # 'posts'.classify # => "Post" # - # Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly such as - # for "business", "address" the classify function would return "busines" and "addres" respectively.. but now - # this has been resolved and corrected in Rails 4 - # - # 'business'.classify # => "Business" - # 'address'.classify # => "Address" - # - # Yet some singular names are not handled correctly and I guess we would work upon it to improve upon these shortcomings + # Some singular names are not handled correctly, such as: # # "radius".classify #=> "Radiu" it should be "Radius" # "feet".classify #=> "Foot", it should be "Feet" -- cgit v1.2.3 From 84d3f7bd097ce88bc7fb2924e6ad2afb4297d01b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:05:35 +0530 Subject: Revert "Document Rails::Generators::MailerGenerator" This reverts commit dfb69f2b8a85586ad70071baba416747cbb07364. Reason: Let's not nodoc without reason. [ci skip] --- actionmailer/lib/rails/generators/mailer/mailer_generator.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb index c77cb6ab5e..d5bf864595 100644 --- a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb +++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb @@ -1,13 +1,11 @@ -module Rails # :nodoc: - module Generators # :nodoc: - # Implements the Rails::Generators for creating new mailers. +module Rails + module Generators class MailerGenerator < NamedBase source_root File.expand_path("../templates", __FILE__) argument :actions, type: :array, default: [], banner: "method method" check_class_collision - # Generates the mailer file for the application. def create_mailer_file template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb") end -- cgit v1.2.3 From 99819d3c8e0fe3a05f8d9fe0ae93f73dfd5155a8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:06:06 +0530 Subject: Revert "nodoc ActionMailer module from lib/action_mailer/*.rb" This reverts commit 328e876a1569058e47eaf7ea3f4f045a83b585fa. Reason: Let's not nodoc without reason. [ci skip] --- actionmailer/lib/action_mailer/base.rb | 2 +- actionmailer/lib/action_mailer/collector.rb | 2 +- actionmailer/lib/action_mailer/delivery_methods.rb | 2 +- actionmailer/lib/action_mailer/log_subscriber.rb | 2 +- actionmailer/lib/action_mailer/mail_helper.rb | 2 +- actionmailer/lib/action_mailer/railtie.rb | 2 +- actionmailer/lib/action_mailer/test_case.rb | 2 +- actionmailer/lib/action_mailer/test_helper.rb | 2 +- actionmailer/lib/action_mailer/version.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index c363eca8ea..fcdd6747b8 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -5,7 +5,7 @@ require 'active_support/core_ext/hash/except' require 'active_support/core_ext/module/anonymous' require 'action_mailer/log_subscriber' -module ActionMailer # :nodoc: +module ActionMailer # Action Mailer allows you to send email from your application using a mailer model and views. # # = Mailer Models diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index b2b4957369..a44195ae98 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -2,7 +2,7 @@ require 'abstract_controller/collector' require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/array/extract_options' -module ActionMailer # :nodoc: +module ActionMailer class Collector # :nodoc: all include AbstractController::Collector attr_reader :responses diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index 5a7c4d8bfb..9a1a27c8ed 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -1,6 +1,6 @@ require 'tmpdir' -module ActionMailer # :nodoc: +module ActionMailer # This module handles everything related to mail delivery, from registering # new delivery methods to configuring the mail object to be sent. module DeliveryMethods diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index f2ee1d3ec4..c108156792 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -1,4 +1,4 @@ -module ActionMailer # :nodoc: +module ActionMailer # Implements the ActiveSupport::LogSubscriber for logging notifications when # email is delivered and received. class LogSubscriber < ActiveSupport::LogSubscriber diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 642f90bd3e..892eb2472f 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,4 +1,4 @@ -module ActionMailer # :nodoc: +module ActionMailer # Provides helper methods for ActionMailer::Base that can be used for easily # formatting messages, accessing mailer or message instances, and the # attachments list. diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 9f2e5abed5..7677ff3a7c 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -2,7 +2,7 @@ require "action_mailer" require "rails" require "abstract_controller/railties/routes_helpers" -module ActionMailer # :nodoc: +module ActionMailer class Railtie < Rails::Railtie # :nodoc: config.action_mailer = ActiveSupport::OrderedOptions.new config.eager_load_namespaces << ActionMailer diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 2f5c4b268c..207f949fe2 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,6 +1,6 @@ require 'active_support/test_case' -module ActionMailer # :nodoc: +module ActionMailer class NonInferrableMailerError < ::StandardError def initialize(name) super "Unable to determine the mailer to test from #{name}. " + diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 58e46a7af2..6452bf616c 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -1,4 +1,4 @@ -module ActionMailer # :nodoc: +module ActionMailer module TestHelper # Asserts that the number of emails sent matches the given number. # diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 19bf7a8c51..9d00091972 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,4 +1,4 @@ -module ActionMailer # :nodoc: +module ActionMailer # Returns the version of the currently loaded ActionMailer as a Gem::Version def self.version Gem::Version.new "4.1.0.beta" -- cgit v1.2.3 From c62b7c1f079967055aa9ddd897fba40475707df4 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:06:38 +0530 Subject: Revert "ActionMailer::Collector should be nodoc'd" This reverts commit e47c85c696de1c4137c222bedc846b2cdbb0893f. Reason: Let's not nodoc without reason. [ci skip] --- actionmailer/lib/action_mailer/collector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index a44195ae98..e8883a8235 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/array/extract_options' module ActionMailer - class Collector # :nodoc: all + class Collector include AbstractController::Collector attr_reader :responses -- cgit v1.2.3 From 1ad0d1ed4e4955ae3069f363a686d98476a31bff Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:14:37 +0530 Subject: Revert "Changed the CHANGELOG for active_support and improved the doc for inflector method classify" This reverts commit 8d5fcb691e7496900f1c77dff8d6e729c1b56201. Reason: Changelogs are not to be edited in docrails. [ci skip] --- activesupport/CHANGELOG.md | 8 -------- activesupport/lib/active_support/inflector/methods.rb | 9 ++++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index df584eb643..7c666a9b83 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -23,12 +23,4 @@ *Daniel Schierbeck* -* Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly - such as for "business", "address" the classify function would return "busines" and "addres" respectively.. but now this has been resolved and corrected in Rails 4 - - # 'business'.classify # => "Business" - # 'address'.classify # => "Address" - - *Aditya Kapoor* - Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activesupport/CHANGELOG.md) for previous changes. diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 0a24e5afb8..3c46cd9690 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -145,7 +145,14 @@ module ActiveSupport # 'egg_and_hams'.classify # => "EggAndHam" # 'posts'.classify # => "Post" # - # Some singular names are not handled correctly, such as: + # Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly such as + # for "business", "address" the classify function would return "busines" and "addres" respectively.. but now + # this has been resolved and corrected in Rails 4 + # + # 'business'.classify # => "Business" + # 'address'.classify # => "Address" + # + # Yet some singular names are not handled correctly and I guess we would work upon it to improve upon these shortcomings # # "radius".classify #=> "Radiu" it should be "Radius" # "feet".classify #=> "Foot", it should be "Feet" -- cgit v1.2.3 From 8f8058922d0e4fa858fb512f53ff6a78041a395b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:32:20 +0530 Subject: Revert "Corrected documentation and added some more for the classify method in inflectors" This reverts commit 8f901dee9e2072dd20e0a252a89dd501d783d85b. --- activesupport/lib/active_support/inflector/methods.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 3c46cd9690..39648727fd 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -138,25 +138,16 @@ module ActiveSupport pluralize(underscore(class_name)) end - # Create a class name from a plural table name like Rails does for table names to models. - # Note that this returns a string and not a class. (To convert to an actual class - # follow +classify+ with +constantize+.) + # Create a class name from a plural table name like Rails does for table + # names to models. Note that this returns a string and not a Class (To + # convert to an actual class follow +classify+ with +constantize+). # # 'egg_and_hams'.classify # => "EggAndHam" # 'posts'.classify # => "Post" # - # Earlier in the Rails 3.2.x series, the some of the singular names were not handled correctly such as - # for "business", "address" the classify function would return "busines" and "addres" respectively.. but now - # this has been resolved and corrected in Rails 4 - # - # 'business'.classify # => "Business" - # 'address'.classify # => "Address" + # Singular names are not handled correctly: # - # Yet some singular names are not handled correctly and I guess we would work upon it to improve upon these shortcomings - # - # "radius".classify #=> "Radiu" it should be "Radius" - # "feet".classify #=> "Foot", it should be "Feet" - # "abacus".classify #=> "Abacu" it should be "Abacus" + # 'business'.classify # => "Busines" def classify(table_name) # strip out any leading schema name camelize(singularize(table_name.to_s.sub(/.*\./, ''))) -- cgit v1.2.3 From 7f24d3d6956a7775771302d143e3b09de681d12f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 19 May 2013 21:32:17 +0530 Subject: copy edits[ci skip] --- .../active_record/associations/builder/association.rb | 19 ++++++++----------- .../generators/active_record/model/model_generator.rb | 2 +- railties/lib/rails/generators/named_base.rb | 4 +--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 4b72846ef6..6a3658f328 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -1,17 +1,14 @@ -# This is the parent Association class which defines certain class variables (valid_options) and -# instance variables (model, name, scope, options, reflection) which would be common across all the associations that we known today in Rails.. -# Every association need to have the values of these variables set and they are used at multiple places -# The heirarchy is defined as follows: +# This is the parent Association class which defines the variables +# used by all associations. +# +# The hierarchy is defined as follows: # Association # - SingularAssociation -# - BelongsTo -# - HasOne +# - BelongsToAssociation +# - HasOneAssociation # - CollectionAssociation -# - HasMany -# - HasAndBelongsToMany -# -# The HasMany :Through association is a special case of HasMany association with the :through option set for it -# +# - HasManyAssociation +# - HasAndBelongsToManyAssociation module ActiveRecord::Associations::Builder class Association #:nodoc: diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index 821df0e0d6..7e8d68ce69 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -13,7 +13,7 @@ module ActiveRecord class_option :indexes, :type => :boolean, :default => true, :desc => "Add indexes for references and belongs_to columns" - # creates the migration file for the model first followed by the model file itself + # creates the migration file for the model. def create_migration_file return unless options[:migration] && options[:parent].nil? diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index fbb747970d..e712c747b0 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -19,9 +19,7 @@ module Rails end # Defines the template that would be used for the migration file. - # The source defines the source template file that would be used in creating the migration - # The args is an array containing any other options and the name of the file which would be saved on the filesystem - + # The arguments include the source template file, the migration filename etc. no_tasks do def template(source, *args, &block) inside_template do -- cgit v1.2.3 From 632de544405453912637ce332263b91d3c519239 Mon Sep 17 00:00:00 2001 From: Leo Gallucci Date: Sun, 19 May 2013 20:46:12 -0300 Subject: Missing ending ``` at 14.2 Merging of scopes http://edgeguides.rubyonrails.org/active_record_querying.html#merging-of-scopes --- guides/source/active_record_querying.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 19b214f114..c4d69908ed 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1202,6 +1202,7 @@ class User < ActiveRecord::Base scope :active, -> { where state: 'active' } scope :inactive, -> { where state: 'inactive' } end +``` ```ruby User.active.inactive -- cgit v1.2.3 From 4237d74213f01a882a1122dd0d3f53d80561ca5f Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 20 May 2013 10:35:43 +0530 Subject: Fix typo in test name and documentation --- activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb | 2 +- activerecord/test/cases/associations_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index d51d425c3c..a8e5ab81e4 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -30,7 +30,7 @@ module ActiveRecord assert @conn.valid_type?(column.type) end - # sqlite databses should be able to support any type and not + # sqlite databases should be able to support any type and not # just the ones mentioned in the native_database_types. # Therefore test_invalid column should always return true # even if the type is not valid. diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 0f2d22a4a2..c3b728296e 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -217,7 +217,7 @@ class AssociationProxyTest < ActiveRecord::TestCase assert_equal post.body, "More cool stuff!" end - def test_reload_returns_assocition + def test_reload_returns_association david = developers(:david) assert_nothing_raised do assert_equal david.projects, david.projects.reload.reload -- cgit v1.2.3 From 2243ce3c97b1d8723d07eef5f1deb90d650f368d Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 20 May 2013 10:40:05 +0530 Subject: Fix wrong `case_sensitive` in uniqueness validity test --- activerecord/test/cases/validations/uniqueness_validation_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 57457359b1..2b33f01783 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -268,7 +268,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase end def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer - Topic.validates_uniqueness_of(:title, :case_sensitve => true) + Topic.validates_uniqueness_of(:title, :case_sensitive => true) Topic.create!('title' => 101) t2 = Topic.new('title' => 101) -- cgit v1.2.3 From 97a607b32b69e79d074702cc44e70bf975a46f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 20 May 2013 15:17:11 -0300 Subject: No need CHANGELOG entry for a test fix [ci skip] --- actionmailer/CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 41436de526..9e9d07b386 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,6 +1,3 @@ -* Fix ActionMailer testcase break with mail 2.5.4. - ActionMailer's testcase was wrong, because :transfer_encoding option was ignored in mail 2.5.3. - - *kennyj* +* No changes. Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md) for previous changes. -- cgit v1.2.3 From 378ea96905e5f95be1a413b7bdd6fbb000265129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 20 May 2013 20:46:04 +0200 Subject: Add has_named_route? to the mapper API --- actionpack/lib/action_dispatch/routing/mapper.rb | 5 +++++ actionpack/test/dispatch/routing_test.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c3fd0c18ec..3c58a2cfc3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -515,6 +515,11 @@ module ActionDispatch end end + # Query if the following named route was already defined. + def has_named_route?(name) + @set.named_routes.routes[name.to_sym] + end + private def app_name(app) return unless app.respond_to?(:routes) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5b42ca0f21..16ba746b9c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2662,6 +2662,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_raises(ArgumentError) { routes.redirect Object.new } end + def test_named_route_check + before, after = nil + + draw do + before = has_named_route?(:hello) + get "/hello", as: :hello, to: "hello#world" + after = has_named_route?(:hello) + end + + assert !before, "expected to not have named route :hello before route definition" + assert after, "expected to have named route :hello after route definition" + end + def test_explicitly_avoiding_the_named_route draw do scope :as => "routes" do -- cgit v1.2.3 From 743ea1afc676d2941beb5b76728e41a51339c3d0 Mon Sep 17 00:00:00 2001 From: Zack Hubert Date: Mon, 20 May 2013 16:16:49 -0600 Subject: Spelling correction in Upgrading Guide Fixes spelling of 'erratta' to 'errata' --- guides/source/upgrading_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 694592a9de..6c3e763f53 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -46,7 +46,7 @@ on the Rails blog. #### A note about media types -The erratta for the `PATCH` verb [specifies that a 'diff' media type should be +The errata for the `PATCH` verb [specifies that a 'diff' media type should be used with `PATCH`](http://www.rfc-editor.org/errata_search.php?rfc=5789). One such format is [JSON Patch](http://tools.ietf.org/html/rfc6902). While Rails does not support JSON Patch natively, it's easy enough to add support: -- cgit v1.2.3 From 658e9e0f35104c8e47f7442b2fcd9c7b1d405787 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 17:35:17 -0700 Subject: pass where values to the helper function rather than rely on internal state --- activerecord/lib/active_record/relation/merger.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index eea43aff0e..8e2ae9a9b1 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -137,19 +137,19 @@ module ActiveRecord if values[:where].empty? || relation.where_values.empty? relation.where_values + values[:where] else - sanitized_wheres + values[:where] + sanitized_wheres(relation.where_values, values[:where]) + values[:where] end end # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. - def sanitized_wheres + def sanitized_wheres(lhs_wheres, rhs_wheres) seen = Set.new - values[:where].each do |w| + rhs_wheres.each do |w| seen << w.left if w.respond_to?(:operator) && w.operator == :== end - relation.where_values.reject do |w| + lhs_wheres.reject do |w| w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) end end -- cgit v1.2.3 From 3f4f56aed8b2e06817741b266a533228ce594c5b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 17:38:05 -0700 Subject: save the where values in variables so we don't need to look them up all the time --- activerecord/lib/active_record/relation/merger.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 8e2ae9a9b1..f689682cfa 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -132,12 +132,13 @@ module ActiveRecord end def merged_wheres - values[:where] ||= [] + rhs_wheres = values[:where] || [] + lhs_wheres = relation.where_values - if values[:where].empty? || relation.where_values.empty? - relation.where_values + values[:where] + if rhs_wheres.empty? || lhs_wheres.empty? + lhs_wheres + rhs_wheres else - sanitized_wheres(relation.where_values, values[:where]) + values[:where] + sanitized_wheres(lhs_wheres, rhs_wheres) + rhs_wheres end end -- cgit v1.2.3 From 52ed881fa296a05374a5a3395f92a653b3721298 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 17:39:29 -0700 Subject: change method name to reflect what it actually does. --- activerecord/lib/active_record/relation/merger.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index f689682cfa..0f54d91d86 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -138,13 +138,13 @@ module ActiveRecord if rhs_wheres.empty? || lhs_wheres.empty? lhs_wheres + rhs_wheres else - sanitized_wheres(lhs_wheres, rhs_wheres) + rhs_wheres + reject_overwrites(lhs_wheres, rhs_wheres) + rhs_wheres end end # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. - def sanitized_wheres(lhs_wheres, rhs_wheres) + def reject_overwrites(lhs_wheres, rhs_wheres) seen = Set.new rhs_wheres.each do |w| seen << w.left if w.respond_to?(:operator) && w.operator == :== -- cgit v1.2.3 From bff89a2022aedec60929f6d6744eefc84a5c102a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 17:49:16 -0700 Subject: eliminate some conditionals --- activerecord/lib/active_record/relation/merger.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 0f54d91d86..98afeb8cc5 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -145,10 +145,10 @@ module ActiveRecord # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. def reject_overwrites(lhs_wheres, rhs_wheres) - seen = Set.new - rhs_wheres.each do |w| - seen << w.left if w.respond_to?(:operator) && w.operator == :== + nodes = rhs_wheres.find_all do |w| + w.respond_to?(:operator) && w.operator == :== end + seen = Set.new(nodes) { |node| node.left } lhs_wheres.reject do |w| w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) -- cgit v1.2.3 From 847752a295d411ccff31f3137c140ec0f5445c07 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 20 May 2013 18:02:46 -0700 Subject: partition the where values so we can access the removed ones --- activerecord/lib/active_record/relation/merger.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 98afeb8cc5..58ac239190 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -145,12 +145,17 @@ module ActiveRecord # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. def reject_overwrites(lhs_wheres, rhs_wheres) + partition_overwrites(lhs_wheres, rhs_wheres).last + end + + def partition_overwrites(lhs_wheres, rhs_wheres) nodes = rhs_wheres.find_all do |w| w.respond_to?(:operator) && w.operator == :== end seen = Set.new(nodes) { |node| node.left } - lhs_wheres.reject do |w| + # returns [deleted, keepers] + lhs_wheres.partition do |w| w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) end end -- cgit v1.2.3 From 4a4a566b122e8bf080d0b9c5964ae46d523c9dc6 Mon Sep 17 00:00:00 2001 From: Alexander Balashov Date: Tue, 21 May 2013 12:26:13 +0400 Subject: In batches test @total was assigned but not used. Use it in tests instead of Post.count --- activerecord/test/cases/batches_test.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index ba6b0b1362..e09fa95756 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -12,7 +12,7 @@ class EachTest < ActiveRecord::TestCase end def test_each_should_execute_one_query_per_batch - assert_queries(Post.count + 1) do + assert_queries(@total + 1) do Post.find_each(:batch_size => 1) do |post| assert_kind_of Post, post end @@ -51,7 +51,7 @@ class EachTest < ActiveRecord::TestCase end def test_find_in_batches_should_return_batches - assert_queries(Post.count + 1) do + assert_queries(@total + 1) do Post.find_in_batches(:batch_size => 1) do |batch| assert_kind_of Array, batch assert_kind_of Post, batch.first @@ -60,7 +60,7 @@ class EachTest < ActiveRecord::TestCase end def test_find_in_batches_should_start_from_the_start_option - assert_queries(Post.count) do + assert_queries(@total) do Post.find_in_batches(:batch_size => 1, :start => 2) do |batch| assert_kind_of Array, batch assert_kind_of Post, batch.first @@ -69,14 +69,12 @@ class EachTest < ActiveRecord::TestCase end def test_find_in_batches_shouldnt_execute_query_unless_needed - post_count = Post.count - assert_queries(2) do - Post.find_in_batches(:batch_size => post_count) {|batch| assert_kind_of Array, batch } + Post.find_in_batches(:batch_size => @total) {|batch| assert_kind_of Array, batch } end assert_queries(1) do - Post.find_in_batches(:batch_size => post_count + 1) {|batch| assert_kind_of Array, batch } + Post.find_in_batches(:batch_size => @total + 1) {|batch| assert_kind_of Array, batch } end end -- cgit v1.2.3 From 78903731e432dc3ad2a00cb3b30741b962f3afcd Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 21 May 2013 15:47:57 +0200 Subject: the rake task `db:test:prepare` needs to load the configuration Without loading the configuration the task will not perform any work. --- activerecord/lib/active_record/railties/databases.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 434af3c5f8..f69e9b2217 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -360,7 +360,7 @@ db_namespace = namespace :db do end # desc 'Check for pending migrations and load the test schema' - task :prepare do + task :prepare => :load_config do unless ActiveRecord::Base.configurations.blank? db_namespace['test:load'].invoke end -- cgit v1.2.3 From a483ae6477fab482e95b3415bb9b0cf54f198699 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 21 May 2013 10:35:35 -0700 Subject: push partion logic down and initialization logic up --- activerecord/lib/active_record/relation/merger.rb | 26 ++++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 58ac239190..eb72d551da 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -99,7 +99,10 @@ module ActiveRecord end def merge_multi_values - relation.where_values = merged_wheres + rhs_wheres = values[:where] || [] + lhs_wheres = relation.where_values + + relation.where_values = merged_wheres(lhs_wheres, rhs_wheres) relation.bind_values = merged_binds if values[:reordering] @@ -131,30 +134,23 @@ module ActiveRecord end end - def merged_wheres - rhs_wheres = values[:where] || [] - lhs_wheres = relation.where_values - - if rhs_wheres.empty? || lhs_wheres.empty? - lhs_wheres + rhs_wheres - else - reject_overwrites(lhs_wheres, rhs_wheres) + rhs_wheres - end + def merged_wheres(lhs_wheres, rhs_wheres) + partition_overwrites(lhs_wheres, rhs_wheres).last + rhs_wheres end # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. - def reject_overwrites(lhs_wheres, rhs_wheres) - partition_overwrites(lhs_wheres, rhs_wheres).last - end - + # returns [things_to_remove, things_to_keep] def partition_overwrites(lhs_wheres, rhs_wheres) + if lhs_wheres.empty? || rhs_wheres.empty? + return [[], lhs_wheres] + end + nodes = rhs_wheres.find_all do |w| w.respond_to?(:operator) && w.operator == :== end seen = Set.new(nodes) { |node| node.left } - # returns [deleted, keepers] lhs_wheres.partition do |w| w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) end -- cgit v1.2.3 From d2d5f15f0729d00132a240dd9e5169dce5962a0d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 21 May 2013 10:38:51 -0700 Subject: push partitioning up so bind elimination can get the removed wheres --- activerecord/lib/active_record/relation/merger.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index eb72d551da..38f49912d1 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -102,7 +102,9 @@ module ActiveRecord rhs_wheres = values[:where] || [] lhs_wheres = relation.where_values - relation.where_values = merged_wheres(lhs_wheres, rhs_wheres) + _, kept = partition_overwrites(lhs_wheres, rhs_wheres) + + relation.where_values = kept + rhs_wheres relation.bind_values = merged_binds if values[:reordering] @@ -134,10 +136,6 @@ module ActiveRecord end end - def merged_wheres(lhs_wheres, rhs_wheres) - partition_overwrites(lhs_wheres, rhs_wheres).last + rhs_wheres - end - # Remove equalities from the existing relation with a LHS which is # present in the relation being merged in. # returns [things_to_remove, things_to_keep] -- cgit v1.2.3 From 50823452f70341447a010df27dd514fd97bfe8a9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 21 May 2013 10:55:56 -0700 Subject: remove bind values for where clauses that were removed --- activerecord/lib/active_record/relation/merger.rb | 17 ++++++++--------- activerecord/test/cases/relations_test.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 38f49912d1..a65ef1898a 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -99,13 +99,15 @@ module ActiveRecord end def merge_multi_values - rhs_wheres = values[:where] || [] lhs_wheres = relation.where_values + rhs_wheres = values[:where] || [] + lhs_binds = relation.bind_values + rhs_binds = values[:bind] || [] - _, kept = partition_overwrites(lhs_wheres, rhs_wheres) + removed, kept = partition_overwrites(lhs_wheres, rhs_wheres) relation.where_values = kept + rhs_wheres - relation.bind_values = merged_binds + relation.bind_values = filter_binds(lhs_binds, removed) + rhs_binds if values[:reordering] # override any order specified in the original relation @@ -128,12 +130,9 @@ module ActiveRecord end end - def merged_binds - if values[:bind] - (relation.bind_values + values[:bind]).uniq(&:first) - else - relation.bind_values - end + def filter_binds(lhs_binds, removed_wheres) + set = Set.new removed_wheres.map { |x| x.left.name } + lhs_binds.dup.delete_if { |col,_| set.include? col.name } end # Remove equalities from the existing relation with a LHS which is diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index cf6af4e8f4..3c1fae78ce 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1546,4 +1546,14 @@ class RelationTest < ActiveRecord::TestCase assert merged.to_sql.include?("wtf") assert merged.to_sql.include?("bbq") end + + def test_merging_removes_rhs_bind_parameters + left = Post.where(id: Arel::Nodes::BindParam.new('?')) + column = Post.columns_hash['id'] + left.bind_values += [[column, 20]] + right = Post.where(id: 10) + + merged = left.merge(right) + assert_equal [], merged.bind_values + end end -- cgit v1.2.3 From f3ebbeae6eb647767ccd49e25821b1ba33923596 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 21 May 2013 11:01:19 -0700 Subject: avoid creating a set if no where values are removed --- activerecord/lib/active_record/relation/merger.rb | 2 ++ activerecord/test/cases/relations_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index a65ef1898a..c114ea0c0d 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -131,6 +131,8 @@ module ActiveRecord end def filter_binds(lhs_binds, removed_wheres) + return lhs_binds if removed_wheres.empty? + set = Set.new removed_wheres.map { |x| x.left.name } lhs_binds.dup.delete_if { |col,_| set.include? col.name } end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 3c1fae78ce..b64ff13d29 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1556,4 +1556,16 @@ class RelationTest < ActiveRecord::TestCase merged = left.merge(right) assert_equal [], merged.bind_values end + + def test_merging_keeps_lhs_bind_parameters + column = Post.columns_hash['id'] + binds = [[column, 20]] + + right = Post.where(id: Arel::Nodes::BindParam.new('?')) + right.bind_values += binds + left = Post.where(id: 10) + + merged = left.merge(right) + assert_equal binds, merged.bind_values + end end -- cgit v1.2.3