aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-06-09 10:29:55 -0300
committerEmilio Tagua <miloops@gmail.com>2009-06-09 10:29:55 -0300
commit103b282130dd340143654801430aed787da4c9c6 (patch)
treeeddbe800d02f1a3c23f6266b808e74656af31f82 /activesupport/test
parentfd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90 (diff)
parenta94e7d7897a300a95d5d5a00c5efc573b42bcb58 (diff)
downloadrails-103b282130dd340143654801430aed787da4c9c6.tar.gz
rails-103b282130dd340143654801430aed787da4c9c6.tar.bz2
rails-103b282130dd340143654801430aed787da4c9c6.zip
Merge commit 'rails/master'
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/module/model_naming_test.rb8
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb3
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb2
-rw-r--r--activesupport/test/json/encoding_test.rb19
-rw-r--r--activesupport/test/new_callback_inheritance_test.rb10
-rw-r--r--activesupport/test/new_callbacks_test.rb78
6 files changed, 68 insertions, 52 deletions
diff --git a/activesupport/test/core_ext/module/model_naming_test.rb b/activesupport/test/core_ext/module/model_naming_test.rb
index da3b6c4932..37119f378a 100644
--- a/activesupport/test/core_ext/module/model_naming_test.rb
+++ b/activesupport/test/core_ext/module/model_naming_test.rb
@@ -14,6 +14,14 @@ class ModelNamingTest < Test::Unit::TestCase
assert_equal 'post_track_backs', @model_name.plural
end
+ def test_element
+ assert_equal 'track_back', @model_name.element
+ end
+
+ def test_collection
+ assert_equal 'post/track_backs', @model_name.collection
+ end
+
def test_partial_path
assert_equal 'post/track_backs/track_back', @model_name.partial_path
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 237a843f9a..6991b174b7 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -112,6 +112,8 @@ class StringInflectionsTest < Test::Unit::TestCase
def test_string_to_time
assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time
assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local)
+ assert_equal Time.utc(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time
+ assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time(:local)
assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time
assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local)
end
@@ -120,6 +122,7 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime
assert_equal 0, "2039-02-27 23:50".to_datetime.offset # use UTC offset
assert_equal ::Date::ITALY, "2039-02-27 23:50".to_datetime.start # use Ruby's default start value
+ assert_equal DateTime.civil(2039, 2, 27, 23, 50, 19 + Rational(275038, 1000000), "-04:00"), "2039-02-27T23:50:19.275038-04:00".to_datetime
end
def test_string_to_date
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 03ae70d420..bb60968a4f 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'active_support/time_with_zone'
+require 'active_support/time'
require 'active_support/json'
class TimeWithZoneTest < Test::Unit::TestCase
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 1a0e6d543c..983235d06c 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -9,6 +9,12 @@ class TestJSONEncoding < Test::Unit::TestCase
end
end
+ class Custom
+ def as_json(options)
+ 'custom'
+ end
+ end
+
TrueTests = [[ true, %(true) ]]
FalseTests = [[ false, %(false) ]]
NilTests = [[ nil, %(null) ]]
@@ -27,6 +33,7 @@ class TestJSONEncoding < Test::Unit::TestCase
[ :"a b", %("a b") ]]
ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]]
+ CustomTests = [[ Custom.new, '"custom"' ]]
VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'],
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
@@ -76,7 +83,7 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_exception_raised_when_encoding_circular_reference
a = [1]
a << a
- assert_raise(ActiveSupport::JSON::CircularReferenceError) { ActiveSupport::JSON.encode(a) }
+ assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) }
end
def test_hash_key_identifiers_are_always_quoted
@@ -129,11 +136,9 @@ end
class JsonOptionsTests < Test::Unit::TestCase
def test_enumerable_should_passthrough_options_to_elements
- json_options = { :include => :posts }
- ActiveSupport::JSON.expects(:encode).with(1, json_options)
- ActiveSupport::JSON.expects(:encode).with(2, json_options)
- ActiveSupport::JSON.expects(:encode).with('foo', json_options)
-
- [1, 2, 'foo'].send(:rails_to_json, json_options)
+ value, options = Object.new, Object.new
+ def value.as_json(options) options end
+ def options.encode_json(encoder) self end
+ assert_equal options, ActiveSupport::JSON.encode(value, options)
end
end
diff --git a/activesupport/test/new_callback_inheritance_test.rb b/activesupport/test/new_callback_inheritance_test.rb
index 95020389b0..da0c19eaea 100644
--- a/activesupport/test/new_callback_inheritance_test.rb
+++ b/activesupport/test/new_callback_inheritance_test.rb
@@ -11,8 +11,8 @@ class GrandParent
end
define_callbacks :dispatch
- dispatch_callback :before, :before1, :before2, :per_key => {:if => proc {|c| c.action_name == "index" || c.action_name == "update" }}
- dispatch_callback :after, :after1, :after2, :per_key => {:if => proc {|c| c.action_name == "update" || c.action_name == "delete" }}
+ set_callback :dispatch, :before, :before1, :before2, :per_key => {:if => proc {|c| c.action_name == "index" || c.action_name == "update" }}
+ set_callback :dispatch, :after, :after1, :after2, :per_key => {:if => proc {|c| c.action_name == "update" || c.action_name == "delete" }}
def before1
@log << "before1"
@@ -39,12 +39,12 @@ class GrandParent
end
class Parent < GrandParent
- skip_dispatch_callback :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}
- skip_dispatch_callback :after, :after2, :per_key => {:unless => proc {|c| c.action_name == "delete" }}
+ skip_callback :dispatch, :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}
+ skip_callback :dispatch, :after, :after2, :per_key => {:unless => proc {|c| c.action_name == "delete" }}
end
class Child < GrandParent
- skip_dispatch_callback :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}, :if => :state_open?
+ skip_callback :dispatch, :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}, :if => :state_open?
def state_open?
@state == :open
diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb
index 7bec47224d..7e092b5f63 100644
--- a/activesupport/test/new_callbacks_test.rb
+++ b/activesupport/test/new_callbacks_test.rb
@@ -10,11 +10,11 @@ module NewCallbacksTest
define_callbacks :save
def self.before_save(*filters, &blk)
- save_callback(:before, *filters, &blk)
+ set_callback(:save, :before, *filters, &blk)
end
def self.after_save(*filters, &blk)
- save_callback(:after, *filters, &blk)
+ set_callback(:save, :after, *filters, &blk)
end
class << self
@@ -37,7 +37,7 @@ module NewCallbacksTest
def callback_object(callback_method)
klass = Class.new
klass.send(:define_method, callback_method) do |model|
- model.history << [callback_method, :object]
+ model.history << [:"#{callback_method}_save", :object]
end
klass.new
end
@@ -54,7 +54,7 @@ module NewCallbacksTest
send(callback_method, callback_symbol(callback_method_sym))
send(callback_method, callback_string(callback_method_sym))
send(callback_method, callback_proc(callback_method_sym))
- send(callback_method, callback_object(callback_method_sym))
+ send(callback_method, callback_object(callback_method_sym.to_s.gsub(/_save/, '')))
send(callback_method) { |model| model.history << [callback_method_sym, :block] }
end
@@ -64,10 +64,10 @@ module NewCallbacksTest
end
class PersonSkipper < Person
- skip_save_callback :before, :before_save_method, :if => :yes
- skip_save_callback :after, :before_save_method, :unless => :yes
- skip_save_callback :after, :before_save_method, :if => :no
- skip_save_callback :before, :before_save_method, :unless => :no
+ skip_callback :save, :before, :before_save_method, :if => :yes
+ skip_callback :save, :after, :before_save_method, :unless => :yes
+ skip_callback :save, :after, :before_save_method, :if => :no
+ skip_callback :save, :before, :before_save_method, :unless => :no
def yes; true; end
def no; false; end
end
@@ -77,8 +77,8 @@ module NewCallbacksTest
define_callbacks :dispatch
- dispatch_callback :before, :log, :per_key => {:unless => proc {|c| c.action_name == :index || c.action_name == :show }}
- dispatch_callback :after, :log2
+ set_callback :dispatch, :before, :log, :per_key => {:unless => proc {|c| c.action_name == :index || c.action_name == :show }}
+ set_callback :dispatch, :after, :log2
attr_reader :action_name, :logger
def initialize(action_name)
@@ -102,8 +102,8 @@ module NewCallbacksTest
end
class Child < ParentController
- skip_dispatch_callback :before, :log, :per_key => {:if => proc {|c| c.action_name == :update} }
- skip_dispatch_callback :after, :log2
+ skip_callback :dispatch, :before, :log, :per_key => {:if => proc {|c| c.action_name == :update} }
+ skip_callback :dispatch, :after, :log2
end
class OneTimeCompile < Record
@@ -188,19 +188,19 @@ module NewCallbacksTest
class AroundPerson < MySuper
attr_reader :history
- save_callback :before, :nope, :if => :no
- save_callback :before, :nope, :unless => :yes
- save_callback :after, :tweedle
- save_callback :before, "tweedle_dee"
- save_callback :before, proc {|m| m.history << "yup" }
- save_callback :before, :nope, :if => proc { false }
- save_callback :before, :nope, :unless => proc { true }
- save_callback :before, :yup, :if => proc { true }
- save_callback :before, :yup, :unless => proc { false }
- save_callback :around, :tweedle_dum
- save_callback :around, :w0tyes, :if => :yes
- save_callback :around, :w0tno, :if => :no
- save_callback :around, :tweedle_deedle
+ set_callback :save, :before, :nope, :if => :no
+ set_callback :save, :before, :nope, :unless => :yes
+ set_callback :save, :after, :tweedle
+ set_callback :save, :before, "tweedle_dee"
+ set_callback :save, :before, proc {|m| m.history << "yup" }
+ set_callback :save, :before, :nope, :if => proc { false }
+ set_callback :save, :before, :nope, :unless => proc { true }
+ set_callback :save, :before, :yup, :if => proc { true }
+ set_callback :save, :before, :yup, :unless => proc { false }
+ set_callback :save, :around, :tweedle_dum
+ set_callback :save, :around, :w0tyes, :if => :yes
+ set_callback :save, :around, :w0tno, :if => :no
+ set_callback :save, :around, :tweedle_deedle
def no; false; end
def yes; true; end
@@ -260,7 +260,7 @@ module NewCallbacksTest
define_callbacks :save
attr_reader :stuff
- save_callback :before, :omg, :per_key => {:if => :yes}
+ set_callback :save, :before, :omg, :per_key => {:if => :yes}
def yes() true end
@@ -354,15 +354,15 @@ module NewCallbacksTest
define_callbacks :save, "result == :halt"
- save_callback :before, :first
- save_callback :before, :second
- save_callback :around, :around_it
- save_callback :before, :third
- save_callback :after, :first
- save_callback :around, :around_it
- save_callback :after, :second
- save_callback :around, :around_it
- save_callback :after, :third
+ set_callback :save, :before, :first
+ set_callback :save, :before, :second
+ set_callback :save, :around, :around_it
+ set_callback :save, :before, :third
+ set_callback :save, :after, :first
+ set_callback :save, :around, :around_it
+ set_callback :save, :after, :second
+ set_callback :save, :around, :around_it
+ set_callback :save, :after, :third
attr_reader :history, :saved
@@ -397,11 +397,11 @@ module NewCallbacksTest
end
class CallbackObject
- def before_save(caller)
+ def before(caller)
caller.record << "before"
end
- def around_save(caller)
+ def around(caller)
caller.record << "around before"
yield
caller.record << "around after"
@@ -412,7 +412,7 @@ module NewCallbacksTest
include ActiveSupport::NewCallbacks
define_callbacks :save
- save_callback :before, CallbackObject.new
+ set_callback :save, :before, CallbackObject.new
attr_accessor :record
def initialize
@@ -430,7 +430,7 @@ module NewCallbacksTest
include ActiveSupport::NewCallbacks
define_callbacks :save
- save_callback :around, CallbackObject.new
+ set_callback :save, :around, CallbackObject.new
attr_accessor :record
def initialize