jodosha-cached-models 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +142 -0
- data/MIT-LICENSE +20 -0
- data/README +95 -0
- data/Rakefile +81 -0
- data/about.yml +8 -0
- data/cached-models.gemspec +18 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/activerecord/lib/active_record.rb +4 -0
- data/lib/activerecord/lib/active_record/associations.rb +404 -0
- data/lib/activerecord/lib/active_record/associations/association_collection.rb +127 -0
- data/lib/activerecord/lib/active_record/associations/association_proxy.rb +39 -0
- data/lib/activerecord/lib/active_record/associations/has_many_association.rb +7 -0
- data/lib/activerecord/lib/active_record/base.rb +73 -0
- data/lib/cached-models.rb +1 -0
- data/lib/cached_models.rb +4 -0
- data/setup.rb +1585 -0
- data/tasks/cached_models_tasks.rake +117 -0
- data/test/active_record/associations/has_and_belongs_to_many_association_test.rb +12 -0
- data/test/active_record/associations/has_many_association_test.rb +355 -0
- data/test/active_record/associations/has_one_association_test.rb +12 -0
- data/test/active_record/base_test.rb +32 -0
- data/test/fixtures/addresses.yml +7 -0
- data/test/fixtures/authors.yml +13 -0
- data/test/fixtures/blogs.yml +7 -0
- data/test/fixtures/categories.yml +3 -0
- data/test/fixtures/categories_posts.yml +3 -0
- data/test/fixtures/comments.yml +19 -0
- data/test/fixtures/posts.yml +23 -0
- data/test/fixtures/tags.yml +14 -0
- data/test/models/address.rb +3 -0
- data/test/models/author.rb +12 -0
- data/test/models/blog.rb +4 -0
- data/test/models/category.rb +3 -0
- data/test/models/comment.rb +3 -0
- data/test/models/post.rb +8 -0
- data/test/models/tag.rb +3 -0
- data/test/test_helper.rb +88 -0
- data/uninstall.rb +1 -0
- metadata +112 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class HasOneAssociationTest < Test::Unit::TestCase
|
4
|
+
include ActiveRecord::Associations
|
5
|
+
|
6
|
+
def test_should_not_raise_exception_when_use_has_one
|
7
|
+
assert_nothing_raised ArgumentError do
|
8
|
+
authors(:luca).address
|
9
|
+
addresses(:luca).author
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
fixtures :authors
|
5
|
+
|
6
|
+
def test_should_have_cache
|
7
|
+
assert_equal RAILS_CACHE, ActiveRecord::Base.rails_cache if defined? Rails
|
8
|
+
assert_kind_of ActiveSupport::Cache::Store, ActiveRecord::Base.rails_cache
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_wrap_rails_cache
|
12
|
+
assert_equal RAILS_CACHE, Post.new.send(:rails_cache) if defined? Rails
|
13
|
+
assert_kind_of ActiveSupport::Cache::Store, Post.new.send(:rails_cache)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_reflection_cache_key
|
17
|
+
author = authors(:luca)
|
18
|
+
actual = author.send(:reflection_cache_key, Author.reflections[:cached_posts])
|
19
|
+
assert_equal "#{author.cache_key}/cached_posts", actual
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_cached_association
|
23
|
+
author = authors(:luca)
|
24
|
+
assert_equal({}, author.send(:cached_associations))
|
25
|
+
|
26
|
+
author.cached_posts # force cache loading
|
27
|
+
assert_equal({:cached_posts => true}, author.send(:cached_associations))
|
28
|
+
|
29
|
+
author.send(:cache_delete, Author.reflections[:cached_posts])
|
30
|
+
assert_equal({:cached_posts => false}, author.send(:cached_associations))
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
comment:
|
2
|
+
post_id: 1
|
3
|
+
email: john@doe.com
|
4
|
+
text: Good luck for your blog.
|
5
|
+
|
6
|
+
positive_comment:
|
7
|
+
post_id: 2
|
8
|
+
email: john@doe.com
|
9
|
+
text: Very nice plugin, thank you!
|
10
|
+
|
11
|
+
negative_comment:
|
12
|
+
post_id: 2
|
13
|
+
email: doe@john.com
|
14
|
+
text: Crappy stuff!
|
15
|
+
|
16
|
+
comment_for_fight_club:
|
17
|
+
post_id: 3
|
18
|
+
email: john@doe.com
|
19
|
+
text: Awsome book!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
welcome:
|
2
|
+
id: 1
|
3
|
+
blog_id: 1
|
4
|
+
author_id: 1
|
5
|
+
title: Welcome
|
6
|
+
text: Welcome to my blog
|
7
|
+
published_at: <%= 3.years.ago %>
|
8
|
+
|
9
|
+
cached_models:
|
10
|
+
id: 2
|
11
|
+
blog_id: 1
|
12
|
+
author_id: 1
|
13
|
+
title: Cached Models
|
14
|
+
text: Cached Models plugin overview
|
15
|
+
published_at: <%= 2.weeks.ago %>
|
16
|
+
|
17
|
+
fight_club:
|
18
|
+
id: 3
|
19
|
+
blog_id: 2
|
20
|
+
author_id: 2
|
21
|
+
title: Fight Club
|
22
|
+
text: This is a Fight Club review
|
23
|
+
published_at: <%= 1.week.ago %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
announcements_on_welcome:
|
2
|
+
taggable_id: 1
|
3
|
+
taggable_type: Post
|
4
|
+
name: announcements
|
5
|
+
|
6
|
+
plugin_on_cached_models:
|
7
|
+
taggable_id: 2
|
8
|
+
taggable_type: Post
|
9
|
+
name: plugin
|
10
|
+
|
11
|
+
rails_on_cached_models:
|
12
|
+
taggable_id: 2
|
13
|
+
taggable_type: Post
|
14
|
+
name: rails
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Author < ActiveRecord::Base
|
2
|
+
belongs_to :blog, :cached => true
|
3
|
+
has_many :posts
|
4
|
+
has_many :cached_posts, :cached => true, :class_name => 'Post'
|
5
|
+
has_many :uniq_cached_posts, :cached => true, :class_name => 'Post', :uniq => true
|
6
|
+
has_many :cached_dependent_posts, :cached => true, :class_name => 'Post', :dependent => :destroy
|
7
|
+
has_many :posts_with_comments, :class_name => 'Post', :include => :comments
|
8
|
+
has_many :cached_posts_with_comments, :class_name => 'Post', :include => :comments, :cached => true
|
9
|
+
has_many :comments, :through => :posts
|
10
|
+
has_many :cached_comments, :through => :posts, :source => :comments, :cached => true
|
11
|
+
has_one :address
|
12
|
+
end
|
data/test/models/blog.rb
ADDED
data/test/models/post.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
belongs_to :author, :cached => true
|
3
|
+
belongs_to :blog
|
4
|
+
has_many :comments
|
5
|
+
has_many :tags, :as => :taggable
|
6
|
+
has_many :cached_tags, :as => :taggable, :class_name => 'Tag', :cached => true
|
7
|
+
has_and_belongs_to_many :categories
|
8
|
+
end
|
data/test/models/tag.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
RAILS_ENV = "test" unless defined? RAILS_ENV
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'active_support/test_case'
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
require 'action_controller/integration'
|
10
|
+
|
11
|
+
# FIXME load path
|
12
|
+
require File.dirname(__FILE__) + '/../../../../config/environment'
|
13
|
+
$:.unshift File.dirname(__FILE__) + '/models'
|
14
|
+
require 'author'
|
15
|
+
require 'post'
|
16
|
+
|
17
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures"
|
18
|
+
ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path
|
19
|
+
|
20
|
+
module WillPaginate #:nodoc:
|
21
|
+
def paginate(*args)
|
22
|
+
options = args.extract_options!
|
23
|
+
current_page, per_page = options[:page], options[:per_page]
|
24
|
+
offset = (current_page - 1) * per_page
|
25
|
+
|
26
|
+
count_options = options.except :page, :per_page
|
27
|
+
find_options = count_options.except(:count).update(:offset => offset, :limit => per_page)
|
28
|
+
|
29
|
+
args << find_options
|
30
|
+
@reflection.klass.find(*args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ActiveRecord
|
35
|
+
module Associations
|
36
|
+
class AssociationCollection < AssociationProxy #:nodoc:
|
37
|
+
include WillPaginate
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Test::Unit::TestCase
|
43
|
+
self.use_transactional_fixtures = true
|
44
|
+
self.use_instantiated_fixtures = false
|
45
|
+
fixtures :all
|
46
|
+
|
47
|
+
# Assert the given condition is false
|
48
|
+
def assert_false(condition, message = nil)
|
49
|
+
assert !condition, message
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def cache
|
54
|
+
ActiveRecord::Base.rails_cache
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def uses_mocha(description)
|
59
|
+
require 'rubygems'
|
60
|
+
require 'mocha'
|
61
|
+
yield
|
62
|
+
rescue LoadError
|
63
|
+
$stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
|
64
|
+
end
|
65
|
+
|
66
|
+
def uses_memcached(description)
|
67
|
+
require 'memcache'
|
68
|
+
MemCache.new('localhost').stats
|
69
|
+
yield
|
70
|
+
rescue MemCache::MemCacheError
|
71
|
+
$stderr.puts "Skipping #{description} tests. Start memcached and try again."
|
72
|
+
end
|
73
|
+
|
74
|
+
if ENV['SKIP_MOCHA'] == 'true'
|
75
|
+
class Object
|
76
|
+
def expects(*args)
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def method_missing(method_name, *args, &block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class NilClass
|
85
|
+
def method_missing(method_name, *args, &block)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jodosha-cached-models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luca Guidi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: activerecord
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.1.0
|
32
|
+
version:
|
33
|
+
description: CachedModels provides to your ActiveRecord models a transparent approach to use ActiveSupport caching mechanism.
|
34
|
+
email: guidi.luca@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README
|
41
|
+
- CHANGELOG
|
42
|
+
files:
|
43
|
+
- CHANGELOG
|
44
|
+
- MIT-LICENSE
|
45
|
+
- README
|
46
|
+
- Rakefile
|
47
|
+
- about.yml
|
48
|
+
- cached-models.gemspec
|
49
|
+
- init.rb
|
50
|
+
- install.rb
|
51
|
+
- lib/activerecord/lib/active_record.rb
|
52
|
+
- lib/activerecord/lib/active_record/associations.rb
|
53
|
+
- lib/activerecord/lib/active_record/associations/association_collection.rb
|
54
|
+
- lib/activerecord/lib/active_record/associations/association_proxy.rb
|
55
|
+
- lib/activerecord/lib/active_record/associations/has_many_association.rb
|
56
|
+
- lib/activerecord/lib/active_record/base.rb
|
57
|
+
- lib/cached-models.rb
|
58
|
+
- lib/cached_models.rb
|
59
|
+
- setup.rb
|
60
|
+
- tasks/cached_models_tasks.rake
|
61
|
+
- test/active_record/associations/has_and_belongs_to_many_association_test.rb
|
62
|
+
- test/active_record/associations/has_many_association_test.rb
|
63
|
+
- test/active_record/associations/has_one_association_test.rb
|
64
|
+
- test/active_record/base_test.rb
|
65
|
+
- test/fixtures/addresses.yml
|
66
|
+
- test/fixtures/authors.yml
|
67
|
+
- test/fixtures/blogs.yml
|
68
|
+
- test/fixtures/categories.yml
|
69
|
+
- test/fixtures/categories_posts.yml
|
70
|
+
- test/fixtures/comments.yml
|
71
|
+
- test/fixtures/posts.yml
|
72
|
+
- test/fixtures/tags.yml
|
73
|
+
- test/models/address.rb
|
74
|
+
- test/models/author.rb
|
75
|
+
- test/models/blog.rb
|
76
|
+
- test/models/category.rb
|
77
|
+
- test/models/comment.rb
|
78
|
+
- test/models/post.rb
|
79
|
+
- test/models/tag.rb
|
80
|
+
- test/test_helper.rb
|
81
|
+
- uninstall.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://lucaguidi.com/pages/cached_models
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: cached-models
|
104
|
+
rubygems_version: 1.2.0
|
105
|
+
signing_key:
|
106
|
+
specification_version: 2
|
107
|
+
summary: Transparent caching policy for your models
|
108
|
+
test_files:
|
109
|
+
- test/active_record/associations/has_and_belongs_to_many_association_test.rb
|
110
|
+
- test/active_record/associations/has_many_association_test.rb
|
111
|
+
- test/active_record/associations/has_one_association_test.rb
|
112
|
+
- test/active_record/base_test.rb
|