Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
rizwanreza committed Jun 14, 2010
2 parents 4b05de1 + c125116 commit bf74290
Show file tree
Hide file tree
Showing 28 changed files with 185 additions and 152 deletions.
2 changes: 2 additions & 0 deletions actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* subject is automatically looked up on I18n using mailer_name and action_name as scope as in t(".subject") [JK]

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

* Added ability to pass Proc objects to the defaults hash [ML]
Expand Down
8 changes: 4 additions & 4 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -60,21 +60,21 @@ module ActionMailer #:nodoc:
#
# If you want to explicitly render only certain templates, pass a block:
#
# mail(:to => user.emai) do |format|
# mail(:to => user.email) do |format|
# format.text
# format.html
# end
#
# The block syntax is useful if also need to specify information specific to a part:
#
# mail(:to => user.emai) do |format|
# mail(:to => user.email) do |format|
# format.text(:content_transfer_encoding => "base64")
# format.html
# end
#
# Or even to render a special view:
#
# mail(:to => user.emai) do |format|
# mail(:to => user.email) do |format|
# format.text
# format.html { render "some_other_template" }
# end
Expand Down Expand Up @@ -657,7 +657,7 @@ def set_content_type(m, user_content_type, class_default)

def default_i18n_subject #:nodoc:
mailer_scope = self.class.mailer_name.gsub('/', '.')
I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
end

def collect_responses_and_parts_order(headers) #:nodoc:
Expand Down
88 changes: 51 additions & 37 deletions actionmailer/lib/action_mailer/test_case.rb
Expand Up @@ -8,55 +8,69 @@ def initialize(name)
end

class TestCase < ActiveSupport::TestCase
include TestHelper
module Behavior
extend ActiveSupport::Concern

setup :initialize_test_deliveries
setup :set_expected_mail
include TestHelper

class << self
def tests(mailer)
write_inheritable_attribute(:mailer_class, mailer)
end
module ClassMethods
def tests(mailer)
write_inheritable_attribute(:mailer_class, mailer)
end

def mailer_class
if mailer = read_inheritable_attribute(:mailer_class)
mailer
else
tests determine_default_mailer(name)
def mailer_class
if mailer = read_inheritable_attribute(:mailer_class)
mailer
else
tests determine_default_mailer(name)
end
end
end

def determine_default_mailer(name)
name.sub(/Test$/, '').constantize
rescue NameError => e
raise NonInferrableMailerError.new(name)
def determine_default_mailer(name)
name.sub(/Test$/, '').constantize
rescue NameError => e
raise NonInferrableMailerError.new(name)
end
end
end

protected
def initialize_test_deliveries
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
end
module InstanceMethods

def set_expected_mail
@expected = Mail.new
@expected.content_type ["text", "plain", { "charset" => charset }]
@expected.mime_version = '1.0'
end
protected

private
def charset
"UTF-8"
end
def initialize_test_deliveries
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
end

def set_expected_mail
@expected = Mail.new
@expected.content_type ["text", "plain", { "charset" => charset }]
@expected.mime_version = '1.0'
end

private

def charset
"UTF-8"
end

def encode(subject)
Mail::Encodings.q_value_encode(subject, charset)
end

def encode(subject)
Mail::Encodings.q_value_encode(subject, charset)
def read_fixture(action)
IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
end
end

def read_fixture(action)
IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
included do
setup :initialize_test_deliveries
setup :set_expected_mail
end
end

include Behavior

end
end
10 changes: 2 additions & 8 deletions actionmailer/lib/action_mailer/test_helper.rb
@@ -1,5 +1,7 @@
module ActionMailer
module TestHelper
extend ActiveSupport::Concern

# Asserts that the number of emails sent matches the given number.
#
# def test_emails
Expand Down Expand Up @@ -57,11 +59,3 @@ def assert_no_emails(&block)
end
end
end

module Test
module Unit
class TestCase
include ActionMailer::TestHelper
end
end
end
Expand Up @@ -5,7 +5,7 @@ class <%= class_name %> < ActionMailer::Base
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.actionmailer.<%= file_name %>.<%= action %>.subject
# en.<%= file_name %>.<%= action %>.subject
#
def <%= action %>
@greeting = "Hi"
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/test/base_test.rb
Expand Up @@ -325,7 +325,7 @@ def give_a_greeting
email = BaseMailer.welcome(:subject => nil)
assert_equal "Welcome", email.subject

