environment_design_controller_test.rb
6.53 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
require File.dirname(__FILE__) + '/../test_helper'
require 'environment_design_controller'
# Re-raise errors caught by the controller.
class EnvironmentDesignController; def rescue_action(e) raise e end; end
class EnvironmentDesignControllerTest < Test::Unit::TestCase
ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock ]
def setup
@controller = EnvironmentDesignController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_local_files_reference
assert_local_files_reference
end
def test_valid_xhtml
assert_valid_xhtml
end
should 'indicate only actual blocks as such' do
assert(@controller.available_blocks.all? {|item| item.new.is_a? Block})
end
ALL_BLOCKS.map do |block|
define_method "test_should_#{block.to_s}_is_available" do
assert_includes @controller.available_blocks,block
end
end
should 'all available block in test' do
assert_equal ALL_BLOCKS, @controller.available_blocks
end
should 'be able to edit LinkListBlock' do
login_as(create_admin_user(Environment.default))
l = LinkListBlock.create!(:links => [{:name => 'link 1', :address => '/address_1'}])
Environment.default.boxes.create!
Environment.default.boxes.first.blocks << l
get :edit, :id => l.id
assert_tag :tag => 'input', :attributes => { :name => 'block[links][][name]' }
assert_tag :tag => 'input', :attributes => { :name => 'block[links][][address]' }
end
should 'be able to save LinkListBlock' do
login_as(create_admin_user(Environment.default))
l = LinkListBlock.create!()
Environment.default.boxes.create!
Environment.default.boxes.first.blocks << l
post :save, :id => l.id, :block => { :links => [{:name => 'link 1', :address => '/address_1'}] }
l.reload
assert_equal [{'name' => 'link 1', 'address' => '/address_1'}], l.links
end
should 'be able to edit ArticleBlock with portal community' do
login_as(create_admin_user(Environment.default))
l = ArticleBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << l
community = mock()
Environment.any_instance.stubs(:portal_community).returns(community)
article = mock()
community.stubs(:articles).returns([article])
article.expects(:folder?).returns(false)
article.expects(:path).returns('some_path')
article.expects(:id).returns(1)
get :edit, :id => l.id
assert_tag :tag => 'select', :attributes => { :id => 'block_article_id' }
end
should 'be able to edit ArticleBlock without portal community' do
login_as(create_admin_user(Environment.default))
l = ArticleBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << l
community = mock()
Environment.any_instance.expects(:portal_community).returns(nil)
get :edit, :id => l.id
assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' }
end
should 'be able to edit EnvironmentStatisticsBlock' do
login_as(create_admin_user(Environment.default))
b = EnvironmentStatisticsBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
end
should 'be able to edit EnterprisesBlock' do
login_as(create_admin_user(Environment.default))
b = EnterprisesBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
end
should 'be able to edit PeopleBlock' do
login_as(create_admin_user(Environment.default))
b = PeopleBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
end
should 'be able to edit SlideshowBlock' do
login_as(create_admin_user(Environment.default))
b = SlideshowBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'select', :attributes => { :id => 'block_gallery_id' }
end
should 'be able to edit LoginBlock' do
login_as(create_admin_user(Environment.default))
b = LoginBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
end
should 'be able to edit RecentDocumentsBlock' do
login_as(create_admin_user(Environment.default))
b = RecentDocumentsBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
end
should 'be able to edit CommunitiesBlock' do
login_as(create_admin_user(Environment.default))
b = CommunitiesBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
end
should 'be able to edit SellersSearchBlock' do
login_as(create_admin_user(Environment.default))
b = SellersSearchBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
end
should 'be able to edit FeedReaderBlock' do
login_as(create_admin_user(Environment.default))
b = FeedReaderBlock.create!
e = Environment.default
e.boxes.create!
e.boxes.first.blocks << b
get :edit, :id => b.id
assert_tag :tag => 'input', :attributes => { :id => 'block_address' }
end
should 'create back link to environment control panel' do
Environment.default.boxes.create!.blocks << CommunitiesBlock.new
Environment.default.boxes.create!.blocks << EnterprisesBlock.new
Environment.default.boxes.create!.blocks << LoginBlock.new
login_as(create_admin_user(Environment.default))
get :index
assert_tag :tag => 'a', :attributes => {:href => '/admin'}, :child => {:tag => 'span', :content => "Back to control panel"}
end
should 'render add a new block functionality' do
login_as(create_admin_user(Environment.default))
get :add_block
assert_response :success
assert_template 'add_block'
end
end