Commit 2993c34804a3c72ff841d1cc75ee4bd3f9b7c3b4

Authored by JoenioCosta
1 parent 82450da5

ActionItem355: restructure views of profile_editor

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1815 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/profile_editor_controller.rb
@@ -10,13 +10,13 @@ class ProfileEditorController < MyProfileController @@ -10,13 +10,13 @@ class ProfileEditorController < MyProfileController
10 10
11 # edits the profile info (posts back) 11 # edits the profile info (posts back)
12 def edit 12 def edit
  13 + @profile_data = profile
13 if request.post? 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 redirect_to :action => 'index' 17 redirect_to :action => 'index'
16 - return  
17 end 18 end
18 end 19 end
19 - render :action => profile.class.name.underscore  
20 end 20 end
21 21
22 def change_image 22 def change_image
app/models/profile.rb
@@ -64,21 +64,21 @@ class Profile < ActiveRecord::Base @@ -64,21 +64,21 @@ class Profile < ActiveRecord::Base
64 64
65 has_many :domains, :as => :owner 65 has_many :domains, :as => :owner
66 belongs_to :environment 66 belongs_to :environment
67 - 67 +
68 has_many :role_assignments, :as => :resource 68 has_many :role_assignments, :as => :resource
69 69
70 has_many :articles, :dependent => :destroy 70 has_many :articles, :dependent => :destroy
71 belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' 71 belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id'
72 72
73 has_one :image, :as => :owner 73 has_one :image, :as => :owner
74 - 74 +
75 has_many :consumptions 75 has_many :consumptions
76 has_many :consumed_product_categories, :through => :consumptions, :source => :product_category 76 has_many :consumed_product_categories, :through => :consumptions, :source => :product_category
77 - 77 +
78 has_many :tasks, :foreign_key => :target_id 78 has_many :tasks, :foreign_key => :target_id
79 79
80 has_and_belongs_to_many :categories 80 has_and_belongs_to_many :categories
81 - 81 +
82 def top_level_articles(reload = false) 82 def top_level_articles(reload = false)
83 if reload 83 if reload
84 @top_level_articles = nil 84 @top_level_articles = nil
app/views/profile_editor/_organization.rhtml 0 → 100644
@@ -0,0 +1,8 @@ @@ -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) %>
app/views/profile_editor/_person.rhtml 0 → 100644
@@ -0,0 +1,11 @@ @@ -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
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -organization.rhtml  
2 \ No newline at end of file 0 \ No newline at end of file
app/views/profile_editor/enterprise.rhtml
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -organization.rhtml  
2 \ No newline at end of file 0 \ No newline at end of file
app/views/profile_editor/organization.rhtml
@@ -1,17 +0,0 @@ @@ -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,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 &lt; Test::Unit::TestCase @@ -50,21 +50,15 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
50 50
51 def test_edit_person_info 51 def test_edit_person_info
52 person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person 52 person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
53 -  
54 assert person.valid? 53 assert person.valid?
55 get :edit, :profile => person.identifier 54 get :edit, :profile => person.identifier
56 assert_response :success 55 assert_response :success
57 - assert_template 'person' 56 + assert_template 'edit'
58 end 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 assert_redirected_to :action => 'index' 62 assert_redirected_to :action => 'index'
69 end 63 end
70 64
@@ -219,7 +213,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -219,7 +213,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
219 org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') 213 org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')
220 Organization.any_instance.stubs(:update_attributes).returns(false) 214 Organization.any_instance.stubs(:update_attributes).returns(false)
221 post :edit, :profile => 'testorg' 215 post :edit, :profile => 'testorg'
222 - assert_template 'organization' 216 + assert_template 'edit'
223 end 217 end
224 218
225 should 'show edit profile button' do 219 should 'show edit profile button' do
@@ -228,4 +222,30 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -228,4 +222,30 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
228 assert_tag :tag => 'a', :content => 'Edit Profile' 222 assert_tag :tag => 'a', :content => 'Edit Profile'
229 end 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 end 251 end
test/unit/person_test.rb
@@ -255,4 +255,10 @@ class PersonTest &lt; Test::Unit::TestCase @@ -255,4 +255,10 @@ class PersonTest &lt; Test::Unit::TestCase
255 assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'") 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 end 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 end 264 end