qor_cache 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +60 -0
  5. data/Rakefile +14 -0
  6. data/config/qor/cache.rb +31 -0
  7. data/config/qor/test.rb +25 -0
  8. data/lib/qor_cache/active_record.rb +68 -0
  9. data/lib/qor_cache/configuration.rb +16 -0
  10. data/lib/qor_cache/kernel.rb +17 -0
  11. data/lib/qor_cache/railtie.rb +17 -0
  12. data/lib/qor_cache/version.rb +5 -0
  13. data/lib/qor_cache.rb +73 -0
  14. data/qor_cache.gemspec +24 -0
  15. data/test/dummy/.gitignore +2 -0
  16. data/test/dummy/README.rdoc +261 -0
  17. data/test/dummy/Rakefile +7 -0
  18. data/test/dummy/app/assets/javascripts/application.js +15 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  20. data/test/dummy/app/controllers/application_controller.rb +3 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/mailers/.gitkeep +0 -0
  23. data/test/dummy/app/models/.gitkeep +0 -0
  24. data/test/dummy/app/models/color_variation.rb +16 -0
  25. data/test/dummy/app/models/product.rb +20 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/test/dummy/config/application.rb +59 -0
  28. data/test/dummy/config/boot.rb +10 -0
  29. data/test/dummy/config/database.yml +25 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +37 -0
  32. data/test/dummy/config/environments/production.rb +67 -0
  33. data/test/dummy/config/environments/test.rb +37 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/inflections.rb +15 -0
  36. data/test/dummy/config/initializers/mime_types.rb +5 -0
  37. data/test/dummy/config/initializers/secret_token.rb +7 -0
  38. data/test/dummy/config/initializers/session_store.rb +8 -0
  39. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  40. data/test/dummy/config/locales/en.yml +5 -0
  41. data/test/dummy/config/qor/cache.rb +11 -0
  42. data/test/dummy/config/routes.rb +58 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/db/migrate/20121025062539_create_products.rb +10 -0
  45. data/test/dummy/db/migrate/20121025062642_create_color_variations.rb +12 -0
  46. data/test/dummy/lib/assets/.gitkeep +0 -0
  47. data/test/dummy/log/.gitkeep +0 -0
  48. data/test/dummy/public/404.html +26 -0
  49. data/test/dummy/public/422.html +26 -0
  50. data/test/dummy/public/500.html +25 -0
  51. data/test/dummy/public/favicon.ico +0 -0
  52. data/test/dummy/script/rails +6 -0
  53. data/test/dummy/test/fixtures/color_variations.yml +11 -0
  54. data/test/dummy/test/fixtures/products.yml +9 -0
  55. data/test/dummy/test/unit/color_variation_test.rb +7 -0
  56. data/test/dummy/test/unit/product_test.rb +7 -0
  57. data/test/factories.rb +13 -0
  58. data/test/qor_cache_fields_test.rb +29 -0
  59. data/test/qor_cache_key_test.rb +64 -0
  60. data/test/qor_cache_methods_test.rb +140 -0
  61. data/test/test_helper.rb +18 -0
  62. metadata +217 -0
