From f037e40738e5640655e4d22961a631dc93ee5f7c Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 19 Jan 2008 00:01:05 +0000 Subject: [PATCH] ActionItem152: "finishing" article block and general structure for editing any type of box --- app/controllers/box_organizer_controller.rb | 32 ++++++++++++++++++++++++++++++++ app/controllers/my_profile/profile_design_controller.rb | 21 --------------------- app/views/box_organizer/_article_block.rhtml | 1 + app/views/box_organizer/edit.rhtml | 12 ++++++++++++ test/functional/profile_design_controller_test.rb | 17 ++++++++++++++++- test/unit/application_helper_test.rb | 3 +++ 6 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 app/views/box_organizer/_article_block.rhtml create mode 100644 app/views/box_organizer/edit.rhtml diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index 595809d..2711bf6 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -49,4 +49,36 @@ class BoxOrganizerController < ApplicationController redirect_to :back end + def add_block + type = params[:type] + if ! type.blank? + if available_blocks.map(&:name).include?(type) + boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new + redirect_to :action => 'index' + else + raise ArgumentError.new("Type %s is not allowed. Go away." % type) + end + else + @block_types = available_blocks + @boxes = boxes_holder.boxes + render :action => 'add_block', :layout => false + end + end + + def edit + @block = boxes_holder.blocks.find(params[:id]) + render :action => 'edit', :layout => false + end + + def save + @block = boxes_holder.blocks.find(params[:id]) + @block.update_attributes(params[:block]) + redirect_to :action => 'index' + end + + def boxes_editor? + true + end + protected :boxes_editor? + end diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index a87994b..44ce6de 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -7,28 +7,7 @@ class ProfileDesignController < BoxOrganizerController end def index - render :action => 'index' end - def add_block - type = params[:type] - if ! type.blank? - if available_blocks.map(&:name).include?(type) - boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new - redirect_to :action => 'index' - else - raise ArgumentError.new("Type %s is not allowed. Go away." % type) - end - else - @block_types = available_blocks - @boxes = boxes_holder.boxes - render :action => 'add_block', :layout => false - end - end - - def boxes_editor? - true - end - protected :boxes_editor? end diff --git a/app/views/box_organizer/_article_block.rhtml b/app/views/box_organizer/_article_block.rhtml new file mode 100644 index 0000000..bb54766 --- /dev/null +++ b/app/views/box_organizer/_article_block.rhtml @@ -0,0 +1 @@ +<%= select('block', 'article_id', @block.box.owner.articles.map {|item| [ item.path, item.id]}) %> diff --git a/app/views/box_organizer/edit.rhtml b/app/views/box_organizer/edit.rhtml new file mode 100644 index 0000000..7c2d6d7 --- /dev/null +++ b/app/views/box_organizer/edit.rhtml @@ -0,0 +1,12 @@ +

<%= _('Editing block') %>

+ +<% form_tag(:action => 'save', :id => @block.id) do %> + + <%= render :partial => partial_for_class(@block.class) %> + + <% button_bar do %> + <%= submit_button(:save, _('Save')) %> + <%= lightbox_close_button(_('Cancel')) %> + <% end %> + +<% end %> diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 67de176..462e197 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -22,7 +22,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase holder.boxes << @box3 ###### BOX 1 - @b1 = Block.new + @b1 = ArticleBlock.new @box1.blocks << @b1 @b1.save! @@ -163,6 +163,21 @@ class ProfileDesignControllerTest < Test::Unit::TestCase end end + should 'provide edit screen for blocks' do + get :edit, :profile => 'ze', :id => @b1.id + assert_template 'edit' + assert_no_tag :tag => 'body' # e.g. no layout + end + + should 'be able to save a block' do + post :save, :profile => 'ze', :id => @b1.id, :block => { :article_id => 999 } + + assert_redirected_to :action => 'index' + + @b1.reload + assert_equal 999, @b1.article_id + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 1405340..d9370d1 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -16,4 +16,7 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_equal 'runtime_error', partial_for_class(RuntimeError) end + should 'stop without reaching nil superclass' do + end + end -- libgit2 0.21.2