diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index 8cd6f6d..3a8efa7 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -10,13 +10,13 @@ class ProfileEditorController < MyProfileController
# edits the profile info (posts back)
def edit
+ @profile_data = profile
if request.post?
- if profile.update_attributes(params[:profile_data])
+ profile.image || profile.build_image
+ if profile.update_attributes(params[:profile_data]) and profile.image.update_attributes(params[:image])
redirect_to :action => 'index'
- return
end
end
- render :action => profile.class.name.underscore
end
def change_image
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 8562cf5..c18db38 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -64,21 +64,21 @@ class Profile < ActiveRecord::Base
has_many :domains, :as => :owner
belongs_to :environment
-
+
has_many :role_assignments, :as => :resource
has_many :articles, :dependent => :destroy
belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id'
has_one :image, :as => :owner
-
+
has_many :consumptions
has_many :consumed_product_categories, :through => :consumptions, :source => :product_category
-
+
has_many :tasks, :foreign_key => :target_id
has_and_belongs_to_many :categories
-
+
def top_level_articles(reload = false)
if reload
@top_level_articles = nil
diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml
new file mode 100644
index 0000000..4715e4b
--- /dev/null
+++ b/app/views/profile_editor/_organization.rhtml
@@ -0,0 +1,8 @@
+ <%= f.text_field(:acronym) %>
+ <%= f.text_field(:foundation_year) %>
+ <%= f.text_field(:contact_person) %>
+ <%= f.text_field(:contact_email) %>
+ <%= f.text_field(:legal_form) %>
+ <%= f.text_field(:economic_activity) %>
+ <%= f.text_area(:management_information, :rows => 5) %>
+ <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %>
diff --git a/app/views/profile_editor/_person.rhtml b/app/views/profile_editor/_person.rhtml
new file mode 100644
index 0000000..9640f8c
--- /dev/null
+++ b/app/views/profile_editor/_person.rhtml
@@ -0,0 +1,11 @@
+ <%= f.text_field(:name) %>
+ <%= f.text_field(:contact_information) %>
+ <%= f.text_field(:contact_phone) %>
+ <%= _('Sex: ') %>
+ <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %>
+ <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %>
+ <%= f.text_field(:birth_date) %>
+ <%= f.text_field(:address) %>
+ <%= f.text_field(:city) %>
+ <%= f.text_field(:state) %>
+ <%= f.text_field(:country) %>
diff --git a/app/views/profile_editor/community.rhtml b/app/views/profile_editor/community.rhtml
deleted file mode 120000
index 8eae631..0000000
--- a/app/views/profile_editor/community.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-organization.rhtml
\ No newline at end of file
diff --git a/app/views/profile_editor/enterprise.rhtml b/app/views/profile_editor/enterprise.rhtml
deleted file mode 120000
index 8eae631..0000000
--- a/app/views/profile_editor/enterprise.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-organization.rhtml
\ No newline at end of file
diff --git a/app/views/profile_editor/organization.rhtml b/app/views/profile_editor/organization.rhtml
deleted file mode 100644
index 9c30364..0000000
--- a/app/views/profile_editor/organization.rhtml
+++ /dev/null
@@ -1,17 +0,0 @@
-
<%= _('Edit organization info') %>
-
-<%= error_messages_for :profile %>
-
-<% labelled_form_for :profile_data, @profile do |f| %>
- <%= f.text_field(:acronym) %>
- <%= f.text_field(:foundation_year) %>
- <%= f.text_field(:contact_person) %>
- <%= f.text_field(:contact_email) %>
- <%= f.text_field(:legal_form) %>
- <%= f.text_field(:economic_activity) %>
- <%= f.text_area(:management_information, :rows => 5) %>
- <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %>
- <% button_bar do %>
- <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %>
- <% end %>
-<% end %>
diff --git a/app/views/profile_editor/person.rhtml b/app/views/profile_editor/person.rhtml
deleted file mode 100644
index 8dd4783..0000000
--- a/app/views/profile_editor/person.rhtml
+++ /dev/null
@@ -1,22 +0,0 @@
-<%= _('Edit person info') %>
-
-<%= error_messages_for :profile %>
-
-<% labelled_form_for :profile_data, @profile do |f| %>
- <%= f.text_field(:name) %>
- <%= f.text_field(:contact_information) %>
- <%= f.text_field(:contact_phone) %>
- <%= _('Sex: ') %>
- <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %>
- <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %>
- <%= f.text_field(:birth_date) %>
- <%= f.text_field(:address) %>
- <%= f.text_field(:city) %>
- <%= f.text_field(:state) %>
- <%= f.text_field(:country) %>
- <% button_bar do %>
- <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %>
- <% end %>
-<% end %>
-
-<%# = generate_form :info, @info, {...} %>
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 7a5209c..6846b66 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -50,21 +50,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
def test_edit_person_info
person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
-
assert person.valid?
get :edit, :profile => person.identifier
assert_response :success
- assert_template 'person'
+ assert_template 'edit'
end
- def test_saving_profile_info
- person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
- person.address = 'my address'
- person.contact_information = 'my contact information'
- person.save!
-
- post :edit, :profile => 'test_profile', :profile_data => { 'contact_information' => 'new contact information', 'address' => 'new address' }
-
+ should 'saving profile info' do
+ person = create_user('test_profile').person
+ post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address' }
assert_redirected_to :action => 'index'
end
@@ -219,7 +213,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')
Organization.any_instance.stubs(:update_attributes).returns(false)
post :edit, :profile => 'testorg'
- assert_template 'organization'
+ assert_template 'edit'
end
should 'show edit profile button' do
@@ -228,4 +222,30 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
assert_tag :tag => 'a', :content => 'Edit Profile'
end
+ should 'show image field on edit profile' do
+ person = create_user('testuser').person
+ get :edit, :profile => 'testuser'
+ assert_tag :tag => 'input', :attributes => { :name => 'image[uploaded_data]' }
+ end
+
+ should 'show categories field on edit profile' do
+ cat1 = Environment.default.categories.create!(:name => 'top category')
+ cat2 = Environment.default.categories.create!(:name => 'sub category', :parent => cat1)
+ person = create_user('testuser').person
+ get :edit, :profile => 'testuser'
+ assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]' }
+ end
+
+ should 'render edit template' do
+ person = create_user('test_profile').person
+ get :edit, :profile => person.identifier
+ assert_template 'edit'
+ end
+
+ should 'render person partial' do
+ person = create_user('test_profile').person
+ get :edit, :profile => person.identifier
+ assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' }
+ end
+
end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index 4787628..189ee42 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -255,4 +255,10 @@ class PersonTest < Test::Unit::TestCase
assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'")
end
+ should 'required name' do
+ person = Person.new
+ assert !person.valid?
+ assert person.errors.invalid?(:name)
+ end
+
end
--
libgit2 0.21.2