aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-11-17 10:28:23 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-17 10:29:28 -0800
commita2f14e23441ec016f9643b9054f409006b0e16b3 (patch)
treed38b2baff24ee9c06fe808a850b3149284eaa2be /activerecord
parent649f2513a453cae319be8b63a9de25ae11fb9e8f (diff)
downloadrails-a2f14e23441ec016f9643b9054f409006b0e16b3.tar.gz
rails-a2f14e23441ec016f9643b9054f409006b0e16b3.tar.bz2
rails-a2f14e23441ec016f9643b9054f409006b0e16b3.zip
Revert "Merge pull request #1163 from amatsuda/sexier_migration_31"
This reverts commit 0e407a90413d8a19002b85508d811ccdf2190783, reversing changes made to 533a9f84b035756eedf9fdccf0c494dc9701ba72. Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/migration_test.rb
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb10
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb18
-rw-r--r--activerecord/lib/active_record/session_store.rb7
-rw-r--r--activerecord/test/cases/migration_test.rb120
4 files changed, 13 insertions, 142 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 1d837f29be..faa42e2d19 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -155,17 +155,11 @@ module ActiveRecord
# )
#
# See also TableDefinition#column for details on how to create columns.
- def create_table(table_name, options = {}, &blk)
+ def create_table(table_name, options = {})
td = table_definition
td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
- if block_given?
- if blk.arity == 1
- yield td
- else
- td.instance_eval(&blk)
- end
- end
+ yield td if block_given?
if options[:force] && table_exists?(table_name)
drop_table(table_name)
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 35df0a1542..bc3804b3d9 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -480,30 +480,28 @@ module ActiveRecord
drop_table(from)
end
- def copy_table(from, to, options = {}, &block) #:nodoc:
- from_columns, from_primary_key = columns(from), primary_key(from)
- options = options.merge(:id => (!from_columns.detect {|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
- table_definition = nil
+ def copy_table(from, to, options = {}) #:nodoc:
+ options = options.merge(:id => (!columns(from).detect{|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
create_table(to, options) do |definition|
- table_definition = definition
- from_columns.each do |column|
+ @definition = definition
+ columns(from).each do |column|
column_name = options[:rename] ?
(options[:rename][column.name] ||
options[:rename][column.name.to_sym] ||
column.name) : column.name
- table_definition.column(column_name, column.type,
+ @definition.column(column_name, column.type,
:limit => column.limit, :default => column.default,
:precision => column.precision, :scale => column.scale,
:null => column.null)
end
- table_definition.primary_key from_primary_key if from_primary_key
- table_definition.instance_eval(&block) if block
+ @definition.primary_key(primary_key(from)) if primary_key(from)
+ yield @definition if block_given?
end
copy_table_indexes(from, to, options[:rename] || {})
copy_table_contents(from, to,
- table_definition.columns.map {|column| column.name},
+ @definition.columns.map {|column| column.name},
options[:rename] || {})
end
diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb
index 92550c7efc..76c37cc367 100644
--- a/activerecord/lib/active_record/session_store.rb
+++ b/activerecord/lib/active_record/session_store.rb
@@ -64,13 +64,12 @@ module ActiveRecord
end
def create_table!
- id_col_name, data_col_name = session_id_column, data_column_name
connection_pool.clear_table_cache!(table_name)
connection.create_table(table_name) do |t|
- t.string id_col_name, :limit => 255
- t.text data_col_name
+ t.string session_id_column, :limit => 255
+ t.text data_column_name
end
- connection.add_index table_name, id_col_name, :unique => true
+ connection.add_index table_name, session_id_column, :unique => true
end
end
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index ae5b2a62b5..3e219f2a49 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -1639,126 +1639,6 @@ if ActiveRecord::Base.connection.supports_migrations?
end
- class SexyMigrationsTest < ActiveRecord::TestCase
- def test_references_column_type_adds_id
- with_new_table do |t|
- t.expects(:column).with('customer_id', :integer, {})
- t.references :customer
- end
- end
-
- def test_references_column_type_with_polymorphic_adds_type
- with_new_table do |t|
- t.expects(:column).with('taggable_type', :string, {})
- t.expects(:column).with('taggable_id', :integer, {})
- t.references :taggable, :polymorphic => true
- end
- end
-
- def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
- with_new_table do |t|
- t.expects(:column).with('taggable_type', :string, {:null => false})
- t.expects(:column).with('taggable_id', :integer, {:null => false})
- t.references :taggable, :polymorphic => true, :null => false
- end
- end
-
- def test_belongs_to_works_like_references
- with_new_table do |t|
- t.expects(:column).with('customer_id', :integer, {})
- t.belongs_to :customer
- end
- end
-
- def test_timestamps_creates_updated_at_and_created_at
- with_new_table do |t|
- t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
- t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
- t.timestamps
- end
- end
-
- def test_integer_creates_integer_column
- with_new_table do |t|
- t.expects(:column).with(:foo, 'integer', {})
- t.expects(:column).with(:bar, 'integer', {})
- t.integer :foo, :bar
- end
- end
-
- def test_string_creates_string_column
- with_new_table do |t|
- t.expects(:column).with(:foo, 'string', {})
- t.expects(:column).with(:bar, 'string', {})
- t.string :foo, :bar
- end
- end
-
- if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLite3Adapter) || current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter)
- def test_xml_creates_xml_column
- type = current_adapter?(:PostgreSQLAdapter) ? 'xml' : :text
-
- with_new_table do |t|
- t.expects(:column).with(:data, type, {})
- t.xml :data
- end
- end
- else
- def test_xml_creates_xml_column
- with_new_table do |t|
- assert_raises(NotImplementedError) do
- t.xml :data
- end
- end
- end
- end
-
- protected
- def with_new_table
- Person.connection.create_table :delete_me, :force => true do |t|
- yield t
- end
- ensure
- Person.connection.drop_table :delete_me rescue nil
- end
-
- end # SexyMigrationsTest
-
- class SexierMigrationsTest < ActiveRecord::TestCase
- def test_create_table_with_column_without_block_parameter
- Person.connection.create_table :testings, :force => true do
- column :foo, :string
- end
- assert Person.connection.column_exists?(:testings, :foo, :string)
- ensure
- Person.connection.drop_table :testings rescue nil
- end
-
- def test_create_table_with_sexy_column_without_block_parameter
- Person.connection.create_table :testings, :force => true do
- integer :bar
- end
- assert Person.connection.column_exists?(:testings, :bar, :integer)
- ensure
- Person.connection.drop_table :testings rescue nil
- end
-
- def test_create_table_should_not_have_mixed_syntax
- assert_raise(NoMethodError) do
- Person.connection.create_table :testings, :force => true do |t|
- t.string :foo
- integer :bar
- end
- end
- assert_raise(NameError) do
- Person.connection.create_table :testings, :force => true do
- t.string :foo
- integer :bar
- end
- end
- end
- end # SexierMigrationsTest
-
class MigrationLoggerTest < ActiveRecord::TestCase
def test_migration_should_be_run_without_logger
previous_logger = ActiveRecord::Base.logger