Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-snag2 committed Apr 29, 2024
1 parent 001c783 commit 3fd2748
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
appraise 'ar-6.1' do
gem 'activerecord', '~> 6.1.0'
gem 'mysql2'
end

appraise 'ar-7.0' do
gem 'activerecord', '~> 7.0.0'
gem 'mysql2'
end

appraise 'ar-7.1' do
gem 'activerecord', '~> 7.1.0'
gem 'mysql2'
end
1 change: 1 addition & 0 deletions gemfiles/ar_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
source "https://rubygems.org"

gem "activerecord", "~> 6.1.0"
gem "mysql2"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/ar_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"
gem "mysql2"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/ar_7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
source "https://rubygems.org"

gem "activerecord", "~> 7.1.0"
gem "mysql2"

gemspec path: "../"
39 changes: 39 additions & 0 deletions spec/arproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,43 @@ def execute(sql, name)
it { expect(thr1.value).not_to eq(thr2.value) }
end
end

context 'use mysql adapter' do
class ProxyX < Arproxy::Base
class << self
def push(*args)
@calls ||= []
@calls << args
end

def calls
@calls
end
end

def execute(sql, name, **kwargs)
ProxyX.push(sql, name, kwargs)
super
end
end

before do
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || "mysql2://[email protected]/ar_test")

Arproxy.clear_configuration
Arproxy.configure do |config|
config.adapter = 'mysql2'
config.use ProxyX
end
Arproxy.enable!
end

subject { connection.execute "SHOW DATABASES", "NAME" }
let(:connection) { ActiveRecord::Base.connection }

it do
expect(subject.to_a).to include(["ar_test"])
expect(ProxyX.calls.last).to include('SHOW DATABASES')
end
end
end

0 comments on commit 3fd2748

Please sign in to comment.