mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
tests, favor public API over inspecting columns where possible.
This is a follow up to07786c5e75
andcd2596f55e
This commit is contained in:
parent
c9a5ed22d5
commit
bec9e83359
3 changed files with 20 additions and 23 deletions
|
@ -20,9 +20,9 @@ class DefaultTest < ActiveRecord::TestCase
|
|||
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
def test_multiline_default_text
|
||||
record = Default.new
|
||||
# older postgres versions represent the default with escapes ("\\012" for a newline)
|
||||
assert( "--- []\n\n" == Default.columns_hash['multiline_default'].default ||
|
||||
"--- []\\012\\012" == Default.columns_hash['multiline_default'].default)
|
||||
assert("--- []\n\n" == record.multiline_default || "--- []\\012\\012" == record.multiline_default)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ class DefaultNumbersTest < ActiveRecord::TestCase
|
|||
|
||||
def test_default_negative_integer
|
||||
record = DefaultNumber.new
|
||||
assert_equal -5, record.negative_integer
|
||||
assert_equal (-5), record.negative_integer
|
||||
assert_equal "-5", record.negative_integer_before_type_cast
|
||||
end
|
||||
|
||||
|
@ -122,19 +122,21 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
|
|||
def test_mysql_text_not_null_defaults_non_strict
|
||||
using_strict(false) do
|
||||
with_text_blob_not_null_table do |klass|
|
||||
assert_equal '', klass.columns_hash['non_null_blob'].default
|
||||
assert_equal '', klass.columns_hash['non_null_text'].default
|
||||
record = klass.new
|
||||
assert_equal '', record.non_null_blob
|
||||
assert_equal '', record.non_null_text
|
||||
|
||||
assert_nil klass.columns_hash['null_blob'].default
|
||||
assert_nil klass.columns_hash['null_text'].default
|
||||
assert_nil record.null_blob
|
||||
assert_nil record.null_text
|
||||
|
||||
instance = klass.create!
|
||||
record.save!
|
||||
record.reload
|
||||
|
||||
assert_equal '', instance.non_null_text
|
||||
assert_equal '', instance.non_null_blob
|
||||
assert_equal '', record.non_null_text
|
||||
assert_equal '', record.non_null_blob
|
||||
|
||||
assert_nil instance.null_text
|
||||
assert_nil instance.null_blob
|
||||
assert_nil record.null_text
|
||||
assert_nil record.null_blob
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -142,10 +144,11 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
|
|||
def test_mysql_text_not_null_defaults_strict
|
||||
using_strict(true) do
|
||||
with_text_blob_not_null_table do |klass|
|
||||
assert_nil klass.columns_hash['non_null_blob'].default
|
||||
assert_nil klass.columns_hash['non_null_text'].default
|
||||
assert_nil klass.columns_hash['null_blob'].default
|
||||
assert_nil klass.columns_hash['null_text'].default
|
||||
record = klass.new
|
||||
assert_nil record.non_null_blob
|
||||
assert_nil record.non_null_text
|
||||
assert_nil record.null_blob
|
||||
assert_nil record.null_text
|
||||
|
||||
assert_raises(ActiveRecord::StatementInvalid) { klass.create }
|
||||
end
|
||||
|
|
|
@ -32,10 +32,7 @@ create sequence test_oracle_defaults_seq minvalue 10000
|
|||
fixed_time date default TO_DATE('2004-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),
|
||||
char1 varchar2(1) default 'Y',
|
||||
char2 varchar2(50) default 'a varchar field',
|
||||
char3 clob default 'a text field',
|
||||
positive_integer integer default 1,
|
||||
negative_integer integer default -1,
|
||||
decimal_number number(3,2) default 2.78
|
||||
char3 clob default 'a text field'
|
||||
)
|
||||
SQL
|
||||
execute "create sequence defaults_seq minvalue 10000"
|
||||
|
|
|
@ -32,10 +32,7 @@ ActiveRecord::Schema.define do
|
|||
char1 char(1) default 'Y',
|
||||
char2 character varying(50) default 'a varchar field',
|
||||
char3 text default 'a text field',
|
||||
positive_integer integer default 1,
|
||||
negative_integer integer default -1,
|
||||
bigint_default bigint default 0::bigint,
|
||||
decimal_number decimal(3,2) default 2.78,
|
||||
multiline_default text DEFAULT '--- []
|
||||
|
||||
'::text
|
||||
|
|
Loading…
Reference in a new issue