aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xactiverecord/test/abstract_unit.rb11
-rwxr-xr-xactiverecord/test/associations_test.rb26
-rwxr-xr-xactiverecord/test/base_test.rb10
3 files changed, 18 insertions, 29 deletions
diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb
index d9c60ab6bd..6348394685 100755
--- a/activerecord/test/abstract_unit.rb
+++ b/activerecord/test/abstract_unit.rb
@@ -18,6 +18,17 @@ class Test::Unit::TestCase #:nodoc:
def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names, &block)
end
+
+ def assert_date_from_db(expected, actual, message = nil)
+ # SQL Server doesn't have a separate column type just for dates,
+ # so the time is in the string and incorrectly formatted
+
+ if current_adapter?(:SQLServerAdapter)
+ assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
+ else
+ assert_equal expected.to_s, actual.to_s, message
+ end
+ end
end
def current_adapter?(type)
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index b329968f22..79c7cc8120 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -1170,7 +1170,6 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
no_of_devels = Developer.count
no_of_projects = Project.count
now = Date.today
- sqlnow = Time.now.strftime("%Y/%m/%d 00:00:00")
ken = Developer.new("name" => "Ken")
ken.projects.push_with_attributes( Project.find(1), :joined_on => now )
p = Project.new("name" => "Foomatic")
@@ -1185,13 +1184,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
assert_equal 2, ken.projects(true).size
kenReloaded = Developer.find_by_name 'Ken'
- # SQL Server doesn't have a separate column type just for dates,
- # so the time is in the string and incorrectly formatted
- if current_adapter?(:SQLServerAdapter)
- kenReloaded.projects.each { |prj| assert_equal(sqlnow, prj.joined_on.to_s) }
- else
- kenReloaded.projects.each { |prj| assert_equal(now.to_s, prj.joined_on.to_s) }
- end
+ kenReloaded.projects.each {|prj| assert_date_from_db(now, prj.joined_on)}
end
def test_habtm_saving_multiple_relationships
@@ -1298,10 +1291,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end
def test_additional_columns_from_join_table
- # SQL Server doesn't have a separate column type just for dates,
- # so the time is in the string and incorrectly formatted
- expected = (current_adapter?(:SQLServerAdapter) ? Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00") : Date.new(2004, 10, 10).to_s)
- assert_equal expected, Developer.find(1).projects.first.joined_on.to_s
+ assert_date_from_db Date.new(2004, 10, 10), Developer.find(1).projects.first.joined_on
end
def test_destroy_all
@@ -1316,15 +1306,9 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
def test_rich_association
jamis = developers(:jamis)
jamis.projects.push_with_attributes(projects(:action_controller), :joined_on => Date.today)
- # SQL Server doesn't have a separate column type just for dates,
- # so the time is in the string and incorrectly formatted
- if current_adapter?(:SQLServerAdapter)
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
- else
- assert_equal Date.today.to_s, jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
- assert_equal Date.today.to_s, developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
- end
+
+ assert_date_from_db Date.today, jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on
+ assert_date_from_db Date.today, developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on
end
def test_associations_with_conditions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 42fefa9001..d2f347e0cb 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -649,27 +649,21 @@ class BasicsTest < Test::Unit::TestCase
end
def test_multiparameter_attributes_on_date
- # SQL Server doesn't have a separate column type just for dates, so all are returned as time
- return true if current_adapter?(:SQLServerAdapter)
-
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
topic = Topic.find(1)
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_equal Date.new(2004, 6, 24).to_s, topic.last_read.to_date.to_s
+ assert_date_from_db Date.new(2004, 6, 24), topic.last_read.to_date
end
def test_multiparameter_attributes_on_date_with_empty_date
- # SQL Server doesn't have a separate column type just for dates, so all are returned as time
- return true if current_adapter?(:SQLServerAdapter)
-
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
topic = Topic.find(1)
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_equal Date.new(2004, 6, 1).to_s, topic.last_read.to_date.to_s
+ assert_date_from_db Date.new(2004, 6, 1), topic.last_read.to_date
end
def test_multiparameter_attributes_on_date_with_all_empty