block_test.rb
4.38 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require File.dirname(__FILE__) + '/../test_helper'
class BlockTest < Test::Unit::TestCase
should 'describe itself' do
assert_kind_of String, Block.description
end
should 'access owner through box' do
user = create_user('testinguser').person
box = fast_create(Box, :owner_id => user, :owner_type => 'Person')
block = Block.new
block.box = box
block.save!
assert_equal user, block.owner
end
should 'have no owner when there is no box' do
assert_nil Block.new.owner
end
should 'provide no footer by default' do
assert_nil Block.new.footer
end
should 'provide an empty default title' do
assert_equal '', Block.new.default_title
end
should 'be editable by default' do
assert Block.new.editable?
end
should 'have default titles' do
b = Block.new
b.expects(:default_title).returns('my title')
assert_equal 'my title', b.title
end
should 'have default view_title ' do
b = Block.new
b.expects(:title).returns('my title')
assert_equal 'my title', b.view_title
end
should 'be cacheable' do
b = Block.new
assert b.cacheable?
end
should 'list enabled blocks' do
block1 = fast_create(Block, :title => 'test 1')
block2 = fast_create(Block, :title => 'test 2', :enabled => false)
assert_includes Block.enabled, block1
assert_not_includes Block.enabled, block2
end
should 'be displayed everywhere by default' do
assert_equal true, Block.new.visible?
end
should 'not display when set to hidden' do
assert_equal false, Block.new(:display => 'never').visible?
assert_equal false, Block.new(:display => 'never').visible?(:article => Article.new)
end
should 'be able to be displayed only in the homepage' do
profile = Profile.new
home_page = Article.new
profile.home_page = home_page
block = Block.new(:display => 'home_page_only')
block.stubs(:owner).returns(profile)
assert_equal true, block.visible?(:article => home_page)
assert_equal false, block.visible?(:article => Article.new)
end
should 'be able to be displayed only in the homepage (index) of the environment' do
block = Block.new(:display => 'home_page_only')
assert_equal true, block.visible?(:article => nil, :request_path => '/')
assert_equal false, block.visible?(:article => nil)
end
should 'be able to be displayed everywhere except in the homepage' do
profile = Profile.new
home_page = Article.new
profile.home_page = home_page
block = Block.new(:display => 'except_home_page')
block.stubs(:owner).returns(profile)
assert_equal false, block.visible?(:article => home_page)
assert_equal true, block.visible?(:article => Article.new)
end
should 'be able to be displayed everywhere except on profile index' do
profile = Profile.new(:identifier => 'testinguser')
block = Block.new(:display => 'except_home_page')
block.stubs(:owner).returns(profile)
assert_equal false, block.visible?(:article => nil, :request_path => '/testinguser')
assert_equal true, block.visible?(:article => nil)
end
should 'be able to save display setting' do
user = create_user('testinguser').person
box = fast_create(Box, :owner_id => user.id)
block = create(Block, :display => 'never', :box_id => box.id)
block.reload
assert_equal 'never', block.display
end
should 'be able to update display setting' do
user = create_user('testinguser').person
box = fast_create(Box, :owner_id => user.id)
block = create(Block, :display => 'never', :box_id => box.id)
assert block.update_attributes!(:display => 'always')
block.reload
assert_equal 'always', block.display
end
should 'display block in all languages by default' do
profile = Profile.new
block = Block.new
block.stubs(:owner).returns(profile)
assert_equal 'all', block.language
end
should 'be able to be displayed in all languages' do
profile = Profile.new
block = Block.new(:language => 'all')
block.stubs(:owner).returns(profile)
assert_equal true, block.visible?(:locale => 'pt')
assert_equal true, block.visible?(:locale => 'en')
end
should 'be able to be displayed only in the selected language' do
profile = Profile.new
block = Block.new(:language => 'pt')
block.stubs(:owner).returns(profile)
assert_equal true, block.visible?(:locale => 'pt')
assert_equal false, block.visible?(:locale => 'en')
end
end