Sha256: 8fdc57f64044569795fa4c25a4c64d346163abea1b058d7046c594f133683681
Contents?: true
Size: 1.53 KB
Versions: 19
Compression:
Stored size: 1.53 KB
Contents
require "spec_helper" describe "Connections" do describe "Simple::SQL.connect" do before do org = create(:organization) 2.times { create(:user, organization_id: org.id) } end after do expect(User.count).to eq(2) end describe 'automatic connections' do let(:db) { Simple::SQL.connect } it 'can mix Simple::SQL inside ActiveRecord' do User.transaction do User.delete_all expect(db.ask("SELECT count(*) FROM users")).to eq(0) raise ActiveRecord::Rollback end db.transaction do db.ask("DELETE FROM users") expect(User.count).to eq(0) raise ActiveRecord::Rollback end end end describe 'explizit connections' do let(:db) { Simple::SQL.connect(::Simple::SQL::Config.determine_url) } it 'runs in separate transactions' do User.transaction do User.delete_all expect(db.ask("SELECT count(*) FROM users")).to eq(2) raise ActiveRecord::Rollback end db.transaction do db.ask("DELETE FROM users") expect(User.count).to eq(2) raise ActiveRecord::Rollback end end end end describe "Simple::SQL.disconnect!" do let(:default_db) { Simple::SQL.connect } let(:db) { Simple::SQL.connect(::Simple::SQL::Config.determine_url) } it 'disconnects everything' do Simple::SQL.disconnect! expect(ActiveRecord::Base.connection_pool.connections.length).to eq(0) end end end
Version data entries
19 entries across 19 versions & 1 rubygems