spec/tests/schema_spec.rb in torque-postgresql-3.2.1 vs spec/tests/schema_spec.rb in torque-postgresql-3.2.2

- old
+ new

@@ -38,10 +38,30 @@ expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy connection.schemas_whitelist.push('legacy') expect(connection.schema_exists?(:legacy)).to be_truthy end + + context 'reverting' do + let(:migration) { ActiveRecord::Migration::Current.new('Testing') } + + before { connection.create_schema(:legacy) } + + it 'reverts the creation of a schema' do + expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy + migration.revert { migration.connection.create_schema(:legacy) } + expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey + end + + it 'reverts the creation of a table' do + connection.create_table(:users, schema: :legacy) { |t| t.string(:name) } + + expect(connection.table_exists?('legacy.users')).to be_truthy + migration.revert { migration.connection.create_table(:users, schema: :legacy) } + expect(connection.table_exists?('legacy.users')).to be_falsey + end + end end context 'on schema' do let(:dump_result) do ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new)) @@ -84,18 +104,31 @@ end end context 'on relation' do let(:model) { Internal::User } + let(:table_name) { Torque::PostgreSQL::TableName.new(model, 'users') } it 'adds the schema to the query' do + model.reset_table_name + expect(table_name.to_s).to eq('internal.users') expect(model.all.to_sql).to match(/FROM "internal"."users"/) end it 'can load the schema from the module' do allow(Internal).to receive(:schema).and_return('internal') allow(model).to receive(:schema).and_return(nil) + model.reset_table_name + expect(table_name.to_s).to eq('internal.users') expect(model.all.to_sql).to match(/FROM "internal"."users"/) + end + + it 'does not change anything if the model has not configured a schema' do + allow(model).to receive(:schema).and_return(nil) + + model.reset_table_name + expect(table_name.to_s).to eq('users') + expect(model.all.to_sql).to match(/FROM "users"/) end end end