Commit e3612219c538e60df4a428fabfc36ccf782fa281

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 43432446

adapt functional test to new proposal to add blocks

Showing 1 changed file with 63 additions and 104 deletions   Show diff stats
test/functional/profile_design_controller_test.rb
@@ -78,8 +78,29 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -78,8 +78,29 @@ class ProfileDesignControllerTest < ActionController::TestCase
78 ###################################################### 78 ######################################################
79 # BEGIN - tests for BoxOrganizerController features 79 # BEGIN - tests for BoxOrganizerController features
80 ###################################################### 80 ######################################################
  81 +
  82 + def test_should_add_block_to_end_of_another_block
  83 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.class.name}", :target => "end-of-box-#{@box2.id}"
  84 + @box2.reload
  85 + block = @box2.blocks.last
  86 +
  87 + assert_equal @b1.class.name, block.class.name
  88 + assert_equal @box2.blocks.size, block.position
  89 + end
  90 +
  91 + def test_should_add_block_to_begin_of_another_block
  92 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.class.name}", :target => "before-block-#{@b4.id}"
  93 +
  94 + previous_position = @b4.position
  95 +
  96 + @b4.box.reload
  97 + @b4.reload
  98 +
  99 + assert_equal @b4.position, previous_position + 1
  100 + end
  101 +
81 def test_should_move_block_to_the_end_of_another_block 102 def test_should_move_block_to_the_end_of_another_block
82 - get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" 103 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
83 104
84 @b1.reload 105 @b1.reload
85 @box2.reload 106 @box2.reload
@@ -91,7 +112,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -91,7 +112,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
91 112
92 def test_should_move_block_to_the_middle_of_another_block 113 def test_should_move_block_to_the_middle_of_another_block
93 # block 4 is in box 2 114 # block 4 is in box 2
94 - get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}" 115 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}"
95 116
96 @b1.reload 117 @b1.reload
97 @b4.reload 118 @b4.reload
@@ -102,7 +123,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -102,7 +123,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
102 end 123 end
103 124
104 def test_block_can_be_moved_up 125 def test_block_can_be_moved_up
105 - get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}" 126 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}"
106 127
107 @b4.reload 128 @b4.reload
108 @b3.reload 129 @b3.reload
@@ -114,7 +135,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -114,7 +135,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
114 assert_equal [1,2,3], [@b3,@b4,@b5].map {|item| item.position} 135 assert_equal [1,2,3], [@b3,@b4,@b5].map {|item| item.position}
115 136
116 # b3 -> before b5 137 # b3 -> before b5
117 - get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}" 138 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
118 139
119 [@b3,@b4,@b5].each do |item| 140 [@b3,@b4,@b5].each do |item|
120 item.reload 141 item.reload
@@ -123,13 +144,8 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -123,13 +144,8 @@ class ProfileDesignControllerTest < ActionController::TestCase
123 assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position} 144 assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position}
124 end 145 end
125 146
126 - def test_move_block_should_redirect_when_not_called_via_ajax  
127 - get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"  
128 - assert_redirected_to :action => 'index'  
129 - end  
130 -  
131 def test_move_block_should_render_when_called_via_ajax 147 def test_move_block_should_render_when_called_via_ajax
132 - xml_http_request :get, :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}" 148 + xml_http_request :get, :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
133 assert_template 'move_block' 149 assert_template 'move_block'
134 end 150 end
135 151
@@ -169,7 +185,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -169,7 +185,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
169 end 185 end
170 end 186 end
171 187
172 - should 'a block plugin with center position add new blocks only in this position' do 188 + should 'a block plugin add new blocks in any position' do
173 class CustomBlock1 < Block; end; 189 class CustomBlock1 < Block; end;
174 class CustomBlock2 < Block; end; 190 class CustomBlock2 < Block; end;
175 class CustomBlock3 < Block; end; 191 class CustomBlock3 < Block; end;
@@ -197,60 +213,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -197,60 +213,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
197 end 213 end
198 214
199 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) 215 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
200 - get :add_block, :profile => 'designtestuser'  
201 - assert_response :success  
202 -  
203 - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)  
204 - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2)  
205 - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3)  
206 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)  
207 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5)  
208 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6)  
209 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7)  
210 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8)  
211 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9)  
212 - end  
213 -  
214 - should 'a block plugin with side position add new blocks only in this position' do  
215 - class CustomBlock1 < Block; end;  
216 - class CustomBlock2 < Block; end;  
217 - class CustomBlock3 < Block; end;  
218 - class CustomBlock4 < Block; end;  
219 - class CustomBlock5 < Block; end;  
220 - class CustomBlock6 < Block; end;  
221 - class CustomBlock7 < Block; end;  
222 - class CustomBlock8 < Block; end;  
223 - class CustomBlock9 < Block; end;  
224 -  
225 - class TestBlockPlugin < Noosfero::Plugin  
226 - def self.extra_blocks  
227 - {  
228 - CustomBlock1 => {:type => Person, :position => [1]},  
229 - CustomBlock2 => {:type => Person, :position => 1},  
230 - CustomBlock3 => {:type => Person, :position => '1'},  
231 - CustomBlock4 => {:type => Person, :position => [2]},  
232 - CustomBlock5 => {:type => Person, :position => 2},  
233 - CustomBlock6 => {:type => Person, :position => '2'},  
234 - CustomBlock7 => {:type => Person, :position => [3]},  
235 - CustomBlock8 => {:type => Person, :position => 3},  
236 - CustomBlock9 => {:type => Person, :position => '3'},  
237 - }  
238 - end  
239 - end  
240 -  
241 - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])  
242 - get :add_block, :profile => 'designtestuser' 216 + get :index, :profile => 'designtestuser'
243 assert_response :success 217 assert_response :success
244 218
245 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1)  
246 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2)  
247 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3)  
248 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4)  
249 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)  
250 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6)  
251 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7)  
252 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8)  
253 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) 219 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock1)
  220 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock2)
  221 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock3)
  222 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock4)
  223 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock5)
  224 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock6)
  225 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock7)
  226 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock8)
  227 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock9)
