kasket 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,11 @@ module Kasket
23
23
  end
24
24
 
25
25
  def kasket_key_prefix
26
- @kasket_key_prefix ||= "kasket-#{Kasket::Version::PROTOCOL}/#{table_name}/version=#{column_names.join.sum}/"
26
+ @kasket_key_prefix ||= "kasket-#{Kasket::Version::PROTOCOL}/#{kasket_activerecord_version}/#{table_name}/version=#{column_names.join.sum}/"
27
+ end
28
+
29
+ def kasket_activerecord_version
30
+ "R#{ActiveRecord::VERSION::MAJOR}#{ActiveRecord::VERSION::MINOR}"
27
31
  end
28
32
 
29
33
  def kasket_key_for(attribute_value_pairs)
@@ -2,7 +2,7 @@
2
2
  module Kasket
3
3
  class Version
4
4
  MAJOR = 3
5
- MINOR = 0
5
+ MINOR = 1
6
6
  PATCH = 0
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  PROTOCOL = 3
@@ -2,11 +2,9 @@ require File.expand_path("helper", File.dirname(__FILE__))
2
2
  require "digest/md5"
3
3
 
4
4
  class ConfigurationMixinTest < ActiveSupport::TestCase
5
-
6
5
  context "Generating cache keys" do
7
-
8
6
  should "not choke on empty numeric attributes" do
9
- expected_cache_key = "kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/blog_id=null"
7
+ expected_cache_key = "#{Post.kasket_key_prefix}blog_id=null"
10
8
  query_attributes = [ [:blog_id, ''] ]
11
9
 
12
10
  assert_equal expected_cache_key, Post.kasket_key_for(query_attributes)
@@ -27,9 +25,13 @@ class ConfigurationMixinTest < ActiveSupport::TestCase
27
25
 
28
26
  should "downcase string attributes" do
29
27
  query_attributes = [ [:title, 'ThIs'] ]
30
- expected_cache_key = "kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/title='this'"
28
+ expected_cache_key = "#{Post.kasket_key_prefix}title='this'"
31
29
 
32
30
  assert_equal expected_cache_key, Post.kasket_key_for(query_attributes)
33
31
  end
32
+
33
+ should "build correct prefix" do
34
+ assert_equal "kasket-#{Kasket::Version::PROTOCOL}/R#{ActiveRecord::VERSION::MAJOR}#{ActiveRecord::VERSION::MINOR}/posts/version=#{POST_VERSION}/", Post.kasket_key_prefix
35
+ end
34
36
  end
35
37
  end
@@ -118,7 +118,7 @@ class ParserTest < ActiveSupport::TestCase
118
118
  context "key generation" do
119
119
  should "include the table name and version" do
120
120
  kasket_query = parse(:conditions => {:id => 1})
121
- assert_match(/^kasket-#{Kasket::Version::PROTOCOL}\/posts\/version=#{POST_VERSION}\//, kasket_query[:key])
121
+ assert_match(/^kasket-#{Kasket::Version::PROTOCOL}\/R#{ActiveRecord::VERSION::MAJOR}#{ActiveRecord::VERSION::MINOR}\/posts\/version=#{POST_VERSION}\//, kasket_query[:key])
122
122
  end
123
123
 
124
124
  should "include all indexed attributes" do
@@ -1,7 +1,6 @@
1
1
  require File.expand_path("helper", File.dirname(__FILE__))
2
2
 
3
3
  class ReadMixinTest < ActiveSupport::TestCase
4
-
5
4
  context "find by sql with kasket" do
6
5
  setup do
7
6
  @post_database_result = { 'id' => 1, 'title' => 'Hello' }
@@ -20,25 +19,25 @@ class ReadMixinTest < ActiveSupport::TestCase
20
19
  end
21
20
 
22
21
  should "read results" do
23
- Kasket.cache.write("kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/id=1", @post_database_result)
22
+ Kasket.cache.write("#{Post.kasket_key_prefix}id=1", @post_database_result)
24
23
  assert_equal @post_records, Post.find_by_sql('SELECT * FROM `posts` WHERE (id = 1)')
25
24
  end
26
25
 
27
26
  should "support sql with ?" do
28
- Kasket.cache.write("kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/id=1", @post_database_result)
27
+ Kasket.cache.write("#{Post.kasket_key_prefix}id=1", @post_database_result)
29
28
  assert_equal @post_records, Post.find_by_sql(['SELECT * FROM `posts` WHERE (id = ?)', 1])
30
29
  end
31
30
 
32
31
  should "store results in kasket" do
33
32
  Post.find_by_sql('SELECT * FROM `posts` WHERE (id = 1)')
34
33
 
35
- assert_equal @post_database_result, Kasket.cache.read("kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/id=1")
34
+ assert_equal @post_database_result, Kasket.cache.read("#{Post.kasket_key_prefix}id=1")
36
35
  end
37
36
 
38
37
  should "store multiple records in cache" do
39
38
  Comment.find_by_sql('SELECT * FROM `comments` WHERE (post_id = 1)')
40
- stored_value = Kasket.cache.read("kasket-#{Kasket::Version::PROTOCOL}/comments/version=#{COMMENT_VERSION}/post_id=1")
41
- assert_equal(["kasket-#{Kasket::Version::PROTOCOL}/comments/version=#{COMMENT_VERSION}/id=1", "kasket-#{Kasket::Version::PROTOCOL}/comments/version=#{COMMENT_VERSION}/id=2"], stored_value)
39
+ stored_value = Kasket.cache.read("#{Comment.kasket_key_prefix}post_id=1")
40
+ assert_equal(["#{Comment.kasket_key_prefix}id=1", "#{Comment.kasket_key_prefix}id=2"], stored_value)
42
41
  assert_equal(@comment_database_result, stored_value.map {|key| Kasket.cache.read(key)})
43
42
 
44
43
  Comment.expects(:find_by_sql_without_kasket).never
@@ -48,7 +47,7 @@ class ReadMixinTest < ActiveSupport::TestCase
48
47
 
49
48
  context "modifying results" do
50
49
  setup do
51
- Kasket.cache.write("kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/id=1", {'id' => 1, 'title' => "asd"})
50
+ Kasket.cache.write("#{Post.kasket_key_prefix}id=1", {'id' => 1, 'title' => "asd"})
52
51
  @sql = 'SELECT * FROM `posts` WHERE (id = 1)'
53
52
  @record = Post.find_by_sql(@sql).first
54
53
  assert_equal "asd", @record.title # read from cache ?
@@ -8,7 +8,7 @@ class VisitorTest < ActiveSupport::TestCase
8
8
  :attributes=>[[:id, "1"]],
9
9
  :from=>"posts",
10
10
  :index=>[:id],
11
- :key=>"kasket-#{Kasket::Version::PROTOCOL}/posts/version=#{POST_VERSION}/id=1"
11
+ :key=>"#{Post.kasket_key_prefix}id=1"
12
12
  }
13
13
  assert_equal expected, Post.where(:id => 1).to_kasket_query
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kasket
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-20 00:00:00.000000000 Z
13
+ date: 2013-06-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  segments:
186
186
  - 0
187
- hash: -2318002147869765262
187
+ hash: 3156155160128101763
188
188
  required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  none: false
190
190
  requirements:
@@ -193,10 +193,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  segments:
195
195
  - 0
196
- hash: -2318002147869765262
196
+ hash: 3156155160128101763
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 1.8.24
199
+ rubygems_version: 1.8.25
200
200
  signing_key:
201
201
  specification_version: 3
202
202
  summary: A write back caching layer on active record