aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz <wycats@Yehuda-Katz.local>2009-11-09 10:57:20 -0800
committerYehuda Katz <wycats@Yehuda-Katz.local>2009-11-09 10:57:20 -0800
commit790c062280c0d23c2033e4983c13d402c0424f2a (patch)
tree7b652b420411779072c2371a42e84c83525f63b1
parent51fe6d05e73a4e0f8481f4e441f4ca886d65a69c (diff)
parent303991288633effea5a1d1774dbd861951303fe5 (diff)
downloadrails-790c062280c0d23c2033e4983c13d402c0424f2a.tar.gz
rails-790c062280c0d23c2033e4983c13d402c0424f2a.tar.bz2
rails-790c062280c0d23c2033e4983c13d402c0424f2a.zip
Merge branch 'master' of github.com:rails/rails
-rwxr-xr-xactionpack/lib/action_dispatch/http/request.rb2
-rw-r--r--actionpack/lib/action_view/test_case.rb1
-rw-r--r--actionpack/test/dispatch/request_test.rb4
-rw-r--r--actionpack/test/template/test_case_test.rb13
-rwxr-xr-xactivemodel/Rakefile19
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb2
-rw-r--r--activerecord/test/models/pirate.rb2
-rw-r--r--activerecord/test/models/ship.rb2
-rw-r--r--activeresource/lib/active_resource/base.rb39
-rw-r--r--activeresource/lib/active_resource/connection.rb9
-rw-r--r--activesupport/lib/active_support/cache.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb3
-rw-r--r--activesupport/lib/active_support/dependencies.rb2
-rw-r--r--activesupport/lib/active_support/deprecated_callbacks.rb5
-rw-r--r--activesupport/lib/active_support/inflector/inflections.rb4
-rw-r--r--activesupport/lib/active_support/json/backends/jsongem.rb21
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb5
-rw-r--r--activesupport/lib/active_support/notifications.rb2
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb4
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb1
-rw-r--r--activesupport/test/multibyte_chars_test.rb10
21 files changed, 90 insertions, 63 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 9314ff5c53..c24b404e2f 100755
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -167,7 +167,7 @@ module ActionDispatch
@env["action_dispatch.request.formats"] ||=
if parameters[:format]
- [Mime[parameters[:format]]]
+ Array.wrap(Mime[parameters[:format]])
elsif xhr? || (accept && !accept.include?(?,))
accepts
else
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 8beda24aba..86bbad822d 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -120,6 +120,7 @@ module ActionView
def _view
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.class.send :include, _helpers
+ view.output_buffer = self.output_buffer
view
end
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 239fda98e0..b62df9a6b2 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -432,6 +432,10 @@ class RequestTest < ActiveSupport::TestCase
request = stub_request
request.expects(:parameters).at_least_once.returns({ :format => :txt })
assert_equal with_set(Mime::TEXT), request.formats
+
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => :unknown })
+ assert request.formats.empty?
end
test "negotiate_mime" do
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index ca72c13ffa..05a409d05a 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -24,7 +24,7 @@ module ActionView
test_case.class_eval do
test "helpers defined on ActionView::TestCase are available" do
assert test_case.ancestors.include?(ASharedTestHelper)
- assert 'Holla!', from_shared_helper
+ assert_equal 'Holla!', from_shared_helper
end
end
end
@@ -38,10 +38,15 @@ module ActionView
assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
end
+ test "can render a layout with block" do
+ assert_equal "Before (ChrisCruft)\n!\nAfter",
+ render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
+ end
+
helper AnotherTestHelper
test "additional helper classes can be specified as in a controller" do
assert test_case.ancestors.include?(AnotherTestHelper)
- assert 'Howdy!', from_another_helper
+ assert_equal 'Howdy!', from_another_helper
end
end
@@ -58,14 +63,14 @@ module ActionView
helper AnotherTestHelper
test "additional helper classes can be specified as in a controller" do
assert test_case.ancestors.include?(AnotherTestHelper)
- assert 'Howdy!', from_another_helper
+ assert_equal 'Howdy!', from_another_helper
test_case.helper_class.module_eval do
def render_from_helper
from_another_helper
end
end
- assert 'Howdy!', render(:partial => 'test/from_helper')
+ assert_equal 'Howdy!', render(:partial => 'test/from_helper')
end
end
diff --git a/activemodel/Rakefile b/activemodel/Rakefile
index 8897987518..a63e1982b9 100755
--- a/activemodel/Rakefile
+++ b/activemodel/Rakefile
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), 'lib', 'active_model', 'version')
+dir = File.dirname(__FILE__)
+require "#{dir}/lib/active_model/version"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME = 'activemodel'
@@ -12,16 +13,16 @@ require 'rake/testtask'
task :default => :test
Rake::TestTask.new do |t|
- t.libs << "test"
- t.test_files = Dir.glob("test/cases/**/*_test.rb").sort
+ t.libs << "#{dir}/test"
+ t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb").sort
t.verbose = true
t.warning = true
end
task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- Dir.glob("test/**/*_test.rb").all? do |file|
- system(ruby, '-w', '-Ilib:test', file)
+ Dir.glob("#{dir}/test/**/*_test.rb").all? do |file|
+ system(ruby, '-w', "-I#{dir}/lib", "-I#{dir}/test", file)
end or raise "Failures"
end
@@ -30,20 +31,20 @@ require 'rake/rdoctask'
# Generate the RDoc documentation
Rake::RDocTask.new do |rdoc|
- rdoc.rdoc_dir = 'doc'
+ rdoc.rdoc_dir = "#{dir}/doc"
rdoc.title = "Active Model"
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
rdoc.options << '--charset' << 'utf-8'
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
- rdoc.rdoc_files.include('README', 'CHANGES')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include("#{dir}/README", "#{dir}/CHANGES")
+ rdoc.rdoc_files.include("#{dir}/lib/**/*.rb")
end
require 'rake/packagetask'
require 'rake/gempackagetask'
-spec = eval(File.read('activemodel.gemspec'))
+spec = eval(File.read("#{dir}/activemodel.gemspec"))
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index edcf547e01..ca3110a374 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -250,6 +250,8 @@ module ActiveRecord
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
end
}, __FILE__, __LINE__
+
+ add_autosave_association_callbacks(reflection)
else
raise ArgumentError, "No association found for name `#{association_name}'. Has it been defined yet?"
end
diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb
index 05c5b666ae..f2c05dd48f 100644
--- a/activerecord/test/models/pirate.rb
+++ b/activerecord/test/models/pirate.rb
@@ -18,7 +18,7 @@ class Pirate < ActiveRecord::Base
has_many :treasure_estimates, :through => :treasures, :source => :price_estimates
# These both have :autosave enabled because accepts_nested_attributes_for is used on them.
- has_one :ship, :validate => true
+ has_one :ship
has_one :non_validated_ship, :class_name => 'Ship'
has_many :birds
has_many :birds_with_method_callbacks, :class_name => "Bird",
diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb
index d0df951622..06759d64b8 100644
--- a/activerecord/test/models/ship.rb
+++ b/activerecord/test/models/ship.rb
@@ -1,7 +1,7 @@
class Ship < ActiveRecord::Base
self.record_timestamps = false
- belongs_to :pirate, :validate => true
+ belongs_to :pirate
has_many :parts, :class_name => 'ShipPart', :autosave => true
accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index bd2abdd38e..18105e8887 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -274,8 +274,8 @@ module ActiveResource
@site = nil
else
@site = create_site_uri_from(site)
- @user = URI.decode(@site.user) if @site.user
- @password = URI.decode(@site.password) if @site.password
+ @user = uri_parser.unescape(@site.user) if @site.user
+ @password = uri_parser.unescape(@site.password) if @site.password
end
end
@@ -737,12 +737,12 @@ module ActiveResource
# Accepts a URI and creates the site URI from that.
def create_site_uri_from(site)
- site.is_a?(URI) ? site.dup : URI.parse(site)
+ site.is_a?(URI) ? site.dup : uri_parser.parse(site)
end
# Accepts a URI and creates the proxy URI from that.
def create_proxy_uri_from(proxy)
- proxy.is_a?(URI) ? proxy.dup : URI.parse(proxy)
+ proxy.is_a?(URI) ? proxy.dup : uri_parser.parse(proxy)
end
# contains a set of the current prefix parameters.
@@ -767,6 +767,10 @@ module ActiveResource
[ prefix_options, query_options ]
end
+
+ def uri_parser
+ @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
+ end
end
attr_accessor :attributes #:nodoc:
@@ -1152,15 +1156,16 @@ module ActiveResource
def respond_to?(method, include_priv = false)
method_name = method.to_s
if attributes.nil?
- return super
+ super
elsif attributes.has_key?(method_name)
- return true
- elsif ['?','='].include?(method_name.last) && attributes.has_key?(method_name.first(-1))
- return true
+ true
+ elsif method_name =~ /(?:=|\?)$/ && attributes.include?($`)
+ true
+ else
+ # super must be called at the end of the method, because the inherited respond_to?
+ # would return true for generated readers, even if the attribute wasn't present
+ super
end
- # super must be called at the end of the method, because the inherited respond_to?
- # would return true for generated readers, even if the attribute wasn't present
- super
end
protected
@@ -1249,13 +1254,15 @@ module ActiveResource
def method_missing(method_symbol, *arguments) #:nodoc:
method_name = method_symbol.to_s
- case method_name.last
+ if method_name =~ /(=|\?)$/
+ case $1
when "="
- attributes[method_name.first(-1)] = arguments.first
+ attributes[$`] = arguments.first
when "?"
- attributes[method_name.first(-1)]
- else
- attributes.has_key?(method_name) ? attributes[method_name] : super
+ attributes[$`]
+ end
+ else
+ attributes.include?(method_name) ? attributes[method_name] : super
end
end
end
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 98cb1a932b..193be89a82 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -31,20 +31,21 @@ module ActiveResource
def initialize(site, format = ActiveResource::Formats::XmlFormat)
raise ArgumentError, 'Missing site URI' unless site
@user = @password = nil
+ @uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
self.site = site
self.format = format
end
# Set URI for remote service.
def site=(site)
- @site = site.is_a?(URI) ? site : URI.parse(site)
- @user = URI.decode(@site.user) if @site.user
- @password = URI.decode(@site.password) if @site.password
+ @site = site.is_a?(URI) ? site : @uri_parser.parse(site)
+ @user = @uri_parser.unescape(@site.user) if @site.user
+ @password = @uri_parser.unescape(@site.password) if @site.password
end
# Set the proxy for remote service.
def proxy=(proxy)
- @proxy = proxy.is_a?(URI) ? proxy : URI.parse(proxy)
+ @proxy = proxy.is_a?(URI) ? proxy : @uri_parser.parse(proxy)
end
# Sets the user for remote service.
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index b91ae65e9f..f2d957f154 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -1,4 +1,5 @@
require 'benchmark'
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/benchmark'
require 'active_support/core_ext/exception'
require 'active_support/core_ext/class/attribute_accessors'
@@ -43,7 +44,7 @@ module ActiveSupport
# ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# # => returns MyOwnCacheStore.new
def self.lookup_store(*store_option)
- store, *parameters = *([ store_option ].flatten)
+ store, *parameters = *Array.wrap(store_option).flatten
case store
when Symbol
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 190173f8a0..35ccec5df4 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -1,4 +1,5 @@
require 'active_support/time'
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/reverse_merge'
class Hash
@@ -138,7 +139,7 @@ class Hash
case value.class.to_s
when 'Hash'
if value['type'] == 'array'
- child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway
+ child_key, entries = Array.wrap(value.detect { |k,v| k != 'type' }) # child_key is throwaway
if entries.nil? || (c = value['__content__'] && c.blank?)
[]
else
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 7f6f012721..e858bcdc80 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -339,7 +339,7 @@ module ActiveSupport #:nodoc:
next
end
[ nesting_camel ]
- end.flatten.compact.uniq
+ end.compact.flatten.compact.uniq
end
# Search for a file in load_paths matching the provided suffix.
diff --git a/activesupport/lib/active_support/deprecated_callbacks.rb b/activesupport/lib/active_support/deprecated_callbacks.rb
index 20fb03cbeb..f56fef0b6d 100644
--- a/activesupport/lib/active_support/deprecated_callbacks.rb
+++ b/activesupport/lib/active_support/deprecated_callbacks.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/array/extract_options'
+require 'active_support/core_ext/array/wrap'
module ActiveSupport
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
@@ -194,8 +195,8 @@ module ActiveSupport
end
def should_run_callback?(*args)
- [options[:if]].flatten.compact.all? { |a| evaluate_method(a, *args) } &&
- ![options[:unless]].flatten.compact.any? { |a| evaluate_method(a, *args) }
+ Array.wrap(options[:if]).flatten.compact.all? { |a| evaluate_method(a, *args) } &&
+ !Array.wrap(options[:unless]).flatten.compact.any? { |a| evaluate_method(a, *args) }
end
end
diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb
index 24ce58e5c2..785e245ea4 100644
--- a/activesupport/lib/active_support/inflector/inflections.rb
+++ b/activesupport/lib/active_support/inflector/inflections.rb
@@ -1,5 +1,3 @@
-# require "active_support/core_ext/string/access"
-
module ActiveSupport
module Inflector
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
@@ -210,4 +208,4 @@ module ActiveSupport
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
end
end
-end \ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/json/backends/jsongem.rb b/activesupport/lib/active_support/json/backends/jsongem.rb
index c6c17a3c4e..cfe28d7bb9 100644
--- a/activesupport/lib/active_support/json/backends/jsongem.rb
+++ b/activesupport/lib/active_support/json/backends/jsongem.rb
@@ -23,15 +23,18 @@ module ActiveSupport
private
def convert_dates_from(data)
case data
- when DATE_REGEX
- DateTime.parse(data)
- when Array
- data.map! { |d| convert_dates_from(d) }
- when Hash
- data.each do |key, value|
- data[key] = convert_dates_from(value)
- end
- else data
+ when nil
+ nil
+ when DATE_REGEX
+ DateTime.parse(data)
+ when Array
+ data.map! { |d| convert_dates_from(d) }
+ when Hash
+ data.each do |key, value|
+ data[key] = convert_dates_from(value)
+ end
+ else
+ data
end
end
end
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index d372b0ab1f..c7225fec06 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -1,4 +1,5 @@
# encoding: utf-8
+require 'active_support/core_ext/string/access'
require 'active_support/core_ext/string/behavior'
module ActiveSupport #:nodoc:
@@ -197,7 +198,7 @@ module ActiveSupport #:nodoc:
# 'Café périferôl'.mb_chars.index('ô') #=> 12
# 'Café périferôl'.mb_chars.index(/\w/u) #=> 0
def index(needle, offset=0)
- wrapped_offset = self.first(offset).wrapped_string.length
+ wrapped_offset = first(offset).wrapped_string.length
index = @wrapped_string.index(needle, wrapped_offset)
index ? (self.class.u_unpack(@wrapped_string.slice(0...index)).size) : nil
end
@@ -211,7 +212,7 @@ module ActiveSupport #:nodoc:
# 'Café périferôl'.mb_chars.rindex(/\w/u) #=> 13
def rindex(needle, offset=nil)
offset ||= length
- wrapped_offset = self.first(offset).wrapped_string.length
+ wrapped_offset = first(offset).wrapped_string.length
index = @wrapped_string.rindex(needle, wrapped_offset)
index ? (self.class.u_unpack(@wrapped_string.slice(0...index)).size) : nil
end
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 9eae3bebe2..6304f496f5 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -111,7 +111,7 @@ module ActiveSupport
def subscribe
@queue.subscribe(@pattern) do |*args|
- yield *args
+ yield(*args)
end
end
end
diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb
index 7952eb50c3..0e998d2dbe 100644
--- a/activesupport/lib/active_support/testing/setup_and_teardown.rb
+++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -21,12 +21,12 @@ module ActiveSupport
run_callbacks :setup
result = super
rescue Exception => e
- result = runner.puke(self.class, self.name, e)
+ result = runner.puke(self.class, method_name, e)
ensure
begin
run_callbacks :teardown, :enumerator => :reverse_each
rescue Exception => e
- result = runner.puke(self.class, self.name, e)
+ result = runner.puke(self.class, method_name, e)
end
end
result
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 53a4c7acf5..e7583bef1b 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/time'
require 'active_support/core_ext/date'
require 'active_support/core_ext/date_time'
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 4ff74abf61..0e489c10e1 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -228,10 +228,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert !@chars.include?('a')
end
- def test_include_raises_type_error_when_nil_is_passed
- assert_raise(TypeError) do
- @chars.include?(nil)
- end
+ def test_include_raises_when_nil_is_passed
+ @chars.include?(nil)
+ flunk "Expected chars.include?(nil) to raise TypeError or NoMethodError"
+ rescue Exception => e
end
def test_index_should_return_character_offset
@@ -659,4 +659,4 @@ class MultibyteInternalsTest < ActiveSupport::TestCase
"Expected byte offset #{byte_offset} to translate to #{character_offset}"
end
end
-end \ No newline at end of file
+end