Permalink
Browse files

Merge commit 'mainstream/master'

Conflicts:

	actionpack/lib/action_controller/request.rb
	actionpack/lib/action_controller/resources.rb
  • Loading branch information...
2 parents 73ef94e + 8cb14ee commit 2ebe8d275efa53af967b09ad66dab68acc1aed98 @lifo lifo committed Aug 14, 2008
Showing with 1,561 additions and 889 deletions.
  1. +20 −26 actionmailer/lib/action_mailer/base.rb
  2. 0 actionmailer/test/fixtures/test_mailer/{signed_up.erb → signed_up.html.erb}
  3. +11 −20 actionmailer/test/mail_service_test.rb
  4. +8 −2 actionpack/CHANGELOG
  5. +2 −2 actionpack/lib/action_controller/assertions/response_assertions.rb
  6. +12 −8 actionpack/lib/action_controller/base.rb
  7. +3 −42 actionpack/lib/action_controller/cgi_process.rb
  8. +16 −3 actionpack/lib/action_controller/filters.rb
  9. +16 −14 actionpack/lib/action_controller/headers.rb
  10. +5 −47 actionpack/lib/action_controller/rack_process.rb
  11. +119 −46 actionpack/lib/action_controller/request.rb
  12. +21 −21 actionpack/lib/action_controller/resources.rb
  13. +28 −26 actionpack/lib/action_controller/response.rb
  14. +2 −1 actionpack/lib/action_controller/routing/segments.rb
  15. +1 −1 actionpack/lib/action_controller/session/cookie_store.rb
  16. +25 −19 actionpack/lib/action_controller/test_process.rb
  17. +4 −1 actionpack/lib/action_view/base.rb
  18. +6 −1 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  19. +378 −198 actionpack/lib/action_view/helpers/date_helper.rb
  20. +31 −25 actionpack/lib/action_view/helpers/number_helper.rb
  21. +1 −1 actionpack/lib/action_view/helpers/text_helper.rb
  22. +2 −2 actionpack/lib/action_view/helpers/url_helper.rb
  23. +1 −1 actionpack/lib/action_view/partials.rb
  24. +3 −3 actionpack/lib/action_view/renderable.rb
  25. +9 −1 actionpack/lib/action_view/template.rb
  26. +8 −25 actionpack/test/controller/assert_select_test.rb
  27. +1 −1 actionpack/test/controller/caching_test.rb
  28. +1 −1 actionpack/test/controller/cgi_test.rb
  29. +4 −4 actionpack/test/controller/content_type_test.rb
  30. +31 −31 actionpack/test/controller/mime_responds_test.rb
  31. +9 −0 actionpack/test/controller/new_render_test.rb
  32. +13 −10 actionpack/test/controller/rack_test.rb
  33. +21 −16 actionpack/test/controller/render_test.rb
  34. +51 −44 actionpack/test/controller/request_test.rb
  35. +1 −0 actionpack/test/fixtures/_top_level_partial.html.erb
  36. +1 −0 actionpack/test/fixtures/_top_level_partial_only.erb
  37. +1 −0 actionpack/test/fixtures/test/_counter.html.erb
  38. +2 −1 actionpack/test/template/asset_tag_helper_test.rb
  39. +11 −11 actionpack/test/template/date_helper_i18n_test.rb
  40. +249 −50 actionpack/test/template/date_helper_test.rb
  41. +13 −13 actionpack/test/template/number_helper_i18n_test.rb
  42. +26 −4 actionpack/test/template/render_test.rb
  43. +7 −3 actionpack/test/template/url_helper_test.rb
  44. +1 −1 activerecord/lib/active_record/associations/association_collection.rb
  45. +14 −3 activerecord/lib/active_record/base.rb
  46. +1 −1 activerecord/lib/active_record/calculations.rb
  47. +3 −1 activerecord/lib/active_record/dirty.rb
  48. +26 −6 activerecord/lib/active_record/migration.rb
  49. +5 −1 activerecord/lib/active_record/named_scope.rb
  50. +1 −1 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
  51. +1 −1 activerecord/test/cases/associations/eager_test.rb
  52. +12 −1 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  53. +1 −1 activerecord/test/cases/associations/has_many_associations_test.rb
  54. +7 −1 activerecord/test/cases/base_test.rb
  55. +12 −0 activerecord/test/cases/dirty_test.rb
  56. +1 −1 activerecord/test/cases/lifecycle_test.rb
  57. +1 −1 activerecord/test/cases/method_scoping_test.rb
  58. +20 −0 activerecord/test/cases/migration_test.rb
  59. +10 −3 activerecord/test/cases/named_scope_test.rb
  60. +1 −1 activerecord/test/cases/query_cache_test.rb
  61. +0 −18 activesupport/lib/active_support/cache.rb
  62. +4 −4 activesupport/lib/active_support/cache/compressed_mem_cache_store.rb
  63. +2 −2 activesupport/lib/active_support/cache/file_store.rb
  64. +20 −4 activesupport/lib/active_support/cache/memory_store.rb
  65. +4 −20 activesupport/lib/active_support/core_ext/file.rb
  66. +46 −0 activesupport/lib/active_support/core_ext/file/atomic.rb
  67. +8 −5 activesupport/lib/active_support/inflector.rb
  68. +45 −13 activesupport/lib/active_support/memoizable.rb
  69. +15 −55 activesupport/test/caching_test.rb
  70. +44 −6 activesupport/test/core_ext/file_test.rb
  71. +35 −0 activesupport/test/memoizable_test.rb
  72. +2 −0 railties/CHANGELOG
  73. +3 −0 railties/environments/production.rb
  74. +1 −1 railties/lib/commands/runner.rb
  75. +26 −7 railties/lib/initializer.rb
  76. +1 −1 railties/lib/rails/gem_dependency.rb
  77. +5 −4 railties/lib/tasks/databases.rake
  78. +9 −0 railties/test/gem_dependency_test.rb
