diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-02-06 22:26:47 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-02-06 22:26:47 +0000 |
commit | cfb8ba00037296054543fb6f0c5863869fdf072d (patch) | |
tree | 733a1c647fe6539f5af9ba70fe69fb3d137d2be9 /activerecord | |
parent | 13264afb120de1e8a858ef87a619901da5af5972 (diff) | |
download | rails-cfb8ba00037296054543fb6f0c5863869fdf072d.tar.gz rails-cfb8ba00037296054543fb6f0c5863869fdf072d.tar.bz2 rails-cfb8ba00037296054543fb6f0c5863869fdf072d.zip |
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
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/test/cases/attribute_methods_test.rb | 82 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 38 | ||||
-rw-r--r-- | activerecord/test/cases/helper.rb | 8 |
3 files changed, 70 insertions, 58 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 427c14edbd..b42d419216 100755 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -138,49 +138,51 @@ class AttributeMethodsTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index bd076888e1..93a40267fc 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -937,25 +937,27 @@ class BasicsTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index dc83300efa..1040d1ec41 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -29,6 +29,14 @@ rescue LoadError $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/] |