cashier-ftbpro 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +195 -0
  5. data/Rakefile +11 -0
  6. data/cashier.gemspec +27 -0
  7. data/lib/cashier.rb +257 -0
  8. data/lib/cashier/adapters/cache_store.rb +66 -0
  9. data/lib/cashier/adapters/redis_store.rb +62 -0
  10. data/lib/cashier/cucumber.rb +6 -0
  11. data/lib/cashier/matchers.rb +38 -0
  12. data/lib/cashier/railtie.rb +9 -0
  13. data/lib/cashier/version.rb +3 -0
  14. data/spec/dummy/.gitignore +4 -0
  15. data/spec/dummy/Gemfile +31 -0
  16. data/spec/dummy/README +256 -0
  17. data/spec/dummy/Rakefile +7 -0
  18. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  19. data/spec/dummy/app/controllers/home_controller.rb +7 -0
  20. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  21. data/spec/dummy/app/helpers/home_helper.rb +2 -0
  22. data/spec/dummy/app/views/home/index.html.erb +1 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/spec/dummy/config.ru +4 -0
  25. data/spec/dummy/config/application.rb +44 -0
  26. data/spec/dummy/config/boot.rb +10 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +25 -0
  29. data/spec/dummy/config/environments/production.rb +46 -0
  30. data/spec/dummy/config/environments/test.rb +31 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/dummy/config/initializers/inflections.rb +10 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  34. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  35. data/spec/dummy/config/initializers/session_store.rb +8 -0
  36. data/spec/dummy/config/locales/en.yml +5 -0
  37. data/spec/dummy/config/routes.rb +60 -0
  38. data/spec/dummy/db/seeds.rb +7 -0
  39. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  40. data/spec/dummy/public/404.html +26 -0
  41. data/spec/dummy/public/422.html +26 -0
  42. data/spec/dummy/public/500.html +26 -0
  43. data/spec/dummy/public/favicon.ico +0 -0
  44. data/spec/dummy/public/images/rails.png +0 -0
  45. data/spec/dummy/public/javascripts/application.js +2 -0
  46. data/spec/dummy/public/javascripts/controls.js +965 -0
  47. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  48. data/spec/dummy/public/javascripts/effects.js +1123 -0
  49. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  50. data/spec/dummy/public/javascripts/rails.js +191 -0
  51. data/spec/dummy/public/robots.txt +5 -0
  52. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  53. data/spec/dummy/script/rails +6 -0
  54. data/spec/dummy/test/performance/browsing_test.rb +9 -0
  55. data/spec/dummy/test/test_helper.rb +13 -0
  56. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  57. data/spec/integration/rails_cache_integration_spec.rb +68 -0
  58. data/spec/integration/rails_configuration_spec.rb +9 -0
  59. data/spec/lib/cashier/adapters/cache_store_spec.rb +92 -0
  60. data/spec/lib/cashier/adapters/redis_store_spec.rb +107 -0
  61. data/spec/lib/cashier_spec.rb +154 -0
  62. data/spec/spec_helper.rb +48 -0
  63. metadata +255 -0
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Cashier" do
4
+ before(:each) do
5
+ Cashier.adapter = :cache_store
6
+ end
7
+
8
+ subject { Cashier }
9
+
10
+ let(:adapter) { Cashier.adapter }
11
+
12
+ describe "#store_fragment" do
13
+ it "should write the tag to the cache" do
14
+ adapter.should_receive(:store_fragment_in_tag).with('fragment-key', 'dashboard')
15
+ adapter.should_receive(:store_tags).with(["dashboard"])
16
+
17
+ subject.store_fragment('fragment-key', 'dashboard')
18
+ end
19
+
20
+ it "should flatten tags" do
21
+ adapter.should_receive(:store_fragment_in_tag).with('fragment-key', 'dashboard')
22
+ adapter.should_receive(:store_tags).with(["dashboard"])
23
+
24
+ subject.store_fragment('fragment-key', ['dashboard'])
25
+ end
26
+
27
+ it "should store the tag for book keeping" do
28
+ adapter.should_receive(:store_fragment_in_tag).with('fragment-key', 'dashboard')
29
+ adapter.should_receive(:store_fragment_in_tag).with('fragment-key', 'settings')
30
+
31
+ adapter.should_receive(:store_tags).with(["dashboard", "settings"])
32
+
33
+ subject.store_fragment('fragment-key', 'dashboard', 'settings')
34
+ end
35
+ end
36
+
37
+ describe "Cashier notifications" do
38
+ let(:notification_system) { ActiveSupport::Notifications }
39
+
40
+ it "should raise a callback when I call store_fragment" do
41
+ notification_system.should_receive(:instrument).with("store_fragment.cashier", :data => ["foo", ["bar"]])
42
+ subject.store_fragment("foo", "bar")
43
+ end
44
+
45
+ it "should raise a callback method when I call clear" do
46
+ notification_system.should_receive(:instrument).with("clear.cashier")
47
+ subject.clear
48
+ end
49
+
50
+ it "should raise a callback method when I call expire" do
51
+ notification_system.should_receive(:instrument).with("cache_read.active_support", :key => "cashier-tag-containers:some_tag")
52
+ notification_system.should_receive(:instrument).with("expire.cashier", :data => ["some_tag"])
53
+ subject.expire("some_tag")
54
+ end
55
+ end
56
+
57
+ describe "#expire" do
58
+ before do
59
+ subject.store_fragment('fragment-key', 'dashboard')
60
+ end
61
+
62
+ it "should remove delete the fragment key" do
63
+ adapter.should_receive(:get_fragments_for_tag).with('dashboard').and_return(["fragment-key"])
64
+ adapter.should_receive(:delete_tag).with('dashboard')
65
+ adapter.should_receive(:remove_tags).with(['dashboard'])
66
+
67
+ subject.expire('dashboard')
68
+ end
69
+
70
+ it "should remove the tag" do
71
+ adapter.should_receive(:get_fragments_for_tag).with('dashboard').and_return([])
72
+ adapter.should_receive(:delete_tag).with('dashboard')
73
+ adapter.should_receive(:remove_tags).with(['dashboard'])
74
+
75
+ subject.expire('dashboard')
76
+ end
77
+
78
+ it "should remove the tag from the list of tracked tags" do
79
+ adapter.should_receive(:get_fragments_for_tag).with('dashboard').and_return(['fragment-key'])
80
+ adapter.should_receive(:delete_tag).with('dashboard')
81
+
82
+ subject.expire('dashboard')
83
+ end
84
+ end
85
+
86
+ describe "#tags" do
87
+ it "should return a list of active tags" do
88
+ subject.store_fragment('key1', 'dashboard')
89
+ subject.store_fragment('key2', 'settings')
90
+ subject.store_fragment('key3', 'email')
91
+
92
+ subject.tags.should eql(%w(dashboard settings email))
93
+ end
94
+ end
95
+
96
+ describe '#clear' do
97
+ before(:each) do
98
+ subject.store_fragment('key1', 'dashboard')
99
+ subject.store_fragment('key2', 'settings')
100
+ subject.store_fragment('key3', 'email')
101
+ end
102
+
103
+ it "should expire all tags" do
104
+ adapter.should_receive(:clear)
105
+ subject.clear
106
+ end
107
+
108
+ it "should clear the list of tracked tags" do
109
+ subject.clear
110
+ adapter.tags.should == []
111
+ end
112
+ end
113
+
114
+ describe '#keys' do
115
+ it "should return an array of all the tracked keys" do
116
+ adapter.should_receive(:keys).and_return(%w(key1 key2 key3))
117
+ subject.keys.should eql(%w(key1 key2 key3))
118
+ end
119
+ end
120
+
121
+ describe '#keys_for' do
122
+ it "should return an array of all the keys for the tag" do
123
+ adapter.should_receive(:get_fragments_for_tag).with('dashboard').and_return(%w(key1 key2 key3))
124
+ subject.keys_for('dashboard').should eql(%w(key1 key2 key3))
125
+ end
126
+ end
127
+
128
+ it "should allow me to set the adapter" do
129
+ subject.respond_to?(:adapter=).should be_true
130
+ end
131
+
132
+ it "shold allow to get the adapter" do
133
+ subject.respond_to?(:adapter).should be_true
134
+ end
135
+
136
+ it "should set a container cache key" do
137
+ subject.container_cache_key(:something).should match(/something/)
138
+ end
139
+
140
+ it "should canonize ActiveRecord tags" do
141
+ require 'active_record'
142
+
143
+ ar_class = double("ar_class")
144
+ ar_class.stub(name: :AR)
145
+
146
+ ar = double("active_record")
147
+ ar.stub(class: ar_class)
148
+ ar.stub(is_a?: true)
149
+ ar.stub(to_param: 123)
150
+
151
+ res = Cashier.canonize_tags([1, 2, ar])
152
+ res.should == [1, 2, "AR-123"]
153
+ end
154
+ end
@@ -0,0 +1,48 @@
1
+ require 'simplecov'
2
+ require 'redis'
3
+ require 'dalli'
4
+
5
+ SimpleCov.start
6
+
7
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
8
+
9
+ require 'cashier'
10
+
11
+ ENV['RAILS_ENV'] = 'test'
12
+ require 'dummy/config/environment'
13
+
14
+ require 'rspec/rails'
15
+
16
+ require 'fileutils'
17
+
18
+ RSpec.configure do |config|
19
+ # ==========================> Redis test configuration
20
+ REDIS_PID = Rails.root.join 'tmp', 'pids', 'redis.pid'
21
+
22
+ FileUtils.mkdir_p Rails.root.join 'tmp', 'pids'
23
+ FileUtils.mkdir_p Rails.root.join 'tmp', 'cache'
24
+
25
+ config.before(:suite) do
26
+ redis_options = {
27
+ "daemonize" => 'yes',
28
+ "pidfile" => REDIS_PID,
29
+ "port" => 6397,
30
+ "dir" => Rails.root.join('tmp', 'cache'),
31
+ }.map { |k, v| "#{k} #{v}" }.join('\n')
32
+
33
+ `echo '#{redis_options}' | redis-server -`
34
+
35
+ sleep 0.25
36
+
37
+ Cashier::Adapters::RedisStore.redis = Redis.new(:host => '127.0.0.1', :port => 6397)
38
+ end
39
+
40
+ config.before(:each) do
41
+ Cashier::Adapters::RedisStore.redis.flushdb
42
+ Rails.cache.clear
43
+ end
44
+
45
+ config.after :suite do
46
+ Process.kill "TERM", File.read(REDIS_PID).to_i
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,255 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cashier-ftbpro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Hawkins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ none: false
23
+ type: :development
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '3.0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ none: false
39
+ type: :development
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ prerelease: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: dalli
64
+ prerelease: false
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ none: false
71
+ type: :development
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ none: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ prerelease: false
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ none: false
87
+ type: :development
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ none: false
94
+ - !ruby/object:Gem::Dependency
95
+ name: redis
96
+ prerelease: false
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.2.0
102
+ none: false
103
+ type: :development
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: 2.2.0
109
+ none: false
110
+ description: Associate different cached content with a tag, then expire by tag instead
111
+ of key
112
+ email:
113
+ - me@broadcastingadam.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - cashier.gemspec
124
+ - lib/cashier.rb
125
+ - lib/cashier/adapters/cache_store.rb
126
+ - lib/cashier/adapters/redis_store.rb
127
+ - lib/cashier/cucumber.rb
128
+ - lib/cashier/matchers.rb
129
+ - lib/cashier/railtie.rb
130
+ - lib/cashier/version.rb
131
+ - spec/dummy/.gitignore
132
+ - spec/dummy/Gemfile
133
+ - spec/dummy/Gemfile.lock
134
+ - spec/dummy/README
135
+ - spec/dummy/Rakefile
136
+ - spec/dummy/app/controllers/application_controller.rb
137
+ - spec/dummy/app/controllers/home_controller.rb
138
+ - spec/dummy/app/helpers/application_helper.rb
139
+ - spec/dummy/app/helpers/home_helper.rb
140
+ - spec/dummy/app/views/home/index.html.erb
141
+ - spec/dummy/app/views/layouts/application.html.erb
142
+ - spec/dummy/config.ru
143
+ - spec/dummy/config/application.rb
144
+ - spec/dummy/config/boot.rb
145
+ - spec/dummy/config/environment.rb
146
+ - spec/dummy/config/environments/development.rb
147
+ - spec/dummy/config/environments/production.rb
148
+ - spec/dummy/config/environments/test.rb
149
+ - spec/dummy/config/initializers/backtrace_silencers.rb
150
+ - spec/dummy/config/initializers/inflections.rb
151
+ - spec/dummy/config/initializers/mime_types.rb
152
+ - spec/dummy/config/initializers/secret_token.rb
153
+ - spec/dummy/config/initializers/session_store.rb
154
+ - spec/dummy/config/locales/en.yml
155
+ - spec/dummy/config/routes.rb
156
+ - spec/dummy/db/seeds.rb
157
+ - spec/dummy/lib/tasks/.gitkeep
158
+ - spec/dummy/public/404.html
159
+ - spec/dummy/public/422.html
160
+ - spec/dummy/public/500.html
161
+ - spec/dummy/public/favicon.ico
162
+ - spec/dummy/public/images/rails.png
163
+ - spec/dummy/public/javascripts/application.js
164
+ - spec/dummy/public/javascripts/controls.js
165
+ - spec/dummy/public/javascripts/dragdrop.js
166
+ - spec/dummy/public/javascripts/effects.js
167
+ - spec/dummy/public/javascripts/prototype.js
168
+ - spec/dummy/public/javascripts/rails.js
169
+ - spec/dummy/public/robots.txt
170
+ - spec/dummy/public/stylesheets/.gitkeep
171
+ - spec/dummy/script/rails
172
+ - spec/dummy/test/performance/browsing_test.rb
173
+ - spec/dummy/test/test_helper.rb
174
+ - spec/dummy/vendor/plugins/.gitkeep
175
+ - spec/integration/rails_cache_integration_spec.rb
176
+ - spec/integration/rails_configuration_spec.rb
177
+ - spec/lib/cashier/adapters/cache_store_spec.rb
178
+ - spec/lib/cashier/adapters/redis_store_spec.rb
179
+ - spec/lib/cashier_spec.rb
180
+ - spec/spec_helper.rb
181
+ homepage: https://github.com/threadedlabs/cashier
182
+ licenses: []
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ none: false
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ none: false
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 1.8.24
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: Tag based caching for Rails using Redis or Memcached
205
+ test_files:
206
+ - spec/dummy/.gitignore
207
+ - spec/dummy/Gemfile
208
+ - spec/dummy/Gemfile.lock
209
+ - spec/dummy/README
210
+ - spec/dummy/Rakefile
211
+ - spec/dummy/app/controllers/application_controller.rb
212
+ - spec/dummy/app/controllers/home_controller.rb
213
+ - spec/dummy/app/helpers/application_helper.rb
214
+ - spec/dummy/app/helpers/home_helper.rb
215
+ - spec/dummy/app/views/home/index.html.erb
216
+ - spec/dummy/app/views/layouts/application.html.erb
217
+ - spec/dummy/config.ru
218
+ - spec/dummy/config/application.rb
219
+ - spec/dummy/config/boot.rb
220
+ - spec/dummy/config/environment.rb
221
+ - spec/dummy/config/environments/development.rb
222
+ - spec/dummy/config/environments/production.rb
223
+ - spec/dummy/config/environments/test.rb
224
+ - spec/dummy/config/initializers/backtrace_silencers.rb
225
+ - spec/dummy/config/initializers/inflections.rb
226
+ - spec/dummy/config/initializers/mime_types.rb
227
+ - spec/dummy/config/initializers/secret_token.rb
228
+ - spec/dummy/config/initializers/session_store.rb
229
+ - spec/dummy/config/locales/en.yml
230
+ - spec/dummy/config/routes.rb
231
+ - spec/dummy/db/seeds.rb
232
+ - spec/dummy/lib/tasks/.gitkeep
233
+ - spec/dummy/public/404.html
234
+ - spec/dummy/public/422.html
235
+ - spec/dummy/public/500.html
236
+ - spec/dummy/public/favicon.ico
237
+ - spec/dummy/public/images/rails.png
238
+ - spec/dummy/public/javascripts/application.js
239
+ - spec/dummy/public/javascripts/controls.js
240
+ - spec/dummy/public/javascripts/dragdrop.js
241
+ - spec/dummy/public/javascripts/effects.js
242
+ - spec/dummy/public/javascripts/prototype.js
243
+ - spec/dummy/public/javascripts/rails.js
244
+ - spec/dummy/public/robots.txt
245
+ - spec/dummy/public/stylesheets/.gitkeep
246
+ - spec/dummy/script/rails
247
+ - spec/dummy/test/performance/browsing_test.rb
248
+ - spec/dummy/test/test_helper.rb
249
+ - spec/dummy/vendor/plugins/.gitkeep
250
+ - spec/integration/rails_cache_integration_spec.rb
251
+ - spec/integration/rails_configuration_spec.rb
252
+ - spec/lib/cashier/adapters/cache_store_spec.rb
253
+ - spec/lib/cashier/adapters/redis_store_spec.rb
254
+ - spec/lib/cashier_spec.rb
255
+ - spec/spec_helper.rb