@@ -618,6 +618,36 @@ def test_add_null_column_with_no_default
618618 end
619619 end
620620
621+ def test_change_column_whithout_default_option_should_drop_existing_default
622+
623+ Entry . reset_column_information
624+ status_column = Entry . columns . find { |c | c . name == 'status' }
625+ assert_equal :string , status_column . type
626+ assert_equal 'unknown' , status_column . default
627+
628+ Entry . connection . change_column :entries , :status , :text
629+
630+ Entry . reset_column_information
631+ status_column = Entry . columns . find { |c | c . name == 'status' }
632+ assert_equal :text , status_column . type
633+ assert !status_column . default
634+ end
635+
636+ def test_change_column_whith_default_option_should_set_new_default
637+
638+ Entry . reset_column_information
639+ status_column = Entry . columns . find { |c | c . name == 'status' }
640+ assert_equal :string , status_column . type
641+ assert_equal 'unknown' , status_column . default
642+
643+ Entry . connection . change_column :entries , :status , :text , :default => 'new'
644+
645+ Entry . reset_column_information
646+ status_column = Entry . columns . find { |c | c . name == 'status' }
647+ assert_equal :text , status_column . type
648+ assert_equal 'new' , status_column . default
649+ end
650+
621651 def test_add_null_column_with_nil_default
622652 # You must specify a default value with most databases
623653 if ActiveRecord ::Base . connection . adapter_name =~ /mysql/i
@@ -1164,6 +1194,7 @@ def test_select_rows
11641194 when 'id' then assert_not_nil row [ i ]
11651195 when 'title' then assert_equal 'title 1' , row [ i ]
11661196 when 'content' then assert_equal 'content 1' , row [ i ]
1197+ when 'status' then assert_equal 'unknown' , row [ i ]
11671198 when 'user_id'
11681199 if defined? JRUBY_VERSION
11691200 assert_equal user . id , row [ i ]
@@ -1182,6 +1213,7 @@ def test_select_rows
11821213 when 'id' then assert_not_nil row [ i ]
11831214 when 'title' then assert_equal 'title 2' , row [ i ]
11841215 when 'content' then assert_equal 'content 2' , row [ i ]
1216+ when 'status' then assert_equal 'unknown' , row [ i ]
11851217 when 'user_id'
11861218 if defined? JRUBY_VERSION
11871219 assert_equal user . id , row [ i ]
0 commit comments