Skip to content

Commit

Permalink
Merge branch 'master' into normalizecb
Browse files Browse the repository at this point in the history
* master: (61 commits)
  add tests for reset_calbacks
  Fixing build broken by this change
  Extract variable out of loop
  Updated comment to Rails 4
  Fixes NoMethodError: `alias_method_chain` when requiring just active_support/core_ext
  better error message when app name is not passed in `rails new`
  Code cleanup for ActionDispatch::Flash#call
  Fix typo: require -> requires
  Add CHANGELOG entry for #10576
  Merge pull request #10556 from Empact/deprecate-schema-statements-distinct
  Some editorial changes on the documentation.
  respond_to -> respond to in a message from AM::Lint
  specify that dom_(id|class) are deprecated in controllers, views are fine
  copy edits [ci skip]
  Fix class and method name typos
  Replace multi_json with json
  ruby -> Ruby
  Adding documentation to the automatic inverse_of finder.
  Improve CHANGELOG entry [ci kip]
  Call assume_migrated_upto_version on connection
  ...

Conflicts:
	activesupport/lib/active_support/callbacks.rb
  • Loading branch information
tenderlove committed May 13, 2013
2 parents b97ff31 + 37ca5b0 commit d53b5f0
Show file tree
Hide file tree
Showing 58 changed files with 360 additions and 214 deletions.
5 changes: 0 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ platforms :jruby do
gem 'json'
gem 'activerecord-jdbcsqlite3-adapter', '>= 1.2.7'

# This is needed by now to let tests work on JRuby
# TODO: When the JRuby guys merge jruby-openssl in
# jruby this will be removed
gem 'jruby-openssl'

group :db do
gem 'activerecord-jdbcmysql-adapter', '>= 1.2.7'
gem 'activerecord-jdbcpostgresql-adapter', '>= 1.2.7'
Expand Down
89 changes: 52 additions & 37 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def register_interceptors(*interceptors)

# Register an Observer which will be notified when mail is delivered.
# Either a class or a string can be passed in as the Observer. If a string is passed in
# it will be <tt>constantize</tt>d.
# it will be +constantize+d.
def register_observer(observer)
delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
Mail.register_observer(delivery_observer)
Expand All @@ -412,12 +412,20 @@ def register_interceptor(interceptor)
Mail.register_interceptor(delivery_interceptor)
end

# Returns the name of current mailer. This method is also being used as a path for a view lookup.
# If this is an anonymous mailer, this method will return +anonymous+ instead.
def mailer_name
@mailer_name ||= anonymous? ? "anonymous" : name.underscore
end
# Allows to set the name of current mailer.
attr_writer :mailer_name
alias :controller_path :mailer_name

# Sets the defaults through app configuration:
#
# config.action_mailer.default { from: "no-reply@example.org" }
#
# Aliased by ::default_options=
def default(value = nil)
self.default_params = default_params.merge(value).freeze if value
default_params
Expand All @@ -429,13 +437,15 @@ def default(value = nil)

# Receives a raw email, parses it into an email object, decodes it,
# instantiates a new mailer, and passes the email object to the mailer
# object's +receive+ method. If you want your mailer to be able to
# process incoming messages, you'll need to implement a +receive+
# method that accepts the raw email string as a parameter:
# object's +receive+ method.
#
# If you want your mailer to be able to process incoming messages, you'll
# need to implement a +receive+ method that accepts the raw email string
# as a parameter:
#
# class MyMailer < ActionMailer::Base
# def receive(mail)
# ...
# # ...
# end
# end
def receive(raw_mail)
Expand All @@ -446,10 +456,12 @@ def receive(raw_mail)
end
end

# Wraps an email delivery inside of Active Support Notifications instrumentation. This
# method is actually called by the <tt>Mail::Message</tt> object itself through a callback
# when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
# and passing a Mail::Message will do nothing except tell the logger you sent the email.
# Wraps an email delivery inside of ActiveSupport::Notifications instrumentation.
#
# This method is actually called by the Mail::Message object itself
# through a callback when you call +:deliver+ on the Mail::Message,
# calling +deliver_mail+ directly and passing a Mail::Message will do
# nothing except tell the logger you sent the email.
def deliver_mail(mail) #:nodoc:
ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
set_payload_for_mail(payload, mail)
Expand All @@ -475,7 +487,7 @@ def set_payload_for_mail(payload, mail) #:nodoc:
payload[:mail] = mail.encoded
end

def method_missing(method_name, *args)
def method_missing(method_name, *args) # :nodoc:
if respond_to?(method_name)
new(method_name, *args).message
else
Expand Down Expand Up @@ -512,17 +524,18 @@ def method_missing(*args)
end
end

# Returns the name of the mailer object.
def mailer_name
self.class.mailer_name
end

# Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt> object
# which will add them to itself.
# Allows you to pass random and unusual headers to the new Mail::Message
# object which will add them to itself.
#
# headers['X-Special-Domain-Specific-Header'] = "SecretValue"
#
# You can also pass a hash into headers of header field names and values, which
# will then be set on the Mail::Message object:
# You can also pass a hash into headers of header field names and values,
# which will then be set on the Mail::Message object:
#
# headers 'X-Special-Domain-Specific-Header' => "SecretValue",
# 'In-Reply-To' => incoming.message_id
Expand Down Expand Up @@ -578,22 +591,22 @@ def attachments
# Both methods accept a headers hash. This hash allows you to specify the most used headers
# in an email message, these are:
#
# * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will
# ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
# * +:subject+ - The subject of the message, if this is omitted, Action Mailer will
# ask the Rails I18n class for a translated +:subject+ in the scope of
# <tt>[mailer_scope, action_name]</tt> or if this is missing, will translate the
# humanized version of the <tt>action_name</tt>
# * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array
# humanized version of the +action_name+
# * +:to+ - Who the message is destined for, can be a string of addresses, or an array
# of addresses.
# * <tt>:from</tt> - Who the message is from
# * <tt>:cc</tt> - Who you would like to Carbon-Copy on this email, can be a string of addresses,
# * +:from+ - Who the message is from
# * +:cc+ - Who you would like to Carbon-Copy on this email, can be a string of addresses,
# or an array of addresses.
# * <tt>:bcc</tt> - Who you would like to Blind-Carbon-Copy on this email, can be a string of
# * +:bcc+ - Who you would like to Blind-Carbon-Copy on this email, can be a string of
# addresses, or an array of addresses.
# * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
# * <tt>:date</tt> - The date to say the email was sent on.
# * +:reply_to+ - Who to set the Reply-To header of the email to.
# * +:date+ - The date to say the email was sent on.
#
# You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
# class method:
# You can set default values for any of the above headers (except +:date+)
# by using the ::default class method:
#
# class Notifier < ActionMailer::Base
# default from: 'no-reply@test.lindsaar.net',
Expand All @@ -605,17 +618,19 @@ def attachments
# as part of the headers hash or use the <tt>headers['name'] = value</tt>
# method.
#
# When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
# address for the Mail message. Setting this is useful when you want delivery notifications
# sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
# <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
# field for the 'envelope from' value.
# When a +:return_path+ is specified as header, that value will be used as
# the 'envelope from' address for the Mail message. Setting this is useful
# when you want delivery notifications sent to a different address than the
# one in +:from+. Mail will actually use the +:return_path+ in preference
# to the +:sender+ in preference to the +:from+ field for the 'envelope
# from' value.
#
# If you do not pass a block to the +mail+ method, it will find all templates in the
# view paths using by default the mailer name and the method name that it is being
# called from, it will then create parts for each of these templates intelligently,
# making educated guesses on correct content type and sequence, and return a fully
# prepared Mail::Message ready to call <tt>:deliver</tt> on to send.
# If you do not pass a block to the +mail+ method, it will find all
# templates in the view paths using by default the mailer name and the
# method name that it is being called from, it will then create parts for
# each of these templates intelligently, making educated guesses on correct
# content type and sequence, and return a fully prepared Mail::Message
# ready to call +:deliver+ on to send.
#
# For example:
#
Expand Down Expand Up @@ -650,8 +665,8 @@ def attachments
# format.html { render text: "<h1>Hello Mikel!</h1>" }
# end
#
# Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
# <tt>text/html</tt> parts.
# Which will render a +multipart/alternative+ email with +text/plain+ and
# +text/html+ parts.
#
# The block syntax also allows you to customize the part headers if desired:
#
Expand Down
3 changes: 2 additions & 1 deletion actionmailer/lib/action_mailer/mail_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def format_paragraph(text, len = 72, indent = 2)
end
end

indentation = " " * indent
sentences.map { |sentence|
"#{" " * indent}#{sentence.join(' ')}"
"#{indentation}#{sentence.join(' ')}"
}.join "\n"
end
end
Expand Down
14 changes: 4 additions & 10 deletions actionpack/lib/action_dispatch/middleware/flash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,13 @@ def call(env)
session = Request::Session.find(env) || {}
flash_hash = env[KEY]

if flash_hash
if !flash_hash.empty? || session.key?('flash')
session["flash"] = flash_hash.to_session_value
new_hash = flash_hash.dup
else
new_hash = flash_hash
end

env[KEY] = new_hash
if flash_hash && (flash_hash.present? || session.key?('flash'))
session["flash"] = flash_hash.to_session_value
env[KEY] = flash_hash.dup
end

if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
session.key?('flash') && session['flash'].nil?
session.key?('flash') && session['flash'].nil?
session.delete('flash')
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def teardown
$stderr = StringIO.new # suppress the log
json = "[\"person]\": {\"name\": \"David\"}}"
exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
assert_equal MultiJson::DecodeError, exception.original_exception.class
assert_equal JSON::ParserError, exception.original_exception.class
assert_equal exception.original_exception.message, exception.message
ensure
$stderr = STDERR
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_errors_aref

private
def model
assert @model.respond_to?(:to_model), "The object should respond_to to_model"
assert @model.respond_to?(:to_model), "The object should respond to to_model"
@model.to_model
end

Expand Down
24 changes: 24 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
* Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
as it is no longer used by internals.

*Ben Woosley#

* Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
is not blank.

Call `assume_migrated_upto_version` on connection to prevent it from first
being picked up in `method_missing`.

In the base class, `Migration`, `method_missing` expects the argument to be a
table name, and calls `proper_table_name` on the arguments before sending to
`connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
version changes to `prefix_version_suffix`, breaking `rake test:prepare`.

Fixes #10411.

*Kyle Stevens*

* Method `read_attribute_before_type_cast` should accept input as symbol.

*Neeraj Singh*

* Confirm a record has not already been destroyed before decrementing counter cache.

*Ben Tucker*
Expand Down
2 changes: 1 addition & 1 deletion activerecord/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ by relying on a number of conventions that make it easy for Active Record to inf
complex relations and structures from a minimal amount of explicit direction.

Convention over Configuration:
* No XML-files!
* No XML files!
* Lots of reflection and run-time extension
* Magic is not inherently a bad word

Expand Down
Loading

0 comments on commit d53b5f0

Please sign in to comment.