From 4eb7a2a04311576664d9632c317cedebb979d617 Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Thu, 3 Jul 2008 16:56:45 -0400 Subject: [PATCH] todoz --- TODO.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) create mode 100644 TODO.txt diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..15e4ecc --- /dev/null +++ b/TODO.txt @@ -0,0 +1,4 @@ +schema_statements.rb +mysql_adapter.rb +active_record_store.rb +migration_test.rb \ No newline at end of file -- 1.5.6.rc2.26.g8c37 From cf4fc6ddbf76753723f0a12acf3b849437cf4e1c Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Mon, 7 Jul 2008 00:36:20 -0400 Subject: [PATCH] added a test and fix for creating a table without passing in a block. --- .../abstract/schema_statements.rb | 2 +- activerecord/test/cases/migration_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 0f60a91..d5c281d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -95,7 +95,7 @@ module ActiveRecord table_definition = TableDefinition.new(self) table_definition.primary_key(options[:primary_key] || Base.get_primary_key(table_name)) unless options[:id] == false - yield table_definition + yield table_definition if block_given? if options[:force] && table_exists?(table_name) drop_table(table_name, options) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 7ecf755..8e1a8f7 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -93,6 +93,13 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_create_table_without_a_block + assert_nothing_raised { Person.connection.create_table(:testings) } + assert Person.connection.tables.include?('testings') + ensure + Person.connection.drop_table :testings rescue nil + end + def test_create_table_adds_id Person.connection.create_table :testings do |t| t.column :foo, :string -- 1.5.6.rc2.26.g8c37 From 769bec99826ea8d3c8a15cd95d4487a63cf69dee Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Mon, 7 Jul 2008 11:18:27 -0400 Subject: [PATCH] broken, trying to find a way to mock out execute or otherwise test create_table --- activerecord/test/cases/migration_test.rb | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 8e1a8f7..cf064aa 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -100,6 +100,12 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table :testings rescue nil end + def test_create_table_with_options_hash + if current_adapter?(:MysqlAdapter) + raise 'omfg' + end + end + def test_create_table_adds_id Person.connection.create_table :testings do |t| t.column :foo, :string -- 1.5.6.rc2.26.g8c37 From 14e419efd5ed8d7373c220ef90034c5c9cf6218a Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Mon, 7 Jul 2008 11:36:38 -0400 Subject: [PATCH] working mocked create_table test --- activerecord/test/cases/migration_test.rb | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index cf064aa..f62c610 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -101,9 +101,9 @@ if ActiveRecord::Base.connection.supports_migrations? end def test_create_table_with_options_hash - if current_adapter?(:MysqlAdapter) - raise 'omfg' - end + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + adapter.stubs(:execute).with('omfg') + adapter.create_table(:testings) end def test_create_table_adds_id -- 1.5.6.rc2.26.g8c37 From 8fa38f89ccf02b5c3a8e7dd635f622b918546c51 Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Tue, 8 Jul 2008 10:14:16 -0400 Subject: [PATCH] created failing test for create_table with hash options --- activerecord/test/cases/migration_test.rb | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index f62c610..6f25de4 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -102,8 +102,9 @@ if ActiveRecord::Base.connection.supports_migrations? def test_create_table_with_options_hash adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) - adapter.stubs(:execute).with('omfg') - adapter.create_table(:testings) + create_table_regex = /CREATE TABLE testings \(id primary_key\) ((CHARACTER SET=utf8 ENGINE=InnoDB)|(ENGINE=InnoDB CHARACTER SET=utf8))/ + adapter.stubs(:execute).with(create_table_regex) + adapter.create_table(:testings, :options => {'ENGINE' => 'InnoDB', 'CHARACTER SET' => 'utf8'}) end def test_create_table_adds_id -- 1.5.6.rc2.26.g8c37 From e9e1a45a4c37c2ceaaab542b009b9fcc8e32e396 Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Wed, 9 Jul 2008 11:53:41 -0400 Subject: [PATCH] werk --- .../abstract/schema_statements.rb | 4 ++++ activerecord/test/cases/migration_test.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index d5c281d..ecab858 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -101,6 +101,10 @@ module ActiveRecord drop_table(table_name, options) end + if options[:options] && options[:options].is_a?(Hash) + options[:options] = options[:options].collect {|k,v| "#{k}=#{v}" }.join(' ') + end + create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE " create_sql << "#{quote_table_name(table_name)} (" create_sql << table_definition.to_sql diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 6f25de4..8de21fd 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -102,7 +102,7 @@ if ActiveRecord::Base.connection.supports_migrations? def test_create_table_with_options_hash adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) - create_table_regex = /CREATE TABLE testings \(id primary_key\) ((CHARACTER SET=utf8 ENGINE=InnoDB)|(ENGINE=InnoDB CHARACTER SET=utf8))/ + create_table_regex = /CREATE TABLE testings \(id primary_key\) CHARACTER SET\=utf8 ENGINE\=InnoDB/ adapter.stubs(:execute).with(create_table_regex) adapter.create_table(:testings, :options => {'ENGINE' => 'InnoDB', 'CHARACTER SET' => 'utf8'}) end -- 1.5.6.rc2.26.g8c37 From 89844351b05c9ed18489823c1cbfa6a62b82d3ba Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Tue, 15 Jul 2008 11:38:44 -0400 Subject: [PATCH] more create_table tests --- .../abstract/schema_statements.rb | 1 + activerecord/test/cases/migration_test.rb | 24 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index ecab858..3c1b840 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -102,6 +102,7 @@ module ActiveRecord end if options[:options] && options[:options].is_a?(Hash) + options[:options].reverse_merge!({'ENGINE' => 'InnoDB'}) options[:options] = options[:options].collect {|k,v| "#{k}=#{v}" }.join(' ') end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 8de21fd..ab203b4 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -100,13 +100,33 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table :testings rescue nil end + def test_create_table_with_options_string + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + adapter.stubs(:execute).with('CREATE TABLE testings (id primary_key) ENGINE=InnoDB CHARACTER SET=utf8') + adapter.create_table(:testings, :options => 'ENGINE=InnoDB CHARACTER SET=utf8') + end + def test_create_table_with_options_hash adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) - create_table_regex = /CREATE TABLE testings \(id primary_key\) CHARACTER SET\=utf8 ENGINE\=InnoDB/ - adapter.stubs(:execute).with(create_table_regex) + create_table_regex = /CREATE TABLE testings \(id primary_key\) (CHARACTER SET\=utf8 ENGINE\=InnoDB)|(ENGINE\=InnoDB CHARACTER SET\=utf8)/ + adapter.stubs(:execute).with() {|value| value =~ create_table_regex} adapter.create_table(:testings, :options => {'ENGINE' => 'InnoDB', 'CHARACTER SET' => 'utf8'}) end + def test_create_table_with_options_hash_adds_engine_inno_db_default + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + create_table_regex = /CREATE TABLE testings \(id primary_key\) (CHARACTER SET\=utf8 ENGINE\=InnoDB)|(ENGINE\=InnoDB CHARACTER SET\=utf8)/ + adapter.stubs(:execute).with() {|value| value =~ create_table_regex} + adapter.create_table(:testings, :options => {'CHARACTER SET' => 'utf8'}) + end + + def test_create_table_with_options_hash_can_override_engine + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + create_table_regex = /CREATE TABLE testings \(id primary_key\) (CHARACTER SET\=utf8 ENGINE\=MyISAM)|(ENGINE\=MyISAM CHARACTER SET\=utf8)/ + adapter.stubs(:execute).with() {|value| value =~ create_table_regex} + adapter.create_table(:testings, :options => {'ENGINE' => 'MyISAM', 'CHARACTER SET' => 'utf8'}) + end + def test_create_table_adds_id Person.connection.create_table :testings do |t| t.column :foo, :string -- 1.5.6.rc2.26.g8c37 From fd851ddb55d3d6edd938891a07a5f1d5c20f55a3 Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Fri, 18 Jul 2008 19:21:45 -0400 Subject: [PATCH] patch finished! --- activerecord/test/cases/migration_test.rb | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index ab203b4..2656210 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -94,10 +94,9 @@ if ActiveRecord::Base.connection.supports_migrations? end def test_create_table_without_a_block - assert_nothing_raised { Person.connection.create_table(:testings) } - assert Person.connection.tables.include?('testings') - ensure - Person.connection.drop_table :testings rescue nil + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + adapter.stubs(:execute).with('CREATE TABLE testings (id primary_key) ENGINE=InnoDB') + adapter.create_table(:testings) end def test_create_table_with_options_string @@ -106,6 +105,12 @@ if ActiveRecord::Base.connection.supports_migrations? adapter.create_table(:testings, :options => 'ENGINE=InnoDB CHARACTER SET=utf8') end + def test_create_table_with_options_string_overwrites_default_options + adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) + adapter.stubs(:execute).with('CREATE TABLE testings (id primary_key) CHARACTER SET=utf8') + adapter.create_table(:testings, :options => 'CHARACTER SET=utf8') + end + def test_create_table_with_options_hash adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) create_table_regex = /CREATE TABLE testings \(id primary_key\) (CHARACTER SET\=utf8 ENGINE\=InnoDB)|(ENGINE\=InnoDB CHARACTER SET\=utf8)/ -- 1.5.6.rc2.26.g8c37 From 90558e842622c33886224a6626f48fd71067b50a Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Fri, 18 Jul 2008 19:27:58 -0400 Subject: [PATCH] removed temp file --- TODO.txt | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-) delete mode 100644 TODO.txt diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 15e4ecc..0000000 --- a/TODO.txt +++ /dev/null @@ -1,4 +0,0 @@ -schema_statements.rb -mysql_adapter.rb -active_record_store.rb -migration_test.rb \ No newline at end of file -- 1.5.6.rc2.26.g8c37 From c507c5eeece55e94a26ee4ea498d4068f7d1821d Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Fri, 18 Jul 2008 19:55:06 -0400 Subject: [PATCH] tweakz --- .../abstract/schema_statements.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 3c1b840..64d5cac 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -106,6 +106,8 @@ module ActiveRecord options[:options] = options[:options].collect {|k,v| "#{k}=#{v}" }.join(' ') end + options[:options] ||= 'ENGINE=InnoDB' + create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE " create_sql << "#{quote_table_name(table_name)} (" create_sql << table_definition.to_sql -- 1.5.6.rc2.26.g8c37 From 05204449aaf6c3c7bc81e1c23675bf073f08d8d2 Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Fri, 18 Jul 2008 20:06:11 -0400 Subject: [PATCH] added documentation --- .../abstract/schema_statements.rb | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 64d5cac..ac4f6c1 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -54,7 +54,8 @@ module ActiveRecord # The name of the primary key, if one is to be added automatically. # Defaults to +id+. # [:options] - # Any extra options you want appended to the table definition. + # Any extra options you want appended to the table definition in hash or string format. + # Defaults to 'Engine=InnoDB'. # [:temporary] # Make a temporary table. # [:force] @@ -62,6 +63,13 @@ module ActiveRecord # Defaults to false. # # ===== Examples + # ====== Add a backend specific option to the generated SQL (MySQL) using a hash + # create_table(:suppliers, :options => {'DEFAULT CHARSET'=>'utf8'}) + # generates: + # CREATE TABLE suppliers ( + # id int(11) DEFAULT NULL auto_increment PRIMARY KEY + # ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + # # ====== Add a backend specific option to the generated SQL (MySQL) # create_table(:suppliers, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') # generates: -- 1.5.6.rc2.26.g8c37