From 9a0af37f7f8c076401c646eae20b5fcd9847906e Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Sat, 7 Aug 2010 23:23:10 -0400 Subject: [PATCH] Various test case conditions for the SQLServerAdapter. --- .../associations/belongs_to_associations_test.rb | 3 +++ activerecord/test/cases/associations/eager_test.rb | 2 +- .../has_and_belongs_to_many_associations_test.rb | 2 +- activerecord/test/cases/attribute_methods_test.rb | 4 ++++ activerecord/test/cases/calculations_test.rb | 2 +- activerecord/test/cases/inheritance_test.rb | 2 +- activerecord/test/cases/query_cache_test.rb | 2 ++ activerecord/test/cases/schema_dumper_test.rb | 2 ++ activerecord/test/schema/schema.rb | 2 +- 9 files changed, 16 insertions(+), 5 deletions(-) diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 0464338..1a95870 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -39,6 +39,9 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase # on Oracle aliases are truncated to 30 characters and are quoted in uppercase assert_no_match(/"firm_with_primary_keys_compani"\."id"/i, sql) assert_match(/"firm_with_primary_keys_compani"\."name"/i, sql) + elsif current_adapter?(:SQLServerAdapter) + assert_no_match(/\[firm_with_primary_keys_companies\]\.\[id\]/, sql) + assert_match(/\[firm_with_primary_keys_companies\]\.\[name\]/, sql) else assert_no_match(/"firm_with_primary_keys_companies"\."id"/, sql) assert_match(/"firm_with_primary_keys_companies"\."name"/, sql) diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 40859d4..4c78728 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -699,7 +699,7 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_count_with_include - if current_adapter?(:SybaseAdapter) + if current_adapter?(:SybaseAdapter,:SQLServerAdapter) assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15") elsif current_adapter?(:OpenBaseAdapter) assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(FETCHBLOB(comments.body)) > 15") diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 6b4a1d9..20a2ed8 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -835,7 +835,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, developer.projects.count end - unless current_adapter?(:PostgreSQLAdapter) + unless current_adapter?(:PostgreSQLAdapter,:SQLServerAdapter) def test_count_with_finder_sql assert_equal 3, projects(:active_record).developers_with_finder_sql.count assert_equal 3, projects(:active_record).developers_with_multiline_finder_sql.count diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index d20b762..42d51af 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -352,6 +352,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase # Oracle does not support boolean expressions in SELECT if current_adapter?(:OracleAdapter) topic = Topic.find(:first, :select => "topics.*, 0 as is_test") + elsif current_adapter?(:SQLServerAdapter) + topic = Topic.find(:first, :select => "topics.*, CASE WHEN 1=2 THEN 1 ELSE 0 END as is_test") else topic = Topic.find(:first, :select => "topics.*, 1=2 as is_test") end @@ -363,6 +365,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase # Oracle does not support boolean expressions in SELECT if current_adapter?(:OracleAdapter) topic = Topic.find(:first, :select => "topics.*, 1 as is_test") + elsif current_adapter?(:SQLServerAdapter) + topic = Topic.find(:first, :select => "topics.*, CASE WHEN 2=2 THEN 1 ELSE 0 END as is_test") else topic = Topic.find(:first, :select => "topics.*, 2=2 as is_test") end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 2c9d23c..7561270 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -285,7 +285,7 @@ class CalculationsTest < ActiveRecord::TestCase def test_should_sum_expression # Oracle adapter returns floating point value 636.0 after SUM - if current_adapter?(:OracleAdapter) + if current_adapter?(:OracleAdapter,:SQLServerAdapter) assert_equal 636, Account.sum("2 * credit_limit") else assert_equal 636, Account.sum("2 * credit_limit").to_i diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 8c09fc4..d584ec7 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -58,7 +58,7 @@ class InheritanceTest < ActiveRecord::TestCase end def test_a_bad_type_column - #SQLServer need to turn Identity Insert On before manually inserting into the Identity column + #SybaseAdapter need to turn Identity Insert On before manually inserting into the Identity column if current_adapter?(:SybaseAdapter) Company.connection.execute "SET IDENTITY_INSERT companies ON" end diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index f0d97a0..a1202e4 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -57,6 +57,8 @@ class QueryCacheTest < ActiveRecord::TestCase # Oracle adapter returns count() as Fixnum or Float if current_adapter?(:OracleAdapter) assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") + elsif current_adapter?(:SQLServerAdapter) + assert_instance_of Fixnum, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") elsif current_adapter?(:SQLite3Adapter) && SQLite3::Version::VERSION > '1.2.5' # Future versions of the sqlite3 adapter will return numeric assert_instance_of Fixnum, diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 1c43e3c..0a71c9f 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -210,6 +210,8 @@ class SchemaDumperTest < ActiveRecord::TestCase # Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers if current_adapter?(:OracleAdapter) assert_match %r{t.integer\s+"atoms_in_universe",\s+:precision => 38,\s+:scale => 0}, output + elsif current_adapter?(:SQLServerAdapter) + assert_match %r{t.decimal\s+"atoms_in_universe",\s+:precision => 38,\s+:scale => 0}, output else assert_match %r{t.decimal\s+"atoms_in_universe",\s+:precision => 55,\s+:scale => 0}, output end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index fc3810f..d4b7f66 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -335,7 +335,7 @@ ActiveRecord::Schema.define do t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78 t.float :temperature # Oracle supports precision up to 38 - if current_adapter?(:OracleAdapter) + if current_adapter?(:OracleAdapter,:SQLServerAdapter) t.decimal :atoms_in_universe, :precision => 38, :scale => 0 else t.decimal :atoms_in_universe, :precision => 55, :scale => 0 -- 1.7.1