Commit 00cf38bc3ea065a5054d901ce4e22c6b661eba57

Authored by Antonio Terceiro
2 parents 247ad826 0d740187

Merge branch 'AI3147-edit_profile_bug' into 'master'

AI3147 edit profile bug

Added support for mass-assignment for all of person's, community's and enterprise's fields.

Before this, if a environment admin enabled all fields on the fields environment page, you got an error when trying to edit a profile.

The Action Item was created at: http://noosfero.org/Development/ActionItem3147
app/models/community.rb
1 1 class Community < Organization
2 2  
3   - attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
  3 + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type, :address_reference, :district, :tag_list, :language
4 4 after_destroy :check_invite_member_for_destroy
5 5  
6 6 def self.type_name
... ...
app/models/enterprise.rb
... ... @@ -2,6 +2,8 @@
2 2 # only enterprises can offer products and services.
3 3 class Enterprise < Organization
4 4  
  5 + attr_accessible :business_name, :address_reference, :district, :tag_list, :organization_website, :historic_and_current_context, :activities_short_description, :products_per_catalog_page
  6 +
5 7 SEARCH_DISPLAYS += %w[map full]
6 8  
7 9 def self.type_name
... ...
app/models/person.rb
1 1 # A person is the profile of an user holding all relationships with the rest of the system
2 2 class Person < Profile
3 3  
4   - attr_accessible :organization, :contact_information, :sex, :birth_date
  4 + attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website
5 5  
6 6 SEARCH_FILTERS += %w[
7 7 more_popular
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -6,7 +6,7 @@ class ProfileEditorController; def rescue_action(e) raise e end; end
6 6  
7 7 class ProfileEditorControllerTest < ActionController::TestCase
8 8 all_fixtures
9   -
  9 +
10 10 def setup
11 11 @controller = ProfileEditorController.new
12 12 @request = ActionController::TestRequest.new
... ... @@ -20,11 +20,11 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
20 20 def test_local_files_reference
21 21 assert_local_files_reference :get, :index, :profile => profile.identifier
22 22 end
23   -
  23 +
24 24 def test_valid_xhtml
25 25 assert_valid_xhtml
26 26 end
27   -
  27 +
28 28 def test_index
29 29 get :index, :profile => profile.identifier
30 30 assert_template 'index'
... ... @@ -50,7 +50,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
50 50 end
51 51  
52 52 should 'saving profile info' do
53   - person = profile
  53 + person = profile
54 54 post :edit, :profile => profile.identifier, :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' }
55 55 assert_redirected_to :controller => 'profile_editor', :action => 'index'
56 56 person = Person.find(person.id)
... ... @@ -60,6 +60,15 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
60 60 assert_equal 'female', person.sex
61 61 end
62 62  
  63 + should 'mass assign all environment configurable person fields' do
  64 + person = profile
  65 +
  66 + post :edit, :profile => profile.identifier, :profile_data => { "nickname" => "ze", "description" => "Just a regular ze.", "contact_information" => "What?", "contact_phone" => "+0551133445566", "cell_phone" => "+0551188889999", "comercial_phone" => "+0551144336655", "jabber_id" => "ze1234", "personal_website" => "http://ze.com.br", "sex" => "male", "birth_date" => "2014-06-04", "nationality" => "Brazilian", "country" => "BR", "state" => "DF", "city" => "Brasilia", "zip_code" => "70300-010", "address" => "Palacio do Planalto", "address_reference" => "Praca dos tres poderes", "district" => "DF", "schooling" => "Undergraduate", "schooling_status" => "Concluded", "formation" => "Engineerings", "area_of_study" => "Metallurgy", "professional_activity" => "Metallurgic", "organization" => "Metal Corp.", "organization_website" => "http://metal.com" }
  67 +
  68 + assert_response :redirect
  69 + assert_redirected_to :controller => 'profile_editor', :action => 'index'
  70 + end
  71 +
63 72 should 'not permmit if not logged' do
64 73 logout
65 74 get :index, :profile => profile.identifier
... ... @@ -164,6 +173,15 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
164 173 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' }
165 174 end
166 175  
  176 + should 'mass assign all environment configurable community fields' do
  177 + cmm = fast_create(Community)
  178 +
  179 + post :edit, :profile => cmm.identifier, :profile_data => { "name" => "new name", "display_name" => "N&w N@me", "description"=>"We sell food and other stuff.", "contact_person"=>"Joseph of the Jungle", "contact_email"=>"sac@company.net", "contact_phone"=>"+0551133445566", "legal_form"=>"New Name corp.", "economic_activity"=>"Food", "management_information"=>"No need for that here.", "address"=>"123, baufas street", "address_reference"=>"Next to baufas house", "district"=>"DC", "zip_code"=>"123456", "city"=>"Whashington", "state"=>"DC", "country"=>"US", "tag_list"=>"food, corporations", "language"=>"English" }
  180 +
  181 + assert_response :redirect
  182 + assert_redirected_to :controller => 'profile_editor', :action => 'index'
  183 + end
  184 +
167 185 should 'show field values on edit enterprise info' do
168 186 Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once
169 187 org = fast_create(Enterprise)
... ... @@ -173,6 +191,15 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
173 191 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' }
174 192 end
175 193  
  194 + should 'mass assign all environment configurable enterprise fields' do
  195 + enterprise = fast_create(Enterprise)
  196 +
  197 + post :edit, :profile => enterprise.identifier, :profile_data => { "name"=>"Enterprise", "display_name"=>"Enterprise name", "business_name"=>"Enterprise", "description"=>"Hello IT.", "contact_person"=>"Joseph", "contact_email"=>"joe@enterprise.net", "contact_phone"=>"+0551133445566", "legal_form"=>"Enterprise corp.", "economic_activity"=>"Food", "management_information"=>"None.", "address"=>"123, baufas street", "address_reference"=>"Next to baufas house", "district"=>"DC", "zip_code"=>"123456", "city"=>"Washington", "state"=>"DC", "country"=>"US", "tag_list"=>"food, corporations", "organization_website"=>"http://enterprise.net", "historic_and_current_context"=>"Historic.", "activities_short_description"=>"Activies.", "acronym"=>"E", "foundation_year"=>"1995",}
  198 +
  199 + assert_response :redirect
  200 + assert_redirected_to :controller => 'profile_editor', :action => 'index'
  201 + end
  202 +
176 203 should 'display profile publication option in edit profile screen' do
177 204 get :edit, :profile => profile.identifier
178 205 assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' }
... ... @@ -426,7 +453,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
426 453 get :index, :profile => ent.identifier
427 454 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/enable" }
428 455 end
429   -
  456 +
430 457 should 'link to disable enterprise' do
431 458 ent = fast_create(Enterprise, :enabled => true)
432 459 get :index, :profile => ent.identifier
... ...