kasket 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kasket.rb +1 -7
- data/lib/kasket/read_mixin.rb +7 -5
- data/lib/kasket/version.rb +8 -0
- data/test/find_some_test.rb +39 -20
- data/test/helper.rb +3 -1
- metadata +6 -2
data/lib/kasket.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_record'
|
|
3
3
|
require 'active_support'
|
4
4
|
|
5
5
|
require 'kasket/active_record_patches'
|
6
|
+
require 'kasket/version'
|
6
7
|
|
7
8
|
module Kasket
|
8
9
|
autoload :ConfigurationMixin, 'kasket/configuration_mixin'
|
@@ -11,13 +12,6 @@ module Kasket
|
|
11
12
|
|
12
13
|
CONFIGURATION = {:max_collection_size => 100}
|
13
14
|
|
14
|
-
class Version
|
15
|
-
MAJOR = 1
|
16
|
-
MINOR = 0
|
17
|
-
PATCH = 3
|
18
|
-
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
19
|
-
end
|
20
|
-
|
21
15
|
module_function
|
22
16
|
|
23
17
|
def setup(options = {})
|
data/lib/kasket/read_mixin.rb
CHANGED
@@ -41,14 +41,16 @@ module Kasket
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
instance
|
47
|
-
|
44
|
+
if missing_ids.any?
|
45
|
+
without_kasket do
|
46
|
+
find_all_by_id(missing_ids).each do |instance|
|
47
|
+
instance.store_in_kasket
|
48
|
+
key_value_map[instance.kasket_key] = instance
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
key_value_map.values
|
53
|
+
key_value_map.values.compact
|
52
54
|
end
|
53
55
|
|
54
56
|
protected
|
data/test/find_some_test.rb
CHANGED
@@ -3,34 +3,53 @@ require File.expand_path("helper", File.dirname(__FILE__))
|
|
3
3
|
class FindSomeTest < ActiveSupport::TestCase
|
4
4
|
fixtures :blogs, :posts
|
5
5
|
|
6
|
-
|
7
|
-
post1 = Post.first
|
8
|
-
post2 = Post.last
|
6
|
+
def setup
|
7
|
+
@post1 = Post.first
|
8
|
+
@post2 = Post.last
|
9
|
+
Post.find(@post1.id, @post2.id)
|
10
|
+
assert Kasket.cache.read(@post1.kasket_key)
|
11
|
+
assert Kasket.cache.read(@post2.kasket_key)
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
should "use cache for find(id, id) calls" do
|
15
|
+
Post.connection.expects(:select_all).never
|
16
|
+
Post.find(@post1.id, @post2.id)
|
17
|
+
end
|
12
18
|
|
13
|
-
|
19
|
+
should "cache when found using find(id, id) calls" do
|
20
|
+
Kasket.cache.delete(@post1.kasket_key)
|
21
|
+
Kasket.cache.delete(@post2.kasket_key)
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
Post.find(@post1.id, @post2.id)
|
24
|
+
|
25
|
+
assert Kasket.cache.read(@post1.kasket_key)
|
26
|
+
assert Kasket.cache.read(@post2.kasket_key)
|
19
27
|
end
|
20
28
|
|
21
29
|
should "only lookup the records that are not in the cache" do
|
22
|
-
|
23
|
-
post2 = Post.last
|
24
|
-
assert_equal(post1, Post.find(post1.id))
|
25
|
-
assert(Kasket.cache.read(post1.kasket_key))
|
26
|
-
assert_nil(Kasket.cache.read(post2.kasket_key))
|
30
|
+
Kasket.cache.delete(@post2.kasket_key)
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
# has to lookup post2 via db
|
33
|
+
Post.expects(:find_by_sql_without_kasket).returns([@post2])
|
34
|
+
found_posts = Post.find(@post1.id, @post2.id)
|
35
|
+
assert_equal [@post1, @post2].map(&:id).sort, found_posts.map(&:id).sort
|
31
36
|
|
37
|
+
# now all are cached
|
32
38
|
Post.expects(:find_by_sql_without_kasket).never
|
33
|
-
found_posts = Post.find(post1.id, post2.id)
|
34
|
-
assert_equal
|
39
|
+
found_posts = Post.find(@post1.id, @post2.id)
|
40
|
+
assert_equal [@post1, @post2].map(&:id).sort, found_posts.map(&:id).sort
|
41
|
+
end
|
42
|
+
|
43
|
+
context "unfound" do
|
44
|
+
should "ignore unfound when using find_all_by_id" do
|
45
|
+
found_posts = Post.find_all_by_id([@post1.id, 1231232])
|
46
|
+
assert_equal [@post1.id], found_posts.map(&:id)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "not ignore unfound when using find" do
|
50
|
+
assert_raise ActiveRecord::RecordNotFound do
|
51
|
+
Post.find(@post1.id, 1231232)
|
52
|
+
end
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
data/test/helper.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.4
|
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: 2012-
|
13
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/kasket/query_parser.rb
|
139
139
|
- lib/kasket/read_mixin.rb
|
140
140
|
- lib/kasket/reload_association_mixin.rb
|
141
|
+
- lib/kasket/version.rb
|
141
142
|
- lib/kasket/write_mixin.rb
|
142
143
|
- lib/kasket.rb
|
143
144
|
- README.rdoc
|
@@ -168,6 +169,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
169
|
- - ! '>='
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
hash: 4530626145164262218
|
171
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
176
|
none: false
|
173
177
|
requirements:
|