From 0ee1cb2cd32bfaf47deaf5440dd5b9cf0915ab6a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 2 Oct 2007 05:32:14 +0000 Subject: Ruby 1.9 compat, consistent load paths git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/array.rb | 8 +-- .../lib/active_support/core_ext/bigdecimal.rb | 3 +- .../core_ext/bigdecimal/conversions.rb | 6 +++ .../core_ext/bigdecimal/formatting.rb | 7 --- activesupport/lib/active_support/core_ext/cgi.rb | 4 +- activesupport/lib/active_support/core_ext/class.rb | 6 +-- activesupport/lib/active_support/core_ext/date.rb | 6 +-- .../lib/active_support/core_ext/date_time.rb | 6 +-- activesupport/lib/active_support/core_ext/float.rb | 2 +- activesupport/lib/active_support/core_ext/hash.rb | 2 +- .../lib/active_support/core_ext/integer.rb | 4 +- .../lib/active_support/core_ext/kernel.rb | 10 ++-- .../lib/active_support/core_ext/module.rb | 16 +++--- .../lib/active_support/core_ext/numeric.rb | 4 +- .../lib/active_support/core_ext/object.rb | 6 +-- .../lib/active_support/core_ext/pathname.rb | 2 +- activesupport/lib/active_support/core_ext/range.rb | 2 +- .../lib/active_support/core_ext/string.rb | 12 ++--- activesupport/lib/active_support/core_ext/test.rb | 3 +- .../lib/active_support/core_ext/test/difference.rb | 62 ---------------------- .../core_ext/test/unit/assertions.rb | 62 ++++++++++++++++++++++ activesupport/lib/active_support/core_ext/time.rb | 6 +-- 22 files changed, 118 insertions(+), 121 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb delete mode 100644 activesupport/lib/active_support/core_ext/bigdecimal/formatting.rb delete mode 100644 activesupport/lib/active_support/core_ext/test/difference.rb create mode 100644 activesupport/lib/active_support/core_ext/test/unit/assertions.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb index 1d18900bab..4c973488a5 100644 --- a/activesupport/lib/active_support/core_ext/array.rb +++ b/activesupport/lib/active_support/core_ext/array.rb @@ -1,7 +1,7 @@ -require File.dirname(__FILE__) + '/array/conversions' -require File.dirname(__FILE__) + '/array/extract_options' -require File.dirname(__FILE__) + '/array/grouping' -require File.dirname(__FILE__) + '/array/random_access' +require 'active_support/core_ext/array/conversions' +require 'active_support/core_ext/array/extract_options' +require 'active_support/core_ext/array/grouping' +require 'active_support/core_ext/array/random_access' class Array #:nodoc: include ActiveSupport::CoreExtensions::Array::Conversions diff --git a/activesupport/lib/active_support/core_ext/bigdecimal.rb b/activesupport/lib/active_support/core_ext/bigdecimal.rb index 436b3e000f..b442ae9655 100644 --- a/activesupport/lib/active_support/core_ext/bigdecimal.rb +++ b/activesupport/lib/active_support/core_ext/bigdecimal.rb @@ -1,3 +1,2 @@ require 'bigdecimal' - -require File.dirname(__FILE__) + '/bigdecimal/formatting.rb' +require 'active_support/core_ext/bigdecimal/conversions' diff --git a/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb b/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb new file mode 100644 index 0000000000..dcdb08aea0 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb @@ -0,0 +1,6 @@ +class BigDecimal #:nodoc: + alias :_original_to_s :to_s + def to_s(format="F") + _original_to_s(format) + end +end diff --git a/activesupport/lib/active_support/core_ext/bigdecimal/formatting.rb b/activesupport/lib/active_support/core_ext/bigdecimal/formatting.rb deleted file mode 100644 index d86adbea6c..0000000000 --- a/activesupport/lib/active_support/core_ext/bigdecimal/formatting.rb +++ /dev/null @@ -1,7 +0,0 @@ -class BigDecimal #:nodoc: - - alias :_original_to_s :to_s - def to_s(format="F") - _original_to_s(format) - end -end \ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/cgi.rb b/activesupport/lib/active_support/core_ext/cgi.rb index 072a7c99d2..db90e5c745 100644 --- a/activesupport/lib/active_support/core_ext/cgi.rb +++ b/activesupport/lib/active_support/core_ext/cgi.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/cgi/escape_skipping_slashes' +require 'active_support/core_ext/cgi/escape_skipping_slashes' class CGI #:nodoc: - extend(ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes) + extend ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes end diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 7bacdb3903..83eb8135f4 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,3 +1,3 @@ -require File.dirname(__FILE__) + '/class/attribute_accessors' -require File.dirname(__FILE__) + '/class/inheritable_attributes' -require File.dirname(__FILE__) + '/class/removal' \ No newline at end of file +require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/class/inheritable_attributes' +require 'active_support/core_ext/class/removal' diff --git a/activesupport/lib/active_support/core_ext/date.rb b/activesupport/lib/active_support/core_ext/date.rb index 9d9051dfbe..3f56c560b6 100644 --- a/activesupport/lib/active_support/core_ext/date.rb +++ b/activesupport/lib/active_support/core_ext/date.rb @@ -1,7 +1,7 @@ require 'date' -require File.dirname(__FILE__) + '/date/behavior' -require File.dirname(__FILE__) + '/date/calculations' -require File.dirname(__FILE__) + '/date/conversions' +require 'active_support/core_ext/date/behavior' +require 'active_support/core_ext/date/calculations' +require 'active_support/core_ext/date/conversions' class Date#:nodoc: include ActiveSupport::CoreExtensions::Date::Behavior diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb index 7ce1b78090..1d711de70b 100644 --- a/activesupport/lib/active_support/core_ext/date_time.rb +++ b/activesupport/lib/active_support/core_ext/date_time.rb @@ -1,7 +1,7 @@ require 'date' -require "#{File.dirname(__FILE__)}/time/behavior" -require "#{File.dirname(__FILE__)}/date_time/calculations" -require "#{File.dirname(__FILE__)}/date_time/conversions" +require 'active_support/core_ext/time/behavior' +require 'active_support/core_ext/date_time/calculations' +require 'active_support/core_ext/date_time/conversions' class DateTime include ActiveSupport::CoreExtensions::Time::Behavior diff --git a/activesupport/lib/active_support/core_ext/float.rb b/activesupport/lib/active_support/core_ext/float.rb index ac5d5a47e6..86862b7150 100644 --- a/activesupport/lib/active_support/core_ext/float.rb +++ b/activesupport/lib/active_support/core_ext/float.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/float/rounding' +require 'active_support/core_ext/float/rounding' class Float #:nodoc: include ActiveSupport::CoreExtensions::Float::Rounding diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb index b805d2da62..6cbd9dd378 100644 --- a/activesupport/lib/active_support/core_ext/hash.rb +++ b/activesupport/lib/active_support/core_ext/hash.rb @@ -1,5 +1,5 @@ %w(keys indifferent_access reverse_merge conversions diff slice except).each do |ext| - require "#{File.dirname(__FILE__)}/hash/#{ext}" + require "active_support/core_ext/hash/#{ext}" end class Hash #:nodoc: diff --git a/activesupport/lib/active_support/core_ext/integer.rb b/activesupport/lib/active_support/core_ext/integer.rb index 9346b88fd5..d1e6d76acb 100644 --- a/activesupport/lib/active_support/core_ext/integer.rb +++ b/activesupport/lib/active_support/core_ext/integer.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/integer/even_odd' -require File.dirname(__FILE__) + '/integer/inflections' +require 'active_support/core_ext/integer/even_odd' +require 'active_support/core_ext/integer/inflections' class Integer #:nodoc: include ActiveSupport::CoreExtensions::Integer::EvenOdd diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index 6475be7efa..1922d804bf 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/kernel/daemonizing' -require File.dirname(__FILE__) + '/kernel/reporting' -require File.dirname(__FILE__) + '/kernel/agnostics' -require File.dirname(__FILE__) + '/kernel/requires' -require File.dirname(__FILE__) + '/kernel/debugger' +require 'active_support/core_ext/kernel/daemonizing' +require 'active_support/core_ext/kernel/reporting' +require 'active_support/core_ext/kernel/agnostics' +require 'active_support/core_ext/kernel/requires' +require 'active_support/core_ext/kernel/debugger' diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 26c9bdf778..da8d5b3762 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,8 +1,8 @@ -require File.dirname(__FILE__) + '/module/inclusion' -require File.dirname(__FILE__) + '/module/attribute_accessors' -require File.dirname(__FILE__) + '/module/attr_internal' -require File.dirname(__FILE__) + '/module/attr_accessor_with_default' -require File.dirname(__FILE__) + '/module/delegation' -require File.dirname(__FILE__) + '/module/introspection' -require File.dirname(__FILE__) + '/module/loading' -require File.dirname(__FILE__) + '/module/aliasing' +require 'active_support/core_ext/module/inclusion' +require 'active_support/core_ext/module/attribute_accessors' +require 'active_support/core_ext/module/attr_internal' +require 'active_support/core_ext/module/attr_accessor_with_default' +require 'active_support/core_ext/module/delegation' +require 'active_support/core_ext/module/introspection' +require 'active_support/core_ext/module/loading' +require 'active_support/core_ext/module/aliasing' diff --git a/activesupport/lib/active_support/core_ext/numeric.rb b/activesupport/lib/active_support/core_ext/numeric.rb index 88fead7aa4..59da205b3d 100644 --- a/activesupport/lib/active_support/core_ext/numeric.rb +++ b/activesupport/lib/active_support/core_ext/numeric.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/numeric/time' -require File.dirname(__FILE__) + '/numeric/bytes' +require 'active_support/core_ext/numeric/time' +require 'active_support/core_ext/numeric/bytes' class Numeric #:nodoc: include ActiveSupport::CoreExtensions::Numeric::Time diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 57238f38f5..3b055d3185 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -1,3 +1,3 @@ -require File.dirname(__FILE__) + '/object/extending' -require File.dirname(__FILE__) + '/object/instance_variables' -require File.dirname(__FILE__) + '/object/misc' +require 'active_support/core_ext/object/extending' +require 'active_support/core_ext/object/instance_variables' +require 'active_support/core_ext/object/misc' diff --git a/activesupport/lib/active_support/core_ext/pathname.rb b/activesupport/lib/active_support/core_ext/pathname.rb index 9e78c273d9..4c5318ee63 100644 --- a/activesupport/lib/active_support/core_ext/pathname.rb +++ b/activesupport/lib/active_support/core_ext/pathname.rb @@ -1,5 +1,5 @@ require 'pathname' -require File.dirname(__FILE__) + '/pathname/clean_within' +require 'active_support/core_ext/pathname/clean_within' class Pathname#:nodoc: extend ActiveSupport::CoreExtensions::Pathname::CleanWithin diff --git a/activesupport/lib/active_support/core_ext/range.rb b/activesupport/lib/active_support/core_ext/range.rb index ca77511521..ee7868a2f8 100644 --- a/activesupport/lib/active_support/core_ext/range.rb +++ b/activesupport/lib/active_support/core_ext/range.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/range/conversions' +require 'active_support/core_ext/range/conversions' class Range #:nodoc: include ActiveSupport::CoreExtensions::Range::Conversions diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index ef2f334fe2..724b2af2ee 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -1,9 +1,9 @@ -require File.dirname(__FILE__) + '/string/inflections' -require File.dirname(__FILE__) + '/string/conversions' -require File.dirname(__FILE__) + '/string/access' -require File.dirname(__FILE__) + '/string/starts_ends_with' -require File.dirname(__FILE__) + '/string/iterators' unless 'test'.respond_to?(:each_char) -require File.dirname(__FILE__) + '/string/unicode' +require 'active_support/core_ext/string/inflections' +require 'active_support/core_ext/string/conversions' +require 'active_support/core_ext/string/access' +require 'active_support/core_ext/string/starts_ends_with' +require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char) +require 'active_support/core_ext/string/unicode' class String #:nodoc: include ActiveSupport::CoreExtensions::String::Access diff --git a/activesupport/lib/active_support/core_ext/test.rb b/activesupport/lib/active_support/core_ext/test.rb index 193599b8dc..c0b19bdc58 100644 --- a/activesupport/lib/active_support/core_ext/test.rb +++ b/activesupport/lib/active_support/core_ext/test.rb @@ -1,2 +1 @@ -require File.dirname(__FILE__) + '/test/difference' - +require 'active_support/core_ext/test/unit/assertions' diff --git a/activesupport/lib/active_support/core_ext/test/difference.rb b/activesupport/lib/active_support/core_ext/test/difference.rb deleted file mode 100644 index 2ae4b7d6d1..0000000000 --- a/activesupport/lib/active_support/core_ext/test/difference.rb +++ /dev/null @@ -1,62 +0,0 @@ -module Test #:nodoc: - module Unit #:nodoc: - # FIXME: no Proc#binding in Ruby 2, must change this API - module Assertions #:nodoc: - # Test numeric difference between the return value of an expression as a result of what is evaluated - # in the yielded block. - # - # assert_difference 'Article.count' do - # post :create, :article => {...} - # end - # - # An arbitrary expression is passed in and evaluated. - # - # assert_difference 'assigns(:article).comments(:reload).size' do - # post :create, :comment => {...} - # end - # - # An arbitrary positive or negative difference can be specified. The default is +1. - # - # assert_difference 'Article.count', -1 do - # post :delete, :id => ... - # end - # - # An array of expressions can also be passed in and evaluated. - # - # assert_difference [ 'Article.count', 'Post.count' ], +2 do - # post :create, :article => {...} - # end - # - # A error message can be specified. - # - # assert_difference 'Article.count', -1, "An Article should be destroyed" do - # post :delete, :id => ... - # end - def assert_difference(expressions, difference = 1, message = nil, &block) - expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send!(:binding)) } } - - original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call } - yield - expression_evaluations.each_with_index do |expression, i| - assert_equal original_values[i] + difference, expression.call, message - end - end - - # Assertion that the numeric result of evaluating an expression is not changed before and after - # invoking the passed in block. - # - # assert_no_difference 'Article.count' do - # post :create, :article => invalid_attributes - # end - # - # A error message can be specified. - # - # assert_no_difference 'Article.count', "An Article should not be destroyed" do - # post :create, :article => invalid_attributes - # end - def assert_no_difference(expressions, message = nil, &block) - assert_difference expressions, 0, message, &block - end - end - end -end diff --git a/activesupport/lib/active_support/core_ext/test/unit/assertions.rb b/activesupport/lib/active_support/core_ext/test/unit/assertions.rb new file mode 100644 index 0000000000..2ae4b7d6d1 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/test/unit/assertions.rb @@ -0,0 +1,62 @@ +module Test #:nodoc: + module Unit #:nodoc: + # FIXME: no Proc#binding in Ruby 2, must change this API + module Assertions #:nodoc: + # Test numeric difference between the return value of an expression as a result of what is evaluated + # in the yielded block. + # + # assert_difference 'Article.count' do + # post :create, :article => {...} + # end + # + # An arbitrary expression is passed in and evaluated. + # + # assert_difference 'assigns(:article).comments(:reload).size' do + # post :create, :comment => {...} + # end + # + # An arbitrary positive or negative difference can be specified. The default is +1. + # + # assert_difference 'Article.count', -1 do + # post :delete, :id => ... + # end + # + # An array of expressions can also be passed in and evaluated. + # + # assert_difference [ 'Article.count', 'Post.count' ], +2 do + # post :create, :article => {...} + # end + # + # A error message can be specified. + # + # assert_difference 'Article.count', -1, "An Article should be destroyed" do + # post :delete, :id => ... + # end + def assert_difference(expressions, difference = 1, message = nil, &block) + expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send!(:binding)) } } + + original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call } + yield + expression_evaluations.each_with_index do |expression, i| + assert_equal original_values[i] + difference, expression.call, message + end + end + + # Assertion that the numeric result of evaluating an expression is not changed before and after + # invoking the passed in block. + # + # assert_no_difference 'Article.count' do + # post :create, :article => invalid_attributes + # end + # + # A error message can be specified. + # + # assert_no_difference 'Article.count', "An Article should not be destroyed" do + # post :create, :article => invalid_attributes + # end + def assert_no_difference(expressions, message = nil, &block) + assert_difference expressions, 0, message, &block + end + end + end +end diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb index a9e6a4385c..d87c4ec65a 100644 --- a/activesupport/lib/active_support/core_ext/time.rb +++ b/activesupport/lib/active_support/core_ext/time.rb @@ -8,9 +8,9 @@ class Time end end -require File.dirname(__FILE__) + '/time/behavior' -require File.dirname(__FILE__) + '/time/calculations' -require File.dirname(__FILE__) + '/time/conversions' +require 'active_support/core_ext/time/behavior' +require 'active_support/core_ext/time/calculations' +require 'active_support/core_ext/time/conversions' class Time#:nodoc: include ActiveSupport::CoreExtensions::Time::Behavior -- cgit v1.2.3