254 end 228 end
255 229
256 should 'a block plugin cannot be listed for unspecified types' do 230 should 'a block plugin cannot be listed for unspecified types' do
@@ -279,17 +253,17 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -279,17 +253,17 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
279 end 253 end
280 254
281 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) 255 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
282 - get :add_block, :profile => 'designtestuser' 256 + get :index, :profile => 'designtestuser'
283 assert_response :success 257 assert_response :success
284 258
285 - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)  
286 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2)  
287 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3)  
288 - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)  
289 - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)  
290 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6)  
291 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7)  
292 - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) 259 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock1)
  260 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock2)
  261 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock3)
  262 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock4)
  263 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock5)
  264 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock6)
  265 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock7)
  266 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock8)
293 end 267 end
294 268
295 should 'not edit main block with never option' do 269 should 'not edit main block with never option' do
@@ -331,6 +305,12 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -331,6 +305,12 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
331 assert_equal json_response.include?("/{profile}/"+article3.path), false 305 assert_equal json_response.include?("/{profile}/"+article3.path), false
332 end 306 end
333 307
  308 + should 'display popup for show block information' do
  309 + get :show_block_type_info, :profile => 'designtestuser', :type => ArticleBlock.name
  310 + assert_response :success
  311 + assert_no_tag :tag => 'body'
  312 + end
  313 +
