Commit 5bff0b1ddbd744b86cfe31e616878b4190a6fea6
1 parent
e0f4d9ee
Exists in
staging
and in
42 other branches
ActionItem7: making everything work together
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@456 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
115 additions
and
9 deletions
Show diff stats
app/controllers/application.rb
... | ... | @@ -30,10 +30,14 @@ class ApplicationController < ActionController::Base |
30 | 30 | before_filter :load_profile_from_params |
31 | 31 | def load_profile_from_params |
32 | 32 | if params[:profile] |
33 | - @profile = Profile.find_by_identifier(params[:profile]) | |
33 | + @profile ||= Profile.find_by_identifier(params[:profile]) | |
34 | 34 | end |
35 | 35 | end |
36 | 36 | |
37 | + def profile | |
38 | + @profile | |
39 | + end | |
40 | + | |
37 | 41 | def self.acts_as_virtual_community_admin_controller |
38 | 42 | before_filter :load_admin_controller |
39 | 43 | end | ... | ... |
app/controllers/profile_editor_controller.rb
... | ... | @@ -4,8 +4,11 @@ class ProfileEditorController < ApplicationController |
4 | 4 | # edits the profile info (posts back) |
5 | 5 | def edit |
6 | 6 | if request.post? |
7 | + profile.info.update_attributes(params[:info]) | |
8 | + redirect_to :action => 'index' | |
7 | 9 | else |
8 | - render :action => profile.info.class.tableize | |
10 | + @info = profile.info | |
11 | + render :action => @info.class.name.underscore | |
9 | 12 | end |
10 | 13 | end |
11 | 14 | end | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -158,4 +158,12 @@ module ApplicationHelper |
158 | 158 | @profile || raise("There is no current profile") |
159 | 159 | end |
160 | 160 | |
161 | + # displays an | |
162 | + # | |
163 | + # Current implementation generates a <label> tag for +label+ and wrap the | |
164 | + # label and the control with a <div> tag with class 'formfield' | |
165 | + def display_form_field(label, html_for_field) | |
166 | + content_tag('div', content_tag('div', content_tag('label', label)) + html_for_field, :class => 'formfield') | |
167 | + end | |
168 | + | |
161 | 169 | end | ... | ... |
app/models/person.rb
app/models/person_info.rb
... | ... | @@ -0,0 +1,13 @@ |
1 | +<h2><%= _('Edit person info') %></h2> | |
2 | + | |
3 | +<% form_for :info, @info do |f| %> | |
4 | + | |
5 | + <%= display_form_field(_('Name'), f.text_field(:name)) %> | |
6 | + | |
7 | + <%= display_form_field(_('Address'), f.text_area(:address, :rows => 5)) %> | |
8 | + | |
9 | + <%= display_form_field(_('Contact Information'), f.text_area(:contact_information, :rows => 5)) %> | |
10 | + | |
11 | + <%= submit_tag _('Save') %> | |
12 | + | |
13 | +<% end %> | ... | ... |
db/migrate/013_create_person_infos.rb
test/functional/profile_editor_controller_test.rb
... | ... | @@ -11,8 +11,46 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
11 | 11 | @response = ActionController::TestResponse.new |
12 | 12 | end |
13 | 13 | |
14 | - # Replace this with your real tests. | |
15 | - def test_truth | |
16 | - assert true | |
14 | + def test_index | |
15 | + profile = Person.new | |
16 | + profile.person_info.name = 'a test profile' | |
17 | + profile.person_info.address = 'my address' | |
18 | + profile.person_info.contact_information = 'my contact information' | |
19 | + @controller.instance_variable_set('@profile', profile) | |
20 | + | |
21 | + get :index, :profile => 'test_profile' | |
22 | + assert_response :success | |
23 | + assert_not_nil assigns(:profile) | |
24 | + | |
25 | + assert_tag :tag => 'td', :content => 'a test profile' | |
26 | + assert_tag :tag => 'td', :content => 'my address' | |
27 | + assert_tag :tag => 'td', :content => 'my contact information' | |
28 | + end | |
29 | + | |
30 | + def test_edit_person_info | |
31 | + profile = Person.new | |
32 | + profile.name = 'a test profile' | |
33 | + profile.person_info.address = 'my address' | |
34 | + profile.person_info.contact_information = 'my contact information' | |
35 | + @controller.instance_variable_set('@profile', profile) | |
36 | + | |
37 | + get :edit, :profile => 'test_profile' | |
38 | + assert_response :success | |
39 | + assert_template 'person_info' | |
40 | + | |
17 | 41 | end |
42 | + | |
43 | + def test_saving_profile_info | |
44 | + profile = Person.new | |
45 | + profile.name = 'a test profile' | |
46 | + profile.person_info.address = 'my address' | |
47 | + profile.person_info.contact_information = 'my contact information' | |
48 | + @controller.instance_variable_set('@profile', profile) | |
49 | + | |
50 | + profile.person_info.expects(:update_attributes).with({ 'contact_information' => 'new contact information', 'address' => 'new address' }).returns(true) | |
51 | + post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } | |
52 | + | |
53 | + assert_redirected_to :action => 'index' | |
54 | + end | |
55 | + | |
18 | 56 | end | ... | ... |
test/integration/edit_enterprise_test.rb
... | ... | @@ -13,7 +13,7 @@ class EditEnterpriseTest < ActionController::IntegrationTest |
13 | 13 | |
14 | 14 | follow_redirect! |
15 | 15 | assert_response :success |
16 | - assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/edit/5'} | |
16 | + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/enterprise/edit/5'} | |
17 | 17 | |
18 | 18 | get '/myprofile/ze/enterprise/edit/5' |
19 | 19 | assert_response :success | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
2 | + | |
3 | +class EditingPersonInfoTest < ActionController::IntegrationTest | |
4 | + | |
5 | + fixtures :users, :profiles, :comatose_pages, :domains, :virtual_communities, :person_infos | |
6 | + | |
7 | + should 'allow to edit person info' do | |
8 | + | |
9 | + profile = Profile.find_by_identifier('ze') | |
10 | + | |
11 | + login('ze', 'test') | |
12 | + | |
13 | + get '/myprofile/ze' | |
14 | + assert_response :success | |
15 | + | |
16 | + assert_tag :tag => 'td', :content => profile.person_info.name | |
17 | + assert_tag :tag => 'td', :content => profile.person_info.address | |
18 | + assert_tag :tag => 'td', :content => profile.person_info.contact_information | |
19 | + | |
20 | + get '/myprofile/ze/profile_editor/edit' | |
21 | + assert_response :success | |
22 | + | |
23 | + post '/myprofile/ze/profile_editor/edit', :info => { :address => 'a new address', :contact_information => 'a new contact information' } | |
24 | + assert_response :redirect | |
25 | + | |
26 | + end | |
27 | +end | ... | ... |
test/unit/person_info_test.rb
... | ... | @@ -12,9 +12,8 @@ class PersonInfoTest < Test::Unit::TestCase |
12 | 12 | |
13 | 13 | should 'provide needed information in summary' do |
14 | 14 | person_info = PersonInfo.new |
15 | - person_info.person = Person.new | |
16 | - person_info.person.name = 'person name' | |
17 | 15 | |
16 | + person_info.name = 'person name' | |
18 | 17 | person_info.address = 'my address' |
19 | 18 | person_info.contact_information = 'my contact information' |
20 | 19 | ... | ... |