aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-03-11 11:25:47 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-03-11 11:25:47 -0300
commitc9219a75fc03cb5e7e1a267659426c894bc8da42 (patch)
tree94301dc8fd9a399e93ef49a2697a01875a83de68 /activerecord/test
parent36db762a78188e2eeef6a3cfb36d8c442cd03f01 (diff)
parent6b6a01c52bacb2df2914029309144eacff25a3de (diff)
downloadrails-c9219a75fc03cb5e7e1a267659426c894bc8da42.tar.gz
rails-c9219a75fc03cb5e7e1a267659426c894bc8da42.tar.bz2
rails-c9219a75fc03cb5e7e1a267659426c894bc8da42.zip
Merge pull request #23677 from kamipo/passing_table_name_to_column_initialize
Passing `table_name` to `Column#initialize` to avoid `instance_variable_set`
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/adapters/postgresql/serial_test.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/serial_test.rb b/activerecord/test/cases/adapters/postgresql/serial_test.rb
index 2d6f1e0910..76bcec9672 100644
--- a/activerecord/test/cases/adapters/postgresql/serial_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/serial_test.rb
@@ -10,6 +10,7 @@ class PostgresqlSerialTest < ActiveRecord::PostgreSQLTestCase
@connection = ActiveRecord::Base.connection
@connection.create_table "postgresql_serials", force: true do |t|
t.serial :seq
+ t.integer :serials_id, default: -> { "nextval('postgresql_serials_id_seq')" }
end
end
@@ -24,10 +25,22 @@ class PostgresqlSerialTest < ActiveRecord::PostgreSQLTestCase
assert column.serial?
end
+ def test_not_serial_column
+ column = PostgresqlSerial.columns_hash["serials_id"]
+ assert_equal :integer, column.type
+ assert_equal "integer", column.sql_type
+ assert_not column.serial?
+ end
+
def test_schema_dump_with_shorthand
output = dump_table_schema "postgresql_serials"
assert_match %r{t\.serial\s+"seq",\s+null: false$}, output
end
+
+ def test_schema_dump_with_not_serial
+ output = dump_table_schema "postgresql_serials"
+ assert_match %r{t\.integer\s+"serials_id",\s+default: -> \{ "nextval\('postgresql_serials_id_seq'::regclass\)" \}$}, output
+ end
end
class PostgresqlBigSerialTest < ActiveRecord::PostgreSQLTestCase
@@ -39,6 +52,7 @@ class PostgresqlBigSerialTest < ActiveRecord::PostgreSQLTestCase
@connection = ActiveRecord::Base.connection
@connection.create_table "postgresql_big_serials", force: true do |t|
t.bigserial :seq
+ t.bigint :serials_id, default: -> { "nextval('postgresql_big_serials_id_seq')" }
end
end
@@ -53,8 +67,20 @@ class PostgresqlBigSerialTest < ActiveRecord::PostgreSQLTestCase
assert column.serial?
end
+ def test_not_bigserial_column
+ column = PostgresqlBigSerial.columns_hash["serials_id"]
+ assert_equal :integer, column.type
+ assert_equal "bigint", column.sql_type
+ assert_not column.serial?
+ end
+
def test_schema_dump_with_shorthand
output = dump_table_schema "postgresql_big_serials"
assert_match %r{t\.bigserial\s+"seq",\s+null: false$}, output
end
+
+ def test_schema_dump_with_not_bigserial
+ output = dump_table_schema "postgresql_big_serials"
+ assert_match %r{t\.integer\s+"serials_id",\s+limit: 8,\s+default: -> \{ "nextval\('postgresql_big_serials_id_seq'::regclass\)" \}$}, output
+ end
end