@@ -62,6 +62,48 @@ class ReferencesForeignKeyInCreateTest < ActiveRecord::TestCase
62
62
assert_equal ( [ [ "testings" , "testing_parents" , "parent_id" ] ] ,
63
63
fks . map { |fk | [ fk . from_table , fk . to_table , fk . column ] } )
64
64
end
65
+
66
+ if current_adapter? ( :PostgreSQLAdapter )
67
+ test "deferrable: false option can be passed" do
68
+ @connection . create_table :testings do |t |
69
+ t . references :testing_parent , foreign_key : { deferrable : false }
70
+ end
71
+
72
+ fks = @connection . foreign_keys ( "testings" )
73
+ assert_equal ( [ [ "testings" , "testing_parents" , "testing_parent_id" , false ] ] ,
74
+ fks . map { |fk | [ fk . from_table , fk . to_table , fk . column , fk . deferrable ] } )
75
+ end
76
+
77
+ test "deferrable: :immediate option can be passed" do
78
+ @connection . create_table :testings do |t |
79
+ t . references :testing_parent , foreign_key : { deferrable : :immediate }
80
+ end
81
+
82
+ fks = @connection . foreign_keys ( "testings" )
83
+ assert_equal ( [ [ "testings" , "testing_parents" , "testing_parent_id" , :immediate ] ] ,
84
+ fks . map { |fk | [ fk . from_table , fk . to_table , fk . column , fk . deferrable ] } )
85
+ end
86
+
87
+ test "deferrable: :deferred option can be passed" do
88
+ @connection . create_table :testings do |t |
89
+ t . references :testing_parent , foreign_key : { deferrable : :deferred }
90
+ end
91
+
92
+ fks = @connection . foreign_keys ( "testings" )
93
+ assert_equal ( [ [ "testings" , "testing_parents" , "testing_parent_id" , :deferred ] ] ,
94
+ fks . map { |fk | [ fk . from_table , fk . to_table , fk . column , fk . deferrable ] } )
95
+ end
96
+
97
+ test "deferrable and on_(delete|update) option can be passed" do
98
+ @connection . create_table :testings do |t |
99
+ t . references :testing_parent , foreign_key : { on_update : :cascade , on_delete : :cascade , deferrable : :immediate }
100
+ end
101
+
102
+ fks = @connection . foreign_keys ( "testings" )
103
+ assert_equal ( [ [ "testings" , "testing_parents" , "testing_parent_id" , :cascade , :cascade , :immediate ] ] ,
104
+ fks . map { |fk | [ fk . from_table , fk . to_table , fk . column , fk . on_delete , fk . on_update , fk . deferrable ] } )
105
+ end
106
+ end
65
107
end
66
108
end
67
109
end
0 commit comments