mysql2-cs-bind 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Brian Lopez - http://github.com/brianmario
1
+ Copyright (c) 2012- TAGOMORI Satoshi - http://github.com/tagomoris
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -11,12 +11,11 @@ class Mysql2::Client
11
11
  if args.size < 1
12
12
  query(sql, options)
13
13
  else
14
- query(pseudo_bind(sql, args.flatten), options)
14
+ query(Mysql2::Client.pseudo_bind(sql, args.flatten), options)
15
15
  end
16
16
  end
17
17
 
18
- private
19
- def pseudo_bind(sql, values)
18
+ def self.pseudo_bind(sql, values)
20
19
  sql = sql.dup
21
20
 
22
21
  placeholders = []
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "mysql2-cs-bind"
5
- gem.version = "0.0.1"
5
+ gem.version = "0.0.2"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.homepage = "https://github.com/tagomoris/mysql2-cs-bind"
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
  describe Mysql2::Client do
5
5
  before(:each) do
6
6
  @client = Mysql2::Client.new
7
+ @klass = Mysql2::Client
7
8
  end
8
9
 
9
10
  it "should respond to #query" do
@@ -12,37 +13,37 @@ describe Mysql2::Client do
12
13
 
13
14
  context "#pseudo_bind" do
14
15
  it "should return query just same as argument, if without any placeholders" do
15
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x='1'", []).should eql("SELECT x,y,z FROM x WHERE x='1'")
16
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x='1'", []).should eql("SELECT x,y,z FROM x WHERE x='1'")
16
17
  end
17
18
 
18
19
  it "should return replaced query if with placeholders" do
19
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x=?", [1]).should eql("SELECT x,y,z FROM x WHERE x='1'")
20
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x=? AND y=?", [1, 'X']).should eql("SELECT x,y,z FROM x WHERE x='1' AND y='X'")
20
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [1]).should eql("SELECT x,y,z FROM x WHERE x='1'")
21
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=? AND y=?", [1, 'X']).should eql("SELECT x,y,z FROM x WHERE x='1' AND y='X'")
21
22
  end
22
23
 
23
24
  it "should raise ArgumentError if mismatch exists between placeholders and arguments" do
24
25
  expect {
25
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x", [1])
26
+ @klass.pseudo_bind("SELECT x,y,z FROM x", [1])
26
27
  }.should raise_exception(ArgumentError)
27
28
  expect {
28
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x=?", [1,2])
29
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [1,2])
29
30
  }.should raise_exception(ArgumentError)
30
31
  expect {
31
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x=? AND y=?", [1])
32
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=? AND y=?", [1])
32
33
  }.should raise_exception(ArgumentError)
33
34
  expect {
34
- @client.__send__(:pseudo_bind, "SELECT x,y,z FROM x WHERE x=?", [])
35
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [])
35
36
  }.should raise_exception(ArgumentError)
36
37
  end
37
38
 
38
39
  it "should replace placeholder with NULL about nil" do
39
- @client.__send__(:pseudo_bind, "UPDATE x SET y=? WHERE x=?", [nil,1]).should eql("UPDATE x SET y=NULL WHERE x='1'")
40
+ @klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [nil,1]).should eql("UPDATE x SET y=NULL WHERE x='1'")
40
41
  end
41
42
 
42
43
  it "should replace placeholder with formatted timestamp string about Time object" do
43
44
  require 'time'
44
45
  t = Time.strptime('2012/04/20 16:50:45', '%Y/%m/%d %H:%M:%S')
45
- @client.__send__(:pseudo_bind, "UPDATE x SET y=? WHERE x=?", [t,1]).should eql("UPDATE x SET y='2012-04-20 16:50:45' WHERE x='1'")
46
+ @klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [t,1]).should eql("UPDATE x SET y='2012-04-20 16:50:45' WHERE x='1'")
46
47
  end
47
48
  end
48
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2-cs-bind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: