taggable_cache 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,2 +1,10 @@
1
+ lang: ruby
2
+ bundler_args: --without development
3
+ before_install:
4
+ - gem install bundler --pre
1
5
  rvm:
2
6
  - 1.9.3
7
+ gemfile:
8
+ - gemfiles/Gemfile-rails.3.0.x
9
+ - gemfiles/Gemfile-rails.3.1.x
10
+ - gemfiles/Gemfile-rails.3.2.x
data/Gemfile CHANGED
@@ -1,13 +1,17 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'pry'
7
+ gem 'pry-nav'
7
8
  end
8
9
 
10
+ gem 'rake'
9
11
  gem 'rspec-rails', :require => false
10
12
  gem 'rspec'
11
13
  gem 'capybara'
12
- gem 'combustion', '~> 0.3.1'
14
+ gem 'combustion', :git => 'https://brain-geek@github.com/brain-geek/combustion.git' #, '~> 0.3.1'
13
15
  gem 'sqlite3'
16
+
17
+ gem 'rails', '~> 3.2.0'
data/Gemfile.lock CHANGED
@@ -1,19 +1,27 @@
1
+ GIT
2
+ remote: https://brain-geek@github.com/brain-geek/combustion.git
3
+ revision: 3574c523d1ce6d8805ab2218c8d52257b5848640
4
+ specs:
5
+ combustion (0.3.2)
6
+ rails (>= 3.0.0)
7
+ thor (>= 0.14.6)
8
+
1
9
  PATH
2
10
  remote: .
3
11
  specs:
4
- taggable_cache (0.2.0)
12
+ taggable_cache (0.2.1)
5
13
  rails (>= 3.0.8)
6
14
  redis (>= 2.2.2)
7
15
 
8
16
  GEM
9
17
  remote: http://rubygems.org/
10
18
  specs:
11
- actionmailer (3.2.1)
12
- actionpack (= 3.2.1)
19
+ actionmailer (3.2.2)
20
+ actionpack (= 3.2.2)
13
21
  mail (~> 2.4.0)
14
- actionpack (3.2.1)
15
- activemodel (= 3.2.1)
16
- activesupport (= 3.2.1)
22
+ actionpack (3.2.2)
23
+ activemodel (= 3.2.2)
24
+ activesupport (= 3.2.2)
17
25
  builder (~> 3.0.0)
18
26
  erubis (~> 2.7.0)
19
27
  journey (~> 1.0.1)
@@ -21,21 +29,21 @@ GEM
21
29
  rack-cache (~> 1.1)
22
30
  rack-test (~> 0.6.1)
23
31
  sprockets (~> 2.1.2)
24
- activemodel (3.2.1)
25
- activesupport (= 3.2.1)
32
+ activemodel (3.2.2)
33
+ activesupport (= 3.2.2)
26
34
  builder (~> 3.0.0)
27
- activerecord (3.2.1)
28
- activemodel (= 3.2.1)
29
- activesupport (= 3.2.1)
30
- arel (~> 3.0.0)
35
+ activerecord (3.2.2)
36
+ activemodel (= 3.2.2)
37
+ activesupport (= 3.2.2)
38
+ arel (~> 3.0.2)
31
39
  tzinfo (~> 0.3.29)
32
- activeresource (3.2.1)
33
- activemodel (= 3.2.1)
34
- activesupport (= 3.2.1)
35
- activesupport (3.2.1)
40
+ activeresource (3.2.2)
41
+ activemodel (= 3.2.2)
42
+ activesupport (= 3.2.2)
43
+ activesupport (3.2.2)
36
44
  i18n (~> 0.6)
37
45
  multi_json (~> 1.0)
38
- arel (3.0.0)
46
+ arel (3.0.2)
39
47
  builder (3.0.0)
40
48
  capybara (1.1.2)
41
49
  mime-types (>= 1.16)
@@ -46,50 +54,47 @@ GEM
46
54
  xpath (~> 0.1.4)
47
55
  childprocess (0.3.1)
48
56
  ffi (~> 1.0.6)
49
- coderay (0.9.8)
50
- combustion (0.3.1)
51
- rails (>= 3.1.0)
52
- thor (>= 0.14.6)
57
+ coderay (1.0.5)
53
58
  diff-lcs (1.1.3)
54
59
  erubis (2.7.0)
55
60
  ffi (1.0.11)
56
61
  hike (1.2.1)
57
62
  i18n (0.6.0)
58
- journey (1.0.1)
63
+ journey (1.0.3)
59
64
  json (1.6.5)
