1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

make change_column_null reversible. Closes #13576.

Closes #13623.
This commit is contained in:
Yves Senn 2014-01-08 15:51:06 +01:00
parent b502e3db95
commit 724509a9d5
3 changed files with 26 additions and 1 deletions

View file

@ -1,3 +1,7 @@
* Make `change_column_null` revertable. Fixes #13576.
*Yves Senn*, *Nishant Modak*, *Prathamesh Sonpatki*
* Don't create/drop the test database if RAILS_ENV is specified explicitely.
Previously, when the environment was development, we would always

View file

@ -74,7 +74,7 @@ module ActiveRecord
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
:change_column_default, :add_reference, :remove_reference, :transaction,
:drop_join_table, :drop_table, :execute_block, :enable_extension,
:change_column, :execute, :remove_columns, # irreversible methods need to be here too
:change_column, :execute, :remove_columns, :change_column_null # irreversible methods need to be here too
].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
@ -157,6 +157,11 @@ module ActiveRecord
alias :invert_add_belongs_to :invert_add_reference
alias :invert_remove_belongs_to :invert_remove_reference
def invert_change_column_null(args)
args[2] = !args[2]
[:change_column_null, args]
end
# Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
if @delegate.respond_to?(method)

View file

@ -308,6 +308,22 @@ module ActiveRecord
assert_equal 2000, connection.select_values("SELECT money FROM testings").first.to_i
end
def test_change_column_null
testing_table_with_only_foo_attribute do
notnull_migration = Class.new(ActiveRecord::Migration) do
def change
change_column_null :testings, :foo, false
end
end
notnull_migration.new.suppress_messages do
notnull_migration.migrate(:up)
assert_equal false, connection.columns(:testings).find{ |c| c.name == "foo"}.null
notnull_migration.migrate(:down)
assert connection.columns(:testings).find{ |c| c.name == "foo"}.null
end
end
end
def test_column_exists
connection.create_table :testings do |t|
t.column :foo, :string