kasket 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/kasket.rb CHANGED
@@ -14,7 +14,7 @@ module Kasket
14
14
  class Version
15
15
  MAJOR = 0
16
16
  MINOR = 7
17
- PATCH = 7
17
+ PATCH = 8
18
18
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
19
19
  end
20
20
 
@@ -31,11 +31,9 @@ module Kasket
31
31
 
32
32
  def kasket_key_for(attribute_value_pairs)
33
33
  key = attribute_value_pairs.map do |attribute, value|
34
- if (column = columns_hash[attribute.to_s]) && column.number?
35
- value = convert_number_column_value(value)
36
- end
37
-
38
- attribute.to_s + '=' + connection.quote(value, column)
34
+ column = columns_hash[attribute.to_s]
35
+ value = nil if value.blank?
36
+ attribute.to_s + '=' + connection.quote(column.type_cast(value), column)
39
37
  end.join('/')
40
38
 
41
39
  if key.size > (250 - kasket_key_prefix.size) || key =~ /\s/
@@ -45,18 +43,6 @@ module Kasket
45
43
  kasket_key_prefix + key
46
44
  end
47
45
 
48
- def convert_number_column_value(value)
49
- if value == false
50
- 0
51
- elsif value == true
52
- 1
53
- elsif value.is_a?(String) && value.blank?
54
- nil
55
- else
56
- value
57
- end
58
- end
59
-
60
46
  def kasket_key_for_id(id)
61
47
  kasket_key_for([['id', id]])
62
48
  end
data/test/parser_test.rb CHANGED
@@ -9,11 +9,11 @@ class ParserTest < ActiveSupport::TestCase
9
9
  end
10
10
 
11
11
  should "extract conditions" do
12
- assert_equal [[:color, "red"], [:size, "big"]], @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`color` = red AND `posts`.`size` = big)')[:attributes]
12
+ assert_equal [[:blog_id, "big"], [:title, "red"]], @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`title` = red AND `posts`.`blog_id` = big)')[:attributes]
13
13
  end
14
14
 
15
15
  should "extract required index" do
16
- assert_equal [:color, :size], @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`color` = red AND `posts`.`size` = big)')[:index]
16
+ assert_equal [:blog_id, :title], @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`title` = red AND `posts`.`blog_id` = big)')[:index]
17
17
  end
18
18
 
19
19
  should "only support queries against its model's table" do
@@ -26,7 +26,7 @@ class ParserTest < ActiveSupport::TestCase
26
26
  end
27
27
 
28
28
  should "support vaguely formatted queries" do
29
- assert @parser.parse('SELECT * FROM "posts" WHERE (color = red AND size = big)')
29
+ assert @parser.parse('SELECT * FROM "posts" WHERE (title = red AND blog_id = big)')
30
30
  end
31
31
 
32
32
  context "extract options" do
@@ -44,27 +44,27 @@ class ParserTest < ActiveSupport::TestCase
44
44
  context "unsupported queries" do
45
45
 
46
46
  should "include advanced limits" do
47
- assert !@parser.parse('SELECT * FROM `posts` WHERE (color = red AND size = big) LIMIT 2')
47
+ assert !@parser.parse('SELECT * FROM `posts` WHERE (title = red AND blog_id = big) LIMIT 2')
48
48
  end
49
49
 
50
50
  should "include joins" do
51
- assert !@parser.parse('SELECT * FROM `posts`, `trees` JOIN ON apple.tree_id = tree.id WHERE (color = red)')
51
+ assert !@parser.parse('SELECT * FROM `posts`, `trees` JOIN ON apple.tree_id = tree.id WHERE (title = red)')
52
52
  end
53
53
 
54
54
  should "include specific selects" do
55
- assert !@parser.parse('SELECT id FROM `posts` WHERE (color = red)')
55
+ assert !@parser.parse('SELECT id FROM `posts` WHERE (title = red)')
56
56
  end
57
57
 
58
58
  should "include offset" do
59
- assert !@parser.parse('SELECT * FROM `posts` WHERE (color = red) LIMIT 1 OFFSET 2')
59
+ assert !@parser.parse('SELECT * FROM `posts` WHERE (title = red) LIMIT 1 OFFSET 2')
60
60
  end
61
61
 
62
62
  should "include order" do
63
- assert !@parser.parse('SELECT * FROM `posts` WHERE (color = red) ORDER DESC')
63
+ assert !@parser.parse('SELECT * FROM `posts` WHERE (title = red) ORDER DESC')
64
64
  end
65
65
 
66
66
  should "include the OR operator" do
67
- assert !@parser.parse('SELECT * FROM `posts` WHERE (color = red OR size = big) LIMIT 2')
67
+ assert !@parser.parse('SELECT * FROM `posts` WHERE (title = red OR blog_id = big) LIMIT 2')
68
68
  end
69
69
 
70
70
  should "include the IN operator" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 7
9
- version: 0.7.7
8
+ - 8
9
+ version: 0.7.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mick Staugaard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-22 00:00:00 -07:00
18
+ date: 2010-07-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency