Skip to content

Commit

Permalink
fixup! Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-snag2 committed Apr 29, 2024
1 parent 3fd2748 commit de6e2ef
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions spec/arproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def push(*args)
def calls
@calls
end

def clear
@calls = []
end
end

def execute(sql, name, **kwargs)
Expand All @@ -189,6 +193,8 @@ def execute(sql, name, **kwargs)
end
end

class User < ActiveRecord::Base; end

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

Expand All @@ -198,14 +204,24 @@ def execute(sql, name, **kwargs)
config.use ProxyX
end
Arproxy.enable!

con = ActiveRecord::Base.connection
con.execute 'DROP TABLE IF EXISTS users'
con.execute <<-DDL
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL
)
DDL

ProxyX.clear
end

subject { connection.execute "SHOW DATABASES", "NAME" }
let(:connection) { ActiveRecord::Base.connection }
subject { User.create(name: 'test') }

it do
expect(subject.to_a).to include(["ar_test"])
expect(ProxyX.calls.last).to include('SHOW DATABASES')
expect(subject).to be_an_instance_of(User)
expect(ProxyX.calls).to include(["INSERT INTO `users` (`name`) VALUES ('test')", "User Create", an_instance_of(Hash)])
end
end
end

0 comments on commit de6e2ef

Please sign in to comment.