aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-11-01 11:06:47 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-02 17:50:12 -0800
commitb540eca5889d7a28fac39c9ec0df715aa89487ce (patch)
tree76a8ef40d8a9e99f1dc36a5b526b9a4c9c62567c /activesupport/test/core_ext
parent8935854375a6c08acd617beaec30f6fd09a29ea0 (diff)
downloadrails-b540eca5889d7a28fac39c9ec0df715aa89487ce.tar.gz
rails-b540eca5889d7a28fac39c9ec0df715aa89487ce.tar.bz2
rails-b540eca5889d7a28fac39c9ec0df715aa89487ce.zip
Consolidate Object#to_param and #to_query core extensions
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/boolean_ext_test.rb12
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb41
-rw-r--r--activesupport/test/core_ext/nil_ext_test.rb8
-rw-r--r--activesupport/test/core_ext/object/to_param_test.rb19
-rw-r--r--activesupport/test/core_ext/object/to_query_test.rb43
-rw-r--r--activesupport/test/core_ext/object_ext_test.rb7
6 files changed, 62 insertions, 68 deletions
diff --git a/activesupport/test/core_ext/boolean_ext_test.rb b/activesupport/test/core_ext/boolean_ext_test.rb
deleted file mode 100644
index 9439716efb..0000000000
--- a/activesupport/test/core_ext/boolean_ext_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/boolean/conversions'
-
-class BooleanExtAccessTests < Test::Unit::TestCase
- def test_to_param_on_true
- assert_equal true, true.to_param
- end
-
- def test_to_param_on_false
- assert_equal false, false.to_param
- end
-end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index eb4c37aaf0..4642bb1330 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -899,42 +899,6 @@ class HashToXmlTest < Test::Unit::TestCase
# :builder, etc, shouldn't be added to options
assert_equal({:skip_instruct => true}, options)
end
-end
-
-class QueryTest < Test::Unit::TestCase
- def test_simple_conversion
- assert_query_equal 'a=10', :a => 10
- end
-
- def test_cgi_escaping
- assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
- end
-
- def test_nil_parameter_value
- empty = Object.new
- def empty.to_param; nil end
- assert_query_equal 'a=', 'a' => empty
- end
-
- def test_nested_conversion
- assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
- :person => {:name => 'Nicholas', :login => 'seckar'}
- end
-
- def test_multiple_nested
- assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
- :person => {:id => 10}, :account => {:person => {:id => 20}}
- end
-
- def test_array_values
- assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
- :person => {:id => [10, 20]}
- end
-
- def test_array_values_are_not_sorted
- assert_query_equal 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10',
- :person => {:id => [20, 10]}
- end
def test_expansion_count_is_limited
expected = {
@@ -962,9 +926,4 @@ class QueryTest < Test::Unit::TestCase
Hash.from_xml(attack_xml)
end
end
-
- private
- def assert_query_equal(expected, actual, message = nil)
- assert_equal expected.split('&'), actual.to_query.split('&')
- end
end
diff --git a/activesupport/test/core_ext/nil_ext_test.rb b/activesupport/test/core_ext/nil_ext_test.rb
deleted file mode 100644
index 1062676d65..0000000000
--- a/activesupport/test/core_ext/nil_ext_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/nil/conversions'
-
-class NilExtAccessTests < Test::Unit::TestCase
- def test_to_param
- assert_nil nil.to_param
- end
-end
diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb
new file mode 100644
index 0000000000..c3efefddb5
--- /dev/null
+++ b/activesupport/test/core_ext/object/to_param_test.rb
@@ -0,0 +1,19 @@
+require 'abstract_unit'
+require 'active_support/core_ext/object/to_param'
+
+class ToParamTest < Test::Unit::TestCase
+ def test_object
+ foo = Object.new
+ def foo.to_s; 'foo' end
+ assert_equal 'foo', foo.to_param
+ end
+
+ def test_nil
+ assert_nil nil.to_param
+ end
+
+ def test_boolean
+ assert_equal true, true.to_param
+ assert_equal false, false.to_param
+ end
+end
diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb
new file mode 100644
index 0000000000..0fb15be654
--- /dev/null
+++ b/activesupport/test/core_ext/object/to_query_test.rb
@@ -0,0 +1,43 @@
+require 'abstract_unit'
+require 'active_support/core_ext/object/to_query'
+
+class ToQueryTest < Test::Unit::TestCase
+ def test_simple_conversion
+ assert_query_equal 'a=10', :a => 10
+ end
+
+ def test_cgi_escaping
+ assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
+ end
+
+ def test_nil_parameter_value
+ empty = Object.new
+ def empty.to_param; nil end
+ assert_query_equal 'a=', 'a' => empty
+ end
+
+ def test_nested_conversion
+ assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
+ :person => {:name => 'Nicholas', :login => 'seckar'}
+ end
+
+ def test_multiple_nested
+ assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
+ :person => {:id => 10}, :account => {:person => {:id => 20}}
+ end
+
+ def test_array_values
+ assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
+ :person => {:id => [10, 20]}
+ end
+
+ def test_array_values_are_not_sorted
+ assert_query_equal 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10',
+ :person => {:id => [20, 10]}
+ end
+
+ private
+ def assert_query_equal(expected, actual, message = nil)
+ assert_equal expected.split('&'), actual.to_query.split('&')
+ end
+end
diff --git a/activesupport/test/core_ext/object_ext_test.rb b/activesupport/test/core_ext/object_ext_test.rb
index 484eecaab6..04c19ed2aa 100644
--- a/activesupport/test/core_ext/object_ext_test.rb
+++ b/activesupport/test/core_ext/object_ext_test.rb
@@ -1,16 +1,9 @@
require 'abstract_unit'
require 'active_support/core_ext/object/metaclass'
-require 'active_support/core_ext/object/conversions'
class ObjectExtTest < Test::Unit::TestCase
def test_tap_yields_and_returns_self
foo = Object.new
assert_equal foo, foo.tap { |x| assert_equal foo, x; :bar }
end
-
- def test_to_param
- foo = Object.new
- foo.class_eval("def to_s; 'foo'; end")
- assert_equal 'foo', foo.to_param
- end
end