Permalink
Browse files

Merge pull request #3600 from vijaydev/migration_arity

Checking the arity of the block passed to create_table
  • Loading branch information...
2 parents 74233d4 + b805c71 commit 23101de283de13517e30c4c3d1ecc65525264886 @josevalim josevalim committed Nov 10, 2011
View
8 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -158,7 +158,13 @@ def create_table(table_name, options = {}, &blk)
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)
View
15 activerecord/test/cases/migration_test.rb
@@ -1742,6 +1742,21 @@ def test_create_table_with_sexy_column_without_block_parameter
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

0 comments on commit 23101de

Please sign in to comment.