Skip to content

Commit

Permalink
Merge remote branch 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Jun 8, 2010
2 parents e7e6ee3 + ab2877c commit 751f79a
Show file tree
Hide file tree
Showing 77 changed files with 721 additions and 646 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Expand Up @@ -29,10 +29,10 @@ gem "text-format", "~> 1.0.0"

# AR
if mri || RUBY_ENGINE == "rbx"
gem "sqlite3-ruby", "= 1.3.0.beta.2", :require => 'sqlite3'
gem "sqlite3-ruby", "~> 1.3.0", :require => 'sqlite3'

group :db do
gem "pg", ">= 0.9.0"
# gem "pg", ">= 0.9.0"
gem "mysql", ">= 2.8.1"
end
elsif RUBY_ENGINE == "jruby"
Expand All @@ -46,6 +46,7 @@ end

# AP
gem "RedCloth", ">= 4.2.2"
gem "bluecloth", ">= 2.0.7"

group :documentation do
gem 'rdoc', '2.1'
Expand Down
2 changes: 1 addition & 1 deletion RAILS_VERSION
@@ -1 +1 @@
3.0.0.beta3
3.0.0.beta4
2 changes: 1 addition & 1 deletion actionmailer/CHANGELOG
@@ -1,4 +1,4 @@
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Changed encoding behaviour of mail, so updated tests in actionmailer and bumped mail version to 2.2.1 [ML]

Expand Down
2 changes: 1 addition & 1 deletion actionmailer/actionmailer.gemspec
Expand Up @@ -20,5 +20,5 @@ Gem::Specification.new do |s|
s.has_rdoc = true

s.add_dependency('actionpack', version)
s.add_dependency('mail', '~> 2.2.1')
s.add_dependency('mail', '~> 2.2.3')
end
39 changes: 37 additions & 2 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -36,6 +36,9 @@ module ActionMailer #:nodoc:
# * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
# manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
#
# * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email
# in the same manner as <tt>attachments[]=</tt>
#
# * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
# as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt>
# <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
Expand Down Expand Up @@ -173,7 +176,7 @@ module ActionMailer #:nodoc:
#
# class ApplicationMailer < ActionMailer::Base
# def welcome(recipient)
# attachments['free_book.pdf'] = { :data => File.read('path/to/file.pdf') }
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
# mail(:to => recipient, :subject => "New account information")
# end
# end
Expand All @@ -184,6 +187,34 @@ module ActionMailer #:nodoc:
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
# with the filename +free_book.pdf+.
#
# = Inline Attachments
#
# You can also specify that a file should be displayed inline with other HTML. For example a
# corporate logo or a photo or the like.
#
# To do this is simple, in the Mailer:
#
# class ApplicationMailer < ActionMailer::Base
# def welcome(recipient)
# attachments.inline['photo.png'] = File.read('path/to/photo.png')
# mail(:to => recipient, :subject => "Here is what we look like")
# end
# end
#
# And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and
# make a call to +image_tag+ passing in the attachment you want to display and then call
# +url+ on the attachment to get the relative content id path for the image source:
#
# <h1>Please Don't Cringe</h1>
#
# <%= image_tag attachments['photo.png'].url -%>
#
# As we are using ActionView's +image_tag+ method, you can pass in any other options you want:
#
# <h1>Please Don't Cringe</h1>
#
# <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
#
# = Observing and Intercepting Mails
#
# Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
Expand Down Expand Up @@ -612,7 +643,11 @@ def set_content_type(m, user_content_type, class_default)
when user_content_type.present?
user_content_type
when m.has_attachments?
["multipart", "mixed", params]
if m.attachments.detect { |a| a.inline? }
["multipart", "related", params]
else
["multipart", "mixed", params]
end
when m.multipart?
["multipart", "alternative", params]
else
Expand Down
5 changes: 5 additions & 0 deletions actionmailer/lib/action_mailer/mail_helper.rb
Expand Up @@ -32,5 +32,10 @@ def mailer
def message
@_message
end

# Access the message attachments list.
def attachments
@_message.attachments
end
end
end
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/version.rb
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 0
TINY = 0
BUILD = "beta3"
BUILD = "beta4"

STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
end
Expand Down
17 changes: 17 additions & 0 deletions actionmailer/test/base_test.rb
Expand Up @@ -33,6 +33,11 @@ def plain_text_only(hash = {})
mail(hash)
end

