From 80d40ef18430af33f300bc1043758c775db0d0eb Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 13 Aug 2009 14:30:16 -0400 Subject: [PATCH] Fix unit tests under mysql --- test/connection/native_mysql/schema.sql | 13 ++++++++++++- test/schema.native_mysql.expected.rb | 20 ++++++++++++++++---- test/schema_dumper_test.rb | 17 +++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/test/connection/native_mysql/schema.sql b/test/connection/native_mysql/schema.sql index bd90570..f4a9897 100644 --- a/test/connection/native_mysql/schema.sql +++ b/test/connection/native_mysql/schema.sql @@ -3,7 +3,8 @@ create table people ( id int(11) DEFAULT NULL auto_increment PRIMARY KEY, first_name char(255), last_name char(255), - ssn char(64) + ssn char(64), + address_id integer ); drop table if exists people2; create table people2 ( @@ -19,4 +20,14 @@ create table places ( city char(255), cstate char(255), country char(2) +); +drop table if exists items; +create table items ( + id int(11) DEFAULT NULL auto_increment PRIMARY KEY, + person_id int(11) +); +drop table if exists items_people; +create table items_people ( + person_id int(11), + item_id int(11) ); \ No newline at end of file diff --git a/test/schema.native_mysql.expected.rb b/test/schema.native_mysql.expected.rb index 39bdb75..bb41c55 100644 --- a/test/schema.native_mysql.expected.rb +++ b/test/schema.native_mysql.expected.rb @@ -11,10 +11,20 @@ ActiveRecord::Schema.define(:version => 0) do + create_table "items", :force => true do |t| + t.integer "person_id" + end + + create_table "items_people", :id => false, :force => true do |t| + t.integer "person_id" + t.integer "item_id" + end + create_table "people", :force => true do |t| - t.string "first_name" - t.string "last_name" - t.string "ssn", :limit => 64 + t.string "first_name" + t.string "last_name" + t.string "ssn", :limit => 64 + t.integer "address_id" end create_table "people2", :force => true do |t| @@ -30,10 +40,12 @@ t.string "country", :limit => 2 end - create_view "v_people", "select `people`.`first_name` AS `f_name`,`people`.`last_name` AS `l_name`,`people`.`ssn` AS `social_security` from `people`", :force => true do |v| + create_view "v_people", "select `people`.`id` AS `id`,`people`.`first_name` AS `f_name`,`people`.`last_name` AS `l_name`,`people`.`ssn` AS `social_security`,`people`.`address_id` AS `address_id` from `people`", :force => true do |v| + v.column :id v.column :f_name v.column :l_name v.column :social_security + v.column :address_id end end diff --git a/test/schema_dumper_test.rb b/test/schema_dumper_test.rb index b4bda3c..6cee530 100644 --- a/test/schema_dumper_test.rb +++ b/test/schema_dumper_test.rb @@ -6,6 +6,10 @@ def setup ActiveRecord::Base.connection.execute('drop view if exists v_people') ActiveRecord::Base.connection.execute('drop view if exists v_profile') end + def teardown + ActiveRecord::Base.connection.execute('drop view if exists v_people') + ActiveRecord::Base.connection.execute('drop view if exists v_profile') + end def test_view create_people_view stream = StringIO.new @@ -20,14 +24,19 @@ def test_dump_and_load def test_union Person.create(:first_name => 'Joe', :last_name => 'User', :ssn => '123456789') Person2.create(:first_name => 'Jane', :last_name => 'Doe', :ssn => '222334444') - ActiveRecord::Base.connection.create_view(:v_profile, - "(select first_name, last_name, ssn from people) " + - " UNION " + - "(select first_name, last_name, ssn from people2)", :force => true) do |v| + + select_stmt = <<-HERE + select first_name, last_name, ssn from people + UNION + select first_name, last_name, ssn from people2 + HERE + + ActiveRecord::Base.connection.create_view(:v_profile, select_stmt, :force => true) do |v| v.column :first_name v.column :last_name v.column :ssn end + assert_dump_and_load_succeed end def test_symbol_ignore