|
40 | 40 | connection.schemas_whitelist.push('legacy')
|
41 | 41 | expect(connection.schema_exists?(:legacy)).to be_truthy
|
42 | 42 | end
|
| 43 | + |
| 44 | + context 'reverting' do |
| 45 | + let(:migration) { ActiveRecord::Migration::Current.new('Testing') } |
| 46 | + |
| 47 | + before { connection.create_schema(:legacy) } |
| 48 | + |
| 49 | + it 'reverts the creation of a schema' do |
| 50 | + expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy |
| 51 | + migration.revert { migration.connection.create_schema(:legacy) } |
| 52 | + expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey |
| 53 | + end |
| 54 | + |
| 55 | + it 'reverts the creation of a table' do |
| 56 | + connection.create_table(:users, schema: :legacy) { |t| t.string(:name) } |
| 57 | + |
| 58 | + expect(connection.table_exists?('legacy.users')).to be_truthy |
| 59 | + migration.revert { migration.connection.create_table(:users, schema: :legacy) } |
| 60 | + expect(connection.table_exists?('legacy.users')).to be_falsey |
| 61 | + end |
| 62 | + end |
43 | 63 | end
|
44 | 64 |
|
45 | 65 | context 'on schema' do
|
|
86 | 106 |
|
87 | 107 | context 'on relation' do
|
88 | 108 | let(:model) { Internal::User }
|
| 109 | + let(:table_name) { Torque::PostgreSQL::TableName.new(model, 'users') } |
89 | 110 |
|
90 | 111 | it 'adds the schema to the query' do
|
| 112 | + model.reset_table_name |
| 113 | + expect(table_name.to_s).to eq('internal.users') |
91 | 114 | expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
92 | 115 | end
|
93 | 116 |
|
94 | 117 | it 'can load the schema from the module' do
|
95 | 118 | allow(Internal).to receive(:schema).and_return('internal')
|
96 | 119 | allow(model).to receive(:schema).and_return(nil)
|
97 | 120 |
|
| 121 | + model.reset_table_name |
| 122 | + expect(table_name.to_s).to eq('internal.users') |
98 | 123 | expect(model.all.to_sql).to match(/FROM "internal"."users"/)
|
99 | 124 | end
|
| 125 | + |
| 126 | + it 'does not change anything if the model has not configured a schema' do |
| 127 | + allow(model).to receive(:schema).and_return(nil) |
| 128 | + |
| 129 | + model.reset_table_name |
| 130 | + expect(table_name.to_s).to eq('users') |
| 131 | + expect(model.all.to_sql).to match(/FROM "users"/) |
| 132 | + end |
100 | 133 | end
|
101 | 134 | end
|
0 commit comments