kasket 0.7.6 → 0.7.7

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 = 6
17
+ PATCH = 7
18
18
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
19
19
  end
20
20
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require "digest/md5"
2
3
 
3
4
  module Kasket
4
5
  autoload :ReadMixin, 'kasket/read_mixin'
@@ -29,13 +30,19 @@ module Kasket
29
30
  end
30
31
 
31
32
  def kasket_key_for(attribute_value_pairs)
32
- kasket_key_prefix + attribute_value_pairs.map do |attribute, value|
33
+ key = attribute_value_pairs.map do |attribute, value|
33
34
  if (column = columns_hash[attribute.to_s]) && column.number?
34
35
  value = convert_number_column_value(value)
35
36
  end
36
-
37
+
37
38
  attribute.to_s + '=' + connection.quote(value, column)
38
39
  end.join('/')
40
+
41
+ if key.size > (250 - kasket_key_prefix.size) || key =~ /\s/
42
+ key = Digest::MD5.hexdigest(key)
43
+ end
44
+
45
+ kasket_key_prefix + key
39
46
  end
40
47
 
41
48
  def convert_number_column_value(value)
@@ -27,7 +27,7 @@ class CacheExpiryTest < ActiveSupport::TestCase
27
27
  end
28
28
 
29
29
  should "be removed from cache when updated" do
30
- @post.title = "new title"
30
+ @post.title = "new_title"
31
31
  @post.save
32
32
  assert_nil(Rails.cache.read(@post.kasket_key))
33
33
  end
@@ -36,12 +36,12 @@ class CacheExpiryTest < ActiveSupport::TestCase
36
36
  Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "id=#{@post.id}")
37
37
  Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='#{@post.title}'")
38
38
  Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='#{@post.title}'/first")
39
- Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='new title'")
40
- Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='new title'/first")
39
+ Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='new_title'")
40
+ Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "title='new_title'/first")
41
41
  Rails.cache.expects(:delete).with(Post.kasket_key_prefix + "blog_id=#{@post.blog_id}/id=#{@post.id}")
42
42
  Rails.cache.expects(:delete).never
43
43
 
44
- @post.title = "new title"
44
+ @post.title = "new_title"
45
45
  @post.save
46
46
  end
47
47
 
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
+ require "digest/md5"
2
3
 
3
4
  class ConfigurationMixinTest < ActiveSupport::TestCase
4
5
 
@@ -10,7 +11,19 @@ class ConfigurationMixinTest < ActiveSupport::TestCase
10
11
 
11
12
  assert_equal expected_cache_key, Post.kasket_key_for(query_attributes)
12
13
  end
13
-
14
+
15
+ should "not generate keys longer that 255" do
16
+ very_large_number = (1..999).to_a.join
17
+ query_attributes = [ [:blog_id, very_large_number] ]
18
+
19
+ assert(Post.kasket_key_for(query_attributes).size < 255)
20
+ end
21
+
22
+ should "not generate keys with spaces" do
23
+ query_attributes = [ [:title, 'this key has speces'] ]
24
+
25
+ assert(!(Post.kasket_key_for(query_attributes) =~ /\s/))
26
+ end
14
27
  end
15
28
 
16
29
  end
@@ -1,15 +1,15 @@
1
1
  no_comments:
2
2
  blog: a_blog
3
- title: This post has no comments
3
+ title: no_comments
4
4
 
5
5
  has_two_comments:
6
6
  blog: a_blog
7
- title: This post has a few comments
7
+ title: few_comments
8
8
 
9
9
  on_other_blog:
10
10
  blog: other_blog
11
- title: This post has no comments
11
+ title: no_comments
12
12
 
13
13
  has_many_comments:
14
14
  blog: a_blog
15
- title: A shit load of comments on this one
15
+ title: many_comments
data/test/parser_test.rb CHANGED
@@ -81,7 +81,7 @@ class ParserTest < ActiveSupport::TestCase
81
81
  should "include all indexed attributes" do
82
82
  assert_match(/id=1$/, @parser.parse('SELECT * FROM `posts` WHERE (id = 1)')[:key])
83
83
  assert_match(/blog_id=2\/id=1$/, @parser.parse('SELECT * FROM `posts` WHERE (id = 1 AND blog_id = 2)')[:key])
84
- assert_match(/id=1\/title='world''s best title'$/, @parser.parse("SELECT * FROM `posts` WHERE (id = 1 AND title = 'world\\'s best title')")[:key])
84
+ assert_match(/id=1\/title='title'$/, @parser.parse("SELECT * FROM `posts` WHERE (id = 1 AND title = 'title')")[:key])
85
85
  end
86
86
 
87
87
  context "when limit 1" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kasket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 7
9
+ version: 0.7.7
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mick Staugaard
@@ -10,59 +15,75 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-08 00:00:00 +01:00
18
+ date: 2010-04-22 00:00:00 -07:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activerecord
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 4
24
32
  version: 2.3.4
25
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  - !ruby/object:Gem::Dependency
27
36
  name: activesupport
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
31
39
  requirements:
32
40
  - - ">="
33
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 3
45
+ - 4
34
46
  version: 2.3.4
35
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
36
49
  - !ruby/object:Gem::Dependency
37
50
  name: shoulda
38
- type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
41
53
  requirements:
42
54
  - - ">="
43
55
  - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
44
58
  version: "0"
45
- version:
59
+ type: :development
60
+ version_requirements: *id003
46
61
  - !ruby/object:Gem::Dependency
47
62
  name: mocha
48
- type: :development
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
54
70
  version: "0"
55
- version:
71
+ type: :development
72
+ version_requirements: *id004
56
73
  - !ruby/object:Gem::Dependency
57
74
  name: temping
58
- type: :development
59
- version_requirement:
60
- version_requirements: !ruby/object:Gem::Requirement
75
+ prerelease: false
76
+ requirement: &id005 !ruby/object:Gem::Requirement
61
77
  requirements:
62
78
  - - ">="
63
79
  - !ruby/object:Gem::Version
80
+ segments:
81
+ - 1
82
+ - 3
83
+ - 0
64
84
  version: 1.3.0
65
- version:
85
+ type: :development
86
+ version_requirements: *id005
66
87
  description: puts a cap on your queries
67
88
  email: mick@staugaard.com
68
89
  executables: []
@@ -111,18 +132,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
132
  requirements:
112
133
  - - ">="
113
134
  - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
114
137
  version: "0"
115
- version:
116
138
  required_rubygems_version: !ruby/object:Gem::Requirement
117
139
  requirements:
118
140
  - - ">="
119
141
  - !ruby/object:Gem::Version
142
+ segments:
143
+ - 0
120
144
  version: "0"
121
- version:
122
145
  requirements: []
123
146
 
124
147
  rubyforge_project:
125
- rubygems_version: 1.3.5
148
+ rubygems_version: 1.3.6
126
149
  signing_key:
127
150
  specification_version: 3
128
151
  summary: A write back caching layer on active record