334 ###################################################### 314 ######################################################
335 # END - tests for BoxOrganizerController features 315 # END - tests for BoxOrganizerController features
336 ###################################################### 316 ######################################################
@@ -339,27 +319,6 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -339,27 +319,6 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
339 # BEGIN - tests for ProfileDesignController features 319 # BEGIN - tests for ProfileDesignController features
340 ###################################################### 320 ######################################################
341 321
342 - should 'display popup for adding a new block' do  
343 - get :add_block, :profile => 'designtestuser'  
344 - assert_response :success  
345 - assert_no_tag :tag => 'body' # e.g. no layout  
346 - end  
347 -  
348 - should 'actually add a new block' do  
349 - assert_difference 'Block.count' do  
350 - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => RecentDocumentsBlock.name  
351 - assert_redirected_to :action => 'index'  
352 - end  
353 - end  
354 -  
355 - should 'not allow to create unknown types' do  
356 - assert_no_difference 'Block.count' do  
357 - assert_raise ArgumentError do  
358 - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite"  
359 - end  
360 - end  
361 - end  
362 -  
363 should 'provide edit screen for blocks' do 322 should 'provide edit screen for blocks' do
364 get :edit, :profile => 'designtestuser', :id => @b1.id 323 get :edit, :profile => 'designtestuser', :id => @b1.id
365 assert_template 'edit' 324 assert_template 'edit'
@@ -432,7 +391,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -432,7 +391,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
432 person = create_user_with_permission('test_user', 'edit_profile_design', ent) 391 person = create_user_with_permission('test_user', 'edit_profile_design', ent)
433 login_as(person.user.login) 392 login_as(person.user.login)
434 393
435 - get :add_block, :profile => 'test_ent' 394 + get :index, :profile => 'test_ent'
436 395
437 assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'} 396 assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'}
438 end 397 end
@@ -448,18 +407,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -448,18 +407,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
448 407
449 should 'offer to create blog archives block only if has blog' do 408 should 'offer to create blog archives block only if has blog' do
450 holder.articles << Blog.new(:name => 'Blog test', :profile => holder) 409 holder.articles << Blog.new(:name => 'Blog test', :profile => holder)
451 - get :add_block, :profile => 'designtestuser'  
452 - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } 410 + get :index, :profile => 'designtestuser'
  411 + assert_tag :tag => 'div', :attributes => { :id => 'block-BlogArchivesBlock' }
453 end 412 end
454 413
455 should 'not offer to create blog archives block if user dont have blog' do 414 should 'not offer to create blog archives block if user dont have blog' do
456 - get :add_block, :profile => 'designtestuser'  
457 - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } 415 + get :index, :profile => 'designtestuser'
  416 + assert_no_tag :tag => 'div', :attributes => { :id => 'block-BlogArchivesBlock' }
458 end 417 end
459 418
460 should 'offer to create feed reader block' do 419 should 'offer to create feed reader block' do
461 - get :add_block, :profile => 'designtestuser'  
462 - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'FeedReaderBlock' } 420 + get :index, :profile => 'designtestuser'
  421 + assert_tag :tag => 'div', :attributes => { :id => 'block-FeedReaderBlock' }
463 end 422 end
464 423
465 should 'be able to edit FeedReaderBlock' do 424 should 'be able to edit FeedReaderBlock' do
@@ -571,15 +530,15 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -571,15 +530,15 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
571 should 'allow admins to add RawHTMLBlock' do 530 should 'allow admins to add RawHTMLBlock' do
572 profile.stubs(:is_admin?).with(profile.environment).returns(true) 531 profile.stubs(:is_admin?).with(profile.environment).returns(true)
573 @controller.stubs(:user).returns(profile) 532 @controller.stubs(:user).returns(profile)
574 - get :add_block, :profile => 'designtestuser'  
575 - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } 533 + get :index, :profile => 'designtestuser'
  534 + assert_tag :tag => 'div', :attributes => { :id => 'block-RawHTMLBlock' }
576 end 535 end
577 536
578 should 'not allow normal users to add RawHTMLBlock' do 537 should 'not allow normal users to add RawHTMLBlock' do
579 profile.stubs(:is_admin?).with(profile.environment).returns(false) 538 profile.stubs(:is_admin?).with(profile.environment).returns(false)
580 @controller.stubs(:user).returns(profile) 539 @controller.stubs(:user).returns(profile)
581 - get :add_block, :profile => 'designtestuser'  
582 - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } 540 + get :index, :profile => 'designtestuser'
  541 + assert_no_tag :tag => 'div', :attributes => { :id => 'block-RawHTMLBlock' }
583 end 542 end
584 543
585 should 'editing article block displays right selected article' do 544 should 'editing article block displays right selected article' do