diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-12-06 07:06:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-06 07:06:32 -0500 |
commit | cf6c2948d5e0e0d40a03f6858179a659a0a6ed7a (patch) | |
tree | 7a45e553072f3b7d262927b6a87f07da9b1252cd /activerecord/test/cases/migration | |
parent | 5a44a01c7b6b3b168978a7c1e3ecd6e83d12679b (diff) | |
parent | b270bc4ad021f051214420de1278627b1924b3b3 (diff) | |
download | rails-cf6c2948d5e0e0d40a03f6858179a659a0a6ed7a.tar.gz rails-cf6c2948d5e0e0d40a03f6858179a659a0a6ed7a.tar.bz2 rails-cf6c2948d5e0e0d40a03f6858179a659a0a6ed7a.zip |
Merge pull request #25451 from kamipo/translate_not_null_violation_to_specific_exception
Translate NOT NULL violation to the specific exception
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/change_schema_test.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb index bdb90eaa74..03f9c4a9ed 100644 --- a/activerecord/test/cases/migration/change_schema_test.rb +++ b/activerecord/test/cases/migration/change_schema_test.rb @@ -43,7 +43,7 @@ module ActiveRecord t.column :foo, :string, null: false end - assert_raises(ActiveRecord::StatementInvalid) do + assert_raises(ActiveRecord::NotNullViolation) do connection.execute "insert into testings (foo) values (NULL)" end end @@ -233,7 +233,7 @@ module ActiveRecord end connection.add_column :testings, :bar, :string, null: false - assert_raise(ActiveRecord::StatementInvalid) do + assert_raise(ActiveRecord::NotNullViolation) do connection.execute "insert into testings (foo, bar) values ('hello', NULL)" end end @@ -244,12 +244,16 @@ module ActiveRecord t.column :foo, :string end - con = connection - connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}) values (1, 'hello')" - assert_nothing_raised { connection.add_column :testings, :bar, :string, null: false, default: "default" } + quoted_id = connection.quote_column_name("id") + quoted_foo = connection.quote_column_name("foo") + quoted_bar = connection.quote_column_name("bar") + connection.execute("insert into testings (#{quoted_id}, #{quoted_foo}) values (1, 'hello')") + assert_nothing_raised do + connection.add_column :testings, :bar, :string, null: false, default: "default" + end - assert_raises(ActiveRecord::StatementInvalid) do - connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}, #{con.quote_column_name('bar')}) values (2, 'hello', NULL)" + assert_raises(ActiveRecord::NotNullViolation) do + connection.execute("insert into testings (#{quoted_id}, #{quoted_foo}, #{quoted_bar}) values (2, 'hello', NULL)") end end |