Commit ea8173bc551e0c3d0bf09a91e3f1b21c95140d04
1 parent
2993c348
Exists in
master
and in
29 other branches
ActionItem355: move edit_categories and change_image to edit action
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1816 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
12 additions
and
39 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -13,33 +13,15 @@ class ProfileEditorController < MyProfileController | @@ -13,33 +13,15 @@ class ProfileEditorController < MyProfileController | ||
13 | @profile_data = profile | 13 | @profile_data = profile |
14 | if request.post? | 14 | if request.post? |
15 | profile.image || profile.build_image | 15 | profile.image || profile.build_image |
16 | - if profile.update_attributes(params[:profile_data]) and profile.image.update_attributes(params[:image]) | 16 | + if profile.update_attributes(params[:profile_data]) |
17 | + if !params[:image].blank? && !params[:image][:uploaded_data].blank? && !profile.image.update_attributes(params[:image]) | ||
18 | + flash[:notice] = _('Could not upload image') | ||
19 | + return | ||
20 | + end | ||
17 | redirect_to :action => 'index' | 21 | redirect_to :action => 'index' |
18 | end | 22 | end |
19 | end | 23 | end |
20 | end | 24 | end |
21 | 25 | ||
22 | - def change_image | ||
23 | - @image = @profile.image ? @profile.image : @profile.build_image | ||
24 | - if request.post? | ||
25 | - if @profile.image.update_attributes(params[:image]) | ||
26 | - flash[:notice] = _('Image successfully uploaded') | ||
27 | - redirect_to :action => 'index' | ||
28 | - else | ||
29 | - flash[:notice] = _('Could not upload image') | ||
30 | - render :action => 'change_image' | ||
31 | - end | ||
32 | - end | ||
33 | - end | ||
34 | - | ||
35 | - def edit_categories | ||
36 | - @profile_object = profile | ||
37 | - if request.post? | ||
38 | - if profile.update_attributes(params[:profile_object]) | ||
39 | - redirect_to :action => 'index' | ||
40 | - end | ||
41 | - end | ||
42 | - end | ||
43 | - | ||
44 | end | 26 | end |
45 | 27 |
app/views/profile_editor/change_image.rhtml
@@ -1,8 +0,0 @@ | @@ -1,8 +0,0 @@ | ||
1 | -<% form_for :image, @image, | ||
2 | - :html => { :multipart => true }, | ||
3 | - :url => { :action => 'change_image'} do |f| %> | ||
4 | - <%= display_form_field(_('Image'), f.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) ) %> | ||
5 | - <% button_bar do %> | ||
6 | - <%= submit_button('save', _('Upload'), :cancel => {:action => 'index'}) %> | ||
7 | - <% end %> | ||
8 | -<% end %> |
app/views/profile_editor/edit_categories.rhtml
@@ -1,7 +0,0 @@ | @@ -1,7 +0,0 @@ | ||
1 | -<% form_for :profile_object, @profile_object, :url => { :action => 'edit_categories'} do |f| %> | ||
2 | - <%= select_categories('profile_object', _('Select the categories of your interest'), 1) %> | ||
3 | - <% button_bar do %> | ||
4 | - <%= submit_button('save', _('Save'), :cancel => {:action => 'edit_categories'}) %> | ||
5 | - <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> | ||
6 | - <% end %> | ||
7 | -<% end %> |
test/functional/profile_editor_controller_test.rb
@@ -82,7 +82,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -82,7 +82,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
82 | cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! | 82 | cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! |
83 | cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! | 83 | cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! |
84 | person = create_user('test_user').person | 84 | person = create_user('test_user').person |
85 | - post :edit_categories, :profile => 'test_user', :profile_object => {:category_ids => [cat2.id]} | 85 | + post :edit, :profile => 'test_user', :profile_data => {:category_ids => [cat2.id]} |
86 | assert_response :redirect | 86 | assert_response :redirect |
87 | assert_redirected_to :action => 'index' | 87 | assert_redirected_to :action => 'index' |
88 | assert_includes person.categories, cat2 | 88 | assert_includes person.categories, cat2 |
@@ -248,4 +248,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -248,4 +248,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
248 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } | 248 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } |
249 | end | 249 | end |
250 | 250 | ||
251 | + should 'be able to upload an image' do | ||
252 | + person = create_user('test_profile').person | ||
253 | + assert_nil person.image | ||
254 | + post :edit, :profile => 'test_profile', :image => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | ||
255 | + assert_not_nil assigns(:profile).image | ||
256 | + end | ||
251 | end | 257 | end |