From 9b4622a483319f3d1e7f4489442f0d86afb6da36 Mon Sep 17 00:00:00 2001 From: John Paul Ashenfelter Date: Tue, 30 Nov 2010 13:48:25 -0500 Subject: Added a word boundary to uncountable inflection regex for #singularize so short inflections like ors do not affect larger words like sponsors [#6093 state:resolved] --- activesupport/test/inflector_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 2990177bed..e8fe635c03 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -21,6 +21,33 @@ class InflectorTest < Test::Unit::TestCase def test_pluralize_empty_string assert_equal "", ActiveSupport::Inflector.pluralize("") end + + ActiveSupport::Inflector.inflections.uncountable.each do |word| + define_method "test_uncountability_of_#{word}" do + assert_equal word, ActiveSupport::Inflector.singularize(word) + assert_equal word, ActiveSupport::Inflector.pluralize(word) + assert_equal ActiveSupport::Inflector.pluralize(word), ActiveSupport::Inflector.singularize(word) + end + end + + def test_uncountable_word_is_not_greedy + uncountable_word = "ors" + countable_word = "sponsor" + + cached_uncountables = ActiveSupport::Inflector.inflections.uncountables + + ActiveSupport::Inflector.inflections.uncountable << uncountable_word + + assert_equal uncountable_word, ActiveSupport::Inflector.singularize(uncountable_word) + assert_equal uncountable_word, ActiveSupport::Inflector.pluralize(uncountable_word) + assert_equal ActiveSupport::Inflector.pluralize(uncountable_word), ActiveSupport::Inflector.singularize(uncountable_word) + + assert_equal "sponsor", ActiveSupport::Inflector.singularize(countable_word) + assert_equal "sponsors", ActiveSupport::Inflector.pluralize(countable_word) + assert_equal "sponsor", ActiveSupport::Inflector.singularize(ActiveSupport::Inflector.pluralize(countable_word)) + + ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_uncountables + end SingularToPlural.each do |singular, plural| define_method "test_pluralize_#{singular}" do -- cgit v1.2.3 From 1a2c4279913a2af895b03465d4486c51dc61d138 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 22 Dec 2010 09:08:20 +0100 Subject: Ensure that uncountable are removed after test --- activesupport/test/inflector_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index e8fe635c03..60714a152d 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -21,7 +21,7 @@ class InflectorTest < Test::Unit::TestCase def test_pluralize_empty_string assert_equal "", ActiveSupport::Inflector.pluralize("") end - + ActiveSupport::Inflector.inflections.uncountable.each do |word| define_method "test_uncountability_of_#{word}" do assert_equal word, ActiveSupport::Inflector.singularize(word) @@ -29,13 +29,13 @@ class InflectorTest < Test::Unit::TestCase assert_equal ActiveSupport::Inflector.pluralize(word), ActiveSupport::Inflector.singularize(word) end end - + def test_uncountable_word_is_not_greedy uncountable_word = "ors" countable_word = "sponsor" - + cached_uncountables = ActiveSupport::Inflector.inflections.uncountables - + ActiveSupport::Inflector.inflections.uncountable << uncountable_word assert_equal uncountable_word, ActiveSupport::Inflector.singularize(uncountable_word) @@ -45,7 +45,8 @@ class InflectorTest < Test::Unit::TestCase assert_equal "sponsor", ActiveSupport::Inflector.singularize(countable_word) assert_equal "sponsors", ActiveSupport::Inflector.pluralize(countable_word) assert_equal "sponsor", ActiveSupport::Inflector.singularize(ActiveSupport::Inflector.pluralize(countable_word)) - + + ensure ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_uncountables end -- cgit v1.2.3 From b613145284624b7344675072d2502f9212097965 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 22 Dec 2010 09:15:40 +0100 Subject: Fix activesupport tests. These classes are not used anywhere --- activesupport/test/core_ext/object_and_class_ext_test.rb | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 398e6ca9b2..5d68b198f2 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -28,18 +28,6 @@ module Nested end end -module Bar - def bar; end -end - -module Baz - def baz; end -end - -class Foo - include Bar -end - class ObjectTests < ActiveSupport::TestCase class DuckTime def acts_like_time? -- cgit v1.2.3 From 27d0d4fffdb62d221e124b67b7ee3de6bfa1893b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 17 Dec 2010 11:04:20 +0800 Subject: while defining callbacks option :rescuable => true can be passed. There were no tests for this case. This patch adds a test for :rescuable => true option. --- activesupport/test/callbacks_test.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 51b28b6a43..c89b03e243 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -3,6 +3,27 @@ require 'test/unit' require 'active_support' module CallbacksTest + class Phone + include ActiveSupport::Callbacks + define_callbacks :save, :rescuable => true + + set_callback :save, :before, :before_save1 + set_callback :save, :after, :after_save1 + + def before_save1; self.history << :before; end + def after_save1; self.history << :after; end + + def save + self.send(:_run_save_callbacks) do + raise 'boom' + end + end + + def history + @history ||= [] + end + end + class Record include ActiveSupport::Callbacks @@ -338,6 +359,14 @@ module CallbacksTest end class CallbacksTest < Test::Unit::TestCase + def test_save_phone + phone = Phone.new + assert_raise RuntimeError do + phone.save + end + assert_equal [:before, :after], phone.history + end + def test_save_person person = Person.new assert_equal [], person.history @@ -573,5 +602,5 @@ module CallbacksTest ], writer.history end end - + end -- cgit v1.2.3 From 0ac66caac5581c4793d120c8ad4a2cf4137f6ce2 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 29 Dec 2010 22:20:14 +0000 Subject: Fix Duration#to_json --- activesupport/test/core_ext/duration_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index bb453b8d7f..6a01eeed6b 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/time' +require 'active_support/json' class DurationTest < ActiveSupport::TestCase def test_is_a @@ -138,6 +139,10 @@ class DurationTest < ActiveSupport::TestCase assert_equal counter, 60 end + def test_to_json + assert_equal '172800', 2.days.to_json + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz -- cgit v1.2.3 From b1dc9c004e0e81fe69416c117bcc04d2cbd2c83c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 4 Jan 2011 14:09:16 -0800 Subject: use dots for method calls --- activesupport/test/ordered_hash_test.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 72088854fc..69f24dd6f8 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -239,14 +239,14 @@ class OrderedHashTest < Test::Unit::TestCase def test_each_after_yaml_serialization values = [] - @deserialized_ordered_hash = YAML::load(YAML::dump(@ordered_hash)) + @deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash)) @deserialized_ordered_hash.each {|key, value| values << value} assert_equal @values, values end def test_order_after_yaml_serialization - @deserialized_ordered_hash = YAML::load(YAML::dump(@ordered_hash)) + @deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash)) assert_equal @keys, @deserialized_ordered_hash.keys assert_equal @values, @deserialized_ordered_hash.values @@ -255,12 +255,17 @@ class OrderedHashTest < Test::Unit::TestCase def test_order_after_yaml_serialization_with_nested_arrays @ordered_hash[:array] = %w(a b c) - @deserialized_ordered_hash = YAML::load(YAML::dump(@ordered_hash)) + @deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash)) assert_equal @ordered_hash.keys, @deserialized_ordered_hash.keys assert_equal @ordered_hash.values, @deserialized_ordered_hash.values end + def test_has_yaml_tag + @ordered_hash[:array] = %w(a b c) + assert_match '!omap', YAML.dump(@ordered_hash) + end + def test_update_sets_keys @updated_ordered_hash = ActiveSupport::OrderedHash.new @updated_ordered_hash.update(:name => "Bob") -- cgit v1.2.3 From 4fabad7cf125178c95468a573951e587928c333b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 4 Jan 2011 15:01:51 -0800 Subject: test that the custom ordered hash can be round-tripped --- activesupport/test/ordered_hash_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 69f24dd6f8..09203465c3 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -261,6 +261,23 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal @ordered_hash.values, @deserialized_ordered_hash.values end + begin + require 'psych' + + def test_psych_serialize + @deserialized_ordered_hash = Psych.load(Psych.dump(@ordered_hash)) + + values = @deserialized_ordered_hash.map { |_, value| value } + assert_equal @values, values + end + + def test_psych_serialize_tag + yaml = Psych.dump(@ordered_hash) + assert_match '!omap', yaml + end + rescue LoadError + end + def test_has_yaml_tag @ordered_hash[:array] = %w(a b c) assert_match '!omap', YAML.dump(@ordered_hash) -- cgit v1.2.3 From 5c666779872e6702f4d826686eab09db37cba062 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 4 Jan 2011 17:29:40 -0800 Subject: make our yaml output consistent --- activesupport/test/core_ext/time_with_zone_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 5579c27215..2b86da67fa 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -106,7 +106,7 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_to_yaml - assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml + assert_equal "--- 2000-01-01 00:00:00 Z\n", @twz.to_yaml end def test_ruby_to_yaml -- cgit v1.2.3 From 54f3aa86334917bdc947b242c277060a2cfe7b72 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Wed, 5 Jan 2011 21:34:37 +0100 Subject: added tests for XmlMini#to_tag. --- activesupport/test/test_xml_mini.rb | 123 ++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 42 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/test_xml_mini.rb b/activesupport/test/test_xml_mini.rb index 309fa234bf..6dbcd1f40b 100644 --- a/activesupport/test/test_xml_mini.rb +++ b/activesupport/test/test_xml_mini.rb @@ -1,61 +1,100 @@ require 'abstract_unit' require 'active_support/xml_mini' +require 'active_support/builder' -class XmlMiniTest < Test::Unit::TestCase - def test_rename_key_dasherizes_by_default - assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key") - end +module XmlMiniTest + class RenameKeyTest < Test::Unit::TestCase + def test_rename_key_dasherizes_by_default + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key") + end - def test_rename_key_does_nothing_with_dasherize_true - assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) - end + def test_rename_key_does_nothing_with_dasherize_true + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + end - def test_rename_key_does_nothing_with_dasherize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) - end + def test_rename_key_does_nothing_with_dasherize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + end - def test_rename_key_camelizes_with_camelize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => false) - end + def test_rename_key_camelizes_with_camelize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => false) + end - def test_rename_key_camelizes_with_camelize_nil - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => nil) - end + def test_rename_key_camelizes_with_camelize_nil + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => nil) + end - def test_rename_key_camelizes_with_camelize_true - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) - end + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end - def test_rename_key_lower_camelizes_with_camelize_lower - assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) - end + def test_rename_key_lower_camelizes_with_camelize_lower + assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) + end - def test_rename_key_lower_camelizes_with_camelize_upper - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) - end + def test_rename_key_lower_camelizes_with_camelize_upper + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) + end - def test_rename_key_does_not_dasherize_leading_underscores - assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") - end + def test_rename_key_does_not_dasherize_leading_underscores + assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") + end - def test_rename_key_with_leading_underscore_dasherizes_interior_underscores - assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") - end + def test_rename_key_with_leading_underscore_dasherizes_interior_underscores + assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") + end - def test_rename_key_does_not_dasherize_trailing_underscores - assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") - end + def test_rename_key_does_not_dasherize_trailing_underscores + assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") + end - def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores - assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") - end + def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores + assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") + end - def test_rename_key_does_not_dasherize_multiple_leading_underscores - assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") - end + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") + end - def test_rename_key_does_not_dasherize_multiple_leading_underscores - assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") + end end + class ToTagTest < ActiveSupport::TestCase + def assert_xml(xml) + assert_equal xml, @options[:builder].target! + end + + setup do + @xml = ActiveSupport::XmlMini + @options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new} + end + + test "#to_tag accepts a callable object and passes options with the builder" do + @xml.to_tag(:some_tag, lambda {|o| o[:builder].br }, @options) + assert_xml "
" + end + + test "#to_tag accepts a callable object and passes options and tag name" do + @xml.to_tag(:tag, lambda {|o, t| o[:builder].b(t) }, @options) + assert_xml "tag" + end + + test "#to_tag accepts an object responding to #to_xml and passes the options, where :root is key" do + obj = Object.new + obj.instance_eval do + def to_xml(options) options[:builder].yo(options[:root].to_s) end + end + + @xml.to_tag(:tag, obj, @options) + assert_xml "tag" + end + + test "#to_tag accepts arbitrary objects responding to #to_str" do + @xml.to_tag(:b, "Howdy", @options) + assert_xml "Howdy" + end + # TODO: test the remaining functions hidden in #to_tag. + end end -- cgit v1.2.3 From 1cc556dc5263bbbe5845b9a7abde9c84dffa7fb0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 10 Jan 2011 15:43:21 -0800 Subject: adding to_d to BigDecimal --- activesupport/test/core_ext/bigdecimal.rb | 10 ---------- activesupport/test/core_ext/bigdecimal_test.rb | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) delete mode 100644 activesupport/test/core_ext/bigdecimal.rb create mode 100644 activesupport/test/core_ext/bigdecimal_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/bigdecimal.rb b/activesupport/test/core_ext/bigdecimal.rb deleted file mode 100644 index 9faad9146f..0000000000 --- a/activesupport/test/core_ext/bigdecimal.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'abstract_unit' - -class BigDecimalTest < Test::Unit::TestCase - def test_to_yaml - assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) - assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) - assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) - assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) - end -end \ No newline at end of file diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb new file mode 100644 index 0000000000..0272f564de --- /dev/null +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class BigDecimalTest < Test::Unit::TestCase + def test_to_yaml + assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) + assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) + assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) + assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) + end + + def test_to_d + bd = BigDecimal.new '10' + assert_equal bd, bd.to_d + end +end -- cgit v1.2.3 From 199e220e885277dad5e222bf98f00a67b2e6674e Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Wed, 12 Jan 2011 15:18:21 +0100 Subject: Fixed various isolated test missing requires within AS. Signed-off-by: Santiago Pastorino --- activesupport/test/core_ext/bigdecimal_test.rb | 6 ++++-- activesupport/test/core_ext/hash_ext_test.rb | 1 + activesupport/test/json/encoding_test.rb | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index 0272f564de..d592973d7a 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -1,10 +1,12 @@ require 'abstract_unit' +require 'bigdecimal' +require 'active_support/core_ext/big_decimal' class BigDecimalTest < Test::Unit::TestCase def test_to_yaml assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) - assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) - assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) + assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) + assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 74223dd7f2..a0479d45ac 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -4,6 +4,7 @@ require 'bigdecimal' require 'active_support/core_ext/string/access' require 'active_support/ordered_hash' require 'active_support/core_ext/object/conversions' +require 'active_support/inflections' class HashExtTest < Test::Unit::TestCase class IndifferentHash < HashWithIndifferentAccess diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index e0494de6e4..7469ae70fd 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'abstract_unit' +require 'active_support/core_ext/string/inflections' require 'active_support/json' class TestJSONEncoding < Test::Unit::TestCase -- cgit v1.2.3 From d2c17dbd11417012c47b9ac48c62651a1415de5d Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 13 Jan 2011 03:16:16 +0300 Subject: Complex struct encoding test Signed-off-by: Santiago Pastorino --- activesupport/test/json/encoding_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 7469ae70fd..f7ca39f0f6 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -215,6 +215,29 @@ class TestJSONEncoding < Test::Unit::TestCase assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end + def test_struct_encoding + Struct.new('UserNameAndEmail', :name, :email) + Struct.new('UserNameAndDate', :name, :date) + Struct.new('Custom', :name, :sub) + user_email = Struct::UserNameAndEmail.new 'David', 'sample@example.com' + user_birthday = Struct::UserNameAndDate.new 'David', Date.new(2010, 01, 01) + custom = Struct::Custom.new 'David', user_birthday + + + json_strings = "" + json_string_and_date = "" + json_custom = "" + + assert_nothing_raised do + json_strings = user_email.to_json + json_string_and_date = user_birthday.to_json + json_custom = custom.to_json + end + + assert_equal %({"name":"David","email":"sample@example.com"}), json_strings + assert_equal %({"name":"David","date":"2010/01/01"}), json_string_and_date + assert_equal %({"sub":{"name":"David","date":"2010/01/01"},"name":"David"}), json_custom + end protected -- cgit v1.2.3 From d780d1f508c880c59d6d932bd052cb0b1c1c76b0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Jan 2011 16:06:55 -0800 Subject: ordering can change depending on ruby version, so parse the JSON and verify data structure equality --- activesupport/test/json/encoding_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index f7ca39f0f6..d5fcbf15b7 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -234,9 +234,16 @@ class TestJSONEncoding < Test::Unit::TestCase json_custom = custom.to_json end - assert_equal %({"name":"David","email":"sample@example.com"}), json_strings - assert_equal %({"name":"David","date":"2010/01/01"}), json_string_and_date - assert_equal %({"sub":{"name":"David","date":"2010/01/01"},"name":"David"}), json_custom + assert_equal({"name" => "David", + "sub" => { + "name" => "David", + "date" => "2010/01/01" }}, JSON.parse(json_custom)) + + assert_equal({"name" => "David", "email" => "sample@example.com"}, + JSON.parse(json_strings)) + + assert_equal({"name" => "David", "date" => "2010/01/01"}, + JSON.parse(json_string_and_date)) end protected -- cgit v1.2.3 From 2570c85cb7de03a2c9cc183c73707a267f2efb91 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 19 Jan 2011 14:31:22 -0800 Subject: fixing psych support in big decimal, fixing tests to support YAML 1.1 --- activesupport/test/core_ext/bigdecimal_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index d592973d7a..b38e08a9f4 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -4,10 +4,10 @@ require 'active_support/core_ext/big_decimal' class BigDecimalTest < Test::Unit::TestCase def test_to_yaml - assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) - assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) - assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml) - assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) + assert_match("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml) + assert_match("--- .Inf\n", BigDecimal.new('Infinity').to_yaml) + assert_match("--- .NaN\n", BigDecimal.new('NaN').to_yaml) + assert_match("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml) end def test_to_d -- cgit v1.2.3 From 7642b7531d222c9d7a94add50fffca69458e0eef Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 19 Jan 2011 15:19:57 -0800 Subject: prefering psych as the yaml parser if possible, fixing assertions for YAML 1.1 compatibility --- activesupport/test/core_ext/time_with_zone_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 2b86da67fa..5c226c2d09 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -106,11 +106,11 @@ class TimeWithZoneTest < Test::Unit::TestCase end def test_to_yaml - assert_equal "--- 2000-01-01 00:00:00 Z\n", @twz.to_yaml + assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml) end def test_ruby_to_yaml - assert_equal "--- \n:twz: 2000-01-01 00:00:00 Z\n", {:twz => @twz}.to_yaml + assert_match(/---\s*\n:twz: 2000-01-01 00:00:00(\.0+)?\s*Z\n/, {:twz => @twz}.to_yaml) end def test_httpdate -- cgit v1.2.3 From 370bcd1a017816422db2fdb410366752d60d72c8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Jan 2011 14:09:59 -0800 Subject: use ! " " YAML string literal syntax rather than removing both quotes --- activesupport/test/json/decoding_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index d2e3efaa6b..a0beb97537 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -57,9 +57,7 @@ class TestJSONDecoding < ActiveSupport::TestCase ActiveSupport.parse_json_times = true silence_warnings do ActiveSupport::JSON.with_backend backend do - assert_nothing_raised do - assert_equal expected, ActiveSupport::JSON.decode(json) - end + assert_equal expected, ActiveSupport::JSON.decode(json) end end end -- cgit v1.2.3 From c87fb22a061292e66d790e23eee6982c8053d270 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 28 Jan 2011 15:00:52 -0800 Subject: make sure we play nicely when syck is activated --- activesupport/test/safe_buffer_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index bf61f9e58c..a4e2acbb32 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,4 +1,10 @@ require 'abstract_unit' +begin + require 'psych' +rescue LoadError +end + +require 'yaml' class SafeBufferTest < ActiveSupport::TestCase def setup @@ -38,4 +44,20 @@ class SafeBufferTest < ActiveSupport::TestCase new_buffer = @buffer.to_s assert_equal ActiveSupport::SafeBuffer, new_buffer.class end + + def test_to_yaml + str = 'hello!' + buf = ActiveSupport::SafeBuffer.new str + yaml = buf.to_yaml + + assert_match(/^--- #{str}/, yaml) + assert_equal 'hello!', YAML.load(yaml) + end + + def test_nested + str = 'hello!' + data = { 'str' => ActiveSupport::SafeBuffer.new(str) } + yaml = YAML.dump data + assert_equal({'str' => str}, YAML.load(yaml)) + end end -- cgit v1.2.3 From 57bc25c5f8129f57b08a2dc7c319b86778dd8a40 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 9 Jan 2011 10:15:05 -0800 Subject: Use run_callbacks; the generated _run__callbacks method is not a public interface. Signed-off-by: Santiago Pastorino --- activesupport/test/callback_inheritance_test.rb | 2 +- activesupport/test/callbacks_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 8caf000c5d..71249050fc 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -70,7 +70,7 @@ class EmptyParent end def dispatch - _run_dispatch_callbacks + run_callbacks :dispatch self end end diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index c89b03e243..cff914f4ae 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -14,7 +14,7 @@ module CallbacksTest def after_save1; self.history << :after; end def save - self.send(:_run_save_callbacks) do + run_callbacks :save do raise 'boom' end end -- cgit v1.2.3 From 9a0f43d3c1dd35fde074af6cc2825ae1872aabef Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 2 Feb 2011 09:58:40 -0500 Subject: OrderedHash#each* methods return self like Hash does [#6364 state:resolved] Signed-off-by: Santiago Pastorino --- activesupport/test/ordered_hash_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 09203465c3..d2cfd3698f 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -78,19 +78,19 @@ class OrderedHashTest < Test::Unit::TestCase def test_each_key keys = [] - @ordered_hash.each_key { |k| keys << k } + assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k } assert_equal @keys, keys end def test_each_value values = [] - @ordered_hash.each_value { |v| values << v } + assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v } assert_equal @values, values end def test_each values = [] - @ordered_hash.each {|key, value| values << value} + assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} assert_equal @values, values end -- cgit v1.2.3 From 68e3fb81090ba67575e513407fc2463dba3b002b Mon Sep 17 00:00:00 2001 From: Maxime RETY Date: Mon, 14 Jun 2010 16:05:49 +0200 Subject: Fix JSON decoding of newline character with Yaml backend [#3479 state:resolved] Signed-off-by: Santiago Pastorino --- activesupport/test/json/decoding_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index a0beb97537..613c7531d9 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -41,7 +41,11 @@ class TestJSONDecoding < ActiveSupport::TestCase [{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}], %q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) => [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}, - {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}] + {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}], + # tests escaping of "\n" char with Yaml backend + %q("\n") => "\n", + %q("\u000a") => "\n", + %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"} } # load the default JSON backend -- cgit v1.2.3 From 434aa095607669f3b95343e874064d7c74bf921c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 2 Feb 2011 20:52:38 -0200 Subject: Fix tests providing valid JSON --- activesupport/test/json/decoding_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 613c7531d9..436861baad 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -43,8 +43,8 @@ class TestJSONDecoding < ActiveSupport::TestCase [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}, {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}], # tests escaping of "\n" char with Yaml backend - %q("\n") => "\n", - %q("\u000a") => "\n", + %q({"a":"\n"}) => {"a"=>"\n"}, + %q({"a":"\u000a"}) => {"a"=>"\n"}, %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"} } -- cgit v1.2.3 From bf0395837fc735bf98daed23f475b267e48c1118 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 6 Jan 2011 13:26:31 -0800 Subject: Preserve fractional seconds in DateTime#to_time Signed-off-by: Santiago Pastorino --- activesupport/test/core_ext/date_time_ext_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 7d993d84e2..8edb95b63a 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -38,6 +38,8 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.utc_time(2039, 2, 21, 10, 11, 12), DateTime.new(2039, 2, 21, 10, 11, 12, 0, 0).to_time # DateTimes with offsets other than 0 are returned unaltered assert_equal DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)), DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).to_time + # Fractional seconds are preserved + assert_equal Time.utc(2005, 2, 21, 10, 11, 12, 256), DateTime.new(2005, 2, 21, 10, 11, 12 + Rational(256, 1000000), 0).to_time end def test_civil_from_format -- cgit v1.2.3 From 080345baca1076a9788dff4803153600aec31f86 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 6 Jan 2011 13:33:36 -0800 Subject: Ruby 1.8.7+ provides to_date/to_datetime, AS just makes them public. Signed-off-by: Santiago Pastorino --- activesupport/test/core_ext/time_ext_test.rb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 53d497013a..891a6badac 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -533,19 +533,9 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase Time::DATE_FORMATS.delete(:custom) end - def test_to_date - assert_equal Date.new(2005, 2, 21), Time.local(2005, 2, 21, 17, 44, 30).to_date - end - - def test_to_datetime - assert_equal Time.utc(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, 0, 0) - with_env_tz 'US/Eastern' do - assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) - end - with_env_tz 'NZ' do - assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) - end - assert_equal ::Date::ITALY, Time.utc(2005, 2, 21, 17, 44, 30).to_datetime.start # use Ruby's default start value + def test_conversion_methods_are_publicized + assert Time.public_instance_methods.include?(:to_date) || Time.public_instance_methods.include?('to_date') + assert Time.public_instance_methods.include?(:to_datetime) || Time.public_instance_methods.include?('to_datetime') end def test_to_time -- cgit v1.2.3 From c0b4db0c28465866b656c894c16ce35f4d313a12 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 2 Feb 2011 23:35:54 -0500 Subject: fix OrderedHash#each* methods to return Enumerators when called without a block [#6366 state:resolved] Signed-off-by: Santiago Pastorino --- activesupport/test/ordered_hash_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index d2cfd3698f..0a7dadf7a8 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -80,18 +80,24 @@ class OrderedHashTest < Test::Unit::TestCase keys = [] assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k } assert_equal @keys, keys + expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + assert_kind_of expected_class, @ordered_hash.each_key end def test_each_value values = [] assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v } assert_equal @values, values + expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + assert_kind_of expected_class, @ordered_hash.each_value end def test_each values = [] assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} assert_equal @values, values + expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + assert_kind_of expected_class, @ordered_hash.each end def test_each_with_index -- cgit v1.2.3 From 092a4e296de5b69f06edac2fe0993e2a30e33555 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 3 Feb 2011 19:27:33 -0200 Subject: just < 1.9 is fine and 1.9.1 is not supported --- activesupport/test/ordered_hash_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 0a7dadf7a8..50168fa78f 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -80,7 +80,7 @@ class OrderedHashTest < Test::Unit::TestCase keys = [] assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k } assert_equal @keys, keys - expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator assert_kind_of expected_class, @ordered_hash.each_key end @@ -88,7 +88,7 @@ class OrderedHashTest < Test::Unit::TestCase values = [] assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v } assert_equal @values, values - expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator assert_kind_of expected_class, @ordered_hash.each_value end @@ -96,7 +96,7 @@ class OrderedHashTest < Test::Unit::TestCase values = [] assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} assert_equal @values, values - expected_class = RUBY_VERSION < '1.9.1' ? Enumerable::Enumerator : Enumerator + expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator assert_kind_of expected_class, @ordered_hash.each end -- cgit v1.2.3 From 1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98 Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 6 Feb 2011 13:41:56 -0800 Subject: Add initial FileWatcher implementation. The Backend is just an abstract implementation, which will be inherited by backends that do the heavy lifting. --- activesupport/test/file_watcher_test.rb | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 activesupport/test/file_watcher_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/file_watcher_test.rb b/activesupport/test/file_watcher_test.rb new file mode 100644 index 0000000000..54aa9f92f1 --- /dev/null +++ b/activesupport/test/file_watcher_test.rb @@ -0,0 +1,65 @@ +require 'abstract_unit' + +class FileWatcherTest < ActiveSupport::TestCase + class DumbBackend < ActiveSupport::FileWatcher::Backend + end + + def setup + @watcher = ActiveSupport::FileWatcher.new + + # In real life, the backend would take the path and use it to observe the file + # system. In our case, we will manually trigger the events for unit testing, + # so we can pass any path. + @backend = DumbBackend.new("RAILS_WOOT", @watcher) + + @payload = [] + @watcher.watch %r{^app/assets/.*\.scss$} do |pay| + pay.each do |status, files| + files.sort! + end + @payload << pay + end + end + + def test_one_change + @backend.trigger("app/assets/main.scss" => :changed) + assert_equal({:changed => ["app/assets/main.scss"]}, @payload.first) + end + + def test_multiple_changes + @backend.trigger("app/assets/main.scss" => :changed, "app/assets/javascripts/foo.coffee" => :changed) + assert_equal([{:changed => ["app/assets/main.scss"]}], @payload) + end + + def test_multiple_changes_match + @backend.trigger("app/assets/main.scss" => :changed, "app/assets/print.scss" => :changed, "app/assets/javascripts/foo.coffee" => :changed) + assert_equal([{:changed => ["app/assets/main.scss", "app/assets/print.scss"]}], @payload) + end + + def test_multiple_state_changes + @backend.trigger("app/assets/main.scss" => :created, "app/assets/print.scss" => :changed) + assert_equal([{:changed => ["app/assets/print.scss"], :created => ["app/assets/main.scss"]}], @payload) + end + + def test_more_blocks + payload = [] + @watcher.watch %r{^config/routes\.rb$} do |pay| + payload << pay + end + + @backend.trigger "config/routes.rb" => :changed + assert_equal [:changed => ["config/routes.rb"]], payload + assert_equal [], @payload + end + + def test_overlapping_watchers + payload = [] + @watcher.watch %r{^app/assets/main\.scss$} do |pay| + payload << pay + end + + @backend.trigger "app/assets/print.scss" => :changed, "app/assets/main.scss" => :changed + assert_equal [:changed => ["app/assets/main.scss"]], payload + assert_equal [:changed => ["app/assets/main.scss", "app/assets/print.scss"]], @payload + end +end -- cgit v1.2.3 From 1df3b65acccaee908b6a579640f5060094fad8c0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Feb 2011 10:42:03 -0800 Subject: use === so that regular expressions are not required --- activesupport/test/file_watcher_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/file_watcher_test.rb b/activesupport/test/file_watcher_test.rb index 54aa9f92f1..3e577df5af 100644 --- a/activesupport/test/file_watcher_test.rb +++ b/activesupport/test/file_watcher_test.rb @@ -21,6 +21,16 @@ class FileWatcherTest < ActiveSupport::TestCase end end + def test_use_triple_equals + fw = ActiveSupport::FileWatcher.new + called = [] + fw.watch("some_arbitrary_file.rb") do |file| + called << "omg" + end + fw.trigger(%w{ some_arbitrary_file.rb }) + assert_equal ['omg'], called + end + def test_one_change @backend.trigger("app/assets/main.scss" => :changed) assert_equal({:changed => ["app/assets/main.scss"]}, @payload.first) -- cgit v1.2.3 From 3eb25fb8806c0b161d2d1d9cb22d0bdfc7b0ce63 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Wed, 9 Feb 2011 10:23:45 +0100 Subject: fix for AS Gzip returning a UTF-8 string in Ruby 1.9 when it is actually binary [#6386 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/gzip_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/gzip_test.rb b/activesupport/test/gzip_test.rb index 2a24c0bd0d..6adfab0359 100644 --- a/activesupport/test/gzip_test.rb +++ b/activesupport/test/gzip_test.rb @@ -4,4 +4,14 @@ class GzipTest < Test::Unit::TestCase def test_compress_should_decompress_to_the_same_value assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World")) end + + def test_compress_should_return_a_binary_string + compressed = ActiveSupport::Gzip.compress('') + + if "".encoding_aware? + assert_equal Encoding.find('binary'), compressed.encoding + end + + assert !compressed.blank?, "a compressed blank string should not be blank" + end end \ No newline at end of file -- cgit v1.2.3 From 0faa7ee2a05b261ef89fb4652eaa0cfeef86c1d5 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino and Emilio Tagua Date: Wed, 9 Feb 2011 08:36:44 -0200 Subject: Add missing require --- activesupport/test/gzip_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/gzip_test.rb b/activesupport/test/gzip_test.rb index 6adfab0359..f564e63f29 100644 --- a/activesupport/test/gzip_test.rb +++ b/activesupport/test/gzip_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/core_ext/object/blank' class GzipTest < Test::Unit::TestCase def test_compress_should_decompress_to_the_same_value @@ -14,4 +15,4 @@ class GzipTest < Test::Unit::TestCase assert !compressed.blank?, "a compressed blank string should not be blank" end -end \ No newline at end of file +end -- cgit v1.2.3 From 3e02b3702ec640a521214109646bdebb5216bf96 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 9 Feb 2011 14:02:38 -0800 Subject: just use an attr_accessor so we do not pay ||= on every notification call --- activesupport/test/notifications_test.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 9faa11efbc..7b48b3f85b 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -3,14 +3,19 @@ require 'abstract_unit' module Notifications class TestCase < ActiveSupport::TestCase def setup - ActiveSupport::Notifications.notifier = nil - @notifier = ActiveSupport::Notifications.notifier + @old_notifier = ActiveSupport::Notifications.notifier + @notifier = ActiveSupport::Notifications::Fanout.new + ActiveSupport::Notifications.notifier = @notifier @events = [] @named_events = [] @subscription = @notifier.subscribe { |*args| @events << event(*args) } @named_subscription = @notifier.subscribe("named.subscription") { |*args| @named_events << event(*args) } end + def teardown + ActiveSupport::Notifications.notifier = @old_notifier + end + private def event(*args) -- cgit v1.2.3 From f7221f5c7571da50d4d0199c0a7502cc7cd82b6e Mon Sep 17 00:00:00 2001 From: Paul Hieromnimon Date: Thu, 10 Feb 2011 20:38:14 +0800 Subject: Initial html_safe implemention for Array --- activesupport/test/core_ext/string_ext_test.rb | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index bb865cae91..41a23641d4 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -434,6 +434,50 @@ class OutputSafetyTest < ActiveSupport::TestCase assert string.html_safe? end + test "Joining safe elements without a separator is safe" do + array = 5.times.collect {"some string".html_safe} + assert array.join.html_safe? + end + + test "Joining safe elements with a safe separator is safe" do + array = 5.times.collect {"some string".html_safe} + assert array.join("-".html_safe).html_safe? + end + + test "Joining safe elements with an unsafe separator is unsafe" do + array = 5.times.collect {"some string".html_safe} + assert_false array.join("-").html_safe? + end + + test "Joining is unsafe if any element is unsafe even with a safe separator" do + array = 5.times.collect {"some string".html_safe} + array << "some string" + assert_false array.join("-".html_safe).html_safe? + end + + test "Joining is unsafe if any element is unsafe and no separator is given" do + array = 5.times.collect {"some string".html_safe} + array << "some string" + assert_false array.join.html_safe? + end + + test "Joining is unsafe if any element is unsafe and the separator is unsafe" do + array = 5.times.collect {"some string".html_safe} + array << "some string" + assert_false array.join("-").html_safe? + end + + test "Array is safe if all elements are safe" do + array = 5.times.collect { "some string".html_safe } + assert array.html_safe? + end + + test "Array is unsafe if any element is unsafe" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert_false array.html_safe? + end + test 'emits normal string yaml' do assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) end -- cgit v1.2.3 From 1a73407b8506b548a5343c66c16897140203472e Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 10 Feb 2011 22:03:53 +0800 Subject: Corrected the html_safe implementation for Array. Moved the html safe version of join to its own method (safe_join) as not to degrade the performance of join for unrelated html_safe use. [#6298 state:resolved] --- activesupport/test/core_ext/string_ext_test.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 41a23641d4..15e39a06c3 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -435,36 +435,36 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "Joining safe elements without a separator is safe" do - array = 5.times.collect {"some string".html_safe} - assert array.join.html_safe? + array = 5.times.collect { "some string".html_safe } + assert array.safe_join.html_safe? end test "Joining safe elements with a safe separator is safe" do - array = 5.times.collect {"some string".html_safe} - assert array.join("-".html_safe).html_safe? + array = 5.times.collect { "some string".html_safe } + assert array.safe_join("-".html_safe).html_safe? end test "Joining safe elements with an unsafe separator is unsafe" do - array = 5.times.collect {"some string".html_safe} - assert_false array.join("-").html_safe? + array = 5.times.collect { "some string".html_safe } + assert !array.safe_join("-").html_safe? end test "Joining is unsafe if any element is unsafe even with a safe separator" do - array = 5.times.collect {"some string".html_safe} + array = 5.times.collect { "some string".html_safe } array << "some string" - assert_false array.join("-".html_safe).html_safe? + assert !array.safe_join("-".html_safe).html_safe? end test "Joining is unsafe if any element is unsafe and no separator is given" do - array = 5.times.collect {"some string".html_safe} + array = 5.times.collect { "some string".html_safe } array << "some string" - assert_false array.join.html_safe? + assert !array.safe_join.html_safe? end test "Joining is unsafe if any element is unsafe and the separator is unsafe" do - array = 5.times.collect {"some string".html_safe} + array = 5.times.collect { "some string".html_safe } array << "some string" - assert_false array.join("-").html_safe? + assert !array.safe_join("-").html_safe? end test "Array is safe if all elements are safe" do @@ -475,7 +475,7 @@ class OutputSafetyTest < ActiveSupport::TestCase test "Array is unsafe if any element is unsafe" do array = 5.times.collect { "some string".html_safe } array << "some string" - assert_false array.html_safe? + assert !array.html_safe? end test 'emits normal string yaml' do -- cgit v1.2.3 From 98c0c5db50a7679b3d58769ac22cb0a27a62c930 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 10 Feb 2011 23:01:02 +0800 Subject: Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same. --- activesupport/test/core_ext/string_ext_test.rb | 44 -------------------------- 1 file changed, 44 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 15e39a06c3..bb865cae91 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -434,50 +434,6 @@ class OutputSafetyTest < ActiveSupport::TestCase assert string.html_safe? end - test "Joining safe elements without a separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert array.safe_join.html_safe? - end - - test "Joining safe elements with a safe separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert array.safe_join("-".html_safe).html_safe? - end - - test "Joining safe elements with an unsafe separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - assert !array.safe_join("-").html_safe? - end - - test "Joining is unsafe if any element is unsafe even with a safe separator" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join("-".html_safe).html_safe? - end - - test "Joining is unsafe if any element is unsafe and no separator is given" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join.html_safe? - end - - test "Joining is unsafe if any element is unsafe and the separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join("-").html_safe? - end - - test "Array is safe if all elements are safe" do - array = 5.times.collect { "some string".html_safe } - assert array.html_safe? - end - - test "Array is unsafe if any element is unsafe" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.html_safe? - end - test 'emits normal string yaml' do assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) end -- cgit v1.2.3 From 89a5f1463d7e9546ed7a0cf482afea99ba2040e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Feb 2011 16:50:35 +0100 Subject: Revert "Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same." Applied the wrong version. This reverts commit 98c0c5db50a7679b3d58769ac22cb0a27a62c930. --- activesupport/test/core_ext/string_ext_test.rb | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index bb865cae91..15e39a06c3 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -434,6 +434,50 @@ class OutputSafetyTest < ActiveSupport::TestCase assert string.html_safe? end + test "Joining safe elements without a separator is safe" do + array = 5.times.collect { "some string".html_safe } + assert array.safe_join.html_safe? + end + + test "Joining safe elements with a safe separator is safe" do + array = 5.times.collect { "some string".html_safe } + assert array.safe_join("-".html_safe).html_safe? + end + + test "Joining safe elements with an unsafe separator is unsafe" do + array = 5.times.collect { "some string".html_safe } + assert !array.safe_join("-").html_safe? + end + + test "Joining is unsafe if any element is unsafe even with a safe separator" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !array.safe_join("-".html_safe).html_safe? + end + + test "Joining is unsafe if any element is unsafe and no separator is given" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !array.safe_join.html_safe? + end + + test "Joining is unsafe if any element is unsafe and the separator is unsafe" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !array.safe_join("-").html_safe? + end + + test "Array is safe if all elements are safe" do + array = 5.times.collect { "some string".html_safe } + assert array.html_safe? + end + + test "Array is unsafe if any element is unsafe" do + array = 5.times.collect { "some string".html_safe } + array << "some string" + assert !array.html_safe? + end + test 'emits normal string yaml' do assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) end -- cgit v1.2.3 From 1814298d7590988d354955efdb0bc495b359293b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Thu, 10 Feb 2011 16:45:39 +0100 Subject: Removed Array#safe_join in AS core_ext and moved it to a view helper with the same same. This also changes how safe_join works, if items or the separator are not html_safe they are html_escape'd, a html_safe string is always returned. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/core_ext/string_ext_test.rb | 44 -------------------------- 1 file changed, 44 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 15e39a06c3..bb865cae91 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -434,50 +434,6 @@ class OutputSafetyTest < ActiveSupport::TestCase assert string.html_safe? end - test "Joining safe elements without a separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert array.safe_join.html_safe? - end - - test "Joining safe elements with a safe separator is safe" do - array = 5.times.collect { "some string".html_safe } - assert array.safe_join("-".html_safe).html_safe? - end - - test "Joining safe elements with an unsafe separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - assert !array.safe_join("-").html_safe? - end - - test "Joining is unsafe if any element is unsafe even with a safe separator" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join("-".html_safe).html_safe? - end - - test "Joining is unsafe if any element is unsafe and no separator is given" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join.html_safe? - end - - test "Joining is unsafe if any element is unsafe and the separator is unsafe" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.safe_join("-").html_safe? - end - - test "Array is safe if all elements are safe" do - array = 5.times.collect { "some string".html_safe } - assert array.html_safe? - end - - test "Array is unsafe if any element is unsafe" do - array = 5.times.collect { "some string".html_safe } - array << "some string" - assert !array.html_safe? - end - test 'emits normal string yaml' do assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) end -- cgit v1.2.3 From b17d8d727fb510ad8b6eb4302984d290dc2e53b0 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Fri, 11 Feb 2011 16:47:25 +0100 Subject: Fixes an issue when decoding a json string which looks like a date but is invalid. This DateTime parse error is now caught and the original string is instead passed back [#6286 state:resolved] Signed-off-by: Santiago Pastorino --- activesupport/test/json/decoding_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 436861baad..77f24f0de3 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -19,6 +19,8 @@ class TestJSONDecoding < ActiveSupport::TestCase %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, # no time zone %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"}, + # invalid date + %({"a": "1089-10-40"}) => {'a' => "1089-10-40"}, # needs to be *exact* %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, -- cgit v1.2.3 From e8c870726a67a27965b2a5333a5ecf450d4f458f Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sat, 12 Feb 2011 16:29:17 +0100 Subject: Updated the json date regex to recognize xmlschema formatted date times during json decoding. [#3031 state:resolved] Signed-off-by: Santiago Pastorino and Emilio Tagua --- activesupport/test/json/decoding_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 77f24f0de3..24d9f88c09 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -21,6 +21,10 @@ class TestJSONDecoding < ActiveSupport::TestCase %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"}, # invalid date %({"a": "1089-10-40"}) => {'a' => "1089-10-40"}, + # xmlschema date notation + %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)}, + %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)}, + %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)}, # needs to be *exact* %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, -- cgit v1.2.3 From 944d314244676932eb1aa285d23f7d91f0678e68 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 13 Feb 2011 02:10:13 -0200 Subject: Add Date#rfc3339 and Date#iso8601 to AS --- activesupport/test/core_ext/date_ext_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 342a31cdef..b4d7633e5f 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -376,6 +376,16 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end end + if RUBY_VERSION < '1.9' + def test_rfc3339 + assert_equal('1980-02-28', Date.new(1980, 2, 28).rfc3339) + end + + def test_iso8601 + assert_equal('1980-02-28', Date.new(1980, 2, 28).iso8601) + end + end + def test_today Date.stubs(:current).returns(Date.new(2000, 1, 1)) assert_equal false, Date.new(1999, 12, 31).today? -- cgit v1.2.3