aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache.rb13
-rw-r--r--activesupport/lib/active_support/cache/memory_store.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb17
-rw-r--r--activesupport/lib/active_support/inflector.rb2
-rw-r--r--activesupport/lib/active_support/json/encoding.rb14
-rw-r--r--activesupport/lib/active_support/test_case.rb17
-rw-r--r--activesupport/lib/active_support/testing/declarative.rb6
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb98
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb2
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb1
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb1
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb1
-rw-r--r--activesupport/lib/active_support/version.rb6
13 files changed, 144 insertions, 36 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 3c422e0252..448db538ab 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -99,11 +99,16 @@ module ActiveSupport
class Store
cattr_accessor :logger
+ attr_reader :silence, :logger_off
+
def silence!
@silence = true
self
end
+ alias silence? silence
+ alias logger_off? logger_off
+
# Fetches data from the cache, using the given key. If there is data in
# the cache with the given key, then that data is returned.
#
@@ -233,11 +238,15 @@ module ActiveSupport
private
def expires_in(options)
- (options && options[:expires_in]) || 0
+ expires_in = options && options[:expires_in]
+
+ raise ":expires_in must be a number" if expires_in && !expires_in.is_a?(Numeric)
+
+ expires_in || 0
end
def log(operation, key, options)
- logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !@silence && !@logger_off
+ logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !silence? && !logger_off?
end
end
end
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 bab2a401eb..d5282bad6a 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -1,5 +1,13 @@
+require 'test/unit/testcase'
+require 'active_support/testing/setup_and_teardown'
+require 'active_support/testing/assertions'
+require 'active_support/testing/deprecation'
+require 'active_support/testing/declarative'
+require 'active_support/testing/pending'
+require 'active_support/testing/isolation'
+
begin
- gem 'mocha', '>= 0.9.3'
+ gem 'mocha', ">= 0.9.7"
require 'mocha'
rescue LoadError
# Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
@@ -7,13 +15,6 @@ rescue LoadError
Mocha.const_set :ExpectationError, Class.new(StandardError)
end
-require 'test/unit/testcase'
-require 'active_support/testing/setup_and_teardown'
-require 'active_support/testing/assertions'
-require 'active_support/testing/deprecation'
-require 'active_support/testing/declarative'
-require 'active_support/testing/pending'
-
module ActiveSupport
class TestCase < ::Test::Unit::TestCase
if defined? MiniTest
diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb
index a7af7f4224..a7df473644 100644
--- a/activesupport/lib/active_support/testing/declarative.rb
+++ b/activesupport/lib/active_support/testing/declarative.rb
@@ -15,12 +15,6 @@ module ActiveSupport
end
end
- if defined?(Spec)
- class << self
- alias_method :test, :it
- end
- end
-
end
end
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
new file mode 100644
index 0000000000..090e0c5c89
--- /dev/null
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -0,0 +1,98 @@
+module ActiveSupport::Testing
+ class ProxyTestResult
+ def initialize
+ @calls = []
+ end
+
+ def __replay__(result)
+ @calls.each do |name, args|
+ result.send(name, *args)
+ end
+ end
+
+ def method_missing(name, *args)
+ @calls << [name, args]
+ end
+ end
+
+ module Isolation
+ def self.forking_env?
+ !ENV["NO_FORK"] && RUBY_PLATFORM !~ /mswin|mingw|java/
+ end
+
+ def run(result)
+ yield(Test::Unit::TestCase::STARTED, name)
+
+ @_result = result
+
+ proxy = run_in_isolation do |proxy|
+ super(proxy) { }
+ end
+
+ proxy.__replay__(@_result)
+
+ yield(Test::Unit::TestCase::FINISHED, name)
+ end
+
+ module Forking
+ def run_in_isolation(&blk)
+ read, write = IO.pipe
+
+ pid = fork do
+ read.close
+ proxy = ProxyTestResult.new
+ yield proxy
+ write.puts [Marshal.dump(proxy)].pack("m")
+ exit!
+ end
+
+ write.close
+ result = read.read
+ Process.wait2(pid)
+ Marshal.load(result.unpack("m")[0])
+ end
+ end
+
+ module Subprocess
+ # Crazy H4X to get this working in windows / jruby with
+ # no forking.
+ def run_in_isolation(&blk)
+ require "tempfile"
+
+ if ENV["ISOLATION_TEST"]
+ proxy = ProxyTestResult.new
+ yield proxy
+ File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
+ file.puts [Marshal.dump(proxy)].pack("m")
+ end
+ exit!
+ else
+ Tempfile.open("isolation") do |tmpfile|
+ ENV["ISOLATION_TEST"] = @method_name
+ ENV["ISOLATION_OUTPUT"] = tmpfile.path
+
+ load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
+ `#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")} -t\"#{self.class}\"`
+
+ ENV.delete("ISOLATION_TEST")
+ ENV.delete("ISOLATION_OUTPUT")
+
+ return Marshal.load(tmpfile.read.unpack("m")[0])
+ end
+ end
+ end
+ end
+
+ include forking_env? ? Forking : Subprocess
+ end
+end
+
+# Only in subprocess for windows / jruby.
+if ENV['ISOLATION_TEST']
+ require "test/unit/collector/objectspace"
+ class Test::Unit::Collector::ObjectSpace
+ def include?(test)
+ super && test.method_name == ENV['ISOLATION_TEST']
+ end
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb
index 4537c30e9c..b59ac79e7b 100644
--- a/activesupport/lib/active_support/testing/setup_and_teardown.rb
+++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -10,8 +10,6 @@ module ActiveSupport
if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
include ForMiniTest
- elsif defined? Spec
- include ForRspec
else
include ForClassicTestUnit
end
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/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb
index 30f598a8de..3ae6150f2d 100644
--- a/activesupport/lib/active_support/version.rb
+++ b/activesupport/lib/active_support/version.rb
@@ -1,8 +1,8 @@
module ActiveSupport
module VERSION #:nodoc:
- MAJOR = 2
- MINOR = 3
- TINY = 2
+ MAJOR = 3
+ MINOR = 0
+ TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end