diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/abstract_unit.rb | 3 | ||||
-rw-r--r-- | activesupport/test/callback_inheritance_test.rb | 1 | ||||
-rw-r--r-- | activesupport/test/callbacks_test.rb | 1 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/class/attribute_test.rb | 35 | ||||
-rw-r--r-- | activesupport/test/core_ext/class/delegating_attributes_test.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/file_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 20 | ||||
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 11 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/inflector_test_cases.rb | 9 | ||||
-rw-r--r-- | activesupport/test/load_paths_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 47 | ||||
-rw-r--r-- | activesupport/test/whiny_nil_test.rb | 2 |
14 files changed, 116 insertions, 42 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 33be6f65bf..da338a2a26 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -1,5 +1,8 @@ require File.expand_path('../../../load_paths', __FILE__) +lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) + require 'test/unit' require 'mocha' diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 2e978f01be..e74c64ba8d 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -1,5 +1,4 @@ require 'test/unit' -$:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_support' class GrandParent diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 11494e951e..3fb940ad3c 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -1,6 +1,5 @@ # require 'abstract_unit' require 'test/unit' -$:.unshift "#{File.dirname(__FILE__)}/../lib" require 'active_support' module CallbacksTest diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index d4cd5ddbde..b374eca370 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -306,7 +306,7 @@ class ArrayUniqByTests < Test::Unit::TestCase def test_uniq_by assert_equal [1,2], [1,2,3,4].uniq_by { |i| i.odd? } assert_equal [1,2], [1,2,3,4].uniq_by(&:even?) - assert_equal (-5..0).to_a, (-5..5).to_a.uniq_by{ |i| i**2 } + assert_equal((-5..0).to_a, (-5..5).to_a.uniq_by{ |i| i**2 }) end def test_uniq_by! @@ -320,7 +320,7 @@ class ArrayUniqByTests < Test::Unit::TestCase a = (-5..5).to_a a.uniq_by! { |i| i**2 } - assert_equal (-5..0).to_a, a + assert_equal((-5..0).to_a, a) end end diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index ef84b9f255..06b4cf075f 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -2,13 +2,6 @@ require 'abstract_unit' require 'active_support/core_ext/class/attribute' class ClassAttributeTest < ActiveSupport::TestCase - class Base - class_attribute :setting - end - - class Subclass < Base - end - def setup @klass = Class.new { class_attribute :setting } @sub = Class.new(@klass) @@ -40,8 +33,30 @@ class ClassAttributeTest < ActiveSupport::TestCase assert_equal true, @klass.setting? end - test 'no instance delegates' do - assert_raise(NoMethodError) { @klass.new.setting } - assert_raise(NoMethodError) { @klass.new.setting? } + test 'instance reader delegates to class' do + assert_nil @klass.new.setting + + @klass.setting = 1 + assert_equal 1, @klass.new.setting + end + + test 'instance override' do + object = @klass.new + object.setting = 1 + assert_nil @klass.setting + @klass.setting = 2 + assert_equal 1, object.setting + end + + test 'instance query' do + object = @klass.new + assert_equal false, object.setting? + object.setting = 1 + assert_equal true, object.setting? + end + + test 'disabling instance writer' do + object = Class.new { class_attribute :setting, :instance_writer => false }.new + assert_raise(NoMethodError) { object.setting = 'boom' } end end diff --git a/activesupport/test/core_ext/class/delegating_attributes_test.rb b/activesupport/test/core_ext/class/delegating_attributes_test.rb index 011068ab74..636edb8d4b 100644 --- a/activesupport/test/core_ext/class/delegating_attributes_test.rb +++ b/activesupport/test/core_ext/class/delegating_attributes_test.rb @@ -84,6 +84,8 @@ class DelegatingAttributesTest < Test::Unit::TestCase assert_equal "1", Child.some_attribute assert_nil Mokopuna.some_attribute + ensure + Child.some_attribute=nil end end diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index 26be694176..e1258b872e 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -57,6 +57,10 @@ class AtomicWriteTest < Test::Unit::TestCase File.unlink(file_name) rescue nil end + def test_responds_to_to_path + assert_equal __FILE__, File.open(__FILE__, "r").to_path + end + private def file_name "atomic.file" diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 1fe75d5930..9edd7cc7c0 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -55,18 +55,6 @@ class Name end end -$nowhere = <<-EOF -class Name - delegate :nowhere -end -EOF - -$noplace = <<-EOF -class Name - delegate :noplace, :tos => :hollywood -end -EOF - class ModuleTest < Test::Unit::TestCase def setup @david = Someone.new("David", Somewhere.new("Paulina", "Chicago")) @@ -87,8 +75,12 @@ class ModuleTest < Test::Unit::TestCase end def test_missing_delegation_target - assert_raise(ArgumentError) { eval($nowhere) } - assert_raise(ArgumentError) { eval($noplace) } + assert_raise(ArgumentError) do + Name.send :delegate, :nowhere + end + assert_raise(ArgumentError) do + Name.send :delegate, :noplace, :tos => :hollywood + end end def test_delegation_prefix 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 f31e7774e9..437bb78a4e 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -89,7 +89,7 @@ class ClassExtTest < Test::Unit::TestCase end end -class ObjectTests < Test::Unit::TestCase +class ObjectTests < ActiveSupport::TestCase class DuckTime def acts_like_time? true @@ -119,12 +119,9 @@ class ObjectTests < Test::Unit::TestCase assert !duck.acts_like?(:date) end - def test_metaclass - string = "Hello" - string.metaclass.instance_eval do - define_method(:foo) { "bar" } - end - assert_equal "bar", string.foo + def test_singleton_class + o = Object.new + assert_equal class << o; self end, o.singleton_class end end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index d8145d467b..a50e259726 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -444,6 +444,10 @@ class OutputSafetyTest < ActiveSupport::TestCase assert_equal "hello".concat(13), string assert string.html_safe? end + + test 'emits normal string yaml' do + assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) + end end class StringExcludeTest < ActiveSupport::TestCase diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 2fa94b8e9c..ebd26d3fc6 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -158,7 +158,8 @@ module InflectorTestCases "Allow_Under_Scores" => "allow_under_scores", "Trailing bad characters!@#" => "trailing-bad-characters", "!@#Leading bad characters" => "leading-bad-characters", - "Squeeze separators" => "squeeze-separators" + "Squeeze separators" => "squeeze-separators", + "Test with + sign" => "test-with-sign" } StringToParameterizeWithNoSeparator = { @@ -166,7 +167,8 @@ module InflectorTestCases "Random text with *(bad)* characters" => "randomtextwithbadcharacters", "Trailing bad characters!@#" => "trailingbadcharacters", "!@#Leading bad characters" => "leadingbadcharacters", - "Squeeze separators" => "squeezeseparators" + "Squeeze separators" => "squeezeseparators", + "Test with + sign" => "testwithsign" } StringToParameterizeWithUnderscore = { @@ -174,7 +176,8 @@ module InflectorTestCases "Random text with *(bad)* characters" => "random_text_with_bad_characters", "Trailing bad characters!@#" => "trailing_bad_characters", "!@#Leading bad characters" => "leading_bad_characters", - "Squeeze separators" => "squeeze_separators" + "Squeeze separators" => "squeeze_separators", + "Test with + sign" => "test_with_sign" } # Ruby 1.9 doesn't do Unicode normalization yet. diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb new file mode 100644 index 0000000000..9c83d6f061 --- /dev/null +++ b/activesupport/test/load_paths_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class LoadPathsTest < Test::Unit::TestCase + def test_uniq_load_paths + load_paths_count = $LOAD_PATH.inject({}) { |paths, path| + expanded_path = File.expand_path(path) + paths[expanded_path] ||= 0 + paths[expanded_path] += 1 + paths + } + + # CI has a bunch of duplicate load paths + # assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect + end +end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 545811a376..67c3527e23 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -6,7 +6,7 @@ module Notifications ActiveSupport::Notifications.notifier = nil @notifier = ActiveSupport::Notifications.notifier @events = [] - @notifier.subscribe { |*args| @events << event(*args) } + @subscription = @notifier.subscribe { |*args| @events << event(*args) } end private @@ -19,6 +19,23 @@ module Notifications end end + class UnsubscribeTest < TestCase + def test_unsubscribing_removes_a_subscription + @notifier.publish :foo + @notifier.wait + assert_equal [[:foo]], @events + @notifier.unsubscribe(@subscription) + @notifier.publish :foo + @notifier.wait + assert_equal [[:foo]], @events + end + + private + def event(*args) + args + end + end + class SyncPubSubTest < TestCase def test_events_are_published_to_a_listener @notifier.publish :foo @@ -26,7 +43,29 @@ module Notifications assert_equal [[:foo]], @events end - def test_subscriber_with_pattern + def test_publishing_multiple_times_works + @notifier.publish :foo + @notifier.publish :foo + @notifier.wait + assert_equal [[:foo], [:foo]], @events + end + + def test_publishing_after_a_new_subscribe_works + @notifier.publish :foo + @notifier.publish :foo + + @notifier.subscribe("not_existant") do |*args| + @events << ActiveSupport::Notifications::Event.new(*args) + end + + @notifier.publish :foo + @notifier.publish :foo + @notifier.wait + + assert_equal [[:foo]] * 4, @events + end + + def test_log_subscriber_with_pattern events = [] @notifier.subscribe('1') { |*args| events << args } @@ -38,7 +77,7 @@ module Notifications assert_equal [['1'], ['1.a']], events end - def test_subscriber_with_pattern_as_regexp + def test_log_subscriber_with_pattern_as_regexp events = [] @notifier.subscribe(/\d/) { |*args| events << args } @@ -50,7 +89,7 @@ module Notifications assert_equal [['1'], ['a.1'], ['1.a']], events end - def test_multiple_subscribers + def test_multiple_log_subscribers @another = [] @notifier.subscribe { |*args| @another << args } @notifier.publish :foo diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb index 1e4f8d854a..4b9f06dead 100644 --- a/activesupport/test/whiny_nil_test.rb +++ b/activesupport/test/whiny_nil_test.rb @@ -9,6 +9,8 @@ end require 'abstract_unit' require 'active_support/whiny_nil' +NilClass.add_whiner ::ActiveRecord::Base + class WhinyNilTest < Test::Unit::TestCase def test_unchanged nil.method_thats_not_in_whiners |