|
6 | 6 | describe 'self.instances' do |
7 | 7 | it 'loads grants only for the managed users list' do |
8 | 8 | allow(described_class).to receive(:newer_than).and_return(false) |
9 | | - allow(described_class).to receive(:users).and_return(['unused@localhost']) |
10 | | - allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n") |
11 | | - allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular').and_return("GRANT INSERT ON `db_two`.* TO 'bob'@'localhost'\n") |
| 9 | + expect(described_class).not_to receive(:users) |
| 10 | + expect(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n") |
| 11 | + expect(described_class).not_to receive(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular') |
12 | 12 |
|
13 | 13 | instances = described_class.instances(['alice@localhost']) |
14 | 14 |
|
15 | | - expect(described_class).not_to have_received(:users) |
16 | | - expect(described_class).to have_received(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular') |
17 | | - expect(described_class).not_to have_received(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular') |
18 | 15 | expect(instances.map(&:name)).to eq(['alice@localhost/db_one.*']) |
19 | 16 | end |
20 | 17 |
|
21 | 18 | it 'falls back to full user scan when managed user list is empty' do |
22 | 19 | allow(described_class).to receive(:newer_than).and_return(false) |
23 | | - allow(described_class).to receive(:users).and_return(['alice@localhost']) |
| 20 | + expect(described_class).to receive(:users).and_return(['alice@localhost']) |
24 | 21 | allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n") |
25 | 22 |
|
26 | 23 | instances = described_class.instances([]) |
27 | 24 |
|
28 | | - expect(described_class).to have_received(:users) |
29 | 25 | expect(instances.map(&:name)).to eq(['alice@localhost/db_one.*']) |
30 | 26 | end |
31 | 27 | end |
|
45 | 41 | alice_provider = instance_double(described_class, name: 'alice@localhost/db_one.*') |
46 | 42 | bob_provider = instance_double(described_class, name: 'bob@localhost/db_one.*') |
47 | 43 |
|
48 | | - allow(described_class).to receive(:instances).with(['alice@localhost', 'bob@localhost']).and_return([alice_provider, bob_provider]) |
49 | | - allow(grant_one).to receive(:provider=) |
50 | | - allow(grant_two).to receive(:provider=) |
51 | | - allow(grant_three).to receive(:provider=) |
| 44 | + expect(described_class).to receive(:instances).with(['alice@localhost', 'bob@localhost']).and_return([alice_provider, bob_provider]) |
| 45 | + expect(grant_one).to receive(:provider=).with(alice_provider) |
| 46 | + expect(grant_two).not_to receive(:provider=) |
| 47 | + expect(grant_three).to receive(:provider=).with(bob_provider) |
52 | 48 |
|
53 | 49 | described_class.prefetch(resources) |
54 | | - |
55 | | - expect(described_class).to have_received(:instances).with(['alice@localhost', 'bob@localhost']) |
56 | | - expect(grant_one).to have_received(:provider=).with(alice_provider) |
57 | | - expect(grant_two).not_to have_received(:provider=) |
58 | | - expect(grant_three).to have_received(:provider=).with(bob_provider) |
59 | 50 | end |
60 | 51 | end |
61 | 52 | end |
0 commit comments