-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhole_spec.rb
More file actions
48 lines (38 loc) · 1.12 KB
/
whole_spec.rb
File metadata and controls
48 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "sequel"
require "sequel/adapters/mysql"
module Sequel
module MySQLPreviewWhole
class Database < Sequel::MySQL::Database
def execute(sql, opts={})
if sql.match(/^SELECT/) || sql.match(/^DESCRIBE/)
puts "RUNNING: #{sql}"
super(sql, opts)
else
puts "PREVIEW: #{sql}"
end
end
end
end
end
describe Sequel::MySQLPreviewWhole::Database do
let(:connection) { stub("connection") }
before { subject.stub(:synchronize).and_yield(connection) }
it "should allow SELECTs" do
sql = "SELECT * FROM sometable"
subject.should_receive(:puts).with(/^RUNNING:/)
subject.should_receive(:_execute).with(connection, sql, anything)
subject.execute(sql)
end
it "should not allow DELETEs" do
sql = "DELETE FROM sometable"
subject.should_receive(:puts).with(/^PREVIEW:/)
subject.should_not_receive(:_execute)
subject.execute(sql)
end
it "should not allow DROPs" do
sql = "DROP TABLE sometable"
subject.should_receive(:puts).with(/^PREVIEW:/)
subject.should_not_receive(:_execute)
subject.execute(sql)
end
end