Skip to content

Commit

Permalink
Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under…
Browse files Browse the repository at this point in the history
… ActiveSupport [#238 state:resolved]
  • Loading branch information
josh committed Jun 3, 2008
1 parent da91450 commit c08547d
Show file tree
Hide file tree
Showing 27 changed files with 1,554 additions and 1,514 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/dispatcher.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/routing.rb
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/dispatcher_test.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/integration_upload_test.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions activerecord/test/cases/attribute_methods_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -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 }
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -665,7 +665,7 @@ def test_update_many

def test_delete_all
assert Topic.count > 0

assert_equal Topic.count, Topic.delete_all
end

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/inheritance_test.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/multiple_db_test.rb
Expand Up @@ -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'

Expand Down
4 changes: 4 additions & 0 deletions activesupport/lib/active_support.rb
Expand Up @@ -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')

1 comment on commit c08547d

@josh
Copy link
Contributor Author

@josh josh commented on c08547d Sep 10, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.