60
- mail (2.4.1)
65
+ mail (2.4.3)
61
66
  i18n (>= 0.4.0)
62
67
  mime-types (~> 1.16)
63
68
  treetop (~> 1.4.8)
64
- method_source (0.6.7)
65
- ruby_parser (>= 2.3.1)
69
+ method_source (0.7.1)
66
70
  mime-types (1.17.2)
67
- multi_json (1.0.4)
71
+ multi_json (1.1.0)
68
72
  nokogiri (1.5.0)
69
73
  polyglot (0.3.3)
70
- pry (0.9.7.4)
71
- coderay (~> 0.9.8)
72
- method_source (~> 0.6.7)
73
- ruby_parser (>= 2.3.1)
74
- slop (~> 2.1.0)
74
+ pry (0.9.8.4)
75
+ coderay (~> 1.0.5)
76
+ method_source (~> 0.7.1)
77
+ slop (>= 2.4.4, < 3)
78
+ pry-nav (0.1.0)
79
+ pry (~> 0.9.8.1)
75
80
  rack (1.4.1)
76
- rack-cache (1.1)
81
+ rack-cache (1.2)
77
82
  rack (>= 0.4)
78
83
  rack-ssl (1.3.2)
79
84
  rack
80
85
  rack-test (0.6.1)
81
86
  rack (>= 1.0)
82
- rails (3.2.1)
83
- actionmailer (= 3.2.1)
84
- actionpack (= 3.2.1)
85
- activerecord (= 3.2.1)
86
- activeresource (= 3.2.1)
87
- activesupport (= 3.2.1)
87
+ rails (3.2.2)
88
+ actionmailer (= 3.2.2)
89
+ actionpack (= 3.2.2)
90
+ activerecord (= 3.2.2)
91
+ activeresource (= 3.2.2)
92
+ activesupport (= 3.2.2)
88
93
  bundler (~> 1.0)
89
- railties (= 3.2.1)
90
- railties (3.2.1)
91
- actionpack (= 3.2.1)
92
- activesupport (= 3.2.1)
94
+ railties (= 3.2.2)
95
+ railties (3.2.2)
96
+ actionpack (= 3.2.2)
97
+ activesupport (= 3.2.2)
93
98
  rack-ssl (~> 1.3.2)
94
99
  rake (>= 0.8.7)
95
100
  rdoc (~> 3.4)
@@ -111,16 +116,13 @@ GEM
111
116
  activesupport (>= 3.0)
112
117
  railties (>= 3.0)
113
118
  rspec (~> 2.8.0)
114
- ruby_parser (2.3.1)
115
- sexp_processor (~> 3.0)
116
119
  rubyzip (0.9.6.1)
117
- selenium-webdriver (2.19.0)
120
+ selenium-webdriver (2.20.0)
118
121
  childprocess (>= 0.2.5)
119
- ffi (~> 1.0.9)
120
- multi_json (~> 1.0.4)
122
+ ffi (~> 1.0)
123
+ multi_json (~> 1.0)
121
124
  rubyzip
122
- sexp_processor (3.0.10)
123
- slop (2.1.0)
125
+ slop (2.4.4)
124
126
  sprockets (2.1.2)
125
127
  hike (~> 1.2)
126
128
  rack (~> 1.0)
@@ -131,7 +133,7 @@ GEM
131
133
  treetop (1.4.10)
132
134
  polyglot
133
135
  polyglot (>= 0.3.1)
134
- tzinfo (0.3.31)
136
+ tzinfo (0.3.32)
135
137
  xpath (0.1.4)
136
138
  nokogiri (~> 1.3)
137
139
 
@@ -140,8 +142,11 @@ PLATFORMS
140
142
 
141
143
  DEPENDENCIES
142
144
  capybara
143
- combustion (~> 0.3.1)
145
+ combustion!
144
146
  pry
147
+ pry-nav
148
+ rails (~> 3.2.0)
149
+ rake
145
150
  rspec
146
151
  rspec-rails
