Commit 40843cecd5832c3f626a1258e542d52df3eb52c4
1 parent
92346b73
Exists in
master
and in
29 other branches
ActionItem380: admin can edit enterprise description
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1788 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
103 additions
and
17 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -11,7 +11,7 @@ class ProfileEditorController < MyProfileController | @@ -11,7 +11,7 @@ class ProfileEditorController < MyProfileController | ||
11 | # edits the profile info (posts back) | 11 | # edits the profile info (posts back) |
12 | def edit | 12 | def edit |
13 | if request.post? | 13 | if request.post? |
14 | - if profile.info.update_attributes(params[:info]) | 14 | + if profile.update_attributes(params[:profile_data]) and profile.info.save |
15 | redirect_to :action => 'index' | 15 | redirect_to :action => 'index' |
16 | end | 16 | end |
17 | else | 17 | else |
app/helpers/application_helper.rb
@@ -163,6 +163,11 @@ module ApplicationHelper | @@ -163,6 +163,11 @@ module ApplicationHelper | ||
163 | 163 | ||
164 | alias_method :display_form_field, :labelled_form_field | 164 | alias_method :display_form_field, :labelled_form_field |
165 | 165 | ||
166 | + def labelled_fields_for(name, object = nil, options = {}, &proc) | ||
167 | + object ||= instance_variable_get("@#{name}") | ||
168 | + fields_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) | ||
169 | + end | ||
170 | + | ||
166 | def labelled_form_for(name, object = nil, options = {}, &proc) | 171 | def labelled_form_for(name, object = nil, options = {}, &proc) |
167 | object ||= instance_variable_get("@#{name}") | 172 | object ||= instance_variable_get("@#{name}") |
168 | form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) | 173 | form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) |
app/models/profile.rb
@@ -142,6 +142,10 @@ class Profile < ActiveRecord::Base | @@ -142,6 +142,10 @@ class Profile < ActiveRecord::Base | ||
142 | nil | 142 | nil |
143 | end | 143 | end |
144 | 144 | ||
145 | + def info=(args = {}) | ||
146 | + self.info.attributes = args if self.info | ||
147 | + end | ||
148 | + | ||
145 | # returns the contact email for this profile. By default returns the the | 149 | # returns the contact email for this profile. By default returns the the |
146 | # e-mail of the owner user. | 150 | # e-mail of the owner user. |
147 | # | 151 | # |
app/views/profile_editor/organization_info.rhtml
1 | <h1> <%= _('Edit organization info') %> </h1> | 1 | <h1> <%= _('Edit organization info') %> </h1> |
2 | 2 | ||
3 | -<%= error_messages_for :info %> | ||
4 | -<% labelled_form_for :info, @info do |f| %> | ||
5 | - <%= f.text_field(:contact_person) %> | ||
6 | - <%= f.text_field(:acronym) %> | ||
7 | - <%= f.text_field(:foundation_year) %> | ||
8 | - <%= f.text_field(:legal_form) %> | ||
9 | - <%= f.text_field(:economic_activity) %> | ||
10 | - <%= f.text_area(:management_information) %> | 3 | +<%= error_messages_for :profile %> |
4 | + | ||
5 | +<% labelled_form_for :profile_data, @profile do |f| %> | ||
6 | + <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %> | ||
7 | + <% labelled_fields_for 'profile_data[info]', @profile.organization_info do |i| %> | ||
8 | + <%= i.text_field(:contact_person) %> | ||
9 | + <%= i.text_field(:acronym) %> | ||
10 | + <%= i.text_field(:foundation_year) %> | ||
11 | + <%= i.text_field(:legal_form) %> | ||
12 | + <%= i.text_field(:economic_activity) %> | ||
13 | + <%= i.text_area(:management_information, :rows => 5) %> | ||
14 | + <% end %> | ||
11 | <% button_bar do %> | 15 | <% button_bar do %> |
12 | <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %> | 16 | <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %> |
13 | <% end %> | 17 | <% end %> |
test/functional/profile_editor_controller_test.rb
@@ -66,9 +66,8 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -66,9 +66,8 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
66 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | 66 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
67 | person.person_info.address = 'my address' | 67 | person.person_info.address = 'my address' |
68 | person.person_info.contact_information = 'my contact information' | 68 | person.person_info.contact_information = 'my contact information' |
69 | - person.person_info.save | 69 | + person.person_info.save! |
70 | 70 | ||
71 | -# profile.person_info.expects(:update_attributes).with({ 'contact_information' => 'new contact information', 'address' => 'new address' }).returns(true) | ||
72 | post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } | 71 | post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } |
73 | 72 | ||
74 | assert_redirected_to :action => 'index' | 73 | assert_redirected_to :action => 'index' |
@@ -103,43 +102,96 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -103,43 +102,96 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
103 | should 'filter html from name when edit person_info' do | 102 | should 'filter html from name when edit person_info' do |
104 | person = create_user('test_profile').person | 103 | person = create_user('test_profile').person |
105 | name = "name <strong id='name_html_test'>with</strong> html" | 104 | name = "name <strong id='name_html_test'>with</strong> html" |
106 | - post :edit, :profile => person.identifier, :info => { :name => name } | 105 | + post :edit, :profile => person.identifier, :profile_data => { :info => { :name => name } } |
107 | assert_sanitized assigns(:profile).info.name | 106 | assert_sanitized assigns(:profile).info.name |
108 | end | 107 | end |
109 | 108 | ||
110 | should 'filter html from contact_person to organization' do | 109 | should 'filter html from contact_person to organization' do |
111 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 110 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
112 | contact = "name <strong id='name_html_test'>with</strong> html" | 111 | contact = "name <strong id='name_html_test'>with</strong> html" |
113 | - post :edit, :profile => org.identifier, :info => { :contact_person => contact } | 112 | + post :edit, :profile => org.identifier, :profile_data => { :info => { :contact_person => contact } } |
114 | assert_sanitized assigns(:profile).info.contact_person | 113 | assert_sanitized assigns(:profile).info.contact_person |
115 | end | 114 | end |
116 | 115 | ||
117 | should 'filter html from acronym organization' do | 116 | should 'filter html from acronym organization' do |
118 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 117 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
119 | value = "name <strong id='name_html_test'>with</strong> html" | 118 | value = "name <strong id='name_html_test'>with</strong> html" |
120 | - post :edit, :profile => org.identifier, :info => { :acronym => value } | 119 | + post :edit, :profile => org.identifier, :profile_data => { :info => { :acronym => value } } |
121 | assert_sanitized assigns(:profile).info.acronym | 120 | assert_sanitized assigns(:profile).info.acronym |
122 | end | 121 | end |
123 | 122 | ||
124 | should 'filter html from legal_form organization' do | 123 | should 'filter html from legal_form organization' do |
125 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 124 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
126 | value = "name <strong id='name_html_test'>with</strong> html" | 125 | value = "name <strong id='name_html_test'>with</strong> html" |
127 | - post :edit, :profile => org.identifier, :info => { :legal_form => value } | 126 | + post :edit, :profile => org.identifier, :profile_data => { :info => { :legal_form => value } } |
128 | assert_sanitized assigns(:profile).info.legal_form | 127 | assert_sanitized assigns(:profile).info.legal_form |
129 | end | 128 | end |
130 | 129 | ||
131 | should 'filter html from economic_activity organization' do | 130 | should 'filter html from economic_activity organization' do |
132 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 131 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
133 | value = "name <strong id='name_html_test'>with</strong> html" | 132 | value = "name <strong id='name_html_test'>with</strong> html" |
134 | - post :edit, :profile => org.identifier, :info => { :economic_activity => value } | 133 | + post :edit, :profile => org.identifier, :profile_data => { :info => { :economic_activity => value } } |
135 | assert_sanitized assigns(:profile).info.economic_activity | 134 | assert_sanitized assigns(:profile).info.economic_activity |
136 | end | 135 | end |
137 | 136 | ||
138 | should 'filter html from management_information organization' do | 137 | should 'filter html from management_information organization' do |
139 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 138 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
140 | value = "name <strong id='name_html_test'>with</strong> html" | 139 | value = "name <strong id='name_html_test'>with</strong> html" |
141 | - post :edit, :profile => org.identifier, :info => { :management_information => value } | 140 | + post :edit, :profile => org.identifier, :profile_data => { :info => { :management_information => value } } |
142 | assert_sanitized assigns(:profile).info.management_information | 141 | assert_sanitized assigns(:profile).info.management_information |
143 | end | 142 | end |
144 | 143 | ||
144 | + should 'saving profile organization_info' do | ||
145 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
146 | + org.organization_info.create! | ||
147 | + post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'contact person' } } | ||
148 | + assert_equal 'contact person', Organization.find(org.id).organization_info.contact_person | ||
149 | + end | ||
150 | + | ||
151 | + should 'show contact_person field on edit organization' do | ||
152 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
153 | + get :edit, :profile => org.identifier | ||
154 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]' } | ||
155 | + end | ||
156 | + | ||
157 | + should 'save community description' do | ||
158 | + org = Community.create!(:name => 'test org', :identifier => 'testorg') | ||
159 | + post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } | ||
160 | + assert_equal 'my description', Organization.find(org.id).description | ||
161 | + end | ||
162 | + | ||
163 | + should 'show community description' do | ||
164 | + org = Community.create!(:name => 'test org', :identifier => 'testorg') | ||
165 | + get :edit, :profile => 'testorg' | ||
166 | + assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } | ||
167 | + end | ||
168 | + | ||
169 | + should 'not show organization description' do | ||
170 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
171 | + get :edit, :profile => 'testorg' | ||
172 | + assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } | ||
173 | + end | ||
174 | + | ||
175 | + should 'save organization contact_person' do | ||
176 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
177 | + post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'my contact' } } | ||
178 | + assert_equal 'my contact', Organization.find(org.id).info.contact_person | ||
179 | + end | ||
180 | + | ||
181 | + should 'save enterprise contact_person' do | ||
182 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg') | ||
183 | + post :edit, :profile => 'testorg', :profile_data => { :info => { :contact_person => 'my contact' } } | ||
184 | + assert_equal 'my contact', Enterprise.find(org.id).info.contact_person | ||
185 | + end | ||
186 | + | ||
187 | + should 'show field values on edit organization info' do | ||
188 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
189 | + org.info = { :contact_person => 'my contact' } | ||
190 | + org.info.save! | ||
191 | + get :edit, :profile => 'testorg' | ||
192 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' } | ||
193 | + end | ||
194 | + | ||
195 | + should 'show error messages for' | ||
196 | + | ||
145 | end | 197 | end |
test/unit/community_test.rb
@@ -39,4 +39,11 @@ class CommunityTest < Test::Unit::TestCase | @@ -39,4 +39,11 @@ class CommunityTest < Test::Unit::TestCase | ||
39 | assert_kind_of RssFeed, community.articles.find_by_path('feed') | 39 | assert_kind_of RssFeed, community.articles.find_by_path('feed') |
40 | end | 40 | end |
41 | 41 | ||
42 | + should 'save info' do | ||
43 | + community = Community.create!(:name => 'my new community') | ||
44 | + community.info = {:contact_person => 'my contact'} | ||
45 | + community.save! | ||
46 | + assert_equal 'my contact', community.info.contact_person | ||
47 | + end | ||
48 | + | ||
42 | end | 49 | end |
test/unit/organization_test.rb
@@ -124,4 +124,11 @@ class OrganizationTest < Test::Unit::TestCase | @@ -124,4 +124,11 @@ class OrganizationTest < Test::Unit::TestCase | ||
124 | assert_equal true, Organization.new.has_members? | 124 | assert_equal true, Organization.new.has_members? |
125 | end | 125 | end |
126 | 126 | ||
127 | + should 'update organization_info' do | ||
128 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | ||
129 | + assert_nil org.info.contact_person | ||
130 | + org.info = {:contact_person => 'new person'} | ||
131 | + assert_not_nil org.info.contact_person | ||
132 | + end | ||
133 | + | ||
127 | end | 134 | end |
test/unit/person_test.rb
@@ -215,4 +215,11 @@ class PersonTest < Test::Unit::TestCase | @@ -215,4 +215,11 @@ class PersonTest < Test::Unit::TestCase | ||
215 | assert_equal 'randomhacker', p.name | 215 | assert_equal 'randomhacker', p.name |
216 | end | 216 | end |
217 | 217 | ||
218 | + should 'save info' do | ||
219 | + person = create_user('new_person').person | ||
220 | + person.info = {:contact_information => 'my contact'} | ||
221 | + person.save! | ||
222 | + assert_equal 'my contact', person.info.contact_information | ||
223 | + end | ||
224 | + | ||
218 | end | 225 | end |