Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
2 parents 51fe6d0 + 3039912 commit 790c062280c0d23c2033e4983c13d402c0424f2a Yehuda Katz committed Nov 9, 2009
View
2 actionpack/lib/action_dispatch/http/request.rb
@@ -167,7 +167,7 @@ def formats
@env["action_dispatch.request.formats"] ||=
if parameters[:format]
- [Mime[parameters[:format]]]
+ Array.wrap(Mime[parameters[:format]])
elsif xhr? || (accept && !accept.include?(?,))
accepts
else
View
1 actionpack/lib/action_view/test_case.rb
@@ -120,6 +120,7 @@ def make_test_case_available_to_view!
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
View
4 actionpack/test/dispatch/request_test.rb
@@ -432,6 +432,10 @@ def teardown
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
View
13 actionpack/test/template/test_case_test.rb
@@ -24,7 +24,7 @@ def self.included(test_case)
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 @@ class GeneralViewTest < ActionView::TestCase
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 @@ class ClassMethodsTest < ActionView::TestCase
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
View
19 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
View
2 activerecord/lib/active_record/nested_attributes.rb
@@ -250,6 +250,8 @@ def #{association_name}_attributes=(attributes)
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
View
2 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",
View
2 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? }
View
39 activeresource/lib/active_resource/base.rb
@@ -274,8 +274,8 @@ def site=(site)
@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 @@ def instantiate_record(record, prefix_options = {})
# 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 @@ def split_options(options = {})
[ 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 @@ def update_attributes(attributes)
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 @@ def split_options(options = {})
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
View
9 activeresource/lib/active_resource/connection.rb
@@ -31,20 +31,21 @@ def requests
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.
View
3 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 Strategy
# 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
View
3 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 @@ def typecast_xml_value(value)
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
View
2 activesupport/lib/active_support/dependencies.rb
@@ -339,7 +339,7 @@ def loadable_constants_for_path(path, bases = load_paths)
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.
View
5 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 @@ def evaluate_method(method, *args, &block)
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
View
4 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 @@ def classify(table_name)
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
end
end
-end
+end
View
21 activesupport/lib/active_support/json/backends/jsongem.rb
@@ -23,15 +23,18 @@ def decode(json)
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
View
5 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 @@ def include?(other)
# '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 @@ def index(needle, offset=0)
# '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
View
2 activesupport/lib/active_support/notifications.rb
@@ -111,7 +111,7 @@ def bind(pattern)
def subscribe
@queue.subscribe(@pattern) do |*args|
- yield *args
+ yield(*args)
end
end
end
View
4 activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -21,12 +21,12 @@ def run(runner)
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
View
1 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'
View
10 activesupport/test/multibyte_chars_test.rb
@@ -228,10 +228,10 @@ def test_should_know_if_one_includes_the_other
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
+end

0 comments on commit 790c062

Please sign in to comment.