data/test/factories.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :product do
5
+ code 'A1111'
6
+ name 'Product A1111'
7
+ end
8
+
9
+ factory :color_variation do
10
+ code 'C1111'
11
+ name 'ColorVariation A1111'
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+ require 'timeout'
3
+
4
+ class QorCacheFieldsTest < ActiveSupport::TestCase
5
+ test "cache field should works" do
6
+ product = FactoryGirl.create(:product, :code => '1111')
7
+ product.color_variations << FactoryGirl.build(:color_variation)
8
+ product.save
9
+
10
+ color_variation = product.color_variations.first
11
+
12
+ assert_equal color_variation.product_code, '1111'
13
+ end
14
+
15
+ test "cached field should be updated after update" do
16
+ product = FactoryGirl.create(:product, :code => '1111')
17
+ product.color_variations << FactoryGirl.build(:color_variation)
18
+ product.save
19
+
20
+ color_variation = product.color_variations.first
21
+ assert_equal color_variation.product_code, '1111'
22
+
23
+ product.update_attribute(:code, '2222')
24
+ assert_equal color_variation.reload.product_code, '2222'
25
+
26
+ product.update_attribute(:code, '3333')
27
+ assert_equal color_variation.reload.product_code, '3333'
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ class QorCacheKeyTest < ActiveSupport::TestCase
4
+ test "qor_cache_key with one key" do
5
+ cache_key1 = qor_cache_key(:product)
6
+ cache_key2 = qor_cache_key(:product)
7
+ assert_equal cache_key1, cache_key2
8
+
9
+ cache_key_pc1 = qor_cache_key(:product_and_color_variation)
10
+ cache_key_pc2 = qor_cache_key(:product_and_color_variation)
11
+ assert_equal cache_key_pc1, cache_key_pc2
12
+
13
+ product = FactoryGirl.create(:product)
14
+
15
+ cache_key3 = qor_cache_key(:product)
16
+ assert_not_equal cache_key1, cache_key3
17
+
18
+ cache_key_pc3 = qor_cache_key(:product_and_color_variation)
19
+ assert_not_equal cache_key_pc1, cache_key_pc3
20
+
21
+ product.destroy
22
+ assert_not_equal cache_key3, qor_cache_key(:product)
23
+ assert_not_equal cache_key_pc3, qor_cache_key(:product_and_color_variation)
24
+ end
25
+
26
+ test "qor_cache_key with many keys" do
27
+ cache_key1 = qor_cache_key(:product, :color_variation)
28
+ cache_key2 = qor_cache_key(:product, :color_variation)
29
+ assert_equal cache_key1, cache_key2
30
+
31
+ product = FactoryGirl.create(:product)
32
+
33
+ cache_key3 = qor_cache_key(:product, :color_variation)
34
+ assert_not_equal cache_key1, cache_key3
35
+ end
36
+
37
+ test "qor_cache_key with block" do
38
+ def same_value
39
+ "same_value"
40
+ end
41
+ same_1 = qor_cache_key(:product) do
42
+ same_value
43
+ end
44
+
45
+ same_2 = qor_cache_key(:product) do
46
+ same_value
47
+ end
48
+
49
+ assert_equal same_1, same_2
50
+
51
+ def random_value
52
+ rand()
53
+ end
54
+ random_1 = qor_cache_key(:product) do
55
+ random_value
56
+ end
57
+
58
+ random_2 = qor_cache_key(:product) do
59
+ random_value
60
+ end
61
+
62
+ assert_not_equal random_1, random_2
63
+ end
64
+ end
@@ -0,0 +1,140 @@
1
+ require 'test_helper'
2
+ require 'timeout'
3
+
4
+ class QorCacheMethodsTest < ActiveSupport::TestCase
5
+ test "instance method should be cached" do
6
+ product = FactoryGirl.create(:product)
7
+ method = 'slow_method'
8
+
9
+ result1 = product.send(method)
10
+ result2 = product.send(method)
11
+ result3 = product.send("_uncached_#{method}_for_qor_cache".to_sym)
12
+ assert_equal result1, result2
13
+ assert_not_equal result1, result3
14
+ end
15
+
16
+ test "instance method with qor_cache_key" do
17
+ product = FactoryGirl.create(:product)
18
+ cv = FactoryGirl.create(:color_variation)
19
+ method = 'slow_method'
20
+
21
+ result1 = cv.send(method)
22
+ result2 = cv.send(method)
23
+
24
+ product.update_attribute(:updated_at, 1.day.since)
25
+ result3 = cv.send(method)
26
+
27
+ assert_equal result1, result2
28
+ assert_not_equal result1, result3
29
+ end
30
+
31
+ test "instance method with block" do
32
+ product = FactoryGirl.create(:product)
33
+ cv = FactoryGirl.create(:color_variation, :product => product)
34
+ method = 'slow_method_with_product'
35
+
36
+ result1 = cv.send(method)
37
+ result2 = cv.send(method)
38
+
39
+ product.update_attribute(:updated_at, 1.day.since)
40
+ result3 = cv.send(method)
41
+
42
+ assert_equal result1, result2
43
+ assert_not_equal result1, result3
44
+ end
45
+
46
+ test "instance method should be updated after update" do
47
+ product = FactoryGirl.create(:product)
48
+ method = "slow_method"
49
+
50
+ result1 = product.send(method)
51
+ result2 = product.send(method)
52
+ product.update_attribute(:updated_at, 1.minute.since)
53
+ result3 = product.send(method)
54
+ assert_equal result1, result2
55
+ assert_not_equal result1, result3
56
+ end
57
+
58
+ test "instance method with argument" do
59
+ product = FactoryGirl.create(:product)
60
+ method = 'slow_method_with_args'
61
+
62
+ result1 = product.send(method, 1)
63
+ result2 = product.send(method, 1)
64
+ result3 = product.send(method, 2)
65
+ result4 = product.send(method, 2)
66
+ assert_equal result1, result2
67
+ assert_not_equal result1, result3
68
+ assert_equal result3, result4
69
+
70
+ result5 = product.send(method, Product.all)
71
+ result6 = product.send(method, Product.all)
72
+ assert_equal result5, result6
73
+ assert_not_equal result1, result6
74
+ end
75
+
76
+ test "class method should be cached" do
77
+ method = 'slow_class_method'
78
+ result1 = Product.send(method)
79
+ result2 = Product.send(method)
80
+ result3 = Product.send("_uncached_#{method}_for_qor_cache".to_sym)
81
+ assert_equal result1, result2
82
+ assert_not_equal result1, result3
83
+ end
84
+
85
+ test "class method should be updated after update" do
86
+ product = FactoryGirl.create(:product)
87
+ method = "slow_class_method"
88
+
89
+ result1 = Product.send(method)
90
+ result2 = Product.send(method)
91
+ product.update_attribute(:updated_at, 1.minute.since)
92
+ result3 = Product.send(method)
93
+ assert_equal result1, result2
94
+ assert_not_equal result1, result3
95
+ end
96
+
97
+ test "class method should be updated after destroy" do
98
+ product = FactoryGirl.create(:product)
99
+ method = "slow_class_method"
100
+
101
+ result1 = Product.send(method)
102
+ result2 = Product.send(method)
103
+ product.destroy
104
+ result3 = Product.send(method)
105
+ assert_equal result1, result2
106
+ assert_not_equal result1, result3
107
+ end
108
+
109
+ test "class method with argument" do
110
+ product = FactoryGirl.create(:product)
111
+ method = 'slow_class_method_with_args'
112
+
113
+ result1 = Product.send(method, 1)
114
+ result2 = Product.send(method, 1)
115
+ result3 = Product.send(method, 2)
116
+ result4 = Product.send(method, 2)
117
+ assert_equal result1, result2
118
+ assert_not_equal result1, result3
119
+ assert_equal result3, result4
120
+
121
+ result5 = Product.send(method, Product.all)
122
+ result6 = Product.send(method, Product.all)
123
+ assert_equal result5, result6
124
+ assert_not_equal result1, result6
125
+ end
126
+
127
+ test "class method with qor_cache_key" do
128
+ product = FactoryGirl.create(:product)
129
+ method = 'slow_class_method'
130
+
131
+ result1 = ColorVariation.send(method)
132
+ result2 = ColorVariation.send(method)
133
+
134
+ product.update_attribute(:updated_at, 1.day.since)
135
+ result3 = ColorVariation.send(method)
136
+
137
+ assert_equal result1, result2
138
+ assert_not_equal result1, result3
139
+ end
140
+ end
@@ -0,0 +1,18 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ require File.expand_path("../factories.rb", __FILE__)
8
+ FactoryGirl.find_definitions
9
+
10
+ Rails.backtrace_cleaner.remove_silencers!
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ # Load fixtures from the engine
16
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
18
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qor_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jinzhu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qor_test
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: qor_dsl
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Qor Cache
79
+ email:
80
+ - wosmvp@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - config/qor/cache.rb
91
+ - config/qor/test.rb
92
+ - lib/qor_cache.rb
93
+ - lib/qor_cache/active_record.rb
94
+ - lib/qor_cache/configuration.rb
95
+ - lib/qor_cache/kernel.rb
96
+ - lib/qor_cache/railtie.rb
97
+ - lib/qor_cache/version.rb
98
+ - qor_cache.gemspec
99
+ - test/dummy/.gitignore
100
+ - test/dummy/README.rdoc
101
+ - test/dummy/Rakefile
102
+ - test/dummy/app/assets/javascripts/application.js
103
+ - test/dummy/app/assets/stylesheets/application.css
104
+ - test/dummy/app/controllers/application_controller.rb
105
+ - test/dummy/app/helpers/application_helper.rb
106
+ - test/dummy/app/mailers/.gitkeep
107
+ - test/dummy/app/models/.gitkeep
108
+ - test/dummy/app/models/color_variation.rb
109
+ - test/dummy/app/models/product.rb
110
+ - test/dummy/app/views/layouts/application.html.erb
111
+ - test/dummy/config.ru
112
+ - test/dummy/config/application.rb
113
+ - test/dummy/config/boot.rb
114
+ - test/dummy/config/database.yml
115
+ - test/dummy/config/environment.rb
116
+ - test/dummy/config/environments/development.rb
117
+ - test/dummy/config/environments/production.rb
118
+ - test/dummy/config/environments/test.rb
119
+ - test/dummy/config/initializers/backtrace_silencers.rb
120
+ - test/dummy/config/initializers/inflections.rb
121
+ - test/dummy/config/initializers/mime_types.rb
122
+ - test/dummy/config/initializers/secret_token.rb
123
+ - test/dummy/config/initializers/session_store.rb
124
+ - test/dummy/config/initializers/wrap_parameters.rb
125
+ - test/dummy/config/locales/en.yml
126
+ - test/dummy/config/qor/cache.rb
127
+ - test/dummy/config/routes.rb
128
+ - test/dummy/db/migrate/20121025062539_create_products.rb
129
+ - test/dummy/db/migrate/20121025062642_create_color_variations.rb
130
+ - test/dummy/lib/assets/.gitkeep
131
+ - test/dummy/log/.gitkeep
132
+ - test/dummy/public/404.html
133
+ - test/dummy/public/422.html
134
+ - test/dummy/public/500.html
135
+ - test/dummy/public/favicon.ico
136
+ - test/dummy/script/rails
137
+ - test/dummy/test/fixtures/color_variations.yml
138
+ - test/dummy/test/fixtures/products.yml
139
+ - test/dummy/test/unit/color_variation_test.rb
140
+ - test/dummy/test/unit/product_test.rb
141
+ - test/factories.rb
142
+ - test/qor_cache_fields_test.rb
143
+ - test/qor_cache_key_test.rb
144
+ - test/qor_cache_methods_test.rb
145
+ - test/test_helper.rb
146
+ homepage: ''
147
+ licenses: []
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.23
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Qor Cache
170
+ test_files:
171
+ - test/dummy/.gitignore
172
+ - test/dummy/README.rdoc
173
+ - test/dummy/Rakefile
174
+ - test/dummy/app/assets/javascripts/application.js
175
+ - test/dummy/app/assets/stylesheets/application.css
176
+ - test/dummy/app/controllers/application_controller.rb
177
+ - test/dummy/app/helpers/application_helper.rb
178
+ - test/dummy/app/mailers/.gitkeep
179
+ - test/dummy/app/models/.gitkeep
180
+ - test/dummy/app/models/color_variation.rb
181
+ - test/dummy/app/models/product.rb
182
+ - test/dummy/app/views/layouts/application.html.erb
183
+ - test/dummy/config.ru
184
+ - test/dummy/config/application.rb
185
+ - test/dummy/config/boot.rb
186
+ - test/dummy/config/database.yml
187
+ - test/dummy/config/environment.rb
188
+ - test/dummy/config/environments/development.rb
189
+ - test/dummy/config/environments/production.rb
190
+ - test/dummy/config/environments/test.rb
191
+ - test/dummy/config/initializers/backtrace_silencers.rb
192
+ - test/dummy/config/initializers/inflections.rb
193
+ - test/dummy/config/initializers/mime_types.rb
194
+ - test/dummy/config/initializers/secret_token.rb
195
+ - test/dummy/config/initializers/session_store.rb
196
+ - test/dummy/config/initializers/wrap_parameters.rb
197
+ - test/dummy/config/locales/en.yml
198
+ - test/dummy/config/qor/cache.rb
199
+ - test/dummy/config/routes.rb
200
+ - test/dummy/db/migrate/20121025062539_create_products.rb
201
+ - test/dummy/db/migrate/20121025062642_create_color_variations.rb
202
+ - test/dummy/lib/assets/.gitkeep
203
+ - test/dummy/log/.gitkeep
204
+ - test/dummy/public/404.html
205
+ - test/dummy/public/422.html
206
+ - test/dummy/public/500.html
207
+ - test/dummy/public/favicon.ico
208
+ - test/dummy/script/rails
209
+ - test/dummy/test/fixtures/color_variations.yml
210
+ - test/dummy/test/fixtures/products.yml
211
+ - test/dummy/test/unit/color_variation_test.rb
212
+ - test/dummy/test/unit/product_test.rb
213
+ - test/factories.rb
214
+ - test/qor_cache_fields_test.rb
215
+ - test/qor_cache_key_test.rb
216
+ - test/qor_cache_methods_test.rb
217
+ - test/test_helper.rb