Permalink
Browse files

Merge remote branch 'rails/master'

  • Loading branch information...
2 parents 44a9896 + 0dd3b46 commit 583b60d109522907020700225f1c739737297a2d @fxn fxn committed May 4, 2010
Showing with 412 additions and 248 deletions.
  1. +8 −3 actionmailer/lib/action_mailer/base.rb
  2. +30 −0 actionmailer/test/base_test.rb
  3. +1 −1 actionpack/lib/action_controller/caching/fragments.rb
  4. +1 −1 actionpack/lib/action_controller/caching/pages.rb
  5. +5 −5 actionpack/lib/action_controller/metal/instrumentation.rb
  6. +6 −5 actionpack/lib/action_controller/test_case.rb
  7. +4 −4 actionpack/lib/action_view/helpers/form_helper.rb
  8. +3 −7 actionpack/lib/action_view/helpers/translation_helper.rb
  9. +14 −14 actionpack/lib/action_view/locale/en.yml
  10. +2 −2 actionpack/lib/action_view/render/partials.rb
  11. +1 −1 actionpack/lib/action_view/render/rendering.rb
  12. +1 −1 actionpack/lib/action_view/template.rb
  13. +6 −26 actionpack/lib/action_view/template/error.rb
  14. +15 −1 actionpack/{test/lib/fixture_template.rb → lib/action_view/testing/resolvers.rb}
  15. +1 −1 actionpack/test/abstract_unit.rb
  16. +46 −20 actionpack/test/controller/action_pack_assertions_test.rb
  17. +0 −2 actionpack/test/controller/layout_test.rb
  18. +3 −3 actionpack/test/template/form_helper_test.rb
  19. +18 −0 actionpack/test/template/testing/fixture_resolver_test.rb
  20. +12 −0 actionpack/test/template/testing/null_resolver_test.rb
  21. +1 −1 activemodel/lib/active_model/errors.rb
  22. +9 −9 activemodel/lib/active_model/locale/en.yml
  23. +1 −1 activemodel/lib/active_model/validations/exclusion.rb
  24. +1 −1 activemodel/lib/active_model/validations/inclusion.rb
  25. +3 −3 activemodel/lib/active_model/validations/length.rb
  26. +12 −12 activemodel/test/cases/validations/conditional_validation_test.rb
  27. +1 −1 activemodel/test/cases/validations/exclusion_validation_test.rb
  28. +1 −1 activemodel/test/cases/validations/format_validation_test.rb
  29. +7 −7 activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
  30. +1 −1 activemodel/test/cases/validations/i18n_validation_test.rb
  31. +1 −1 activemodel/test/cases/validations/inclusion_validation_test.rb
  32. +12 −12 activemodel/test/cases/validations/length_validation_test.rb
  33. +2 −2 activemodel/test/cases/validations/numericality_validation_test.rb
  34. +6 −1 activerecord/lib/active_record/callbacks.rb
  35. +3 −3 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  36. +1 −1 activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  37. +1 −1 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  38. +2 −6 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  39. +1 −1 activerecord/lib/active_record/fixtures.rb
  40. +2 −2 activerecord/lib/active_record/locale/en.yml
  41. +31 −24 activerecord/lib/active_record/transactions.rb
  42. +2 −2 activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
  43. +1 −1 activeresource/lib/active_resource/connection.rb
  44. +2 −0 activesupport/CHANGELOG
  45. +1 −1 activesupport/activesupport.gemspec
  46. +1 −1 activesupport/lib/active_support/cache.rb
  47. +2 −2 activesupport/lib/active_support/core_ext/date/calculations.rb
  48. +1 −0 activesupport/lib/active_support/core_ext/date/conversions.rb
  49. +3 −2 activesupport/lib/active_support/inflector/transliterate.rb
  50. +9 −0 activesupport/lib/active_support/json/encoding.rb
  51. +10 −4 activesupport/lib/active_support/notifications/instrumenter.rb
  52. +46 −2 activesupport/test/core_ext/date_ext_test.rb
  53. +3 −1 activesupport/test/json/encoding_test.rb
  54. +10 −0 activesupport/test/message_encryptor_test.rb
  55. +4 −2 activesupport/test/notifications_test.rb
  56. +12 −12 railties/guides/source/activerecord_validations_callbacks.textile
  57. +5 −5 railties/guides/source/i18n.textile
  58. +11 −12 railties/lib/rails/backtrace_cleaner.rb
  59. +3 −3 railties/lib/rails/log_subscriber.rb
  60. +1 −1 railties/test/application/initializers/notifications_test.rb
  61. +9 −9 railties/test/log_subscriber_test.rb
