Permalink
Browse files

Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under…

… ActiveSupport [#238 state:resolved]
  • Loading branch information...
1 parent da91450 commit c08547d2266c75f0a82d06dd91c6d0500740e12e @josh josh committed Jun 3, 2008
Showing with 1,554 additions and 1,514 deletions.
  1. +1 −1 actionpack/lib/action_controller/dispatcher.rb
  2. +1 −1 actionpack/lib/action_controller/routing.rb
  3. +2 −2 actionpack/test/controller/dispatcher_test.rb
  4. +1 −1 actionpack/test/controller/integration_upload_test.rb
  5. +2 −2 actionpack/test/controller/routing_test.rb
  6. +1 −1 activerecord/lib/active_record/base.rb
  7. +10 −10 activerecord/test/cases/attribute_methods_test.rb
  8. +14 −14 activerecord/test/cases/base_test.rb
  9. +2 −2 activerecord/test/cases/inheritance_test.rb
  10. +1 −1 activerecord/test/cases/multiple_db_test.rb
  11. +4 −0 activesupport/lib/active_support.rb
  12. +393 −392 activesupport/lib/active_support/dependencies.rb
  13. +25 −7 activesupport/lib/active_support/deprecation.rb
  14. +51 −49 activesupport/lib/active_support/inflections.rb
  15. +264 −262 activesupport/lib/active_support/inflector.rb
  16. +14 −12 activesupport/lib/active_support/ordered_options.rb
  17. +348 −346 activesupport/lib/active_support/values/time_zone.rb
  18. +7 −7 activesupport/test/core_ext/date_ext_test.rb
  19. +12 −12 activesupport/test/core_ext/date_time_ext_test.rb
  20. +4 −4 activesupport/test/core_ext/duration_test.rb
  21. +14 −14 activesupport/test/core_ext/time_ext_test.rb
  22. +120 −120 activesupport/test/core_ext/time_with_zone_test.rb
  23. +120 −120 activesupport/test/dependencies_test.rb
  24. +10 −0 activesupport/test/deprecation_test.rb
  25. +63 −63 activesupport/test/inflector_test.rb
  26. +3 −3 activesupport/test/ordered_options_test.rb
  27. +67 −68 activesupport/test/time_zone_test.rb
@@ -141,7 +141,7 @@ def reload_application
# be reloaded on the next request without restarting the server.
def cleanup_application
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- Dependencies.clear
+ ActiveSupport::Dependencies.clear
ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
@@ -369,7 +369,7 @@ def controller_relative_to(controller, previous)
Routes = RouteSet.new
- ::Inflector.module_eval do
+ ActiveSupport::Inflector.module_eval do
# Ensures that routes are reloaded when Rails inflections are updated.
def inflections_with_route_reloading(&block)
returning(inflections_without_route_reloading(&block)) {
@@ -27,14 +27,14 @@ def teardown
def test_clears_dependencies_after_dispatch_if_in_loading_mode
ActionController::Routing::Routes.expects(:reload).once
- Dependencies.expects(:clear).once
+ ActiveSupport::Dependencies.expects(:clear).once
dispatch(@output, false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
ActionController::Routing::Routes.expects(:reload).never
- Dependencies.expects(:clear).never
+ ActiveSupport::Dependencies.expects(:clear).never
dispatch
end
@@ -28,7 +28,7 @@ class << self
# end
def test_post_with_upload
uses_mocha "test_post_with_upload" do
- Dependencies.stubs(:load?).returns(false)
+ ActiveSupport::Dependencies.stubs(:load?).returns(false)
with_routing do |set|
set.draw do |map|
map.update 'update', :controller => "upload_test", :action => "update", :method => :post
@@ -2392,10 +2392,10 @@ def test_bang_forces_reload
end
def test_adding_inflections_forces_reload
- Inflector::Inflections.instance.expects(:uncountable).with('equipment')
+ ActiveSupport::Inflector::Inflections.instance.expects(:uncountable).with('equipment')
routes.expects(:reload!)
- Inflector.inflections { |inflect| inflect.uncountable('equipment') }
+ ActiveSupport::Inflector.inflections { |inflect| inflect.uncountable('equipment') }
end
def test_load_with_configuration
@@ -372,7 +372,7 @@ def self.inherited(child) #:nodoc:
def self.reset_subclasses #:nodoc:
nonreloadables = []
subclasses.each do |klass|
- unless Dependencies.autoloaded? klass
+ unless ActiveSupport::Dependencies.autoloaded? klass
nonreloadables << klass
next
end
@@ -137,15 +137,15 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
end
end
end
-
+
def test_time_attributes_are_retrieved_in_current_time_zone
in_time_zone "Pacific Time (US & Canada)" do
utc_time = Time.utc(2008, 1, 1)
record = @target.new
record[:written_on] = utc_time
assert_equal utc_time, record.written_on # record.written on is equal to (i.e., simultaneous with) utc_time
assert_kind_of ActiveSupport::TimeWithZone, record.written_on # but is a TimeWithZone
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time # and represents time values adjusted accordingly
end
end
@@ -156,7 +156,7 @@ def test_setting_time_zone_aware_attribute_to_utc
record = @target.new
record.written_on = utc_time
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -168,7 +168,7 @@ def test_setting_time_zone_aware_attribute_in_other_time_zone
record = @target.new
record.written_on = cst_time
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -181,12 +181,12 @@ def test_setting_time_zone_aware_attribute_with_string
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
end
-
+
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new
@@ -202,7 +202,7 @@ def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_i
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
- assert_equal TimeZone[timezone_offset], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone[timezone_offset], record.written_on.time_zone
assert_equal Time.utc(2008, 1, 1), record.written_on.time
end
end
@@ -214,7 +214,7 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
record = @target.new
record.written_on = utc_time.in_time_zone
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -223,12 +223,12 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
def time_related_columns_on_topic
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
end
-
+
def in_time_zone(zone)
old_zone = Time.zone
old_tz = ActiveRecord::Base.time_zone_aware_attributes
- Time.zone = zone ? TimeZone[zone] : nil
+ Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil
ActiveRecord::Base.time_zone_aware_attributes = !zone.nil?
yield
ensure
@@ -133,19 +133,19 @@ def test_read_attributes_before_type_cast
category_attrs = {"name"=>"Test categoty", "type" => nil}
assert_equal category_attrs , category.attributes_before_type_cast
end
-
+
if current_adapter?(:MysqlAdapter)
def test_read_attributes_before_type_cast_on_boolean
bool = Booleantest.create({ "value" => false })
assert_equal 0, bool.attributes_before_type_cast["value"]
end
end
-
+
def test_read_attributes_before_type_cast_on_datetime
developer = Developer.find(:first)
assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"]
end
-
+
def test_hash_content
topic = Topic.new
topic.content = { "one" => 1, "two" => 2 }
@@ -251,7 +251,7 @@ def test_create_through_factory
topic = Topic.create("title" => "New Topic")
topicReloaded = Topic.find(topic.id)
assert_equal(topic, topicReloaded)
- end
+ end
def test_create_through_factory_with_block
topic = Topic.create("title" => "New Topic") do |t|
@@ -576,7 +576,7 @@ def test_table_name_guesses
def test_destroy_all
original_count = Topic.count
topics_by_mary = Topic.count(:conditions => mary = "author_name = 'Mary'")
-
+
Topic.destroy_all mary
assert_equal original_count - topics_by_mary, Topic.count
end
@@ -665,7 +665,7 @@ def test_update_many
def test_delete_all
assert Topic.count > 0
-
+
assert_equal Topic.count, Topic.delete_all
end
@@ -970,7 +970,7 @@ def test_multiparameter_attributes_on_time
topic.attributes = attributes
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
end
-
+
def test_multiparameter_attributes_on_time_with_old_date
attributes = {
"written_on(1i)" => "1850", "written_on(2i)" => "6", "written_on(3i)" => "24",
@@ -998,7 +998,7 @@ def test_multiparameter_attributes_on_time_with_utc
def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
- Time.zone = TimeZone[-28800]
+ Time.zone = ActiveSupport::TimeZone[-28800]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
@@ -1016,7 +1016,7 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
ActiveRecord::Base.time_zone_aware_attributes = false
- Time.zone = TimeZone[-28800]
+ Time.zone = ActiveSupport::TimeZone[-28800]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
@@ -1032,7 +1032,7 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_attributes
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
- Time.zone = TimeZone[-28800]
+ Time.zone = ActiveSupport::TimeZone[-28800]
Topic.skip_time_zone_conversion_for_attributes = [:written_on]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
@@ -1647,15 +1647,15 @@ def test_find_last
last = Developer.find :last
assert_equal last, Developer.find(:first, :order => 'id desc')
end
-
+
def test_last
assert_equal Developer.find(:first, :order => 'id desc'), Developer.last
end
def test_all_with_conditions
assert_equal Developer.find(:all, :order => 'id desc'), Developer.all(:order => 'id desc')
end
-
+
def test_find_ordered_last
last = Developer.find :last, :order => 'developers.salary ASC'
assert_equal last, Developer.find(:all, :order => 'developers.salary ASC').last
@@ -1670,14 +1670,14 @@ def test_find_multiple_ordered_last
last = Developer.find :last, :order => 'developers.name, developers.salary DESC'
assert_equal last, Developer.find(:all, :order => 'developers.name, developers.salary DESC').last
end
-
+
def test_find_scoped_ordered_last
last_developer = Developer.with_scope(:find => { :order => 'developers.salary ASC' }) do
Developer.find(:last)
end
assert_equal last_developer, Developer.find(:all, :order => 'developers.salary ASC').last
end
-
+
def test_abstract_class
assert !ActiveRecord::Base.abstract_class?
assert LoosePerson.abstract_class?
@@ -223,11 +223,11 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
fixtures :companies
def setup
- Dependencies.log_activity = true
+ ActiveSupport::Dependencies.log_activity = true
end
def teardown
- Dependencies.log_activity = false
+ ActiveSupport::Dependencies.log_activity = false
self.class.const_remove :FirmOnTheFly rescue nil
Firm.const_remove :FirmOnTheFly rescue nil
end
@@ -51,7 +51,7 @@ def test_associations
def test_course_connection_should_survive_dependency_reload
assert Course.connection
- Dependencies.clear
+ ActiveSupport::Dependencies.clear
Object.send(:remove_const, :Course)
require_dependency 'models/course'
@@ -53,3 +53,7 @@
require 'active_support/base64'
require 'active_support/time_with_zone'
+
+Inflector = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Inflector', 'ActiveSupport::Inflector')
+Dependencies = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Dependencies', 'ActiveSupport::Dependencies')
+TimeZone = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('TimeZone', 'ActiveSupport::TimeZone')
Oops, something went wrong.

1 comment on commit c08547d

Member

josh commented on c08547d Sep 10, 2008

I think it was related to preloading/threadsafety. Maybe it should be a cattr_accessor instead of a const?

Please sign in to comment.