Skip to content

Commit

Permalink
Fix unit tests under mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed Aug 13, 2009
1 parent b1a4a8c commit 80d40ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
13 changes: 12 additions & 1 deletion test/connection/native_mysql/schema.sql
Expand Up @@ -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 (
Expand All @@ -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)
);
20 changes: 16 additions & 4 deletions test/schema.native_mysql.expected.rb
Expand Up @@ -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|
Expand All @@ -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
17 changes: 13 additions & 4 deletions test/schema_dumper_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 80d40ef

Please sign in to comment.