File tree 9 files changed +205
-1
lines changed
9 files changed +205
-1
lines changed Original file line number Diff line number Diff line change 8
8
* .log
9
9
* .gem
10
10
* .sqlite3
11
+ * .swp
12
+ * .swo
11
13
Original file line number Diff line number Diff line change
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ second_level_cache (1.1.1 )
5
+ rails (> 3.0 )
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.1 )
11
+ actionpack (= 3.2.1 )
12
+ mail (~> 2.4.0 )
13
+ actionpack (3.2.1 )
14
+ activemodel (= 3.2.1 )
15
+ activesupport (= 3.2.1 )
16
+ builder (~> 3.0.0 )
17
+ erubis (~> 2.7.0 )
18
+ journey (~> 1.0.1 )
19
+ rack (~> 1.4.0 )
20
+ rack-cache (~> 1.1 )
21
+ rack-test (~> 0.6.1 )
22
+ sprockets (~> 2.1.2 )
23
+ activemodel (3.2.1 )
24
+ activesupport (= 3.2.1 )
25
+ builder (~> 3.0.0 )
26
+ activerecord (3.2.1 )
27
+ activemodel (= 3.2.1 )
28
+ activesupport (= 3.2.1 )
29
+ arel (~> 3.0.0 )
30
+ tzinfo (~> 0.3.29 )
31
+ activeresource (3.2.1 )
32
+ activemodel (= 3.2.1 )
33
+ activesupport (= 3.2.1 )
34
+ activesupport (3.2.1 )
35
+ i18n (~> 0.6 )
36
+ multi_json (~> 1.0 )
37
+ arel (3.0.0 )
38
+ builder (3.0.0 )
39
+ erubis (2.7.0 )
40
+ hike (1.2.1 )
41
+ i18n (0.6.0 )
42
+ journey (1.0.1 )
43
+ json (1.6.5 )
44
+ mail (2.4.1 )
45
+ i18n (>= 0.4.0 )
46
+ mime-types (~> 1.16 )
47
+ treetop (~> 1.4.8 )
48
+ mime-types (1.17.2 )
49
+ multi_json (1.0.4 )
50
+ polyglot (0.3.3 )
51
+ rack (1.4.1 )
52
+ rack-cache (1.1 )
53
+ rack (>= 0.4 )
54
+ rack-ssl (1.3.2 )
55
+ rack
56
+ rack-test (0.6.1 )
57
+ rack (>= 1.0 )
58
+ rails (3.2.1 )
59
+ actionmailer (= 3.2.1 )
60
+ actionpack (= 3.2.1 )
61
+ activerecord (= 3.2.1 )
62
+ activeresource (= 3.2.1 )
63
+ activesupport (= 3.2.1 )
64
+ bundler (~> 1.0 )
65
+ railties (= 3.2.1 )
66
+ railties (3.2.1 )
67
+ actionpack (= 3.2.1 )
68
+ activesupport (= 3.2.1 )
69
+ rack-ssl (~> 1.3.2 )
70
+ rake (>= 0.8.7 )
71
+ rdoc (~> 3.4 )
72
+ thor (~> 0.14.6 )
73
+ rake (0.9.2.2 )
74
+ rdoc (3.12 )
75
+ json (~> 1.4 )
76
+ redis (2.2.2 )
77
+ sprockets (2.1.2 )
78
+ hike (~> 1.2 )
79
+ rack (~> 1.0 )
80
+ tilt (~> 1.1 , != 1.3.0 )
81
+ sqlite3 (1.3.5 )
82
+ thor (0.14.6 )
83
+ tilt (1.3.3 )
84
+ treetop (1.4.10 )
85
+ polyglot
86
+ polyglot (>= 0.3.1 )
87
+ tzinfo (0.3.31 )
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ activerecord (> 3.0 )
94
+ rake
95
+ redis
96
+ second_level_cache !
97
+ sqlite3
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake ::TestTask . new do |t |
8
+ t . libs << "lib" << "test"
9
+ t . test_files = FileList [ 'test/**/*_test.rb' ]
10
+ end
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
gem . add_runtime_dependency "rails" , [ "> 3.0" ]
19
19
20
20
gem . add_development_dependency "activerecord" , [ "> 3.0" ]
21
+ gem . add_development_dependency "sqlite3"
21
22
gem . add_development_dependency "redis"
22
23
gem . add_development_dependency "rake"
23
24
end
Original file line number Diff line number Diff line change
1
+ ActiveRecord ::Base . connection . create_table ( :books , :force => true ) do |t |
2
+ t . string :title
3
+ t . string :body
4
+ t . integer :user_id
5
+ end
6
+
7
+ class Book < ActiveRecord ::Base
8
+ acts_as_cached
9
+
10
+ belongs_to :user
11
+ end
Original file line number Diff line number Diff line change
1
+ ActiveRecord ::Base . connection . create_table ( :users , :force => true ) do |t |
2
+ t . string :name
3
+ t . string :email
4
+ end
5
+
6
+ class User < ActiveRecord ::Base
7
+ acts_as_cached
8
+
9
+ has_many :books
10
+ end
Original file line number Diff line number Diff line change
1
+ require 'active_record/test_helper'
2
+
3
+ class ActiveRecord ::SecondLevelCacheTest < Test ::Unit ::TestCase
4
+ def setup
5
+ @user = User . create :name => 'csdn' , :email => '[email protected] '
6
+ end
7
+
8
+ def teardown
9
+ User . delete_all
10
+ end
11
+
12
+ def test_should_get_cache_key
13
+ assert_equal "users/#{ @user . id } " , @user . second_level_cache_key
14
+ end
15
+
16
+ def test_should_have_cache_when_create
17
+ no_connection do
18
+ assert_not_nil User . cache_store . get ( @user . second_level_cache_key )
19
+ assert_equal @user , User . find ( @user . id )
20
+ end
21
+ end
22
+
23
+ def test_should_update_cache_when_update
24
+ @user . update_attributes :name => 'change'
25
+
26
+ no_connection do
27
+ assert_equal 'change' , User . find ( @user . id ) . name
28
+ end
29
+ end
30
+
31
+ def test_should_get_cache_when_use_singular_association
32
+ book = @user . books . create
33
+
34
+ no_connection do
35
+ assert_equal @user , book . user
36
+ end
37
+ end
38
+
39
+ def test_should_expire_cache_when_destroy
40
+ @user . destroy
41
+ assert_nil User . cache_store . get ( @user . second_level_cache_key )
42
+ end
43
+ end
Original file line number Diff line number Diff line change
1
+ require 'test_helper'
2
+ require 'active_record'
3
+
4
+ def open_test_db_connect
5
+ ActiveRecord ::Base . establish_connection (
6
+ :adapter => 'sqlite3' ,
7
+ :database => 'test/test.sqlite3'
8
+ )
9
+ end
10
+ open_test_db_connect
11
+
12
+ def close_test_db_connect
13
+ ActiveRecord ::Base . connection . disconnect!
14
+ end
15
+
16
+ class Test ::Unit ::TestCase
17
+ def no_connection
18
+ close_test_db_connect
19
+ assert_nothing_raised { yield }
20
+ ensure
21
+ open_test_db_connect
22
+ end
23
+ end
24
+
25
+ require 'active_record/model/user'
26
+ require 'active_record/model/book'
Original file line number Diff line number Diff line change
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'second_level_cache'
4
+ require 'test/unit'
5
+
6
+ $redis = Redis . new
You can’t perform that action at this time.
0 commit comments