diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index 3af170f..122344c 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -11,7 +11,7 @@ class ProfileEditorController < MyProfileController
# edits the profile info (posts back)
def edit
if request.post?
- if profile.info.update_attributes(params[:info])
+ if profile.update_attributes(params[:profile_data]) and profile.info.save
redirect_to :action => 'index'
end
else
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0c427b3..006cb36 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -163,6 +163,11 @@ module ApplicationHelper
alias_method :display_form_field, :labelled_form_field
+ def labelled_fields_for(name, object = nil, options = {}, &proc)
+ object ||= instance_variable_get("@#{name}")
+ fields_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
+ end
+
def labelled_form_for(name, object = nil, options = {}, &proc)
object ||= instance_variable_get("@#{name}")
form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
diff --git a/app/models/profile.rb b/app/models/profile.rb
index e442b10..c6d023b 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -142,6 +142,10 @@ class Profile < ActiveRecord::Base
nil
end
+ def info=(args = {})
+ self.info.attributes = args if self.info
+ end
+
# returns the contact email for this profile. By default returns the the
# e-mail of the owner user.
#
diff --git a/app/views/profile_editor/organization_info.rhtml b/app/views/profile_editor/organization_info.rhtml
index b51ef8d..e6901a6 100644
--- a/app/views/profile_editor/organization_info.rhtml
+++ b/app/views/profile_editor/organization_info.rhtml
@@ -1,13 +1,17 @@
<%= _('Edit organization info') %>
-<%= error_messages_for :info %>
-<% labelled_form_for :info, @info do |f| %>
- <%= f.text_field(:contact_person) %>
- <%= f.text_field(:acronym) %>
- <%= f.text_field(:foundation_year) %>
- <%= f.text_field(:legal_form) %>
- <%= f.text_field(:economic_activity) %>
- <%= f.text_area(:management_information) %>
+<%= error_messages_for :profile %>
+
+<% labelled_form_for :profile_data, @profile do |f| %>
+ <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %>
+ <% labelled_fields_for 'profile_data[info]', @profile.organization_info do |i| %>
+ <%= i.text_field(:contact_person) %>
+ <%= i.text_field(:acronym) %>
+ <%= i.text_field(:foundation_year) %>
+ <%= i.text_field(:legal_form) %>
+ <%= i.text_field(:economic_activity) %>
+ <%= i.text_area(:management_information, :rows => 5) %>
+ <% end %>
<% button_bar do %>
<%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %>
<% end %>
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 87337ca..94ae0d4 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -66,9 +66,8 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
person.person_info.address = 'my address'
person.person_info.contact_information = 'my contact information'
- person.person_info.save
+ person.person_info.save!
-# profile.person_info.expects(:update_attributes).with({ 'contact_information' => 'new contact information', 'address' => 'new address' }).returns(true)
post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' }
assert_redirected_to :action => 'index'
@@ -103,43 +102,96 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
should 'filter html from name when edit person_info' do
person = create_user('test_profile').person
name = "name with html"
- post :edit, :profile => person.identifier, :info => { :name => name }
+ post :edit, :profile => person.identifier, :profile_data => { :info => { :name => name } }
assert_sanitized assigns(:profile).info.name
end
should 'filter html from contact_person to organization' do
org = Organization.create!(:name => 'test org', :identifier => 'testorg')
contact = "name with html"
- post :edit, :profile => org.identifier, :info => { :contact_person => contact }
+ post :edit, :profile => org.identifier, :profile_data => { :info => { :contact_person => contact } }
assert_sanitized assigns(:profile).info.contact_person
end
should 'filter html from acronym organization' do
org = Organization.create!(:name => 'test org', :identifier => 'testorg')
value = "name with html"
- post :edit, :profile => org.identifier, :info => { :acronym => value }
+ post :edit, :profile => org.identifier, :profile_data => { :info => { :acronym => value } }
assert_sanitized assigns(:profile).info.acronym
end
should 'filter html from legal_form organization' do
org = Organization.create!(:name => 'test org', :identifier => 'testorg')
value = "name with html"
- post :edit, :profile => org.identifier, :info => { :legal_form => value }
+ post :edit, :profile => org.identifier, :profile_data => { :info => { :legal_form => value } }
assert_sanitized assigns(:profile).info.legal_form
end
should 'filter html from economic_activity organization' do
org = Organization.create!(:name => 'test org', :identifier => 'testorg')
value = "name with html"
- post :edit, :profile => org.identifier, :info => { :economic_activity => value }
+ post :edit, :profile => org.identifier, :profile_data => { :info => { :economic_activity => value } }
assert_sanitized assigns(:profile).info.economic_activity
end
should 'filter html from management_information organization' do
org = Organization.create!(:name => 'test org', :identifier => 'testorg')
value = "name with html"
- post :edit, :profile => org.identifier, :info => { :management_information => value }
+ post :edit, :profile => org.identifier, :profile_data => { :info => { :management_information => value } }
assert_sanitized assigns(:profile).info.management_information
end
+ should 'saving profile organization_info' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ org.organization_info.create!
+ post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'contact person' } }
+ assert_equal 'contact person', Organization.find(org.id).organization_info.contact_person
+ end
+
+ should 'show contact_person field on edit organization' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ get :edit, :profile => org.identifier
+ assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]' }
+ end
+
+ should 'save community description' do
+ org = Community.create!(:name => 'test org', :identifier => 'testorg')
+ post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' }
+ assert_equal 'my description', Organization.find(org.id).description
+ end
+
+ should 'show community description' do
+ org = Community.create!(:name => 'test org', :identifier => 'testorg')
+ get :edit, :profile => 'testorg'
+ assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' }
+ end
+
+ should 'not show organization description' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ get :edit, :profile => 'testorg'
+ assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' }
+ end
+
+ should 'save organization contact_person' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'my contact' } }
+ assert_equal 'my contact', Organization.find(org.id).info.contact_person
+ end
+
+ should 'save enterprise contact_person' do
+ org = Enterprise.create!(:name => 'test org', :identifier => 'testorg')
+ post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'my contact' } }
+ assert_equal 'my contact', Enterprise.find(org.id).info.contact_person
+ end
+
+ should 'show field values on edit organization info' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ org.info = { :contact_person => 'my contact' }
+ org.info.save!
+ get :edit, :profile => 'testorg'
+ assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' }
+ end
+
+ should 'show error messages for'
+
end
diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb
index 4472e44..d678187 100644
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -39,4 +39,11 @@ class CommunityTest < Test::Unit::TestCase
assert_kind_of RssFeed, community.articles.find_by_path('feed')
end
+ should 'save info' do
+ community = Community.create!(:name => 'my new community')
+ community.info = {:contact_person => 'my contact'}
+ community.save!
+ assert_equal 'my contact', community.info.contact_person
+ end
+
end
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index d1433cd..4ad5295 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -124,4 +124,11 @@ class OrganizationTest < Test::Unit::TestCase
assert_equal true, Organization.new.has_members?
end
+ should 'update organization_info' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg')
+ assert_nil org.info.contact_person
+ org.info = {:contact_person => 'new person'}
+ assert_not_nil org.info.contact_person
+ end
+
end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index 171c18b..9a8e836 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -215,4 +215,11 @@ class PersonTest < Test::Unit::TestCase
assert_equal 'randomhacker', p.name
end
+ should 'save info' do
+ person = create_user('new_person').person
+ person.info = {:contact_information => 'my contact'}
+ person.save!
+ assert_equal 'my contact', person.info.contact_information
+ end
+
end
--
libgit2 0.21.2