147
152
  sqlite3
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'taggable_cache', :path => '..'
4
+
5
+ gem 'rake'
6
+ gem 'rspec-rails', :require => false
7
+ gem 'rspec'
8
+ gem 'capybara'
9
+ gem 'combustion', :git => 'https://brain-geek@github.com/brain-geek/combustion.git'
10
+ gem 'sqlite3'
11
+
12
+
13
+ gem 'rails', '~> 3.0.0'
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'taggable_cache', :path => '..'
4
+
5
+ gem 'rake'
6
+ gem 'rspec-rails', :require => false
7
+ gem 'rspec'
8
+ gem 'capybara'
9
+ gem 'combustion', :git => 'https://brain-geek@github.com/brain-geek/combustion.git'
10
+ gem 'sqlite3'
11
+
12
+
13
+ gem 'rails', '~> 3.1.0'
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'taggable_cache', :path => '..'
4
+
5
+ gem 'rake'
6
+ gem 'rspec-rails', :require => false
7
+ gem 'rspec'
8
+ gem 'capybara'
9
+ gem 'combustion', :git => 'https://brain-geek@github.com/brain-geek/combustion.git'
10
+ gem 'sqlite3'
11
+
12
+
13
+ gem 'rails', '~> 3.2.0'
@@ -1,3 +1,9 @@
1
+ require 'active_record'
2
+ require 'action_controller'
3
+ require 'rails'
4
+
5
+ require 'taggable_cache/spectator'
6
+
1
7
  ActiveSupport::Cache::Store.class_eval do
2
8
  def taggable
3
9
  @taggable ||= ::TaggableCache::Store.new
@@ -33,5 +39,10 @@ end
33
39
 
34
40
  module TaggableCache
35
41
  class Railtie < ::Rails::Railtie
42
+ initializer "taggable_cache" do |app|
43
+ # binding.pry
44
+ ActiveRecord::Base.observers << TaggableCache::Spectator
45
+ ActiveRecord::Base.add_observer TaggableCache::Spectator.instance
46
+ end
36
47
  end
37
48
  end
@@ -0,0 +1,9 @@
1
+ class TaggableCache::Spectator < ActiveRecord::Observer
2
+ def event(model)
3
+ Rails.cache.delete_by_tags(model, model.class)
4
+ end
5
+
6
+ alias :after_update :event
7
+ alias :after_destroy :event
8
+ alias :after_create :event
9
+ end
@@ -1,3 +1,3 @@
1
1
  module TaggableCache
2
- VERSION = "0.2.0" # This is for the gem and does not conflict with the rest of the functionality
2
+ VERSION = "0.2.1" # This is for the gem and does not conflict with the rest of the functionality
3
3
  end
@@ -2,4 +2,4 @@ module TaggableCache
2
2
  end
3
3
 
4
4
  require 'taggable_cache/store'
5
- require 'taggable_cache/railtie' if defined?(Rails)
5
+ require 'taggable_cache/railtie'
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+
3
+ describe 'TaggableCache::Rails::Cache' do
4
+ before :all do
5
+ @object = TaggableCache::Store.new
6
+ @page_object = Page.create
7
+ end
8
+
9
+ before :each do
10
+ Redis.new.flushall
11
+ end
12
+
13
+ describe "Rails.cache.write integration" do
14
+ it "adds key to store" do
15
+ Rails.cache.write('key', 'value', :depends_on => [@page_object])
16
+
17
+ @object.get(@page_object).should == ['key']
18
+ end
19
+
20
+ it "does simple writes" do
21
+ Rails.cache.write 'ipsum', 'lorem'
22
+ Rails.cache.read('ipsum').should == 'lorem'
23
+ end
24
+ end
25
+
26
+ describe "Activerecord integration" do
27
+ it "object change" do
28
+ Rails.cache.write('key', 'value', :depends_on => [@page_object])
29
+
30
+ Rails.cache.read('key').should == 'value'
31
+
32
+ #save should trigger deleting depending cache entries
33
+ @page_object.name = @page_object.name.to_s + '1'
34
+ @page_object.save!
35
+
36
+ Rails.cache.read('key').should be_nil
37
+ end
38
+
39
+ it "model change" do
40
+ Rails.cache.write('lorem', 'impsum', :depends_on => [Page])
41
+
42
+ Rails.cache.read('lorem').should == 'impsum'
43
+
44
+ Page.create
45
+
46
+ Rails.cache.read('lorem').should be_nil
47
+ end
48
+
49
+ pending "scope change" do
50
+ it "should not drop if changes are unrelated" do
51
+ Rails.cache.write('lorem', 'impsum', :depends_on => [Page.where(:name => 'bob')])
52
+ Rails.cache.read('lorem').should == 'impsum'
53
+
54
+ page = Page.create(:name => 'jack')
55
+ page.name = 'alice'
56
+ page.save!
57
+ Page.delete(page.id)
58
+
59
+ Rails.cache.read('lorem').should == 'impsum'
60
+ end
61
+
62
+ it "should drop if object has been in scope before changes" do
63
+ page = Page.create(:name => 'jack')
64
+
65
+ Rails.cache.write('lorem', 'impsum', :depends_on => [Page.where(:name => 'jack')])
66
+ Rails.cache.read('lorem').should == 'impsum'
67
+
68
+ page.name = 'alice'
69
+ page.save!
70
+
71
+ Rails.cache.read('lorem').should be_nil
72
+ end
73
+
74
+ it "should drop if object is now in scope" do
75
+ page = Page.create(:name => 'joe')
76
+
77
+ Rails.cache.write('lorem', 'impsum', :depends_on => [Page.where(:name => 'jack')])
78
+ Rails.cache.read('lorem').should == 'impsum'
79
+
80
+ page.name = 'jack'
81
+ page.save!
82
+
83
+ Rails.cache.read('lorem').should be_nil
84
+ end
85
+ end
86
+ end
87
+ end
@@ -12,11 +12,10 @@ describe TaggableCache::Store do
12
12
  before :all do
