kasket 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,8 +14,9 @@ begin
14
14
  gem.authors = ["Mick Staugaard", "Eric Chapweske"]
15
15
  gem.add_dependency('activerecord', '>= 2.3.4')
16
16
  gem.add_dependency('activesupport', '>= 2.3.4')
17
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+ gem.add_development_dependency "shoulda", ">= 0"
18
18
  gem.add_development_dependency "mocha", ">= 0"
19
+ gem.add_development_dependency "temping", ">= 1.3.0"
19
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
21
  end
21
22
  Jeweler::GemcutterTasks.new
data/lib/kasket.rb CHANGED
@@ -15,7 +15,7 @@ module Kasket
15
15
  class Version
16
16
  MAJOR = 0
17
17
  MINOR = 7
18
- PATCH = 2
18
+ PATCH = 3
19
19
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
20
20
  end
21
21
 
@@ -30,13 +30,11 @@ module Kasket
30
30
 
31
31
  def kasket_key_for(attribute_value_pairs)
32
32
  kasket_key_prefix + attribute_value_pairs.map do |attribute, value|
33
- if value.nil?
34
- attribute.to_s + '='
35
- elsif (column = columns_hash[attribute.to_s]) && column.number?
36
- attribute.to_s + '=' + convert_number_column_value(value.to_s)
37
- else
38
- attribute.to_s + '=' + connection.quote(value.to_s)
33
+ if (column = columns_hash[attribute.to_s]) && column.number?
34
+ value = convert_number_column_value(value)
39
35
  end
36
+
37
+ attribute.to_s + '=' + connection.quote(value, column)
40
38
  end.join('/')
41
39
  end
42
40
 
@@ -11,6 +11,7 @@ module Kasket
11
11
  sql = sanitize_sql(sql)
12
12
  query = kasket_parser.parse(sql) if use_kasket?
13
13
  if query && has_kasket_index_on?(query[:index])
14
+
14
15
  if value = Rails.cache.read(query[:key])
15
16
  Array.wrap(value).collect! { |record| instantiate(record.dup) }
16
17
  else
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ConfigurationMixinTest < ActiveSupport::TestCase
4
+
5
+ context "Generating cache keys" do
6
+
7
+ should "not choke on empty numeric attributes" do
8
+ expected_cache_key = "kasket-#{Kasket::Version::STRING}/posts/version=3558/blog_id=NULL"
9
+ query_attributes = [ [:blog_id, ''] ]
10
+
11
+ assert_equal expected_cache_key, Post.kasket_key_for(query_attributes)
12
+ end
13
+
14
+ end
15
+
16
+ end
data/test/helper.rb CHANGED
@@ -6,12 +6,6 @@ require 'active_support'
6
6
  require 'active_record'
7
7
  require 'active_record/fixtures'
8
8
 
9
- ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
10
- ActiveRecord::Base.establish_connection('test')
11
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
12
-
13
- load(File.dirname(__FILE__) + "/schema.rb")
14
-
15
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
17
11
  require 'kasket'
@@ -53,25 +47,4 @@ module Rails
53
47
  end
54
48
  end
55
49
 
56
- class Comment < ActiveRecord::Base
57
- belongs_to :post
58
- end
59
-
60
- class Post < ActiveRecord::Base
61
- belongs_to :blog
62
- has_many :comments
63
-
64
- has_kasket
65
- has_kasket_on :title
66
- has_kasket_on :blog_id, :id
67
-
68
- def make_dirty!
69
- self.updated_at = Time.now
70
- self.connection.execute("UPDATE posts SET updated_at = '#{updated_at.utc.to_s(:db)}' WHERE id = #{id}")
71
- end
72
- kasket_dirty_methods :make_dirty!
73
- end
74
-
75
- class Blog < ActiveRecord::Base
76
- has_many :posts
77
- end
50
+ require 'test_models'
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='world''s best title'$/, @parser.parse("SELECT * FROM `posts` WHERE (id = 1 AND title = 'world\\'s best title')")[:key])
85
85
  end
86
86
 
87
87
  context "when limit 1" do
