|
9 | 9 |
|
10 | 10 | before do |
11 | 11 | prepare_destination |
12 | | - allow(generator_instance).to receive(:invoke) |
13 | 12 | invoke generator_instance |
14 | 13 | end |
15 | 14 |
|
16 | 15 | context "when using default resource name" do |
17 | 16 | let(:generator_instance) { generator } |
18 | 17 |
|
19 | | - it "invokes the active_record:migration generator with correct arguments" do |
20 | | - expect(generator).to have_received(:invoke).with("active_record:migration", |
21 | | - ["add_webauthn_id_to_users", "webauthn_id:string:uniq"]) |
| 18 | + it "creates a migration that adds webauthn_id to users" do |
| 19 | + assert_migration "db/migrate/add_webauthn_id_to_users.rb" do |migration| |
| 20 | + assert_match(/add_column :users, :webauthn_id, :string/, migration) |
| 21 | + assert_match(/add_index :users, :webauthn_id, unique: true/, migration) |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + it "creates a migration that backfills existing records" do |
| 26 | + assert_migration "db/migrate/add_webauthn_id_to_users.rb" do |migration| |
| 27 | + assert_match(/SELECT id FROM users WHERE webauthn_id IS NULL/, migration) |
| 28 | + assert_match(/WebAuthn\.generate_user_id/, migration) |
| 29 | + end |
22 | 30 | end |
23 | 31 | end |
24 | 32 |
|
25 | 33 | context "when using a custom resource name" do |
26 | 34 | let(:generator_instance) { generator([destination_root], ["--resource_name=admin"]) } |
27 | 35 |
|
28 | | - it "invokes the active_record:migration generator with correct arguments" do |
29 | | - expect(generator).to have_received(:invoke).with("active_record:migration", |
30 | | - ["add_webauthn_id_to_admins", "webauthn_id:string:uniq"]) |
| 36 | + it "creates a migration that adds webauthn_id to admins" do |
| 37 | + assert_migration "db/migrate/add_webauthn_id_to_admins.rb" do |migration| |
| 38 | + assert_match(/add_column :admins, :webauthn_id, :string/, migration) |
| 39 | + assert_match(/add_index :admins, :webauthn_id, unique: true/, migration) |
| 40 | + end |
31 | 41 | end |
32 | 42 | end |
33 | 43 | end |
0 commit comments