diff options
Diffstat (limited to 'activesupport/test/core_ext/module_test.rb')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index d4ce81fdfa..6e1b3ca010 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -28,20 +28,10 @@ end Somewhere = Struct.new(:street, :city) do attr_accessor :name - - protected - - def protected_method - end - - private - - def private_method - end end class Someone < Struct.new(:name, :place) - delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place + delegate :street, :city, :to_f, :to => :place delegate :name=, :to => :place, :prefix => true delegate :upcase, :to => "place.city" @@ -70,6 +60,14 @@ Tester = Struct.new(:client) do delegate :name, :to => :client, :prefix => false end +class ParameterSet + delegate :[], :[]=, :to => :@params + + def initialize + @params = {:foo => "bar"} + end +end + class Name delegate :upcase, :to => :@full_name @@ -78,7 +76,7 @@ class Name end end -class ModuleTest < Test::Unit::TestCase +class ModuleTest < ActiveSupport::TestCase def setup @david = Someone.new("David", Somewhere.new("Paulina", "Chicago")) end @@ -93,12 +91,15 @@ class ModuleTest < Test::Unit::TestCase assert_equal "Fred", @david.place.name end - def test_delegation_to_protected_method - assert_raise(NoMethodError) { @david.protected_method } + def test_delegation_to_index_get_method + @params = ParameterSet.new + assert_equal "bar", @params[:foo] end - def test_delegation_to_private_method - assert_raise(NoMethodError) { @david.private_method } + def test_delegation_to_index_set_method + @params = ParameterSet.new + @params[:foo] = "baz" + assert_equal "baz", @params[:foo] end def test_delegation_down_hierarchy @@ -201,8 +202,9 @@ class ModuleTest < Test::Unit::TestCase someone.foo rescue NoMethodError => e file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE}" - assert e.backtrace.first.include?(file_and_line), - "[#{e.backtrace.first}] did not include [#{file_and_line}]" + # We can't simply check the first line of the backtrace, because JRuby reports the call to __send__ in the backtrace. + assert e.backtrace.any?{|a| a.include?(file_and_line)}, + "[#{e.backtrace.inspect}] did not include [#{file_and_line}]" end def test_delegation_exception_backtrace_with_allow_nil @@ -210,8 +212,9 @@ class ModuleTest < Test::Unit::TestCase someone.bar rescue NoMethodError => e file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE_2}" - assert e.backtrace.first.include?(file_and_line), - "[#{e.backtrace.first}] did not include [#{file_and_line}]" + # We can't simply check the first line of the backtrace, because JRuby reports the call to __send__ in the backtrace. + assert e.backtrace.any?{|a| a.include?(file_and_line)}, + "[#{e.backtrace.inspect}] did not include [#{file_and_line}]" end def test_parent @@ -228,6 +231,12 @@ class ModuleTest < Test::Unit::TestCase def test_local_constants assert_equal %w(Constant1 Constant3), Ab.local_constants.sort.map(&:to_s) end + + def test_local_constant_names + ActiveSupport::Deprecation.silence do + assert_equal %w(Constant1 Constant3), Ab.local_constant_names + end + end end module BarMethodAliaser @@ -261,7 +270,7 @@ module BarMethods end end -class MethodAliasingTest < Test::Unit::TestCase +class MethodAliasingTest < ActiveSupport::TestCase def setup Object.const_set :FooClassWithBarMethod, Class.new { def bar() 'bar' end } @instance = FooClassWithBarMethod.new |