aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-09-13 20:25:18 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-09-13 20:25:18 +0100
commitf6c0f688680778a7bf693a69ffee021e1122b01c (patch)
tree09699984d7a4f612689f19e3e0ccb663ae207d3f /activesupport
parent25fd841fe0f1d6f43019595a06aef6d825f5f4d1 (diff)
parent96055414d6197b9705e408c17236f79372a007e5 (diff)
downloadrails-f6c0f688680778a7bf693a69ffee021e1122b01c.tar.gz
rails-f6c0f688680778a7bf693a69ffee021e1122b01c.tar.bz2
rails-f6c0f688680778a7bf693a69ffee021e1122b01c.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/cache/memory_store.rb50
-rw-r--r--activesupport/lib/active_support/cache/synchronized_memory_store.rb46
-rw-r--r--activesupport/lib/active_support/core_ext/hash/except.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string/behavior.rb13
-rw-r--r--activesupport/lib/active_support/inflector.rb2
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb5
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb2
-rw-r--r--activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Colombo.rb30
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb14
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb6
-rw-r--r--activesupport/test/inflector_test_cases.rb5
-rw-r--r--activesupport/test/multibyte_chars_test.rb4
14 files changed, 140 insertions, 43 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index b38a5061d5..7d7a6920e2 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Fixed Sri Jayawardenepura time zone to map to Asia/Colombo [Jamis Buck]
+
* Added Inflector#parameterize for easy slug generation ("Donald E. Knuth".parameterize => "donald-e-knuth") #713 [Matt Darby]
* Changed cache benchmarking to be reported in milliseconds [DHH]
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb
index f3e4b8c13b..c1a713b4c5 100644
--- a/activesupport/lib/active_support/cache/memory_store.rb
+++ b/activesupport/lib/active_support/cache/memory_store.rb
@@ -3,63 +3,35 @@ module ActiveSupport
class MemoryStore < Store
def initialize
@data = {}
- @guard = Monitor.new
- end
-
- def fetch(key, options = {})
- @guard.synchronize do
- super
- end
end
def read(name, options = nil)
- @guard.synchronize do
- super
- @data[name]
- end
+ super
+ @data[name]
end
def write(name, value, options = nil)
- @guard.synchronize do
- super
- @data[name] = value.freeze
- end
+ super
+ @data[name] = value.freeze
end
def delete(name, options = nil)
- @guard.synchronize do
- @data.delete(name)
- end
+ super
+ @data.delete(name)
end
def delete_matched(matcher, options = nil)
- @guard.synchronize do
- @data.delete_if { |k,v| k =~ matcher }
- end
+ super
+ @data.delete_if { |k,v| k =~ matcher }
end
def exist?(name,options = nil)
- @guard.synchronize do
- @data.has_key?(name)
- end
- end
-
- def increment(key, amount = 1)
- @guard.synchronize do
- super
- end
- end
-
- def decrement(key, amount = 1)
- @guard.synchronize do
- super
- end
+ super
+ @data.has_key?(name)
end
def clear
- @guard.synchronize do
- @data.clear
- end
+ @data.clear
end
end
end
diff --git a/activesupport/lib/active_support/cache/synchronized_memory_store.rb b/activesupport/lib/active_support/cache/synchronized_memory_store.rb
new file mode 100644
index 0000000000..d2ff28768f
--- /dev/null
+++ b/activesupport/lib/active_support/cache/synchronized_memory_store.rb
@@ -0,0 +1,46 @@
+module ActiveSupport
+ module Cache
+ class SynchronizedMemoryStore < MemoryStore
+ def initialize
+ super
+ @guard = Monitor.new
+ end
+
+ def fetch(key, options = {})
+ @guard.synchronize { super }
+ end
+
+ def read(name, options = nil)
+ @guard.synchronize { super }
+ end
+
+ def write(name, value, options = nil)
+ @guard.synchronize { super }
+ end
+
+ def delete(name, options = nil)
+ @guard.synchronize { super }
+ end
+
+ def delete_matched(matcher, options = nil)
+ @guard.synchronize { super }
+ end
+
+ def exist?(name,options = nil)
+ @guard.synchronize { super }
+ end
+
+ def increment(key, amount = 1)
+ @guard.synchronize { super }
+ end
+
+ def decrement(key, amount = 1)
+ @guard.synchronize { super }
+ end
+
+ def clear
+ @guard.synchronize { super }
+ end
+ end
+ 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 f26d01553d..949976d741 100644
--- a/activesupport/lib/active_support/core_ext/hash/except.rb
+++ b/activesupport/lib/active_support/core_ext/hash/except.rb
@@ -10,7 +10,7 @@ module ActiveSupport #:nodoc:
module Except
# Returns a new hash without the given keys.
def except(*keys)
- clone.except!(*keys)
+ dup.except!(*keys)
end
# Replaces the hash without the given keys.
diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb
index 25386af70a..7ff2f11eff 100644
--- a/activesupport/lib/active_support/core_ext/string.rb
+++ b/activesupport/lib/active_support/core_ext/string.rb
@@ -6,6 +6,7 @@ require 'active_support/core_ext/string/iterators'
require 'active_support/core_ext/string/unicode'
require 'active_support/core_ext/string/xchar'
require 'active_support/core_ext/string/filters'
+require 'active_support/core_ext/string/behavior'
class String #:nodoc:
include ActiveSupport::CoreExtensions::String::Access
@@ -15,4 +16,5 @@ class String #:nodoc:
include ActiveSupport::CoreExtensions::String::StartsEndsWith
include ActiveSupport::CoreExtensions::String::Iterators
include ActiveSupport::CoreExtensions::String::Unicode
+ include ActiveSupport::CoreExtensions::String::Behavior
end
diff --git a/activesupport/lib/active_support/core_ext/string/behavior.rb b/activesupport/lib/active_support/core_ext/string/behavior.rb
new file mode 100644
index 0000000000..a93ca3027f
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/string/behavior.rb
@@ -0,0 +1,13 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module String #:nodoc:
+ module Behavior
+ # Enable more predictable duck-typing on String-like classes. See
+ # Object#acts_like?.
+ def acts_like_string?
+ true
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index e5f0063285..8a917a9eb2 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -257,7 +257,7 @@ module ActiveSupport
# <%= link_to(@person.name, person_path %>
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
def parameterize(string, sep = '-')
- string.gsub(/[^a-z0-9]+/i, sep).downcase
+ string.chars.normalize(:kd).to_s.gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-z0-9_\-]+/i, sep).downcase
end
# Create the name of a table like Rails does for models to table names. This method
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 185d03020c..de2c83f8d1 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -49,6 +49,11 @@ module ActiveSupport::Multibyte #:nodoc:
false
end
+ # Enable more predictable duck-typing on String-like classes. See Object#acts_like?.
+ def acts_like_string?
+ true
+ end
+
# Create a new Chars instance.
def initialize(str)
@string = str.respond_to?(:string) ? str.string : str
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 788d40bfa8..a294dd0ba3 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -124,7 +124,7 @@ module ActiveSupport
"Kathmandu" => "Asia/Katmandu",
"Astana" => "Asia/Dhaka",
"Dhaka" => "Asia/Dhaka",
- "Sri Jayawardenepura" => "Asia/Dhaka",
+ "Sri Jayawardenepura" => "Asia/Colombo",
"Almaty" => "Asia/Almaty",
"Novosibirsk" => "Asia/Novosibirsk",
"Rangoon" => "Asia/Rangoon",
diff --git a/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Colombo.rb b/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Colombo.rb
new file mode 100644
index 0000000000..f6531fa819
--- /dev/null
+++ b/activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Colombo.rb
@@ -0,0 +1,30 @@
+require 'tzinfo/timezone_definition'
+
+module TZInfo
+ module Definitions
+ module Asia
+ module Colombo
+ include TimezoneDefinition
+
+ timezone 'Asia/Colombo' do |tz|
+ tz.offset :o0, 19164, 0, :LMT
+ tz.offset :o1, 19172, 0, :MMT
+ tz.offset :o2, 19800, 0, :IST
+ tz.offset :o3, 19800, 1800, :IHST
+ tz.offset :o4, 19800, 3600, :IST
+ tz.offset :o5, 23400, 0, :LKT
+ tz.offset :o6, 21600, 0, :LKT
+
+ tz.transition 1879, 12, :o1, 17335550003, 7200
+ tz.transition 1905, 12, :o2, 52211763607, 21600
+ tz.transition 1942, 1, :o3, 116657485, 48
+ tz.transition 1942, 8, :o4, 9722413, 4
+ tz.transition 1945, 10, :o2, 38907909, 16
+ tz.transition 1996, 5, :o5, 832962600
+ tz.transition 1996, 10, :o6, 846266400
+ tz.transition 2006, 4, :o2, 1145039400
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 7a414e946f..44d48e7577 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -341,6 +341,20 @@ class HashExtTest < Test::Unit::TestCase
assert_equal expected, original.except!(:c)
assert_equal expected, original
end
+
+ def test_except_with_original_frozen
+ original = { :a => 'x', :b => 'y' }
+ original.freeze
+ assert_nothing_raised { original.except(:a) }
+ end
+
+ uses_mocha 'except with expectation' do
+ def test_except_with_mocha_expectation_on_original
+ original = { :a => 'x', :b => 'y' }
+ original.expects(:delete).never
+ original.except(:a)
+ end
+ end
end
class IWriteMyOwnXML
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index c9f959ef32..c0decf2c3f 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -201,3 +201,9 @@ class StringInflectionsTest < Test::Unit::TestCase
end
end
end
+
+class StringBehaviourTest < Test::Unit::TestCase
+ def test_acts_like_string
+ assert 'Bambi'.acts_like_string?
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index d399c90385..8057809dbd 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -144,7 +144,10 @@ module InflectorTestCases
StringToParameterized = {
"Donald E. Knuth" => "donald-e-knuth",
- "Random text with *(bad)* characters" => "random-text-with-bad-characters"
+ "Random text with *(bad)* characters" => "random-text-with-bad-characters",
+ "Malmö" => "malmo",
+ "Garçons" => "garcons",
+ "Allow_Under_Scores" => "allow_under_scores"
}
UnderscoreToHuman = {
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 63cfadb7ec..a87309b038 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -167,6 +167,10 @@ class CharsTest < Test::Unit::TestCase
assert_equal false, 'test'.chars.respond_to?(:a_method_that_doesnt_exist)
end
+ def test_acts_like_string
+ assert 'Bambi'.chars.acts_like_string?
+ end
+
protected
def with_kcode(kcode)