@@ -0,0 +1,45 @@
1
+ require 'temping'
2
+ include Temping
3
+
4
+ create_model :comment do
5
+ with_columns do |t|
6
+ t.text "body"
7
+ t.integer "post_id"
8
+ t.datetime "created_at"
9
+ t.datetime "updated_at"
10
+ end
11
+
12
+ belongs_to :post
13
+ end
14
+
15
+ create_model :post do
16
+ with_columns do |t|
17
+ t.string "title"
18
+ t.integer "blog_id"
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ belongs_to :blog
24
+ has_many :comments
25
+
26
+ has_kasket
27
+ has_kasket_on :title
28
+ has_kasket_on :blog_id, :id
29
+
30
+ def make_dirty!
31
+ self.updated_at = Time.now
32
+ self.connection.execute("UPDATE posts SET updated_at = '#{updated_at.utc.to_s(:db)}' WHERE id = #{id}")
33
+ end
34
+ kasket_dirty_methods :make_dirty!
35
+ end
36
+
37
+ create_model :blog do
38
+ with_columns do |t|
39
+ t.string "name"
40
+ t.datetime "created_at"
41
+ t.datetime "updated_at"
42
+ end
43
+
44
+ has_many :posts
45
+ 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: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-04 00:00:00 +01:00
13
+ date: 2010-01-25 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 2.3.4
35
35
  version:
36
36
  - !ruby/object:Gem::Dependency
37
- name: thoughtbot-shoulda
37
+ name: shoulda
38
38
  type: :development
39
39
  version_requirement:
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,6 +53,16 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: "0"
55
55
  version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: temping
58
+ type: :development
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.0
65
+ version:
56
66
  description: puts a cap on your queries
57
67
  email: mick@staugaard.com
58
68
  executables: []
@@ -77,6 +87,7 @@ files:
77
87
  - lib/kasket/reload_association_mixin.rb
78
88
  - lib/kasket/write_mixin.rb
79
89
  - test/cache_expiry_test.rb
90
+ - test/configuration_mixin_test.rb
80
91
  - test/database.yml
81
92
  - test/dirty_test.rb
82
93
  - test/find_one_test.rb
@@ -87,7 +98,7 @@ files:
87
98
  - test/helper.rb
88
99
  - test/parser_test.rb
89
100
  - test/read_mixin_test.rb
90
- - test/schema.rb
101
+ - test/test_models.rb
91
102
  has_rdoc: true
92
103
  homepage: http://github.com/staugaard/kasket
93
104
  licenses: []
@@ -118,10 +129,11 @@ specification_version: 3
118
129
  summary: A write back caching layer on active record
119
130
  test_files:
120
131
  - test/cache_expiry_test.rb
132
+ - test/configuration_mixin_test.rb
121
133
  - test/dirty_test.rb
122
134
  - test/find_one_test.rb
123
135
  - test/find_some_test.rb
124
136
  - test/helper.rb
125
137
  - test/parser_test.rb
126
138
  - test/read_mixin_test.rb
127
- - test/schema.rb
139
+ - test/test_models.rb
data/test/schema.rb DELETED
@@ -1,34 +0,0 @@
1
- # This file is auto-generated from the current state of the database. Instead of editing this file,
2
- # please use the migrations feature of Active Record to incrementally modify your database, and
3
- # then regenerate this schema definition.
4
- #
5
- # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
- # to create the application database on another system, you should be using db:schema:load, not running
7
- # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
- # you'll amass, the slower it'll run and the greater likelihood for issues).
9
- #
10
- # It's strongly recommended to check this file into your version control system.
11
-
12
- ActiveRecord::Schema.define(:version => 1) do
13
-
14
- create_table "comments", :force => true do |t|
15
- t.text "body"
16
- t.integer "post_id"
17
- t.datetime "created_at"
18
- t.datetime "updated_at"
19
- end
20
-
21
- create_table "posts", :force => true do |t|
22
- t.string "title"
23
- t.integer "blog_id"
24
- t.datetime "created_at"
25
- t.datetime "updated_at"
26
- end
27
-
28
- create_table "blogs", :force => true do |t|
29
- t.string "name"
30
- t.datetime "created_at"
31
- t.datetime "updated_at"
32
- end
33
-
34
- end