Skip to content

Commit 6bac30e

Browse files
committed
Add primary_key_trigger_spec.rb (mirror of identity_primary_key_spec.rb)
Lock down the `primary_key_trigger:` contract introduced in the preceding commits. Structure mirrors the existing `identity_primary_key_spec.rb` (the Phase 1 sibling, #2579) so a reader who knows one suite finds familiar shape in the other. Coverage groups: * Default behavior (no `primary_key_trigger:`) — confirms the existing sequence-only path still works and prefetch stays enabled. `primary_key_trigger: false` is exercised separately to pin the falsy-value contract. * `primary_key_trigger: true` — exercises the full opt-in: sequence + trigger creation, prefetch_primary_key? short-circuit, ActiveRecord create! without supplying id (trigger fills via NEXTVAL), explicit id supplied (trigger leaves it alone because :new.id is non-NULL), and the `:trigger_name` override. * `add_column` with `primary_key_trigger: true` — pre-2018 routed through `create_sequence_and_trigger` so the trigger fired for `add_column :foo, :id, :primary_key, primary_key_trigger: true` too. This commit's `create_pk_trigger` call site in `add_column` preserves that. * `prefetch_primary_key?` cache invalidation — symmetric with the identity suite. Drop-and-recreate flips the verdict for the same table name, in both directions. * Invalid combinations — `id: false`, `id: :integer`, `id: :uuid`, composite primary key, and `identity: true` (mutual exclusion). All raise `ArgumentError` from `validate_primary_key_trigger_options!`. * Schema dumper roundtrip — the four cells of the matrix `{trigger-backed, plain, identity} × {default trigger name, custom trigger name}`. Restored from the 2018 removal (61f8a30), updated for the new API: * "low-level INSERT with primary_key_trigger: true" — the pre-2018 "create table with primary key trigger" describe block exercised raw `@conn.execute "INSERT ..."` and `@conn.insert(SQL, nil, "id")` calls (the connection-level API rather than the AR record API). Bringing those examples back catches regressions in the RETURNING wiring without going through the full ActiveRecord create! path. * "low-level INSERT — does not raise NoMethodError for :returning_id Symbol when logging" — guards the regression reported in #2426 where the bind-array contained a Symbol that the logging path expected to respond to `name`. The fix shipped as part of #2579, but the spec was deleted in 61f8a30 alongside the trigger feature; restoring it pins the fix against future drift. * "with non-default :primary_key" / "with non-default :sequence_name" — pre-2018 had separate describe blocks for these combinations. Brought back in their new shape — both options live on `create_table primary_key_trigger: true` (no separate `add_primary_key_trigger` call, since this PR intentionally doesn't restore that public method). * "manual trigger creation via raw DDL" — the pre-2018 "create triggers" test that verified `@conn.execute` accepts the multi-line `CREATE OR REPLACE TRIGGER ... BEGIN ... END;` PL/SQL block. Closes the loop on D2 (the design decision to emit the trigger as a single PL/SQL block rather than wrapping in `EXECUTE IMMEDIATE`): if this test breaks under a future Oracle version or driver change, we know the assumption no longer holds. Specs that did not come back from 61f8a30: * `add_primary_key_trigger` and `has_primary_key_trigger?` — pre-2018 public methods that this PR intentionally does not restore. The Phase 3 issue (#2597) only specifies the `create_table primary_key_trigger:` form; users who wanted the separate `add_primary_key_trigger :tbl, options` shape can call `connection.send(:create_pk_trigger, :tbl, options)` (with the caveat that the private API may change). * "with separate creation of primary key trigger" — exercised `add_primary_key_trigger` inside the same describe; not applicable here since we're not restoring that public method. * schema dumper format `add_primary_key_trigger "test_posts"` — the pre-2018 dumper emitted a separate line after `create_table` for the trigger. The new dumper emits `, primary_key_trigger: true` inline (matching the identity-style pattern), which the "schema_dumper roundtrip" describe in this file covers. Tracked in #2597.
1 parent 943f1cb commit 6bac30e

1 file changed

Lines changed: 440 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)