Commit 2993c34804a3c72ff841d1cc75ee4bd3f9b7c3b4
1 parent
82450da5
Exists in
master
and in
28 other branches
ActionItem355: restructure views of profile_editor
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1815 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
63 additions
and
59 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -10,13 +10,13 @@ class ProfileEditorController < MyProfileController |
10 | 10 | |
11 | 11 | # edits the profile info (posts back) |
12 | 12 | def edit |
13 | + @profile_data = profile | |
13 | 14 | if request.post? |
14 | - if profile.update_attributes(params[:profile_data]) | |
15 | + profile.image || profile.build_image | |
16 | + if profile.update_attributes(params[:profile_data]) and profile.image.update_attributes(params[:image]) | |
15 | 17 | redirect_to :action => 'index' |
16 | - return | |
17 | 18 | end |
18 | 19 | end |
19 | - render :action => profile.class.name.underscore | |
20 | 20 | end |
21 | 21 | |
22 | 22 | def change_image | ... | ... |
app/models/profile.rb
... | ... | @@ -64,21 +64,21 @@ class Profile < ActiveRecord::Base |
64 | 64 | |
65 | 65 | has_many :domains, :as => :owner |
66 | 66 | belongs_to :environment |
67 | - | |
67 | + | |
68 | 68 | has_many :role_assignments, :as => :resource |
69 | 69 | |
70 | 70 | has_many :articles, :dependent => :destroy |
71 | 71 | belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' |
72 | 72 | |
73 | 73 | has_one :image, :as => :owner |
74 | - | |
74 | + | |
75 | 75 | has_many :consumptions |
76 | 76 | has_many :consumed_product_categories, :through => :consumptions, :source => :product_category |
77 | - | |
77 | + | |
78 | 78 | has_many :tasks, :foreign_key => :target_id |
79 | 79 | |
80 | 80 | has_and_belongs_to_many :categories |
81 | - | |
81 | + | |
82 | 82 | def top_level_articles(reload = false) |
83 | 83 | if reload |
84 | 84 | @top_level_articles = nil | ... | ... |
... | ... | @@ -0,0 +1,8 @@ |
1 | + <%= f.text_field(:acronym) %> | |
2 | + <%= f.text_field(:foundation_year) %> | |
3 | + <%= f.text_field(:contact_person) %> | |
4 | + <%= f.text_field(:contact_email) %> | |
5 | + <%= f.text_field(:legal_form) %> | |
6 | + <%= f.text_field(:economic_activity) %> | |
7 | + <%= f.text_area(:management_information, :rows => 5) %> | |
8 | + <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %> | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | + <%= f.text_field(:name) %> | |
2 | + <%= f.text_field(:contact_information) %> | |
3 | + <%= f.text_field(:contact_phone) %> | |
4 | + <%= _('Sex: ') %> | |
5 | + <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %> | |
6 | + <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %> | |
7 | + <%= f.text_field(:birth_date) %> | |
8 | + <%= f.text_field(:address) %> | |
9 | + <%= f.text_field(:city) %> | |
10 | + <%= f.text_field(:state) %> | |
11 | + <%= f.text_field(:country) %> | ... | ... |
app/views/profile_editor/community.rhtml
app/views/profile_editor/enterprise.rhtml
app/views/profile_editor/organization.rhtml
... | ... | @@ -1,17 +0,0 @@ |
1 | -<h1> <%= _('Edit organization info') %> </h1> | |
2 | - | |
3 | -<%= error_messages_for :profile %> | |
4 | - | |
5 | -<% labelled_form_for :profile_data, @profile do |f| %> | |
6 | - <%= f.text_field(:acronym) %> | |
7 | - <%= f.text_field(:foundation_year) %> | |
8 | - <%= f.text_field(:contact_person) %> | |
9 | - <%= f.text_field(:contact_email) %> | |
10 | - <%= f.text_field(:legal_form) %> | |
11 | - <%= f.text_field(:economic_activity) %> | |
12 | - <%= f.text_area(:management_information, :rows => 5) %> | |
13 | - <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %> | |
14 | - <% button_bar do %> | |
15 | - <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %> | |
16 | - <% end %> | |
17 | -<% end %> |
app/views/profile_editor/person.rhtml
... | ... | @@ -1,22 +0,0 @@ |
1 | -<h1><%= _('Edit person info') %></h1> | |
2 | - | |
3 | -<%= error_messages_for :profile %> | |
4 | - | |
5 | -<% labelled_form_for :profile_data, @profile do |f| %> | |
6 | - <%= f.text_field(:name) %> | |
7 | - <%= f.text_field(:contact_information) %> | |
8 | - <%= f.text_field(:contact_phone) %> | |
9 | - <%= _('Sex: ') %> | |
10 | - <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %> | |
11 | - <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %> | |
12 | - <%= f.text_field(:birth_date) %> | |
13 | - <%= f.text_field(:address) %> | |
14 | - <%= f.text_field(:city) %> | |
15 | - <%= f.text_field(:state) %> | |
16 | - <%= f.text_field(:country) %> | |
17 | - <% button_bar do %> | |
18 | - <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> | |
19 | - <% end %> | |
20 | -<% end %> | |
21 | - | |
22 | -<%# = generate_form :info, @info, {...} %> |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -50,21 +50,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
50 | 50 | |
51 | 51 | def test_edit_person_info |
52 | 52 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
53 | - | |
54 | 53 | assert person.valid? |
55 | 54 | get :edit, :profile => person.identifier |
56 | 55 | assert_response :success |
57 | - assert_template 'person' | |
56 | + assert_template 'edit' | |
58 | 57 | end |
59 | 58 | |
60 | - def test_saving_profile_info | |
61 | - person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | |
62 | - person.address = 'my address' | |
63 | - person.contact_information = 'my contact information' | |
64 | - person.save! | |
65 | - | |
66 | - post :edit, :profile => 'test_profile', :profile_data => { 'contact_information' => 'new contact information', 'address' => 'new address' } | |
67 | - | |
59 | + should 'saving profile info' do | |
60 | + person = create_user('test_profile').person | |
61 | + post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address' } | |
68 | 62 | assert_redirected_to :action => 'index' |
69 | 63 | end |
70 | 64 | |
... | ... | @@ -219,7 +213,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
219 | 213 | org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') |
220 | 214 | Organization.any_instance.stubs(:update_attributes).returns(false) |
221 | 215 | post :edit, :profile => 'testorg' |
222 | - assert_template 'organization' | |
216 | + assert_template 'edit' | |
223 | 217 | end |
224 | 218 | |
225 | 219 | should 'show edit profile button' do |
... | ... | @@ -228,4 +222,30 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
228 | 222 | assert_tag :tag => 'a', :content => 'Edit Profile' |
229 | 223 | end |
230 | 224 | |
225 | + should 'show image field on edit profile' do | |
226 | + person = create_user('testuser').person | |
227 | + get :edit, :profile => 'testuser' | |
228 | + assert_tag :tag => 'input', :attributes => { :name => 'image[uploaded_data]' } | |
229 | + end | |
230 | + | |
231 | + should 'show categories field on edit profile' do | |
232 | + cat1 = Environment.default.categories.create!(:name => 'top category') | |
233 | + cat2 = Environment.default.categories.create!(:name => 'sub category', :parent => cat1) | |
234 | + person = create_user('testuser').person | |
235 | + get :edit, :profile => 'testuser' | |
236 | + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]' } | |
237 | + end | |
238 | + | |
239 | + should 'render edit template' do | |
240 | + person = create_user('test_profile').person | |
241 | + get :edit, :profile => person.identifier | |
242 | + assert_template 'edit' | |
243 | + end | |
244 | + | |
245 | + should 'render person partial' do | |
246 | + person = create_user('test_profile').person | |
247 | + get :edit, :profile => person.identifier | |
248 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } | |
249 | + end | |
250 | + | |
231 | 251 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -255,4 +255,10 @@ class PersonTest < Test::Unit::TestCase |
255 | 255 | assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'") |
256 | 256 | end |
257 | 257 | |
258 | + should 'required name' do | |
259 | + person = Person.new | |
260 | + assert !person.valid? | |
261 | + assert person.errors.invalid?(:name) | |
262 | + end | |
263 | + | |
258 | 264 | end | ... | ... |