I18n.backend.store_translations('en', :actionmailer => {:base_mailer => {:welcome => {:subject => "New Subject!"}}})
I18n.backend.store_translations('en', :base_mailer => {:welcome => {:subject => "New Subject!"}})
email = BaseMailer.welcome(:subject => nil)
assert_equal "New Subject!", email.subject
end
Expand Down
2 changes: 2 additions & 0 deletions actionmailer/test/old_base/mail_service_test.rb
Expand Up @@ -1113,6 +1113,8 @@ def test_attr
end

class MethodNamingTest < ActiveSupport::TestCase
include ActionMailer::TestHelper

class TestMailer < ActionMailer::Base
def send
body 'foo'
Expand Down
2 changes: 1 addition & 1 deletion actionpack/actionpack.gemspec
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|
s.add_dependency('i18n', '~> 0.4.1')
s.add_dependency('rack', '~> 1.1.0')
s.add_dependency('rack-test', '~> 0.5.4')
s.add_dependency('rack-mount', '~> 0.6.3')
s.add_dependency('rack-mount', '~> 0.6.4')
s.add_dependency('tzinfo', '~> 0.3.16')
s.add_dependency('erubis', '~> 2.6.5')
end
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/base.rb
Expand Up @@ -2,7 +2,7 @@
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/array/wrap'
require 'active_support/ordered_options.rb'
require 'active_support/ordered_options'

module ActionView #:nodoc:
class NonConcattingString < ActiveSupport::SafeBuffer
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/render/rendering.rb
Expand Up @@ -56,7 +56,7 @@ def _render_template(template, layout = nil, options = {}) #:nodoc:
:identifier => template.identifier, :layout => layout.try(:virtual_path)) do

content = template.render(self, locals) { |*name| _layout_for(*name) }
@_content_for[:layout] = content
@_content_for[:layout] = content if layout

content = _render_layout(layout, locals) if layout
content
Expand Down
@@ -0,0 +1,2 @@
<%= render :inline => 'welcome' %>
<%= yield %>
6 changes: 6 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -229,6 +229,12 @@ def test_render_with_layout
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
end

def test_render_with_layout_which_has_render_inline
assert_equal %(welcome\nHello world!\n),
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
end


# TODO: Move to deprecated_tests.rb
def test_render_with_nested_layout_deprecated
assert_deprecated do
Expand Down
18 changes: 9 additions & 9 deletions actionpack/test/template/text_helper_test.rb
Expand Up @@ -40,15 +40,15 @@ def test_simple_format_should_be_html_safe
assert simple_format("<b> test with html tags </b>").html_safe?
end

def test_simple_format_should_sanitize_unsafe_input
def test_simple_format_should_escape_unsafe_input
assert_equal "<p>&lt;b&gt; test with unsafe string &lt;/b&gt;&lt;script&gt;code!&lt;/script&gt;</p>", simple_format("<b> test with unsafe string </b><script>code!</script>")
end

def test_simple_format_should_not_sanitize_input_if_safe_option
def test_simple_format_should_not_escape_input_if_safe_option
assert_equal "<p><b> test with unsafe string </b><script>code!</script></p>", simple_format("<b> test with unsafe string </b><script>code!</script>", {}, :safe => true)
end

def test_simple_format_should_not_sanitize_safe_input
def test_simple_format_should_not_escape_safe_input
assert_equal "<p><b> test with safe string </b></p>", simple_format("<b> test with safe string </b>".html_safe)
end

Expand All @@ -61,16 +61,16 @@ def test_truncate
assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12)
end

def test_truncate_should_sanitize_unsafe_input
def test_truncate_should_escape_unsafe_input
assert_equal "Hello &lt...", truncate("Hello <script>code!</script>World!!", :length => 12)
end

def test_truncate_should_not_sanitize_input_if_safe_option
def test_truncate_should_not_escape_input_if_safe_option
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!", :length => 12, :safe => true)
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", :length => 12, :safe => true)
end