@@ -354,7 +354,7 @@ def default(value = nil)
# end
# end
def receive(raw_mail)
- ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
+ ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
mail = Mail.new(raw_mail)
set_payload_for_mail(payload, mail)
new.receive(mail)
@@ -366,7 +366,7 @@ def receive(raw_mail)
# 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.
def deliver_mail(mail) #:nodoc:
- ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload|
+ ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
self.set_payload_for_mail(payload, mail)
yield # Let Mail do the delivery actions
end
@@ -566,8 +566,13 @@ def mail(headers={}, &block)
content_type = headers[:content_type]
parts_order = headers[:parts_order]
+ # Call all the procs (if any)
+ default_values = self.class.default.merge(self.class.default) do |k,v|
+ v.respond_to?(:call) ? v.bind(self).call : v
+ end
+
# Handle defaults
- headers = headers.reverse_merge(self.class.default)
+ headers = headers.reverse_merge(default_values)
headers[:subject] ||= default_i18n_subject
# Apply charset at the beginning so all fields are properly quoted
@@ -113,6 +113,23 @@ def different_layout(layout_name='')
end
end
end
+
+ class ProcMailer < ActionMailer::Base
+ default :to => 'system@test.lindsaar.net',
+ 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
+ :subject => Proc.new { give_a_greeting }
+
+ def welcome
+ mail
+ end
+
+ private
+
+ def give_a_greeting
+ "Thanks for signing up this afternoon"
+ end
+
+ end
test "method call to mail does not raise error" do
assert_nothing_raised { BaseMailer.welcome }
@@ -560,6 +577,19 @@ def self.delivering_email(mail)
MyInterceptor.expects(:delivering_email).with(mail)
mail.deliver
end
+
+ test "being able to put proc's into the defaults hash and they get evaluated on mail sending" do
+ mail1 = ProcMailer.welcome
+ yesterday = 1.day.ago
+ Time.stubs(:now).returns(yesterday)
+ mail2 = ProcMailer.welcome
+ assert(mail1['X-Proc-Method'].to_s.to_i > mail2['X-Proc-Method'].to_s.to_i)
+ end
+
+ test "we can call other defined methods on the class as needed" do
+ mail = ProcMailer.welcome
+ assert_equal("Thanks for signing up this afternoon", mail.subject)
+ end
protected
@@ -99,7 +99,7 @@ def expire_fragment(key, options = nil)
end
def instrument_fragment_cache(name, key)
- ActiveSupport::Notifications.instrument("action_controller.#{name}", :key => key){ yield }
+ ActiveSupport::Notifications.instrument("#{name}.action_controller", :key => key){ yield }
end
end
end
@@ -109,7 +109,7 @@ def page_cache_path(path)
end
def instrument_page_cache(name, path)
- ActiveSupport::Notifications.instrument("action_controller.#{name}", :path => path){ yield }
+ ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield }
end
end
@@ -23,9 +23,9 @@ def process_action(action, *args)
:path => (request.fullpath rescue "unknown")
}
- ActiveSupport::Notifications.instrument("action_controller.start_processing", raw_payload.dup)
+ ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
- ActiveSupport::Notifications.instrument("action_controller.process_action", raw_payload) do |payload|
+ ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
result = super
payload[:status] = response.status
append_info_to_payload(payload)
@@ -42,20 +42,20 @@ def render(*args)
end
def send_file(path, options={})
- ActiveSupport::Notifications.instrument("action_controller.send_file",
+ ActiveSupport::Notifications.instrument("send_file.action_controller",
options.merge(:path => path)) do
super
end
end
def send_data(data, options = {})
- ActiveSupport::Notifications.instrument("action_controller.send_data", options) do
+ ActiveSupport::Notifications.instrument("send_data.action_controller", options) do
super
end
end
def redirect_to(*args)
- ActiveSupport::Notifications.instrument("action_controller.redirect_to") do |payload|
+ ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload|
result = super
payload[:status] = self.status
payload[:location] = self.location
@@ -16,12 +16,12 @@ def setup_subscriptions
@templates = Hash.new(0)
@layouts = Hash.new(0)
- ActiveSupport::Notifications.subscribe("action_view.render_template") do |name, start, finish, id, payload|
+ ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout]
@layouts[path] += 1
end
- ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload|
+ ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
path = payload[:virtual_path]
next unless path
partial = path =~ /^.*\/_[^\/]*$/
@@ -36,8 +36,8 @@ def setup_subscriptions
end
def teardown_subscriptions
- ActiveSupport::Notifications.unsubscribe("action_view.render_template")
- ActiveSupport::Notifications.unsubscribe("action_view.render_template!")
+ ActiveSupport::Notifications.unsubscribe("render_template.action_view")
+ ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
end
# Asserts that the request was rendered with the appropriate template file or partials
@@ -57,7 +57,8 @@ def assert_template(options = {}, message = nil)
validate_request!
case options
- when NilClass, String
+ when NilClass, String, Symbol
+ options = options.to_s if Symbol === options
rendered = @templates
msg = build_message(message,
"expecting <?> but rendering with <?>",
@@ -1165,21 +1165,21 @@ def hidden_field(method, options = {})
# submit button label, otherwise, it uses "Update Post".
#
# Those labels can be customized using I18n, under the helpers.submit key and accept
- # the {{model}} as translation interpolation:
+ # the %{model} as translation interpolation:
#
# en:
# helpers:
# submit:
- # create: "Create a {{model}}"
- # update: "Confirm changes to {{model}}"
+ # create: "Create a %{model}"
+ # update: "Confirm changes to %{model}"
#
# It also searches for a key specific for the given object:
#
# en:
# helpers:
# submit:
# post:
- # create: "Add {{model}}"
+ # create: "Add %{model}"
#
def submit(value=nil, options={})
value, options = nil, value if value.is_a?(Hash)
@@ -20,7 +20,7 @@ def translate(key, options = {})
options[:raise] = true
translation = I18n.translate(scope_key_by_partial(key), options)
translation = (translation.respond_to?(:join) ? translation.join : translation)
- if html_safe_translation_key? key
+ if html_safe_translation_key?(key)
translation.html_safe
else
translation
@@ -53,12 +53,8 @@ def scope_key_by_partial(key)
end
def html_safe_translation_key?(key)
- last_key = if key.is_a? Array
- key.last
- else
- key.to_s.split('.').last
- end
- (last_key == "html") || (last_key.ends_with? "_html")
+ key = key.is_a?(Array) ? key.last : key.to_s
+ key =~ /(\b|_|\.)html$/
end
end
end
@@ -102,37 +102,37 @@
half_a_minute: "half a minute"
less_than_x_seconds:
one: "less than 1 second"
- other: "less than {{count}} seconds"
+ other: "less than %{count} seconds"
x_seconds:
one: "1 second"
- other: "{{count}} seconds"
+ other: "%{count} seconds"
less_than_x_minutes:
one: "less than a minute"
- other: "less than {{count}} minutes"
+ other: "less than %{count} minutes"
x_minutes:
one: "1 minute"
- other: "{{count}} minutes"
+ other: "%{count} minutes"
about_x_hours:
one: "about 1 hour"
- other: "about {{count}} hours"
+ other: "about %{count} hours"
x_days:
one: "1 day"
- other: "{{count}} days"
+ other: "%{count} days"
about_x_months:
one: "about 1 month"
- other: "about {{count}} months"
+ other: "about %{count} months"
x_months:
one: "1 month"
- other: "{{count}} months"
+ other: "%{count} months"
about_x_years:
one: "about 1 year"
- other: "about {{count}} years"
+ other: "about %{count} years"
over_x_years:
one: "over 1 year"
- other: "over {{count}} years"
+ other: "over %{count} years"
almost_x_years:
one: "almost 1 year"
- other: "almost {{count}} years"
+ other: "almost %{count} years"
prompts:
year: "Year"
month: "Month"
@@ -148,7 +148,7 @@
# Default translation keys for submit FormHelper
submit:
- create: 'Create {{model}}'
- update: 'Update {{model}}'
- submit: 'Save {{model}}'
+ create: 'Create %{model}'
+ update: 'Update %{model}'
+ submit: 'Save %{model}'
@@ -211,12 +211,12 @@ def render
identifier = ((@template = find_template) ? @template.identifier : @path)
if @collection
- ActiveSupport::Notifications.instrument("action_view.render_collection",
+ ActiveSupport::Notifications.instrument("render_collection.action_view",
:identifier => identifier || "collection", :count => @collection.size) do
render_collection
end
else
- content = ActiveSupport::Notifications.instrument("action_view.render_partial",
+ content = ActiveSupport::Notifications.instrument("render_partial.action_view",
:identifier => identifier) do
render_partial
end
@@ -52,7 +52,7 @@ def _render_template(template, layout = nil, options = {}) #:nodoc:
locals = options[:locals] || {}
layout = find_layout(layout) if layout
- ActiveSupport::Notifications.instrument("action_view.render_template",
+ ActiveSupport::Notifications.instrument("render_template.action_view",
:identifier => template.identifier, :layout => layout.try(:virtual_path)) do
content = template.render(self, locals) { |*name| _layout_for(*name) }
@@ -41,7 +41,7 @@ def initialize(source, identifier, handler, details)
def render(view, locals, &block)
# Notice that we use a bang in this instrumentation because you don't want to
# consume this in production. This is only slow if it's being listened to.
- ActiveSupport::Notifications.instrument("action_view.render_template!", :virtual_path => @virtual_path) do
+ ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do
method_name = compile(locals, view)
view.send(method_name, locals, &block)
end
@@ -21,17 +21,18 @@ def initialize(paths, path, details, partial)
super("Missing #{template_type} #{path} with #{details.inspect} in view paths #{display_paths}")
end
end
+
class Template
# The Template::Error exception is raised when the compilation of the template fails. This exception then gathers a
# bunch of intimate details and uses it to report a very precise exception message.
class Error < ActionViewError #:nodoc:
SOURCE_CODE_RADIUS = 3
- attr_reader :original_exception
+ attr_reader :original_exception, :backtrace
def initialize(template, assigns, original_exception)
@template, @assigns, @original_exception = template, assigns.dup, original_exception
- @backtrace = compute_backtrace
+ @backtrace = original_exception.backtrace
end
def file_name
@@ -42,14 +43,6 @@ def message
ActiveSupport::Deprecation.silence { original_exception.message }
end
- def clean_backtrace
- if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
- Rails.backtrace_cleaner.clean(original_exception.backtrace)
- else
- original_exception.backtrace
- end
- end
-
def sub_template_message
if @sub_templates
"Trace of template inclusion: " +
@@ -87,29 +80,16 @@ def line_number
@line_number ||=
if file_name
regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
-
- $1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp }
+ $1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
end
end
def to_s
- "\n#{self.class} (#{message}) #{source_location}:\n" +
- "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
- end
-
- # don't do anything nontrivial here. Any raised exception from here becomes fatal
- # (and can't be rescued).
- def backtrace
- @backtrace
+ "\n#{self.class} (#{message}) #{source_location}:\n\n" +
+ "#{source_extract(4)}\n #{backtrace.join("\n ")}\n\n"
end
private
- def compute_backtrace
- [
- "#{source_location.capitalize}\n\n#{source_extract(4)}\n " +
- clean_backtrace.join("\n ")
- ]
- end
def source_location
if line_number
Oops, something went wrong.

0 comments on commit 583b60d

Please sign in to comment.