13
13
  @object = TaggableCache::Store.new
14
14
  @redis = Redis.new
15
- #clean up all redis data
16
15
  @redis.flushall
17
16
  end
18
17
 
19
- describe "queque names" do
18
+ describe "id_for" do
20
19
  it "should use id and model name if saved activerecord object" do
21
20
  page = Page.create
22
21
  @object.id_for(page).should == "page-#{page.id}"
@@ -35,45 +34,47 @@ describe TaggableCache::Store do
35
34
  end
36
35
  end
37
36
 
38
- describe "add data to redis" do
39
- it "should push data" do
40
- o1 = Object.new
41
- o2 = Object.new
37
+ describe "Redis interaction" do
38
+ describe "add data" do
39
+ it "should push data" do
40
+ o1 = Object.new
41
+ o2 = Object.new
42
42
 
43
- @object.should_receive(:id_for).with(o1).and_return('member1')
44
- @object.should_receive(:id_for).with(o2).and_return('member2')
45
- @object.should_receive(:id_for).with(nil).and_return(nil)
43
+ @object.should_receive(:id_for).with(o1).and_return('member1')
44
+ @object.should_receive(:id_for).with(o2).and_return('member2')
45
+ @object.should_receive(:id_for).with(nil).and_return(nil)
46
46
 
47
- @object.add('tag_name', o1, nil, o2)
47
+ @object.add('tag_name', o1, nil, o2)
48
48
 
49
- @redis.smembers(nil).should == []
50
- @redis.smembers('member1').should == ['tag_name']
51
- @redis.smembers('member2').should == ['tag_name']
49
+ @redis.smembers(nil).should == []
50
+ @redis.smembers('member1').should == ['tag_name']
51
+ @redis.smembers('member2').should == ['tag_name']
52
+ end
52
53
  end
53
- end
54
54
 
55
- describe "get data from redis" do
56
- it "should return keys and leave nothing behind" do
57
- page = Page.create
55
+ describe "get data" do
56
+ it "should return keys and leave nothing behind" do
57
+ page = Page.create
58
58
 
59
- @object.add('tag_name', page)
60
- @redis.smembers("page-#{page.id}").should == ['tag_name']
61
-
62
- @object.get(page).should == ['tag_name']
63
- @redis.smembers("page-#{page.id}").should be_empty
64
- end
59
+ @object.add('tag_name', page)
60
+ @redis.smembers("page-#{page.id}").should == ['tag_name']
61
+
62
+ @object.get(page).should == ['tag_name']
63
+ @redis.smembers("page-#{page.id}").should be_empty
64
+ end
65
65
 
66
- it "should do multi-get" do
67
- page = Page.create
66
+ it "should do multi-get" do
67
+ page = Page.create
68
68
 
69
- @object.add('tag_name', page)
70
- @object.add('tag2', Page)
71
- @redis.smembers("page-#{page.id}").should == ['tag_name']
72
- @redis.smembers("page").should == ['tag2']
73
-
74
- @object.get(page, Page).should == ['tag_name', 'tag2']
75
- @redis.smembers("page-#{page.id}").should be_empty
76
- @redis.smembers("page").should be_empty
69
+ @object.add('tag_name', page)
70
+ @object.add('tag2', Page)
71
+ @redis.smembers("page-#{page.id}").should == ['tag_name']
72
+ @redis.smembers("page").should == ['tag2']
73
+
74
+ @object.get(page, Page).should == ['tag_name', 'tag2']
75
+ @redis.smembers("page-#{page.id}").should be_empty
76
+ @redis.smembers("page").should be_empty
77
+ end
77
78
  end
78
79
  end