def test_truncate_should_not_sanitize_safe_input
def test_truncate_should_not_escape_safe_input
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!".html_safe, :length => 12)
assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!".html_safe, :length => 12)
end
Expand Down Expand Up @@ -138,21 +138,21 @@ def test_highlight
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
end

def test_highlight_should_sanitize_unsafe_input
def test_highlight_should_escape_unsafe_input
assert_equal(
"This is a <strong class=\"highlight\">beautiful</strong> morning&lt;script&gt;code!&lt;/script&gt;",
highlight("This is a beautiful morning<script>code!</script>", "beautiful")
)
end

def test_highlight_should_not_sanitize_input_if_safe_option
def test_highlight_should_not_escape_input_if_safe_option
assert_equal(
"This is a <strong class=\"highlight\">beautiful</strong> morning<script>code!</script>",
highlight("This is a beautiful morning<script>code!</script>", "beautiful", :safe => true)
)
end

def test_highlight_should_not_sanitize_safe_input
def test_highlight_should_not_escape_safe_input
assert_equal(
"This is a <strong class=\"highlight\">beautiful</strong> morning<script>code!</script>",
highlight("This is a beautiful morning<script>code!</script>".html_safe, "beautiful")
Expand Down
10 changes: 5 additions & 5 deletions activerecord/examples/performance.rb
@@ -1,18 +1,18 @@
#!/usr/bin/env ruby -KU

TIMES = (ENV['N'] || 10000).to_i

require 'rubygems'

gem 'addressable', '~>2.0'
gem 'faker', '~>0.3.1'
gem 'rbench', '~>0.2.3'

require 'addressable/uri'
require 'faker'
require 'rbench'

__DIR__ = File.dirname(__FILE__)
$:.unshift "#{__DIR__}/../lib"
require 'active_record'
require File.expand_path("../../../load_paths", __FILE__)
require "active_record"

conn = { :adapter => 'mysql',
:database => 'activerecord_unittest',
Expand Down Expand Up @@ -55,7 +55,7 @@ def self.look(exhibits) exhibits.each { |e| e.look } end
def self.feel(exhibits) exhibits.each { |e| e.feel } end
end

sqlfile = "#{__DIR__}/performance.sql"
sqlfile = File.expand_path("../performance.sql", __FILE__)

if File.exists?(sqlfile)
mysql_bin = %w[mysql mysql5].select { |bin| `which #{bin}`.length > 0 }
Expand Down
13 changes: 0 additions & 13 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -1068,19 +1068,6 @@ def all_attributes_exists?(attribute_names)
attribute_names.all? { |name| column_methods_hash.include?(name.to_sym) }
end

def attribute_condition(quoted_column_name, argument)
case argument
when nil then "#{quoted_column_name} IS ?"
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "#{quoted_column_name} IN (?)"
when Range then if argument.exclude_end?
"#{quoted_column_name} >= ? AND #{quoted_column_name} < ?"
else
"#{quoted_column_name} BETWEEN ? AND ?"
end
else "#{quoted_column_name} = ?"
end
end

protected
# Scope parameters to method calls within the block. Takes a hash of method_name => parameters hash.
# method_name may be <tt>:find</tt> or <tt>:create</tt>. <tt>:find</tt> parameter is <tt>Relation</tt> while
Expand Down
7 changes: 7 additions & 0 deletions activesupport/CHANGELOG
@@ -1,3 +1,10 @@
*Rails 3.0.0 [Release Candidate] (unreleased)*

* ActiveSupport::OrderedHash#merge and #merge! accept a block. #4838 [Paul Mucur, fxn]

* Date#since, #ago, #beginning_of_day, #end_of_day, and #xmlschema honor now the user time zone if set. [Geoff Buesing]


*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Extracted String#truncate from TextHelper#truncate [DHH]
Expand Down
1 change: 1 addition & 0 deletions activesupport/lib/active_support/cache/file_store.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/file/atomic'
require 'active_support/core_ext/string/conversions'

module ActiveSupport
module Cache
Expand Down

0 comments on commit bf74290

Please sign in to comment.