diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-16 08:16:54 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-16 08:16:54 +0000 |
commit | 2076dca63fde71693e4b8e23c4b1ace0a35b964f (patch) | |
tree | 6355eab91015bf3f6d527ae5eba30709aae1db89 /activerecord/test | |
parent | 1cc8ab865fb0b36df1d202ea4d08952d2881d347 (diff) | |
download | rails-2076dca63fde71693e4b8e23c4b1ace0a35b964f.tar.gz rails-2076dca63fde71693e4b8e23c4b1ace0a35b964f.tar.bz2 rails-2076dca63fde71693e4b8e23c4b1ace0a35b964f.zip |
r3095@asus: jeremy | 2005-11-15 22:40:51 -0800
Ticket #1874 - Firebird adapter
r3107@asus: jeremy | 2005-11-16 00:06:14 -0800
quote column aliases
r3108@asus: jeremy | 2005-11-16 00:08:12 -0800
quote columns in construct_conditions_from_arguments. update sequence_name docs. introduce prefetched primary keys.
r3109@asus: jeremy | 2005-11-16 00:09:08 -0800
double-quote rather than single-quote sqlite columns
r3110@asus: jeremy | 2005-11-16 00:09:56 -0800
quote column names and use attribute_condition in validates_uniqueness_of
r3111@asus: jeremy | 2005-11-16 00:12:24 -0800
Use QUOTED_TYPE constant in tests
r3112@asus: jeremy | 2005-11-16 00:13:28 -0800
restrict test_inserts_with_pre_and_suffix to those adapters which support migrations
r3113@asus: jeremy | 2005-11-16 00:14:09 -0800
Use QUOTED_TYPE constant in tests
r3114@asus: jeremy | 2005-11-16 00:14:30 -0800
Use QUOTED_TYPE constant in tests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3051 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | activerecord/test/associations_go_eager_test.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/associations_test.rb | 12 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/deprecated_associations_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/finder_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/fixtures/comment.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/fixtures_test.rb | 62 | ||||
-rwxr-xr-x | activerecord/test/inheritance_test.rb | 2 |
10 files changed, 52 insertions, 46 deletions
diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb index 5c585283f4..0626243521 100755 --- a/activerecord/test/abstract_unit.rb +++ b/activerecord/test/abstract_unit.rb @@ -8,6 +8,8 @@ require 'active_support/binding_of_caller' require 'active_support/breakpoint' require 'connection' +QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE) + class Test::Unit::TestCase #:nodoc: self.fixture_path = File.dirname(__FILE__) + "/fixtures/" self.use_instantiated_fixtures = false diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index f05e5c6fe2..26dc4456df 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -21,7 +21,7 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_loading_conditions_with_or - posts = authors(:david).posts.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%' OR comments.type = 'SpecialComment'") + posts = authors(:david).posts.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'") assert_nil posts.detect { |p| p.author_id != authors(:david).id }, "expected to find only david's posts" end @@ -120,7 +120,7 @@ class EagerAssociationTest < Test::Unit::TestCase assert_raises(ArgumentError) do posts = authors(:david).posts.find(:all, :include => :comments, - :conditions => "comments.body like 'Normal%' OR comments.type = 'SpecialComment'", + :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'", :limit => 2 ) end diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 351dc4bcb3..ef2872e13c 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -357,7 +357,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase def test_find_all firm = Firm.find_first assert_equal firm.clients, firm.clients.find_all - assert_equal 2, firm.clients.find(:all, :conditions => "type = 'Client'").length + assert_equal 2, firm.clients.find(:all, :conditions => "#{QUOTED_TYPE} = 'Client'").length assert_equal 1, firm.clients.find(:all, :conditions => "name = 'Summit'").length end @@ -373,16 +373,16 @@ class HasManyAssociationsTest < Test::Unit::TestCase firm = Firm.find_first client2 = Client.find(2) assert_equal firm.clients.first, firm.clients.find_first - assert_equal client2, firm.clients.find_first("type = 'Client'") - assert_equal client2, firm.clients.find(:first, :conditions => "type = 'Client'") + assert_equal client2, firm.clients.find_first("#{QUOTED_TYPE} = 'Client'") + assert_equal client2, firm.clients.find(:first, :conditions => "#{QUOTED_TYPE} = 'Client'") end def test_find_first_sanitized firm = Firm.find_first client2 = Client.find(2) - assert_equal client2, firm.clients.find_first(["type = ?", "Client"]) - assert_equal client2, firm.clients.find(:first, :conditions => ['type = ?', 'Client']) - assert_equal client2, firm.clients.find(:first, :conditions => ['type = :type', { :type => 'Client' }]) + assert_equal client2, firm.clients.find_first(["#{QUOTED_TYPE} = ?", "Client"]) + assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = ?", 'Client']) + assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }]) end def test_find_in_collection diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 2db2dbf837..e66c90c7fe 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -505,7 +505,7 @@ class BasicsTest < Test::Unit::TestCase assert_nil topic.last_read assert_nil topic.approved end - + def test_equality assert_equal Topic.find(1), Topic.find(2).parent end @@ -1003,10 +1003,10 @@ class BasicsTest < Test::Unit::TestCase end def test_count_with_join - res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.type = 'Post'" + res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'" res2 = res + 1 assert_nothing_raised do - res2 = Post.count("posts.type = 'Post'", + res2 = Post.count("posts.#{QUOTED_TYPE} = 'Post'", "LEFT JOIN comments ON posts.id=comments.post_id") end assert_equal res, res2 diff --git a/activerecord/test/deprecated_associations_test.rb b/activerecord/test/deprecated_associations_test.rb index d96a587dc0..5772ab1335 100755 --- a/activerecord/test/deprecated_associations_test.rb +++ b/activerecord/test/deprecated_associations_test.rb @@ -312,7 +312,7 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase end def test_has_many_find_all - assert_equal 2, Firm.find_first.find_all_in_clients("type = 'Client'").length + assert_equal 2, Firm.find_first.find_all_in_clients("#{QUOTED_TYPE} = 'Client'").length assert_equal 1, Firm.find_first.find_all_in_clients("name = 'Summit'").length end diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 897657faeb..7e73eec7ad 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -350,7 +350,7 @@ class FinderTest < Test::Unit::TestCase def test_find_by_id_with_conditions_with_or assert_nothing_raised do Post.find([1,2,3], - :conditions => "posts.id <= 3 OR posts.type = 'Post'") + :conditions => "posts.id <= 3 OR posts.#{QUOTED_TYPE} = 'Post'") end end diff --git a/activerecord/test/fixtures/comment.rb b/activerecord/test/fixtures/comment.rb index fd3a43ff5a..3eab263fa4 100644 --- a/activerecord/test/fixtures/comment.rb +++ b/activerecord/test/fixtures/comment.rb @@ -6,7 +6,7 @@ class Comment < ActiveRecord::Base end def self.search_by_type(q) - self.find(:all, :conditions => ['type = ?', q]) + self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q]) end end diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 4a0c96bdd3..6d33d4e1a8 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -7,7 +7,9 @@ end class Firm < Company - has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 AND (type = 'Client' OR type = 'SpecialClient' OR type = 'VerySpecialClient' )" + has_many :clients, :order => "id", :dependent => true, :counter_sql => + "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " + + "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )" has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => true diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index 41fc666945..813291aa18 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -51,42 +51,44 @@ class FixturesTest < Test::Unit::TestCase assert_nil(secondRow["author_email_address"]) end - def test_inserts_with_pre_and_suffix - ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t| - t.column :title, :string - t.column :author_name, :string - t.column :author_email_address, :string - t.column :written_on, :datetime - t.column :bonus_time, :time - t.column :last_read, :date - t.column :content, :text - t.column :approved, :boolean, :default => true - t.column :replies_count, :integer, :default => 0 - t.column :parent_id, :integer - t.column :type, :string, :limit => 50 - end + if ActiveRecord::Base.connection.supports_migrations? + def test_inserts_with_pre_and_suffix + ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t| + t.column :title, :string + t.column :author_name, :string + t.column :author_email_address, :string + t.column :written_on, :datetime + t.column :bonus_time, :time + t.column :last_read, :date + t.column :content, :text + t.column :approved, :boolean, :default => true + t.column :replies_count, :integer, :default => 0 + t.column :parent_id, :integer + t.column :type, :string, :limit => 50 + end - # Store existing prefix/suffix - old_prefix = ActiveRecord::Base.table_name_prefix - old_suffix = ActiveRecord::Base.table_name_suffix + # Store existing prefix/suffix + old_prefix = ActiveRecord::Base.table_name_prefix + old_suffix = ActiveRecord::Base.table_name_suffix - # Set a prefix/suffix we can test against - ActiveRecord::Base.table_name_prefix = 'prefix_' - ActiveRecord::Base.table_name_suffix = '_suffix' + # Set a prefix/suffix we can test against + ActiveRecord::Base.table_name_prefix = 'prefix_' + ActiveRecord::Base.table_name_suffix = '_suffix' - topics = create_fixtures("topics") + topics = create_fixtures("topics") - # Restore prefix/suffix to its previous values - ActiveRecord::Base.table_name_prefix = old_prefix - ActiveRecord::Base.table_name_suffix = old_suffix + # Restore prefix/suffix to its previous values + ActiveRecord::Base.table_name_prefix = old_prefix + ActiveRecord::Base.table_name_suffix = old_suffix - firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'") - assert_equal("The First Topic", firstRow["title"]) + firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'") + assert_equal("The First Topic", firstRow["title"]) - secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'") - assert_nil(secondRow["author_email_address"]) - ensure - ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil + secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'") + assert_nil(secondRow["author_email_address"]) + ensure + ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil + end end def test_insert_with_datetime diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb index 432aee7e0e..d726583126 100755 --- a/activerecord/test/inheritance_test.rb +++ b/activerecord/test/inheritance_test.rb @@ -11,7 +11,7 @@ class InheritanceTest < Test::Unit::TestCase if current_adapter?(:SQLServerAdapter) Company.connection.execute "SET IDENTITY_INSERT companies ON" end - Company.connection.insert "INSERT INTO companies (id, type, name) VALUES(100, 'bad_class!', 'Not happening')" + Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')" #We then need to turn it back Off before continuing. if current_adapter?(:SQLServerAdapter) |