79
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taggable_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &72497550 !ruby/object:Gem::Requirement
16
+ requirement: &81044650 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *72497550
24
+ version_requirements: *81044650
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &72496880 !ruby/object:Gem::Requirement
27
+ requirement: &81044090 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.2.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *72496880
35
+ version_requirements: *81044090
36
36
  description: This gem simplifies cache expiration in rails
37
37
  email: brain-geek@yandex.ua
38
38
  executables: []
@@ -48,23 +48,23 @@ files:
48
48
  - LICENSE.txt
49
49
  - README.rdoc
50
50
  - Rakefile
51
+ - gemfiles/Gemfile-rails.3.0.x
52
+ - gemfiles/Gemfile-rails.3.1.x
53
+ - gemfiles/Gemfile-rails.3.2.x
51
54
  - lib/taggable_cache.rb
52
- - lib/taggable_cache/rails/observer.rb
53
55
  - lib/taggable_cache/railtie.rb
56
+ - lib/taggable_cache/spectator.rb
54
57
  - lib/taggable_cache/store.rb
55
58
  - lib/taggable_cache/version.rb
59
+ - spec/integration/rails_cache_spec.rb
56
60
  - spec/internal/app/controller/action_caching_controller.rb
57
61
  - spec/internal/app/controller/fragment_caching_controller.rb
58
62
  - spec/internal/app/models/page.rb
59
- - spec/internal/app/models/simple_observer.rb
60
63
  - spec/internal/app/views/fragment_caching/index.html.erb
61
64
  - spec/internal/config/database.yml
62
- - spec/internal/config/initializers/taggable.rb
63
65
  - spec/internal/config/routes.rb
64
66
  - spec/internal/db/schema.rb
65
67
  - spec/internal/public/favicon.ico
66
- - spec/models/page_spec.rb
67
- - spec/rails_cache_spec.rb
68
68
  - spec/requests/action_caching_controller_spec.rb
69
69
  - spec/requests/fragment_caching_controller_spec.rb
70
70
  - spec/spec_helper.rb
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -828411823
88
+ hash: -685870733
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
@@ -94,10 +94,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: -828411823
97
+ hash: -685870733
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 1.8.15
100
+ rubygems_version: 1.8.10
101
101
  signing_key:
102
102
  specification_version: 3
103
103
  summary: This gem simplifies cache expiration in rails by providing depends_on option
@@ -1,11 +0,0 @@
1
- module TaggableCache::Rails
2
- class Observer < ActiveRecord::Observer
3
- def event(model)
4
- Rails.cache.delete_by_tags(model, model.class)
5
- end
6
-
7
- alias :after_update :event
8
- alias :after_destroy :event
9
- alias :after_create :event
10
- end
11
- end
@@ -1,5 +0,0 @@
1
- require 'taggable_cache/rails/observer'
2
-
3
- class SimpleObserver < TaggableCache::Rails::Observer
4
- observe Page
5
- end
@@ -1,3 +0,0 @@
1
- #Listing all models with enabled taggable cache
2
-
3
- Combustion::Application.config.active_record.observers = :simple_observer
@@ -1,4 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- describe Page do
4
- end
@@ -1,51 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
-
3
- describe 'TaggableCache::Rails::Cache' do
4
- before :all do
5
- @object = TaggableCache::Store.new
6
- Redis.new.flushall
7
- @page_object = Page.create
8
- end
9
-
10
- before :each do
11
- Rails.cache.delete 'key'
12
- Rails.cache.delete 'lorem'
13
- end
14
-
15
- describe "taggable hooked on Rails.cache.write" do
16
- it "adds key to store" do
17
- Rails.cache.write('key', 'value', :depends_on => [@page_object])
18
-
19
- @object.get(@page_object).should == ['key']
20
- end
21
- end
22
-
23
- describe "taggable hooked as observer" do
24
- it "detects object change" do
25
- Rails.cache.write('key', 'value', :depends_on => [@page_object])
26
-
27
- Rails.cache.read('key').should == 'value'
28
-
29
- #save should trigger deleting depending cache entries
30
- @page_object.name = @page_object.name.to_s + '1'
31
- @page_object.save!
32
-
33
- Rails.cache.read('key').should be_nil
34
- end
35
-
36
- it "detects model change" do
37
- Rails.cache.write('lorem', 'impsum', :depends_on => [Page])
38
-
39
- Rails.cache.read('lorem').should == 'impsum'
40
-
41
- Page.create
42
-
43
- Rails.cache.read('lorem').should be_nil
44
- end
45
-
46
- it "does simple writes" do
47
- Rails.cache.write 'ipsum', 'lorem'
48
- Rails.cache.read('ipsum').should == 'lorem'
49
- end
50
- end
51
- end