diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-12-01 16:49:13 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-12-01 16:57:48 +0100 |
commit | bec9e8335915c8f752b57971185d6731384534d1 (patch) | |
tree | b21c584a9cddfdd24a481409758c60c4dffed1f2 /activerecord | |
parent | c9a5ed22d518a4c526457302f6a5e8abd152a57f (diff) | |
download | rails-bec9e8335915c8f752b57971185d6731384534d1.tar.gz rails-bec9e8335915c8f752b57971185d6731384534d1.tar.bz2 rails-bec9e8335915c8f752b57971185d6731384534d1.zip |
tests, favor public API over inspecting columns where possible.
This is a follow up to https://github.com/rails/rails/commit/07786c5e75a7b0afdf318063510af6b475e3e04c
and https://github.com/rails/rails/commit/cd2596f55e88fe659592612a793c4f4aa723c9be
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/defaults_test.rb | 35 | ||||
-rw-r--r-- | activerecord/test/schema/oracle_specific_schema.rb | 5 | ||||
-rw-r--r-- | activerecord/test/schema/postgresql_specific_schema.rb | 3 |
3 files changed, 20 insertions, 23 deletions
diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index 5d88788482..1892958270 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -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 diff --git a/activerecord/test/schema/oracle_specific_schema.rb b/activerecord/test/schema/oracle_specific_schema.rb index a7817772f4..264d9b8910 100644 --- a/activerecord/test/schema/oracle_specific_schema.rb +++ b/activerecord/test/schema/oracle_specific_schema.rb @@ -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" diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb index 7c3b170c08..7c44409d34 100644 --- a/activerecord/test/schema/postgresql_specific_schema.rb +++ b/activerecord/test/schema/postgresql_specific_schema.rb @@ -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 |