Commit f037e40738e5640655e4d22961a631dc93ee5f7c

Authored by AntonioTerceiro
1 parent e37d4118

ActionItem152: "finishing" article block and general structure for editing any type of box


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1240 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/box_organizer_controller.rb
@@ -49,4 +49,36 @@ class BoxOrganizerController < ApplicationController @@ -49,4 +49,36 @@ class BoxOrganizerController < ApplicationController
49 redirect_to :back 49 redirect_to :back
50 end 50 end
51 51
  52 + def add_block
  53 + type = params[:type]
  54 + if ! type.blank?
  55 + if available_blocks.map(&:name).include?(type)
  56 + boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new
  57 + redirect_to :action => 'index'
  58 + else
  59 + raise ArgumentError.new("Type %s is not allowed. Go away." % type)
  60 + end
  61 + else
  62 + @block_types = available_blocks
  63 + @boxes = boxes_holder.boxes
  64 + render :action => 'add_block', :layout => false
  65 + end
  66 + end
  67 +
  68 + def edit
  69 + @block = boxes_holder.blocks.find(params[:id])
  70 + render :action => 'edit', :layout => false
  71 + end
  72 +
  73 + def save
  74 + @block = boxes_holder.blocks.find(params[:id])
  75 + @block.update_attributes(params[:block])
  76 + redirect_to :action => 'index'
  77 + end
  78 +
  79 + def boxes_editor?
  80 + true
  81 + end
  82 + protected :boxes_editor?
  83 +
52 end 84 end
app/controllers/my_profile/profile_design_controller.rb
@@ -7,28 +7,7 @@ class ProfileDesignController &lt; BoxOrganizerController @@ -7,28 +7,7 @@ class ProfileDesignController &lt; BoxOrganizerController
7 end 7 end
8 8
9 def index 9 def index
10 - render :action => 'index'  
11 end 10 end
12 11
13 - def add_block  
14 - type = params[:type]  
15 - if ! type.blank?  
16 - if available_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 = available_blocks  
24 - @boxes = boxes_holder.boxes  
25 - render :action => 'add_block', :layout => false  
26 - end  
27 - end  
28 -  
29 - def boxes_editor?  
30 - true  
31 - end  
32 - protected :boxes_editor?  
33 12
34 end 13 end
app/views/box_organizer/_article_block.rhtml 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= select('block', 'article_id', @block.box.owner.articles.map {|item| [ item.path, item.id]}) %>
app/views/box_organizer/edit.rhtml 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +<h2><%= _('Editing block') %></h2>
  2 +
  3 +<% form_tag(:action => 'save', :id => @block.id) do %>
  4 +
  5 + <%= render :partial => partial_for_class(@block.class) %>
  6 +
  7 + <% button_bar do %>
  8 + <%= submit_button(:save, _('Save')) %>
  9 + <%= lightbox_close_button(_('Cancel')) %>
  10 + <% end %>
  11 +
  12 +<% end %>
test/functional/profile_design_controller_test.rb
@@ -22,7 +22,7 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -22,7 +22,7 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
22 holder.boxes << @box3 22 holder.boxes << @box3
23 23
24 ###### BOX 1 24 ###### BOX 1
25 - @b1 = Block.new 25 + @b1 = ArticleBlock.new
26 @box1.blocks << @b1 26 @box1.blocks << @b1
27 @b1.save! 27 @b1.save!
28 28
@@ -163,6 +163,21 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase @@ -163,6 +163,21 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
163 end 163 end
164 end 164 end
165 165
  166 + should 'provide edit screen for blocks' do
  167 + get :edit, :profile => 'ze', :id => @b1.id
  168 + assert_template 'edit'
  169 + assert_no_tag :tag => 'body' # e.g. no layout
  170 + end
  171 +
  172 + should 'be able to save a block' do
  173 + post :save, :profile => 'ze', :id => @b1.id, :block => { :article_id => 999 }
  174 +
  175 + assert_redirected_to :action => 'index'
  176 +
  177 + @b1.reload
  178 + assert_equal 999, @b1.article_id
  179 + end
  180 +
166 181
167 end 182 end
168 183
test/unit/application_helper_test.rb
@@ -16,4 +16,7 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase @@ -16,4 +16,7 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase
16 assert_equal 'runtime_error', partial_for_class(RuntimeError) 16 assert_equal 'runtime_error', partial_for_class(RuntimeError)
17 end 17 end
18 18
  19 + should 'stop without reaching nil superclass' do
  20 + end
  21 +
19 end 22 end