forked from cookpad/arproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,10 @@ def push(*args) | |
def calls | ||
@calls | ||
end | ||
|
||
def clear | ||
@calls = [] | ||
end | ||
end | ||
|
||
def execute(sql, name, **kwargs) | ||
|
@@ -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") | ||
|
||
|
@@ -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 |