From da874a4af817ebeb9421934b2a4e4e0032b1234d Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 30 Jul 2005 10:16:21 +0000 Subject: Allow add_column and create_table to specify NOT NULL #1712 [emptysands@gmail.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1955 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/migration_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index 60bdf90bf4..f98986cdfa 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -50,6 +50,31 @@ if ActiveRecord::Base.connection.supports_migrations? ensure Person.connection.drop_table :testings rescue nil end + + def test_create_table_with_not_null_column + Person.connection.create_table :testings do |t| + t.column :foo, :string, :null => false + end + + assert_raises(ActiveRecord::StatementInvalid) do + Person.connection.execute "insert into testings (foo) values (NULL)" + end + ensure + Person.connection.drop_table :testings rescue nil + end + + def test_add_column_not_null + Person.connection.create_table :testings do |t| + t.column :foo, :string + end + Person.connection.add_column :testings, :bar, :string, :null => false + + assert_raises(ActiveRecord::StatementInvalid) do + Person.connection.execute "insert into testings (foo, bar) values ('hello', NULL)" + end + ensure + Person.connection.drop_table :testings rescue nil + end def test_native_types Person.delete_all -- cgit v1.2.3