diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-01 20:36:53 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-01 20:36:53 -0300 |
commit | 084e4a2dd4322c9ea748a426cb37bf90ab83613d (patch) | |
tree | 90c6130b3f8becfd733618752a0649e932f5d514 | |
parent | 260c847817bbc3ad990609b7e41f787e1d2940ea (diff) | |
parent | 92bff2ebf122252cf3ff64160bdfa9891fcff3f4 (diff) | |
download | rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.tar.gz rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.tar.bz2 rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.zip |
Merge commit 'rails/master'
27 files changed, 85 insertions, 53 deletions
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 51b375fef3..3d4d0fb995 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,9 +1,6 @@ require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' - $:.unshift "#{File.dirname(__FILE__)}/../lib" $:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib" diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index e3a7d96941..aab7baf442 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -17,7 +17,7 @@ module ActionView def compile(template) require 'erb' - magic = $1 if template.source =~ /\A(<%#.*coding:\s*(\S+)\s*-?%>)/ + magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/ erb = "#{magic}<% __in_erb_template=true %>#{template.source}" ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src end diff --git a/actionpack/test/old_base/abstract_unit.rb b/actionpack/test/old_base/abstract_unit.rb index c71da7fa6c..3301041a41 100644 --- a/actionpack/test/old_base/abstract_unit.rb +++ b/actionpack/test/old_base/abstract_unit.rb @@ -12,9 +12,6 @@ require 'yaml' require 'stringio' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' - begin require 'ruby-debug' Debugger.settings[:autoeval] = true diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index f023109a60..3c0bd15236 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -10,8 +10,6 @@ ActiveSupport::Deprecation.debug = true require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' begin require 'ruby-debug' diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1f96e6dcc5..bb6869c6ce 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2864,6 +2864,13 @@ module ActiveRecord #:nodoc: @attributes.frozen? end + # Returns duplicated record with unfreezed attributes. + def dup + obj = super + obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup) + obj + end + # Returns +true+ if the record is read only. Records loaded through joins with piggy-back # attributes will be marked as read only since they cannot be saved. def readonly? diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 0f3f6e41a5..f9ac37cc87 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2116,4 +2116,8 @@ class BasicsTest < ActiveRecord::TestCase assert_equal custom_datetime, parrot[attribute] end end + + def test_dup + assert !Minimalistic.new.freeze.dup.frozen? + end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index c30186286d..d1e7caed89 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -6,8 +6,6 @@ require 'config' require 'rubygems' require 'test/unit' require 'stringio' -gem 'mocha', '>= 0.9.5' -require 'mocha' require 'active_record' require 'active_record/test_case' diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index 863c7bf709..05efac79cf 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -1,8 +1,6 @@ require 'rubygems' require 'test/unit' - -gem 'mocha', '>= 0.9.5' -require 'mocha' +require 'active_support/test_case' $:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_resource' diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index 1b30d49155..21ba79cf3d 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -26,7 +26,7 @@ module ActiveSupport def write(name, value, options = nil) super - @data[name] = value.freeze + @data[name] = (value.duplicable? ? value.dup : value).freeze end def delete(name, options = nil) diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index a44344806d..11e01437aa 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -108,14 +108,21 @@ class Module prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" - allow_nil = options[:allow_nil] && "#{to} && " - - file, line = caller[0].split(":") + file, line = caller.first.split(':', 2) + line = line.to_i methods.each do |method| - module_eval(<<-EOS, file, line.to_i) + on_nil = + if options[:allow_nil] + 'return' + else + %(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}") + end + + module_eval(<<-EOS, file, line) def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block) - #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block) # client && client.__send__(:name, *args, &block) + #{on_nil} if #{to}.nil? + #{to}.__send__(#{method.inspect}, *args, &block) # client && client.__send__(:name, *args, &block) end # end EOS end diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index ff70d6d76e..92c1de057b 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -183,7 +183,7 @@ module ActiveSupport if first_letter_in_uppercase lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else - lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] + lower_case_and_underscored_word.to_s.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 068b58b997..f440d6ce58 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,5 +1,7 @@ -# encoding: binary +# encoding: utf-8 require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/instance_variables' require 'active_support/deprecation' @@ -95,12 +97,14 @@ module ActiveSupport def escape(string) string = string.dup.force_encoding(::Encoding::BINARY) if string.respond_to?(:force_encoding) - json = '"' + string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] } - json.gsub(/([\xC0-\xDF][\x80-\xBF]| + json = string. + gsub(escape_regex) { |s| ESCAPED_CHARS[s] }. + gsub(/([\xC0-\xDF][\x80-\xBF]| [\xE0-\xEF][\x80-\xBF]{2}| [\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s| - s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&') - } + '"' + s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&') + } + %("#{json}") end end diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index e99a4854ce..d5282bad6a 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,12 +1,3 @@ -begin - gem 'mocha', '>= 0.9.3' - require 'mocha' -rescue LoadError - # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. - Object.const_set :Mocha, Module.new - Mocha.const_set :ExpectationError, Class.new(StandardError) -end - require 'test/unit/testcase' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' @@ -15,6 +6,15 @@ require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' +begin + gem 'mocha', ">= 0.9.7" + require 'mocha' +rescue LoadError + # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. + Object.const_set :Mocha, Module.new + Mocha.const_set :ExpectationError, Class.new(StandardError) +end + module ActiveSupport class TestCase < ::Test::Unit::TestCase if defined? MiniTest diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb index dfcba6901f..4e78e71b34 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb @@ -2,7 +2,6 @@ $:.unshift "lib" require 'rubygems' require 'test/unit' -require 'mocha' require 'i18n' require 'active_support' diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb index 50d6832c9e..2835ec4eab 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb @@ -2,7 +2,6 @@ $:.unshift "lib" require 'rubygems' require 'test/unit' -require 'mocha' require 'i18n' require 'active_support' diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb index 65f3ac11a6..a1696c77f6 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb @@ -3,7 +3,6 @@ $:.unshift "lib" require 'rubygems' require 'test/unit' -require 'mocha' require 'i18n' require 'time' require 'yaml' diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 77294db798..61914231ef 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -3,9 +3,6 @@ ORIG_ARGV = ARGV.dup require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' - ENV['NO_RELOAD'] = '1' $:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_support' diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index c2a03818e1..928af256f4 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -176,6 +176,12 @@ class MemoryStoreTest < ActiveSupport::TestCase assert_raise(ActiveSupport::FrozenObjectError) { @cache.read('foo').gsub!(/.*/, 'baz') } assert_equal 'bar', @cache.read('foo') end + + def test_original_store_objects_should_not_be_immutable + bar = 'bar' + @cache.write('foo', bar) + assert_nothing_raised { bar.gsub!(/.*/, 'baz') } + end end uses_memcached 'memcached backed store' do diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index c3c696f93a..f8387ae4ab 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -142,7 +142,7 @@ class ModuleTest < Test::Unit::TestCase def test_delegation_without_allow_nil_and_nil_value david = Someone.new("David") - assert_raise(NoMethodError) { david.street } + assert_raise(RuntimeError) { david.street } end def test_parent diff --git a/activesupport/test/fixtures/omgomg.rb b/activesupport/test/fixtures/omgomg.rb new file mode 100644 index 0000000000..a512a93ae4 --- /dev/null +++ b/activesupport/test/fixtures/omgomg.rb @@ -0,0 +1,2 @@ +class OmgOmg +end
\ No newline at end of file diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 8c4d831a39..7d1554910e 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -202,6 +202,12 @@ class InflectorTest < Test::Unit::TestCase end end + def test_symbol_to_lower_camel + SymbolToLowerCamel.each do |symbol, lower_camel| + assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false)) + end + end + %w{plurals singulars uncountables humans}.each do |inflection_type| class_eval " def test_clear_#{inflection_type} diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 584cbff3e7..2fa94b8e9c 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -117,6 +117,13 @@ module InflectorTestCases "area51_controller" => "area51Controller" } + SymbolToLowerCamel = { + :product => 'product', + :special_guest => 'specialGuest', + :application_controller => 'applicationController', + :area51_controller => 'area51Controller' + } + CamelToUnderscoreWithoutReverse = { "HTMLTidy" => "html_tidy", "HTMLTidyGenerator" => "html_tidy_generator", diff --git a/activesupport/test/isolation_test.rb b/activesupport/test/isolation_test.rb index 4adf49ff62..b844bbb673 100644 --- a/activesupport/test/isolation_test.rb +++ b/activesupport/test/isolation_test.rb @@ -50,13 +50,15 @@ if ENV['CHILD'] end test "resets requires one" do - assert !defined?(Racc) - require 'racc/parser' + assert !defined?(OmgOmg) + assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size + require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg")) end test "resets requires two" do - assert !defined?(Racc) - require 'racc/parser' + assert !defined?(OmgOmg) + assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size + require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg")) end end else diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 983235d06c..5d81d09f03 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -75,8 +75,13 @@ class TestJSONEncoding < Test::Unit::TestCase def test_utf8_string_encoded_properly_when_kcode_is_utf8 with_kcode 'UTF8' do - assert_equal '"\\u20ac2.99"', ActiveSupport::JSON.encode('€2.99') - assert_equal '"\\u270e\\u263a"', ActiveSupport::JSON.encode('✎☺') + result = ActiveSupport::JSON.encode('€2.99') + assert_equal '"\\u20ac2.99"', result + assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) + + result = ActiveSupport::JSON.encode('✎☺') + assert_equal '"\\u270e\\u263a"', result + assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) end end diff --git a/ci/geminstaller.yml b/ci/geminstaller.yml index f1ef9b59a0..59bdcebc26 100644 --- a/ci/geminstaller.yml +++ b/ci/geminstaller.yml @@ -7,7 +7,7 @@ gems: - name: memcache-client version: >= 1.5.0 - name: mocha - version: >= 0.9.5 + version: >= 0.9.7 - name: mysql #version: >= 2.7 version: = 2.7 diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index ca30bd3187..4318203a42 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -30,7 +30,10 @@ end begin require_library_or_gem 'ruby-debug' Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) + if Debugger.respond_to?(:settings) + Debugger.settings[:autoeval] = true + Debugger.settings[:autolist] = 1 + end rescue LoadError # ruby-debug wasn't available so neither can the debugging be end diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index dd9d0448b2..9a640bdbc5 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -12,9 +12,6 @@ require 'stringio' require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' - require 'active_support' require 'active_support/test_case' |