aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-11-10 19:05:37 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-11-10 22:55:13 +0530
commitb805c71655ada0e3fcf7ccc1cdf3376e55b2b9ce (patch)
tree239e573b7155f5f41acf0a43eb7d2a4d33690e46 /activerecord
parent74233d48e64650c26600f82ac23eb55c39fea342 (diff)
downloadrails-b805c71655ada0e3fcf7ccc1cdf3376e55b2b9ce.tar.gz
rails-b805c71655ada0e3fcf7ccc1cdf3376e55b2b9ce.tar.bz2
rails-b805c71655ada0e3fcf7ccc1cdf3376e55b2b9ce.zip
Checking the arity of the block passed to create_table
A recent change made to create_table does away with the need for the block argument. Checking the arity will prevent the mixing up of the two syntaxes.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb8
-rw-r--r--activerecord/test/cases/migration_test.rb15
2 files changed, 22 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 0e5e33fa02..be9a02682b 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -158,7 +158,13 @@ module ActiveRecord
td = table_definition
td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
- td.instance_eval(&blk) if blk
+ if block_given?
+ if blk.arity == 1
+ yield td
+ else
+ td.instance_eval(&blk)
+ end
+ end
if options[:force] && table_exists?(table_name)
drop_table(table_name)
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index e8ad37d437..50242a497c 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -1742,6 +1742,21 @@ if ActiveRecord::Base.connection.supports_migrations?
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