@@ -153,172 +153,6 @@ class ::TestEmployee < ActiveRecord::Base; end
153
153
154
154
end
155
155
156
- describe "create table with primary key trigger" do
157
- def create_table_with_trigger ( options = { } )
158
- options . merge! primary_key_trigger : true , force : true
159
- schema_define do
160
- create_table :test_employees , options do |t |
161
- t . string :first_name
162
- t . string :last_name
163
- end
164
- end
165
- end
166
-
167
- def create_table_and_separately_trigger ( options = { } )
168
- options . merge! force : true
169
- schema_define do
170
- create_table :test_employees , options do |t |
171
- t . string :first_name
172
- t . string :last_name
173
- end
174
- add_primary_key_trigger :test_employees , options
175
- end
176
- end
177
-
178
- def drop_table_with_trigger ( options = { } )
179
- seq_name = options [ :sequence_name ]
180
- schema_define do
181
- drop_table :test_employees , ( seq_name ? { sequence_name : seq_name } : { } )
182
- end
183
- Object . send ( :remove_const , "TestEmployee" )
184
- ActiveRecord ::Base . clear_cache!
185
- end
186
-
187
- describe "with default primary key" do
188
- before ( :all ) do
189
- @conn = ActiveRecord ::Base . connection
190
- create_table_with_trigger
191
- class ::TestEmployee < ActiveRecord ::Base
192
- end
193
- end
194
-
195
- after ( :all ) do
196
- drop_table_with_trigger
197
- end
198
-
199
- it "should populate primary key using trigger" do
200
- expect do
201
- @conn . execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
202
- end . not_to raise_error
203
- end
204
-
205
- it "should return new key value using connection insert method" do
206
- insert_id = @conn . insert ( "INSERT INTO test_employees (first_name) VALUES ('Raimonds')" , nil , "id" )
207
- expect ( @conn . select_value ( "SELECT test_employees_seq.currval FROM dual" ) ) . to eq ( insert_id )
208
- end
209
-
210
- it "should create new record for model" do
211
- e = TestEmployee . create! ( first_name : "Raimonds" )
212
- expect ( @conn . select_value ( "SELECT test_employees_seq.currval FROM dual" ) ) . to eq ( e . id )
213
- end
214
-
215
- it "should not generate NoMethodError for :returning_id:Symbol" do
216
- set_logger
217
- @conn . reconnect! unless @conn . active?
218
- @conn . insert ( "INSERT INTO test_employees (first_name) VALUES ('Yasuo')" , nil , "id" )
219
- expect ( @logger . output ( :error ) ) . not_to match ( /^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/ )
220
- clear_logger
221
- end
222
-
223
- end
224
-
225
- describe "with separate creation of primary key trigger" do
226
- before ( :all ) do
227
- ActiveRecord ::Base . establish_connection ( CONNECTION_PARAMS )
228
- @conn = ActiveRecord ::Base . connection
229
- create_table_and_separately_trigger
230
- class ::TestEmployee < ActiveRecord ::Base
231
- end
232
- end
233
-
234
- after ( :all ) do
235
- drop_table_with_trigger
236
- end
237
-
238
- it "should populate primary key using trigger" do
239
- expect do
240
- @conn . execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
241
- end . not_to raise_error
242
- end
243
-
244
- it "should return new key value using connection insert method" do
245
- insert_id = @conn . insert ( "INSERT INTO test_employees (first_name) VALUES ('Raimonds')" , nil , "id" )
246
- expect ( @conn . select_value ( "SELECT test_employees_seq.currval FROM dual" ) ) . to eq ( insert_id )
247
- end
248
-
249
- it "should create new record for model" do
250
- e = TestEmployee . create! ( first_name : "Raimonds" )
251
- expect ( @conn . select_value ( "SELECT test_employees_seq.currval FROM dual" ) ) . to eq ( e . id )
252
- end
253
- end
254
-
255
- describe "with non-default primary key and non-default sequence name" do
256
- before ( :all ) do
257
- ActiveRecord ::Base . establish_connection ( CONNECTION_PARAMS )
258
- @conn = ActiveRecord ::Base . connection
259
- @primary_key = "employee_id"
260
- @sequence_name = "test_employees_s"
261
- create_table_with_trigger ( primary_key : @primary_key , sequence_name : @sequence_name )
262
- class ::TestEmployee < ActiveRecord ::Base
263
- self . primary_key = "employee_id"
264
- end
265
- end
266
-
267
- after ( :all ) do
268
- drop_table_with_trigger ( sequence_name : @sequence_name )
269
- end
270
-
271
- it "should populate primary key using trigger" do
272
- expect do
273
- @conn . execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
274
- end . not_to raise_error
275
- end
276
-
277
- it "should return new key value using connection insert method" do
278
- insert_id = @conn . insert ( "INSERT INTO test_employees (first_name) VALUES ('Raimonds')" , nil , @primary_key )
279
- expect ( @conn . select_value ( "SELECT #{ @sequence_name } .currval FROM dual" ) ) . to eq ( insert_id )
280
- end
281
-
282
- it "should create new record for model with autogenerated sequence option" do
283
- e = TestEmployee . create! ( first_name : "Raimonds" )
284
- expect ( @conn . select_value ( "SELECT #{ @sequence_name } .currval FROM dual" ) ) . to eq ( e . id )
285
- end
286
- end
287
-
288
- describe "with non-default sequence name and non-default trigger name" do
289
- before ( :all ) do
290
- ActiveRecord ::Base . establish_connection ( CONNECTION_PARAMS )
291
- @conn = ActiveRecord ::Base . connection
292
- @sequence_name = "test_employees_s"
293
- create_table_with_trigger ( sequence_name : @sequence_name , trigger_name : "test_employees_t1" )
294
- class ::TestEmployee < ActiveRecord ::Base
295
- self . sequence_name = :autogenerated
296
- end
297
- end
298
-
299
- after ( :all ) do
300
- drop_table_with_trigger ( sequence_name : @sequence_name )
301
- end
302
-
303
- it "should populate primary key using trigger" do
304
- expect do
305
- @conn . execute "INSERT INTO test_employees (first_name) VALUES ('Raimonds')"
306
- end . not_to raise_error
307
- end
308
-
309
- it "should return new key value using connection insert method" do
310
- insert_id = @conn . insert ( "INSERT INTO test_employees (first_name) VALUES ('Raimonds')" , nil , "id" )
311
- expect ( @conn . select_value ( "SELECT #{ @sequence_name } .currval FROM dual" ) ) . to eq ( insert_id )
312
- end
313
-
314
- it "should create new record for model with autogenerated sequence option" do
315
- e = TestEmployee . create! ( first_name : "Raimonds" )
316
- expect ( @conn . select_value ( "SELECT #{ @sequence_name } .currval FROM dual" ) ) . to eq ( e . id )
317
- end
318
- end
319
-
320
- end
321
-
322
156
describe "table and column comments" do
323
157
324
158
def create_test_employees_table ( table_comment = nil , column_comments = { } )
@@ -474,44 +308,6 @@ class ::TestEmployee < ActiveRecord::Base; end
474
308
475
309
end
476
310
477
- describe "create triggers" do
478
-
479
- before ( :all ) do
480
- @conn = ActiveRecord ::Base . connection
481
- schema_define do
482
- create_table :test_employees do |t |
483
- t . string :first_name
484
- t . string :last_name
485
- end
486
- end
487
- class ::TestEmployee < ActiveRecord ::Base ; end
488
- end
489
-
490
- after ( :all ) do
491
- schema_define do
492
- drop_table :test_employees
493
- end
494
- Object . send ( :remove_const , "TestEmployee" )
495
- ActiveRecord ::Base . clear_cache!
496
- end
497
-
498
- it "should create table trigger with :new reference" do
499
- expect do
500
- @conn . execute <<-SQL
501
- CREATE OR REPLACE TRIGGER test_employees_pkt
502
- BEFORE INSERT ON test_employees FOR EACH ROW
503
- BEGIN
504
- IF inserting THEN
505
- IF :new.id IS NULL THEN
506
- SELECT test_employees_seq.NEXTVAL INTO :new.id FROM dual;
507
- END IF;
508
- END IF;
509
- END;
510
- SQL
511
- end . not_to raise_error
512
- end
513
- end
514
-
515
311
describe "add index" do
516
312
before ( :all ) do
517
313
@conn = ActiveRecord ::Base . connection
0 commit comments