Permalink
Browse files

Add uses_tzinfo to active record tests to prevent breaking the cc.rb …

…build etc. Closes #11034 [mpalmer]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8808 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 13264af commit cfb8ba00037296054543fb6f0c5863869fdf072d @NZKoz NZKoz committed Feb 6, 2008
@@ -138,49 +138,51 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
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 Time.utc(2007, 12, 31, 16), record.written_on.time # and represents time values adjusted accordingly
+ uses_tzinfo "Time zone" do
+ 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 Time.utc(2007, 12, 31, 16), record.written_on.time # and represents time values adjusted accordingly
+ end
end
- end
-
- def test_setting_time_zone_aware_attribute_to_utc
- 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
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
- assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
+
+ def test_setting_time_zone_aware_attribute_to_utc
+ 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
+ assert_equal 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_in_other_time_zone
- utc_time = Time.utc(2008, 1, 1)
- cst_time = utc_time.in_time_zone("Central Time (US & Canada)")
- in_time_zone "Pacific Time (US & Canada)" do
- 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 Time.utc(2007, 12, 31, 16), record.written_on.time
+
+ def test_setting_time_zone_aware_attribute_in_other_time_zone
+ utc_time = Time.utc(2008, 1, 1)
+ cst_time = utc_time.in_time_zone("Central Time (US & Canada)")
+ in_time_zone "Pacific Time (US & Canada)" do
+ 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 Time.utc(2007, 12, 31, 16), record.written_on.time
+ end
end
- end
-
- def test_setting_time_zone_aware_attribute_in_current_time_zone
- utc_time = Time.utc(2008, 1, 1)
- in_time_zone "Pacific Time (US & Canada)" do
- record = @target.new
- record.written_on = utc_time.in_current_time_zone
- assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
- assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
+
+ def test_setting_time_zone_aware_attribute_in_current_time_zone
+ utc_time = Time.utc(2008, 1, 1)
+ in_time_zone "Pacific Time (US & Canada)" do
+ record = @target.new
+ record.written_on = utc_time.in_current_time_zone
+ assert_equal utc_time, record.written_on
+ assert_equal 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
@@ -937,25 +937,27 @@ def test_multiparameter_attributes_on_time_with_utc
ActiveRecord::Base.default_timezone = :local
end
- 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]
- 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"
- }
- topic = Topic.find(1)
- topic.attributes = attributes
- assert_equal Time.utc(2004, 6, 24, 23, 24, 0), topic.written_on
- assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on.time
- assert_equal Time.zone, topic.written_on.time_zone
- ensure
- ActiveRecord::Base.time_zone_aware_attributes = false
- ActiveRecord::Base.default_timezone = :local
- Time.zone = nil
+ uses_tzinfo "test_multiparameter_attributes_on_time_with_time_zone_aware_attributes" do
+ 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]
+ 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"
+ }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ assert_equal Time.utc(2004, 6, 24, 23, 24, 0), topic.written_on
+ assert_equal Time.utc(2004, 6, 24, 16, 24, 0), topic.written_on.time
+ assert_equal Time.zone, topic.written_on.time_zone
+ ensure
+ ActiveRecord::Base.time_zone_aware_attributes = false
+ ActiveRecord::Base.default_timezone = :local
+ Time.zone = nil
+ end
end
-
+
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
@@ -29,6 +29,14 @@ def uses_mocha(description)
$stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
end
+def uses_tzinfo(description)
+ require 'rubygems'
+ require 'tzinfo'
+ yield
+rescue LoadError
+ $stderr.puts "Skipping #{description} tests. `gem install tzinfo` and try again."
+end
+
ActiveRecord::Base.connection.class.class_eval do
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]

0 comments on commit cfb8ba0

Please sign in to comment.