def inline_attachment
attachments.inline['logo.png'] = "\312\213\254\232"
mail
end

def attachment_with_content(hash = {})
attachments['invoice.pdf'] = 'This is test File content'
mail(hash)
Expand Down Expand Up @@ -264,6 +269,18 @@ def give_a_greeting
assert_equal("application/pdf", email.parts[1].mime_type)
assert_equal("VGhpcyBpcyB0ZXN0IEZpbGUgY29udGVudA==\r\n", email.parts[1].body.encoded)
end

test "can embed an inline attachment" do
email = BaseMailer.inline_attachment
# Need to call #encoded to force the JIT sort on parts
email.encoded
assert_equal(2, email.parts.length)
assert_equal("multipart/related", email.mime_type)
assert_equal("multipart/alternative", email.parts[0].mime_type)
assert_equal("text/plain", email.parts[0].parts[0].mime_type)
assert_equal("text/html", email.parts[0].parts[1].mime_type)
assert_equal("logo.png", email.parts[1].filename)
end

# Defaults values
test "uses default charset from class" do
Expand Down
@@ -0,0 +1,5 @@
<h1>Inline Image</h1>

<%= image_tag attachments['logo.png'].url %>

<p>This is an image that is inline</p>
@@ -0,0 +1,4 @@
Inline Image

No image for you

6 changes: 3 additions & 3 deletions actionmailer/test/old_base/mail_service_test.rb
Expand Up @@ -674,7 +674,7 @@ def test_unquote_quoted_printable_subject
EOF
mail = Mail.new(msg)
assert_equal "testing testing \326\244", mail.subject
assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
assert_equal "Subject: testing testing =?UTF-8?Q?_=D6=A4=?=\r\n", mail[:subject].encoded
end

def test_unquote_7bit_subject
Expand Down Expand Up @@ -863,15 +863,15 @@ def test_multipart_with_mime_version

def test_multipart_with_utf8_subject
mail = TestMailer.multipart_with_utf8_subject(@recipient)
regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü"
assert_match(string, mail.subject)
end

def test_implicitly_multipart_with_utf8
mail = TestMailer.implicitly_multipart_with_utf8
regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü"
assert_match(string, mail.subject)
Expand Down
12 changes: 11 additions & 1 deletion actionpack/CHANGELOG
@@ -1,4 +1,14 @@
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Add shallow routes back to the new router [Diego Carrion]

resources :posts do
shallow do
resources :comments
end
end

You can now use comment_path for /comments/1 instead of post_comment_path for /posts/1/comments/1.

* Remove middleware laziness [José Valim]

Expand Down
8 changes: 8 additions & 0 deletions actionpack/lib/action_controller/metal/url_for.rb
Expand Up @@ -16,5 +16,13 @@ def _router
raise "In order to use #url_for, you must include the helpers of a particular " \
"router. For instance, `include Rails.application.routes.url_helpers"
end

module ClassMethods
def action_methods
@action_methods ||= begin
super - _router.named_routes.helper_names
end
end
end
end
end
Expand Up @@ -23,6 +23,7 @@ class Tokenizer #:nodoc:

# Create a new Tokenizer for the given text.
def initialize(text)
text.encode! if text.encoding_aware?
@scanner = StringScanner.new(text)
@position = 0
@line = 0
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/middleware/show_exceptions.rb
Expand Up @@ -6,7 +6,7 @@ module ActionDispatch
# This middleware rescues any exception returned by the application and renders
# nice exception pages if it's being rescued locally.
class ShowExceptions
LOCALHOST = ['127.0.0.1', '::1'].freeze
LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, "::1", /^0:0:0:0:0:0:0:1(%.*)?$/].freeze

RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')

Expand Down Expand Up @@ -114,7 +114,7 @@ def rescue_action_in_public(exception)

# True if the request came from localhost, 127.0.0.1.
def local_request?(request)
LOCALHOST.any?{ |local_ip| request.remote_addr == local_ip && request.remote_ip == local_ip }
LOCALHOST.any? { |local_ip| local_ip === request.remote_addr && local_ip === request.remote_ip }
end

def status_code(exception)
Expand Down

0 comments on commit 751f79a

Please sign in to comment.