@@ -216,7 +216,7 @@ module ActionMailer #:nodoc:
# * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
# * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
# * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
- # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
+ # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
# This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
#
# * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
@@ -233,10 +233,10 @@ module ActionMailer #:nodoc:
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
# for unit and functional testing.
#
- # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
+ # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
# pick a different charset from inside a method with +charset+.
# * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
- # can also pick a different content type from inside a method with +content_type+.
+ # can also pick a different content type from inside a method with +content_type+.
# * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
# can also pick a different value from inside a method with +mime_version+.
# * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
@@ -253,9 +253,6 @@ class Base
class_inheritable_accessor :view_paths
cattr_accessor :logger
- cattr_accessor :template_extensions
- @@template_extensions = ['erb', 'builder', 'rhtml', 'rxml']
-
@@smtp_settings = {
:address => "localhost",
:port => 25,
@@ -414,15 +411,10 @@ def deliver(mail)
new.deliver!(mail)
end
- # Register a template extension so mailer templates written in a
- # templating language other than rhtml or rxml are supported.
- # To use this, include in your template-language plugin's init
- # code or on a per-application basis, this can be invoked from
- # <tt>config/environment.rb</tt>:
- #
- # ActionMailer::Base.register_template_extension('haml')
def register_template_extension(extension)
- template_extensions << extension
+ ActiveSupport::Deprecation.warn(
+ "ActionMailer::Base.register_template_extension has been deprecated." +
+ "Use ActionView::Base.register_template_extension instead", caller)
end
def template_root
@@ -455,16 +447,18 @@ def create!(method_name, *parameters) #:nodoc:
# "the_template_file.text.html.erb", etc.). Only do this if parts
# have not already been specified manually.
if @parts.empty?
- templates = Dir.glob("#{template_path}/#{@template}.*")
- templates.each do |path|
- basename = File.basename(path)
- template_regex = Regexp.new("^([^\\\.]+)\\\.([^\\\.]+\\\.[^\\\.]+)\\\.(" + template_extensions.join('|') + ")$")
- next unless md = template_regex.match(basename)
- template_name = basename
- content_type = md.captures[1].gsub('.', '/')
- @parts << Part.new(:content_type => content_type,
- :disposition => "inline", :charset => charset,
- :body => render_message(template_name, @body))
+ Dir.glob("#{template_path}/#{@template}.*").each do |path|
+ template = template_root["#{mailer_name}/#{File.basename(path)}"]
+
+ # Skip unless template has a multipart format
+ next unless template.multipart?
+
+ @parts << Part.new(
+ :content_type => template.content_type,
+ :disposition => "inline",
+ :charset => charset,
+ :body => render_message(template, @body)
+ )
end
unless @parts.empty?
@content_type = "multipart/alternative"
@@ -477,7 +471,7 @@ def create!(method_name, *parameters) #:nodoc:
# normal template exists (or if there were no implicit parts) we render
# it.
template_exists = @parts.empty?
- template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| File.basename(i).split(".").length == 2 }
+ template_exists ||= template_root["#{mailer_name}/#{@template}"]
@body = render_message(@template, @body) if template_exists
# Finally, if there are other message parts and a textual body exists,
@@ -538,7 +532,7 @@ def render_message(method_name, body)
def render(opts)
body = opts.delete(:body)
- if opts[:file] && opts[:file] !~ /\//
+ if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
initialize_template_class(body).render(opts)
@@ -219,7 +219,7 @@ def nested_multipart(recipient)
end
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
end
-
+
def nested_multipart_with_body(recipient)
recipients recipient
subject "nested multipart with body"
@@ -321,7 +321,7 @@ def test_nested_parts
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
assert_equal 2,created.parts.size
assert_equal 2,created.parts.first.parts.size
-
+
assert_equal "multipart/mixed", created.content_type
assert_equal "multipart/alternative", created.parts.first.content_type
assert_equal "bar", created.parts.first.header['foo'].to_s
@@ -366,7 +366,7 @@ def test_signed_up
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_custom_template
expected = new_mail
expected.to = @recipient
@@ -382,26 +382,17 @@ def test_custom_template
end
def test_custom_templating_extension
- #
# N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
expected.body = "Hello there, \n\nMr. #{@recipient}"
expected.from = "system@loudthinking.com"
expected.date = Time.local(2004, 12, 12)
-
+
# Stub the render method so no alternative renderers need be present.
ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
-
- # If the template is not registered, there should be no parts.
- created = nil
- assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
- assert_not_nil created
- assert_equal 0, created.parts.length
-
- ActionMailer::Base.register_template_extension('haml')
-
+
# Now that the template is registered, there should be one part. The text/plain part.
created = nil
assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
@@ -428,7 +419,7 @@ def test_cancelled_account
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_cc_bcc
expected = new_mail
expected.to = @recipient
@@ -550,7 +541,7 @@ def test_perform_deliveries_flag
TestMailer.deliver_signed_up(@recipient)
assert_equal 1, ActionMailer::Base.deliveries.size
end
-
+
def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
ActionMailer::Base.raise_delivery_errors = false
TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception)
@@ -670,7 +661,7 @@ def test_extended_headers
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_utf8_body_is_not_quoted
@recipient = "Foo áëô îü <extended@example.net>"
expected = new_mail "utf-8"
@@ -760,7 +751,7 @@ def test_multipart_with_mime_version
mail = TestMailer.create_multipart_with_mime_version(@recipient)
assert_equal "1.1", mail.mime_version
end
-
+
def test_multipart_with_utf8_subject
mail = TestMailer.create_multipart_with_utf8_subject(@recipient)
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
@@ -825,7 +816,7 @@ def test_implicitly_multipart_messages_with_charset
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
assert_equal "multipart/alternative", mail.header['content-type'].body
-
+
assert_equal 'iso-8859-1', mail.parts[0].sub_header("content-type", "charset")
assert_equal 'iso-8859-1', mail.parts[1].sub_header("content-type", "charset")
assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset")
@@ -852,7 +843,7 @@ def test_various_newlines_multipart
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body
assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body
end
-
+
def test_headers_removed_on_smtp_delivery
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_cc_bcc(@recipient)
View
@@ -7,8 +7,14 @@
* Update Prototype to 1.6.0.2 #599 [Patrick Joyce]
* Conditional GET utility methods. [Jeremy Kemper]
- * etag!([:admin, post, current_user]) sets the ETag response header and returns head(:not_modified) if it matches the If-None-Match request header.
- * last_modified!(post.updated_at) sets Last-Modified and returns head(:not_modified) if it's no later than If-Modified-Since.
+ response.last_modified = @post.updated_at
+ response.etag = [:admin, @post, current_user]
+
+ if request.fresh?(response)
+ head :not_modified
+ else
+ # render ...
+ end
* All 2xx requests are considered successful [Josh Peek]
@@ -87,11 +87,11 @@ def assert_redirected_to(options = {}, message=nil)
#
def assert_template(expected = nil, message=nil)
clean_backtrace do
- rendered = @response.rendered_template
+ rendered = @response.rendered_template.to_s
msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
assert_block(msg) do
if expected.nil?
- @response.rendered_template.nil?
+ @response.rendered_template.blank?
else
rendered.to_s.match(expected)
end
@@ -428,11 +428,7 @@ def controller_path
# By default, all methods defined in ActionController::Base and included modules are hidden.
# More methods can be hidden using <tt>hide_actions</tt>.
def hidden_actions
- unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map { |m| m.to_s })
- end
-
- read_inheritable_attribute(:hidden_actions)
+ read_inheritable_attribute(:hidden_actions) || write_inheritable_attribute(:hidden_actions, [])
end
# Hide each of the given methods from being callable as actions.
@@ -1199,7 +1195,7 @@ def default_render #:nodoc:
end
def perform_action
- if self.class.action_methods.include?(action_name)
+ if action_methods.include?(action_name)
send(action_name)
default_render unless performed?
elsif respond_to? :method_missing
@@ -1208,7 +1204,7 @@ def perform_action
elsif template_exists? && template_public?
default_render
else
- raise UnknownAction, "No action responded to #{action_name}. Actions: #{action_methods.to_a.sort.to_sentence}", caller
+ raise UnknownAction, "No action responded to #{action_name}. Actions: #{action_methods.sort.to_sentence}", caller
end
end
@@ -1234,7 +1230,15 @@ def action_methods
end
def self.action_methods
- @action_methods ||= Set.new(public_instance_methods.map { |m| m.to_s }) - hidden_actions
+ @action_methods ||=
+ # All public instance methods of this class, including ancestors
+ public_instance_methods(true).map { |m| m.to_s }.to_set -
+ # Except for public instance methods of Base and its ancestors
+ Base.public_instance_methods(true).map { |m| m.to_s } +
+ # Be sure to include shadowed public instance methods of this class
+ public_instance_methods(false).map { |m| m.to_s } -
+ # And always exclude explicitly hidden actions
+ hidden_actions
end
def add_variables_to_assigns
@@ -43,7 +43,7 @@ class SessionFixationAttempt < StandardError #:nodoc:
:session_path => "/", # available to all paths in app
:session_key => "_session_id",
:cookie_only => true
- } unless const_defined?(:DEFAULT_SESSION_OPTIONS)
+ }
def initialize(cgi, session_options = {})
@cgi = cgi
@@ -61,53 +61,14 @@ def query_string
end
end
- # The request body is an IO input stream. If the RAW_POST_DATA environment
- # variable is already set, wrap it in a StringIO.
- def body
- if raw_post = env['RAW_POST_DATA']
- raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
- StringIO.new(raw_post)
- else
- @cgi.stdinput
- end
- end
-
- def query_parameters
- @query_parameters ||= self.class.parse_query_parameters(query_string)
- end
-
- def request_parameters
- @request_parameters ||= parse_formatted_request_parameters
+ def body_stream #:nodoc:
+ @cgi.stdinput
end
def cookies
@cgi.cookies.freeze
end
- def host_with_port_without_standard_port_handling
- if forwarded = env["HTTP_X_FORWARDED_HOST"]
- forwarded.split(/,\s?/).last
- elsif http_host = env['HTTP_HOST']
- http_host
- elsif server_name = env['SERVER_NAME']
- server_name
- else
- "#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
- end
- end
-
- def host
- host_with_port_without_standard_port_handling.sub(/:\d+$/, '')
- end
-
- def port
- if host_with_port_without_standard_port_handling =~ /:(\d+)$/
- $1.to_i
- else
- standard_port
- end
- end
-
def session
unless defined?(@session)
if @session_options == false
Oops, something went wrong.

0 comments on commit 2ebe8d2

Please sign in to comment.