aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/base.rb8
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb88
-rw-r--r--actionmailer/lib/action_mailer/test_helper.rb10
-rw-r--r--actionmailer/lib/rails/generators/mailer/templates/mailer.rb2
-rw-r--r--actionmailer/test/base_test.rb2
-rw-r--r--actionmailer/test/old_base/mail_service_test.rb2
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/render/rendering.rb2
-rw-r--r--actionpack/test/fixtures/layouts/yield_with_render_inline_inside.erb2
-rw-r--r--actionpack/test/template/render_test.rb6
-rw-r--r--actionpack/test/template/text_helper_test.rb18
-rwxr-xr-xactiverecord/examples/performance.rb10
-rwxr-xr-xactiverecord/lib/active_record/base.rb13
-rw-r--r--activesupport/CHANGELOG7
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb1
-rw-r--r--activesupport/lib/active_support/callbacks.rb75
-rw-r--r--activesupport/lib/active_support/core_ext/hash/except.rb1
-rw-r--r--activesupport/lib/active_support/json/decoding.rb2
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb21
-rw-r--r--activesupport/test/ordered_hash_test.rb30
-rwxr-xr-xci/ci_build.rb4
-rw-r--r--railties/lib/rails/generators.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory0
-rw-r--r--railties/lib/rails/ruby_version_check.rb20
-rw-r--r--railties/test/generators/app_generator_test.rb1
-rw-r--r--railties/test/generators/mailer_generator_test.rb4
28 files changed, 185 insertions, 152 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 6e2c441e53..f0b9368874 100644
--- a/actionmailer/CHANGELOG
+++ b/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]
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 7da033b6af..8c5c838384 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -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
@@ -657,7 +657,7 @@ module ActionMailer #:nodoc:
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:
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
index d4874c6dbf..b91eed592a 100644
--- a/actionmailer/lib/action_mailer/test_case.rb
+++ b/actionmailer/lib/action_mailer/test_case.rb
@@ -8,55 +8,69 @@ module ActionMailer
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
diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb
index 3a1612442f..5beab87ad2 100644
--- a/actionmailer/lib/action_mailer/test_helper.rb
+++ b/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
@@ -57,11 +59,3 @@ module ActionMailer
end
end
end
-
-module Test
- module Unit
- class TestCase
- include ActionMailer::TestHelper
- end
- end
-end
diff --git a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb
index 7343eb28b3..21e5918ecb 100644
--- a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb
+++ b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb
@@ -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"
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index b9226196fd..88e38a583b 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -325,7 +325,7 @@ class BaseTest < ActiveSupport::TestCase
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
diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb
index e8e8fcedc9..527b37218a 100644
--- a/actionmailer/test/old_base/mail_service_test.rb
+++ b/actionmailer/test/old_base/mail_service_test.rb
@@ -1113,6 +1113,8 @@ class InheritableTemplateRootTest < ActiveSupport::TestCase
end
class MethodNamingTest < ActiveSupport::TestCase
+ include ActionMailer::TestHelper
+
class TestMailer < ActionMailer::Base
def send
body 'foo'
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 02ff908c1c..8e95315252 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -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
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index b7f404f5d8..4d06ca0d89 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -2,7 +2,7 @@ require 'active_support/core_ext/module/attr_internal'
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
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 4198013f57..4d35296932 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -56,7 +56,7 @@ module ActionView
: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
diff --git a/actionpack/test/fixtures/layouts/yield_with_render_inline_inside.erb b/actionpack/test/fixtures/layouts/yield_with_render_inline_inside.erb
new file mode 100644
index 0000000000..7298d79690
--- /dev/null
+++ b/actionpack/test/fixtures/layouts/yield_with_render_inline_inside.erb
@@ -0,0 +1,2 @@
+<%= render :inline => 'welcome' %>
+<%= yield %>
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index aca96e0a24..059dcedad8 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -229,6 +229,12 @@ module RenderTestCases
@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
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 108cf510ff..b0a4c2a9cc 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -40,15 +40,15 @@ class TextHelperTest < ActionView::TestCase
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
@@ -61,16 +61,16 @@ class TextHelperTest < ActionView::TestCase
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
@@ -138,21 +138,21 @@ class TextHelperTest < ActionView::TestCase
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")
diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb
index 53acd62f47..f69576b240 100755
--- a/activerecord/examples/performance.rb
+++ b/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',
@@ -55,7 +55,7 @@ class Exhibit < ActiveRecord::Base
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 }
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 7cff6d9f1a..63ab6efae2 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1068,19 +1068,6 @@ module ActiveRecord #:nodoc:
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
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 6566d3fa06..13ec3c3775 100644
--- a/activesupport/CHANGELOG
+++ b/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]
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index fc225e77a2..84f6f29572 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/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
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index ba15043bde..16fdfd04e9 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class'
@@ -383,21 +384,12 @@ module ActiveSupport
# key. See #define_callbacks for more information.
#
def __define_runner(symbol) #:nodoc:
- send("_update_#{symbol}_superclass_callbacks")
body = send("_#{symbol}_callbacks").compile(nil)
silence_warnings do
undef_method "_run_#{symbol}_callbacks" if method_defined?("_run_#{symbol}_callbacks")
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def _run_#{symbol}_callbacks(key = nil, &blk)
- @_initialized_#{symbol}_callbacks ||= begin
- if self.class.send("_update_#{symbol}_superclass_callbacks")
- self.class.__define_runner(#{symbol.inspect})
- return _run_#{symbol}_callbacks(key, &blk)
- end
- true
- end
-
if key
name = "_run__\#{self.class.name.hash.abs}__#{symbol}__\#{key.hash.abs}__callbacks"
@@ -432,16 +424,15 @@ module ActiveSupport
# CallbackChain.
#
def __update_callbacks(name, filters = [], block = nil) #:nodoc:
- send("_update_#{name}_superclass_callbacks")
-
type = [:before, :after, :around].include?(filters.first) ? filters.shift : :before
options = filters.last.is_a?(Hash) ? filters.pop : {}
filters.unshift(block) if block
- chain = send("_#{name}_callbacks")
- yield chain, type, filters, options if block_given?
-
- __define_runner(name)
+ ([self] + self.descendents).each do |target|
+ chain = target.send("_#{name}_callbacks")
+ yield chain, type, filters, options
+ target.__define_runner(name)
+ end
end
# Set callbacks for a previously defined callback.
@@ -471,14 +462,18 @@ module ActiveSupport
# is a speed improvement for ActionPack.
#
def set_callback(name, *filter_list, &block)
+ mapped = nil
+
__update_callbacks(name, filter_list, block) do |chain, type, filters, options|
- filters.map! do |filter|
- removed = chain.delete_if {|c| c.matches?(type, filter) }
- send("_removed_#{name}_callbacks").push(*removed)
+ mapped ||= filters.map do |filter|
Callback.new(chain, filter, type, options.dup, self)
end
- options[:prepend] ? chain.unshift(*filters) : chain.push(*filters)
+ filters.each do |filter|
+ chain.delete_if {|c| c.matches?(type, filter) }
+ end
+
+ options[:prepend] ? chain.unshift(*mapped) : chain.push(*mapped)
end
end
@@ -496,7 +491,6 @@ module ActiveSupport
end
chain.delete(filter)
- send("_removed_#{name}_callbacks") << filter
end
end
end
@@ -505,8 +499,14 @@ module ActiveSupport
#
def reset_callbacks(symbol)
callbacks = send("_#{symbol}_callbacks")
+
+ self.descendents.each do |target|
+ chain = target.send("_#{symbol}_callbacks")
+ callbacks.each { |c| chain.delete(c) }
+ target.__define_runner(symbol)
+ end
+
callbacks.clear
- send("_removed_#{symbol}_callbacks").concat(callbacks)
__define_runner(symbol)
end
@@ -559,39 +559,6 @@ module ActiveSupport
extlib_inheritable_reader("_#{callback}_callbacks") do
CallbackChain.new(callback, config)
end
-
- extlib_inheritable_reader("_removed_#{callback}_callbacks") do
- []
- end
-
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
- def self._#{callback}_superclass_callbacks
- if superclass.respond_to?(:_#{callback}_callbacks)
- superclass._#{callback}_callbacks + superclass._#{callback}_superclass_callbacks
- else
- []
- end
- end
-
- def self._update_#{callback}_superclass_callbacks
- changed, index = false, 0
-
- callbacks = (_#{callback}_superclass_callbacks -
- _#{callback}_callbacks) - _removed_#{callback}_callbacks
-
- callbacks.each do |callback|
- if new_index = _#{callback}_callbacks.index(callback)
- index = new_index + 1
- else
- changed = true
- _#{callback}_callbacks.insert(index, callback)
- index = index + 1
- end
- end
- changed
- end
- METHOD
-
__define_runner(callback)
end
end
diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb
index 207801d3a7..89729df258 100644
--- a/activesupport/lib/active_support/core_ext/hash/except.rb
+++ b/activesupport/lib/active_support/core_ext/hash/except.rb
@@ -17,7 +17,6 @@ class Hash
# Replaces the hash without the given keys.
def except!(*keys)
- keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
keys.each { |key| delete(key) }
self
end
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index 04ff316a44..c1f6330c6c 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -22,7 +22,7 @@ module ActiveSupport
if name.is_a?(Module)
@backend = name
else
- require "active_support/json/backends/#{name.to_s.downcase}.rb"
+ require "active_support/json/backends/#{name.to_s.downcase}"
@backend = ActiveSupport::JSON::Backends::const_get(name)
end
@parse_error = @backend::ParseError
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index e1a2866863..91de722748 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -23,6 +23,17 @@ module ActiveSupport
# Hash is ordered in Ruby 1.9!
if RUBY_VERSION < '1.9'
+
+ # In MRI the Hash class is core and written in C. In particular, methods are
+ # programmed with explicit C function calls and polymorphism is not honored.
+ #
+ # For example, []= is crucial in this implementation to maintain the @keys
+ # array but hash.c invokes rb_hash_aset() originally. This prevents method
+ # reuse through inheritance and forces us to reimplement stuff.
+ #
+ # For instance, we cannot use the inherited #merge! because albeit the algorithm
+ # itself would work, our []= is not being called at all by the C code.
+
def initialize(*args, &block)
super
@keys = []
@@ -130,12 +141,16 @@ module ActiveSupport
end
def merge!(other_hash)
- other_hash.each {|k,v| self[k] = v }
+ if block_given?
+ other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
+ else
+ other_hash.each { |k, v| self[k] = v }
+ end
self
end
- def merge(other_hash)
- dup.merge!(other_hash)
+ def merge(other_hash, &block)
+ dup.merge!(other_hash, &block)
end
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index d070206d44..0f36f5204d 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -141,10 +141,32 @@ class OrderedHashTest < Test::Unit::TestCase
merged = @ordered_hash.merge other_hash
assert_equal merged.length, @ordered_hash.length + other_hash.length
assert_equal @keys + ['purple', 'violet'], merged.keys
+ end
+
+ def test_merge_with_block
+ hash = ActiveSupport::OrderedHash.new
+ hash[:a] = 0
+ hash[:b] = 0
+ merged = hash.merge(:b => 2, :c => 7) do |key, old_value, new_value|
+ new_value + 1
+ end
+
+ assert_equal 0, merged[:a]
+ assert_equal 3, merged[:b]
+ assert_equal 7, merged[:c]
+ end
+
+ def test_merge_bang_with_block
+ hash = ActiveSupport::OrderedHash.new
+ hash[:a] = 0
+ hash[:b] = 0
+ hash.merge!(:a => 1, :c => 7) do |key, old_value, new_value|
+ new_value + 3
+ end
- @ordered_hash.merge! other_hash
- assert_equal @ordered_hash, merged
- assert_equal @ordered_hash.keys, merged.keys
+ assert_equal 4, hash[:a]
+ assert_equal 0, hash[:b]
+ assert_equal 7, hash[:c]
end
def test_shift
@@ -152,7 +174,7 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal [@keys.first, @values.first], pair
assert !@ordered_hash.keys.include?(pair.first)
end
-
+
def test_keys
original = @ordered_hash.keys.dup
@ordered_hash.keys.pop
diff --git a/ci/ci_build.rb b/ci/ci_build.rb
index cd62381d9c..ee6c357519 100755
--- a/ci/ci_build.rb
+++ b/ci/ci_build.rb
@@ -19,7 +19,7 @@ puts "[CruiseControl] Rails build"
build_results = {}
# Install required version of bundler.
-bundler_install_cmd = "sudo gem install bundler --no-ri --no-rdoc"
+bundler_install_cmd = "gem install bundler --no-ri --no-rdoc"
puts "Running command: #{bundler_install_cmd}"
build_results[:install_bundler] = system bundler_install_cmd
@@ -27,7 +27,7 @@ cd root_dir do
puts
puts "[CruiseControl] Bundling RubyGems"
puts
- build_results[:bundle] = system 'sudo rm -rf ~/.bundle; env CI=1 bundle install'
+ build_results[:bundle] = system 'rm -rf ~/.bundle; env CI=1 bundle install'
end
cd "#{root_dir}/activesupport" do
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index f4990bfb4c..41aecea355 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -327,7 +327,7 @@ module Rails
paths = []
namespaces.each do |namespace|
pieces = namespace.split(":")
- paths << pieces.dup.push(pieces.last).join("/") unless pieces.uniq.size == 1
+ paths << pieces.dup.push(pieces.last).join("/")
paths << pieces.join("/")
end
paths.uniq!
diff --git a/railties/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory b/railties/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory
diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb
index 994df17e65..e8d1d1e039 100644
--- a/railties/lib/rails/ruby_version_check.rb
+++ b/railties/lib/rails/ruby_version_check.rb
@@ -1,10 +1,24 @@
-ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
-if ruby_release < '1.8.7' || (ruby_release > '1.8' && ruby_release < '1.9.2')
+if RUBY_VERSION < '1.8.7'
+ desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
abort <<-end_message
Rails 3 requires Ruby 1.8.7 or 1.9.2.
- You're running #{ruby_release}; please upgrade to continue.
+ You're running
+ #{desc}
+
+ Please upgrade to continue.
+
+ end_message
+elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2'
+ $stderr.puts <<-end_message
+
+ Rails 3 doesn't officially support Ruby 1.9.1 since recent stable
+ releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2
+ before Rails 3 is released!
+
+ You're running
+ #{RUBY_DESCRIPTION}
end_message
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index ffc5636467..6a3b5de9de 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -9,6 +9,7 @@ DEFAULT_APP_FILES = %w(
config.ru
app/controllers
app/helpers
+ app/mailers
app/models
app/views/layouts
config/environments
diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb
index 850b45ff74..450dec7716 100644
--- a/railties/test/generators/mailer_generator_test.rb
+++ b/railties/test/generators/mailer_generator_test.rb
@@ -17,8 +17,8 @@ class MailerGeneratorTest < Rails::Generators::TestCase
def test_mailer_with_i18n_helper
run_generator
assert_file "app/mailers/notifier.rb" do |mailer|
- assert_match /en\.actionmailer\.notifier\.foo\.subject/, mailer
- assert_match /en\.actionmailer\.notifier\.bar\.subject/, mailer
+ assert_match /en\.notifier\.foo\.subject/, mailer
+ assert_match /en\.notifier\.bar\.subject/, mailer
end
end