Commit 4d88ce2dec272861da737e0c00ca34dc78bf7924
1 parent
5a214b37
Exists in
master
and in
29 other branches
ActionItem152: adding new blocks to a design. Now need to create more types of blocks. (again)
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1225 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
78 additions
and
8 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
@@ -2,8 +2,28 @@ class ProfileDesignController < BoxOrganizerController | @@ -2,8 +2,28 @@ class ProfileDesignController < BoxOrganizerController | ||
2 | 2 | ||
3 | needs_profile | 3 | needs_profile |
4 | 4 | ||
5 | + BLOCKS = [ | ||
6 | + Block | ||
7 | + ] | ||
8 | + | ||
5 | def index | 9 | def index |
6 | - render :action => 'index', :layout => true | 10 | + render :action => 'index' |
11 | + end | ||
12 | + | ||
13 | + def add_block | ||
14 | + type = params[:type] | ||
15 | + if ! type.blank? | ||
16 | + if BLOCKS.map(&:name).include?(type) | ||
17 | + boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new | ||
18 | + redirect_to :action => 'index' | ||
19 | + else | ||
20 | + raise ArgumentError.new("Type %s is not allowed. Go away." % type) | ||
21 | + end | ||
22 | + else | ||
23 | + @block_types = BLOCKS | ||
24 | + @boxes = boxes_holder.boxes | ||
25 | + render :action => 'add_block', :layout => false | ||
26 | + end | ||
7 | end | 27 | end |
8 | 28 | ||
9 | def boxes_editor? | 29 | def boxes_editor? |
app/views/box_organizer/add_block.rhtml
1 | -<% button_bar do %> | ||
2 | - <%= submit_button(:add, _("Add")) %> | ||
3 | - <%= lightbox_close_button(_('Close')) %> | 1 | +<% form_tag do %> |
2 | + | ||
3 | + <p><%= _('In what area do you want to put your new block?') %></p> | ||
4 | + | ||
5 | + <%= select_tag('box_id', options_for_select(@boxes.map {|item| [ _("Area %d") % item.position, item.id]})) %> | ||
6 | + | ||
7 | + <p><%= _('Select the type of block you want to add to your page.') %></p> | ||
8 | + | ||
9 | + <% @block_types.each do |item| %> | ||
10 | + <div> | ||
11 | + <%= radio_button_tag('type', item.name) %> | ||
12 | + <%= item.description %> | ||
13 | + </div> | ||
14 | + <% end %> | ||
15 | + | ||
16 | + <% button_bar do %> | ||
17 | + <%= submit_button(:add, _("Add")) %> | ||
18 | + <%= lightbox_close_button(_('Close')) %> | ||
19 | + <% end %> | ||
20 | + | ||
4 | <% end %> | 21 | <% end %> |
app/views/box_organizer/index.rhtml
1 | <h2><%= _('Organizing visual design')%></h2> | 1 | <h2><%= _('Organizing visual design')%></h2> |
2 | 2 | ||
3 | -This is a test ... and this is a sample text. | ||
4 | - | ||
5 | -<%= @controller.boxes_holder.class %> | 3 | +<% button_bar do %> |
4 | + <%= lightbox_button('add', _('Add a block'), { :action => 'add_block' }) %> | ||
5 | +<% end %> |
test/functional/profile_design_controller_test.rb
@@ -58,9 +58,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -58,9 +58,12 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
58 | 58 | ||
59 | @request.env['HTTP_REFERER'] = '/editor' | 59 | @request.env['HTTP_REFERER'] = '/editor' |
60 | 60 | ||
61 | - @controller.expects(:boxes_holder).returns(holder).at_least_once | 61 | + @controller.stubs(:boxes_holder).returns(holder) |
62 | end | 62 | end |
63 | 63 | ||
64 | + ###################################################### | ||
65 | + # BEGIN - tests for BoxOrganizerController features | ||
66 | + ###################################################### | ||
64 | def test_should_move_block_to_the_end_of_another_block | 67 | def test_should_move_block_to_the_end_of_another_block |
65 | get :move_block, :profile => 'ze', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" | 68 | get :move_block, :profile => 'ze', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" |
66 | 69 | ||
@@ -131,5 +134,35 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -131,5 +134,35 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
131 | assert_equal [1,2], [@b2,@b1].map {|item| item.position} | 134 | assert_equal [1,2], [@b2,@b1].map {|item| item.position} |
132 | end | 135 | end |
133 | 136 | ||
137 | + ###################################################### | ||
138 | + # END - tests for BoxOrganizerController features | ||
139 | + ###################################################### | ||
140 | + | ||
141 | + ###################################################### | ||
142 | + # BEGIN - tests for ProfileDesignController features | ||
143 | + ###################################################### | ||
144 | + | ||
145 | + should 'display popup for adding a new block' do | ||
146 | + get :add_block, :profile => 'ze' | ||
147 | + assert_response :success | ||
148 | + assert_no_tag :tag => 'body' # e.g. no layout | ||
149 | + end | ||
150 | + | ||
151 | + should 'actually add a new block' do | ||
152 | + assert_difference Block, :count do | ||
153 | + post :add_block, :profile => 'ze', :box_id => 1, :type => Block.name | ||
154 | + assert_redirected_to :action => 'index' | ||
155 | + end | ||
156 | + end | ||
157 | + | ||
158 | + should 'not allow tp create unknown types' do | ||
159 | + assert_no_difference Block, :count do | ||
160 | + assert_raise ArgumentError do | ||
161 | + post :add_block, :profile => 'ze', :box_id => 1, :type => "PleaseLetMeCrackYourSite" | ||
162 | + end | ||
163 | + end | ||
164 | + end | ||
165 | + | ||
166 | + | ||
134 | end | 167 | end |
135 | 168 |