Permalink
Browse files

added mysql2 tests, fixed mysql test expectations

  • Loading branch information...
1 parent 957f46f commit 0e1876ea7a5a9ce948ad18d61ebe701f0614f546 @abachman abachman committed Apr 5, 2011
View
32 test/connection/native_mysql2/connection.rb
@@ -0,0 +1,32 @@
+print "Using native MySQL2\n"
+
+adapter_name = 'mysql2'
+config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../connection.yml'))[adapter_name]
+
+#require 'logger'
+#ActiveRecord::Base.logger = Logger.new("debug.log")
+
+ActiveRecord::Base.silence do
+ ActiveRecord::Base.configurations = {
+ config['database'] => {
+ :adapter => adapter_name,
+ :username => config['username'],
+ :password => config['password'],
+ :host => config['host'],
+ :database => config['database'],
+ :encoding => config['encoding'],
+ :schema_file => config['schema_file'],
+ }
+ }
+
+ ActiveRecord::Base.establish_connection config['database']
+ ActiveRecord::Migration.verbose = false
+
+ puts "Resetting database"
+ conn = ActiveRecord::Base.connection
+ conn.recreate_database(conn.current_database)
+ conn.reconnect!
+ lines = open(File.join(File.dirname(__FILE__), ActiveRecord::Base.configurations[config['database']][:schema_file])).readlines
+ lines.join.split(';').each { |line| conn.execute(line) }
+ conn.reconnect!
+end
View
33 test/connection/native_mysql2/schema.sql
@@ -0,0 +1,33 @@
+drop table if exists people;
+create table people (
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
+ first_name char(255),
+ last_name char(255),
+ ssn char(64),
+ address_id integer
+);
+drop table if exists people2;
+create table people2 (
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
+ first_name char(255),
+ last_name char(255),
+ ssn char(64)
+);
+drop table if exists places;
+create table places (
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
+ address text,
+ 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)
+);
View
6 test/schema.native_mysql.expected.rb
@@ -48,4 +48,10 @@
v.column :address_id
end
+ create_view "v_profile", "select `people`.`first_name` AS `first_name`,`people`.`last_name` AS `last_name`,`people`.`ssn` AS `ssn` from `people` union select `people2`.`first_name` AS `first_name`,`people2`.`last_name` AS `last_name`,`people2`.`ssn` AS `ssn` from `people2`", :force => true do |v|
+ v.column :first_name
+ v.column :last_name
+ v.column :ssn
+ end
+
end
View
57 test/schema.native_mysql2.expected.rb
@@ -0,0 +1,57 @@
+# This file is auto-generated from the current state of the database. Instead of editing this file,
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+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.integer "address_id"
+ end
+
+ create_table "people2", :force => true do |t|
+ t.string "first_name"
+ t.string "last_name"
+ t.string "ssn", :limit => 64
+ end
+
+ create_table "places", :force => true do |t|
+ t.text "address"
+ t.string "city"
+ t.string "cstate"
+ t.string "country", :limit => 2
+ end
+
+ 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
+
+ create_view "v_profile", "select `people`.`first_name` AS `first_name`,`people`.`last_name` AS `last_name`,`people`.`ssn` AS `ssn` from `people` union select `people2`.`first_name` AS `first_name`,`people2`.`last_name` AS `last_name`,`people2`.`ssn` AS `ssn` from `people2`", :force => true do |v|
+ v.column :first_name
+ v.column :last_name
+ v.column :ssn
+ end
+
+end

0 comments on commit 0e1876e

Please sign in to comment.