/
reload_test.rb
85 lines (73 loc) · 1.8 KB
/
reload_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require File.expand_path("helper", File.dirname(__FILE__))
class ReloadTest < ActiveSupport::TestCase
context "Loading a polymorphic belongs_to" do
should "not clear cache when loading nil" do
@post = Post.first
@post.poly = nil
@post.save!
Kasket.expects(:clear_local).never
assert_nil @post.poly
end
context "that is uncached" do
setup do
@post = Post.first
@post.poly = Blog.first
@post.save!
assert @post.poly
end
should "not clear local when it is unloaded" do
Kasket.expects(:clear_local).never
assert Post.first.poly
end
should "not clear local when it is loaded" do
Kasket.expects(:clear_local).never
assert @post.poly.reload
end
end
context "that is cached" do
setup do
@post = Post.first
@post.poly = Comment.first
@post.save!
assert @post.poly
end
should "clear local when it is loaded" do
Kasket.expects(:clear_local)
@post.poly.reload
end
end
end
context "Reloading a model" do
setup do
@post = Post.first
assert @post
assert @post.title
end
should "clear local cache" do
Kasket.expects(:clear_local)
@post.reload
end
end
context "Reloading a belongs_to association" do
setup do
@post = Comment.first.post
assert @post
assert @post.title
end
should "clear local cache" do
Kasket.expects(:clear_local)
@post.reload
end
end
context "Reloading a has_one_through association" do
setup do
@author = Comment.first.author
assert @author
assert @author.name
end
should "clear local cache" do
Kasket.expects(:clear_local)
@author.reload
end
end
end