From ea8173bc551e0c3d0bf09a91e3f1b21c95140d04 Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Tue, 20 May 2008 19:36:02 +0000 Subject: [PATCH] ActionItem355: move edit_categories and change_image to edit action --- app/controllers/my_profile/profile_editor_controller.rb | 28 +++++----------------------- app/views/profile_editor/change_image.rhtml | 8 -------- app/views/profile_editor/edit_categories.rhtml | 7 ------- test/functional/profile_editor_controller_test.rb | 8 +++++++- 4 files changed, 12 insertions(+), 39 deletions(-) delete mode 100644 app/views/profile_editor/change_image.rhtml delete mode 100644 app/views/profile_editor/edit_categories.rhtml diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 3a8efa7..c4ed49c 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -13,33 +13,15 @@ class ProfileEditorController < MyProfileController @profile_data = profile if request.post? profile.image || profile.build_image - if profile.update_attributes(params[:profile_data]) and profile.image.update_attributes(params[:image]) + if profile.update_attributes(params[:profile_data]) + if !params[:image].blank? && !params[:image][:uploaded_data].blank? && !profile.image.update_attributes(params[:image]) + flash[:notice] = _('Could not upload image') + return + end redirect_to :action => 'index' end end end - def change_image - @image = @profile.image ? @profile.image : @profile.build_image - if request.post? - if @profile.image.update_attributes(params[:image]) - flash[:notice] = _('Image successfully uploaded') - redirect_to :action => 'index' - else - flash[:notice] = _('Could not upload image') - render :action => 'change_image' - end - end - end - - def edit_categories - @profile_object = profile - if request.post? - if profile.update_attributes(params[:profile_object]) - redirect_to :action => 'index' - end - end - end - end diff --git a/app/views/profile_editor/change_image.rhtml b/app/views/profile_editor/change_image.rhtml deleted file mode 100644 index e64c8bc..0000000 --- a/app/views/profile_editor/change_image.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -<% form_for :image, @image, - :html => { :multipart => true }, - :url => { :action => 'change_image'} do |f| %> - <%= display_form_field(_('Image'), f.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) ) %> - <% button_bar do %> - <%= submit_button('save', _('Upload'), :cancel => {:action => 'index'}) %> - <% end %> -<% end %> diff --git a/app/views/profile_editor/edit_categories.rhtml b/app/views/profile_editor/edit_categories.rhtml deleted file mode 100644 index 7b08c76..0000000 --- a/app/views/profile_editor/edit_categories.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -<% form_for :profile_object, @profile_object, :url => { :action => 'edit_categories'} do |f| %> - <%= select_categories('profile_object', _('Select the categories of your interest'), 1) %> - <% button_bar do %> - <%= submit_button('save', _('Save'), :cancel => {:action => 'edit_categories'}) %> - <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> - <% end %> -<% end %> diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 6846b66..3e6963b 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -82,7 +82,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! person = create_user('test_user').person - post :edit_categories, :profile => 'test_user', :profile_object => {:category_ids => [cat2.id]} + post :edit, :profile => 'test_user', :profile_data => {:category_ids => [cat2.id]} assert_response :redirect assert_redirected_to :action => 'index' assert_includes person.categories, cat2 @@ -248,4 +248,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } end + should 'be able to upload an image' do + person = create_user('test_profile').person + assert_nil person.image + post :edit, :profile => 'test_profile', :image => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} + assert_not_nil assigns(:profile).image + end end -- libgit2 0.21.2