Commit ec0761a4546cf4ebf56538d75d3fc67d6f65930f
1 parent
7f93cfa3
Exists in
master
and in
29 other branches
ActionItem380: moving all fields from PersonInfo and OrganizationInfo to profile…
… using settings_items git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1802 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
31 changed files
with
261 additions
and
310 deletions
Show diff stats
app/controllers/my_profile/enterprise_editor_controller.rb
@@ -16,7 +16,7 @@ class EnterpriseEditorController < MyProfileController | @@ -16,7 +16,7 @@ class EnterpriseEditorController < MyProfileController | ||
16 | 16 | ||
17 | # Saves the changes made in an enterprise | 17 | # Saves the changes made in an enterprise |
18 | def update | 18 | def update |
19 | - if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) | 19 | + if @enterprise.update_attributes(params[:enterprise]) |
20 | redirect_to :action => 'index' | 20 | redirect_to :action => 'index' |
21 | else | 21 | else |
22 | flash[:notice] = _('Could not update the enterprise') | 22 | flash[:notice] = _('Could not update the enterprise') |
app/controllers/my_profile/profile_editor_controller.rb
@@ -11,12 +11,11 @@ class ProfileEditorController < MyProfileController | @@ -11,12 +11,11 @@ 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.update_attributes(params[:profile_data]) and profile.info.save | 14 | + if profile.update_attributes(params[:profile_data]) |
15 | redirect_to :action => 'index' | 15 | redirect_to :action => 'index' |
16 | end | 16 | end |
17 | else | 17 | else |
18 | - @info = profile.info | ||
19 | - render :action => @info.class.name.underscore | 18 | + render :action => profile.class.name.underscore |
20 | end | 19 | end |
21 | end | 20 | end |
22 | 21 |
app/helpers/profile_helper.rb
1 | module ProfileHelper | 1 | module ProfileHelper |
2 | 2 | ||
3 | def display_profile_info(profile) | 3 | def display_profile_info(profile) |
4 | - info = profile.info | ||
5 | - if info.nil? | ||
6 | - content_tag('div', _('This profile does not have any public information')) | ||
7 | - else | ||
8 | - table_rows = content_tag( 'tr', | ||
9 | - content_tag( 'th', | ||
10 | - "\n" + | ||
11 | - button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) + | ||
12 | - "\n", | ||
13 | - :colspan => 2, :class => 'header' ) | ||
14 | - ) + "\n" | ||
15 | - info.summary.each do |item| | ||
16 | - name = item[0] | ||
17 | - value = item[1] | ||
18 | - if value.is_a?(Proc) | ||
19 | - value = self.instance_eval(value) | ||
20 | - end | ||
21 | - table_rows << content_tag('tr', content_tag('th', name) + content_tag('td', value)) | ||
22 | - table_rows << "\n" | 4 | + table_rows = content_tag( 'tr', |
5 | + content_tag( 'th', | ||
6 | + "\n" + | ||
7 | + button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) + | ||
8 | + "\n", | ||
9 | + :colspan => 2, :class => 'header' ) | ||
10 | + ) + "\n" | ||
11 | + profile.summary.each do |item| | ||
12 | + name = item[0] | ||
13 | + value = item[1] | ||
14 | + if value.is_a?(Proc) | ||
15 | + value = self.instance_eval(value) | ||
23 | end | 16 | end |
24 | - | ||
25 | - content_tag( | ||
26 | - 'table', | ||
27 | - table_rows, | ||
28 | - :class => 'profile_info' | ||
29 | - ) | 17 | + table_rows << content_tag('tr', content_tag('th', _(name)) + content_tag('td', value)) |
18 | + table_rows << "\n" | ||
30 | end | 19 | end |
20 | + | ||
21 | + content_tag( | ||
22 | + 'table', | ||
23 | + table_rows, | ||
24 | + :class => 'profile_info' | ||
25 | + ) | ||
31 | end | 26 | end |
32 | 27 | ||
33 | end | 28 | end |
app/models/create_enterprise.rb
@@ -112,13 +112,13 @@ class CreateEnterprise < Task | @@ -112,13 +112,13 @@ class CreateEnterprise < Task | ||
112 | enterprise.send("#{field}=", self.send(field)) | 112 | enterprise.send("#{field}=", self.send(field)) |
113 | end | 113 | end |
114 | 114 | ||
115 | - organization_info_data = self.data.reject do |key,value| | 115 | + organization_data = self.data.reject do |key,value| |
116 | profile_fields.include?(key.to_s) | 116 | profile_fields.include?(key.to_s) |
117 | end | 117 | end |
118 | 118 | ||
119 | enterprise.user = self.requestor.user | 119 | enterprise.user = self.requestor.user |
120 | 120 | ||
121 | - enterprise.organization_info = OrganizationInfo.new(organization_info_data) | 121 | + enterprise.update_attributes(organization_data) |
122 | enterprise.save! | 122 | enterprise.save! |
123 | end | 123 | end |
124 | 124 |
app/models/organization.rb
1 | -# Represents any organization of the system and has an organization_info object to hold its info | 1 | +# Represents any organization of the system |
2 | class Organization < Profile | 2 | class Organization < Profile |
3 | 3 | ||
4 | - has_one :organization_info | ||
5 | - | ||
6 | belongs_to :region | 4 | belongs_to :region |
7 | 5 | ||
8 | has_one :validation_info | 6 | has_one :validation_info |
9 | 7 | ||
10 | has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id | 8 | has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id |
11 | 9 | ||
12 | - after_create do |org| | ||
13 | - OrganizationInfo.create!(:organization_id => org.id) | ||
14 | - end | ||
15 | - | ||
16 | - def contact_email | ||
17 | - self.organization_info ? self.organization_info.contact_email : nil | ||
18 | - end | ||
19 | - | ||
20 | def validation_methodology | 10 | def validation_methodology |
21 | self.validation_info ? self.validation_info.validation_methodology : nil | 11 | self.validation_info ? self.validation_info.validation_methodology : nil |
22 | end | 12 | end |
@@ -45,8 +35,19 @@ class Organization < Profile | @@ -45,8 +35,19 @@ class Organization < Profile | ||
45 | !self.validation_info.nil? | 35 | !self.validation_info.nil? |
46 | end | 36 | end |
47 | 37 | ||
48 | - def info | ||
49 | - organization_info | 38 | + settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated |
39 | + | ||
40 | + validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT, :if => (lambda { |org| ! org.foundation_year.nil? }) | ||
41 | + | ||
42 | + validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| ! org.contact_email.nil? }) | ||
43 | + | ||
44 | + xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ] | ||
45 | + | ||
46 | + def summary | ||
47 | + # FIXME diplays too few fields | ||
48 | + ['acronym', 'foundation_year', 'contact_email'].map do |col| | ||
49 | + [ col.humanize, self.send(col) ] | ||
50 | + end | ||
50 | end | 51 | end |
51 | 52 | ||
52 | # Yes, organizations have members. | 53 | # Yes, organizations have members. |
app/models/organization_info.rb
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -class OrganizationInfo < ActiveRecord::Base | ||
2 | - belongs_to :organization | ||
3 | - | ||
4 | - validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true | ||
5 | - | ||
6 | - validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |info| ! info.contact_email.nil? }) | ||
7 | - | ||
8 | - xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ] | ||
9 | - | ||
10 | - def summary | ||
11 | - # FIXME diplays too few fields | ||
12 | - [ 'acronym', 'foundation_year', 'contact_email'].map do |col| | ||
13 | - [ OrganizationInfo.columns_hash[col].human_name, self.send(col) ] | ||
14 | - end | ||
15 | - end | ||
16 | -end |
app/models/person.rb
@@ -21,8 +21,14 @@ class Person < Profile | @@ -21,8 +21,14 @@ class Person < Profile | ||
21 | def remove_friend(friend) | 21 | def remove_friend(friend) |
22 | friends.delete(friend) | 22 | friends.delete(friend) |
23 | end | 23 | end |
24 | - | ||
25 | - has_one :person_info | 24 | + |
25 | + settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country | ||
26 | + | ||
27 | + def summary | ||
28 | + ['name', 'contact_information', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col| | ||
29 | + [ col.humanize, self.send(col) ] | ||
30 | + end | ||
31 | + end | ||
26 | 32 | ||
27 | def self.conditions_for_profiles(conditions, person) | 33 | def self.conditions_for_profiles(conditions, person) |
28 | new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) | 34 | new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) |
@@ -50,20 +56,9 @@ class Person < Profile | @@ -50,20 +56,9 @@ class Person < Profile | ||
50 | 56 | ||
51 | alias :communities :community_memberships | 57 | alias :communities :community_memberships |
52 | 58 | ||
53 | - | ||
54 | - def info | ||
55 | - person_info | ||
56 | - end | ||
57 | - | ||
58 | validates_presence_of :user_id | 59 | validates_presence_of :user_id |
59 | validates_uniqueness_of :user_id | 60 | validates_uniqueness_of :user_id |
60 | 61 | ||
61 | - def initialize(*args) | ||
62 | - super(*args) | ||
63 | - self.person_info ||= PersonInfo.new | ||
64 | - self.person_info.person = self | ||
65 | - end | ||
66 | - | ||
67 | def email | 62 | def email |
68 | self.user.nil? ? nil : self.user.email | 63 | self.user.nil? ? nil : self.user.email |
69 | end | 64 | end |
@@ -105,7 +100,11 @@ class Person < Profile | @@ -105,7 +100,11 @@ class Person < Profile | ||
105 | hacked_after_create :insert_default_homepage_and_feed | 100 | hacked_after_create :insert_default_homepage_and_feed |
106 | 101 | ||
107 | def name | 102 | def name |
108 | - person_info.nil? ? self[:name] : (person_info.name || self[:name]) | 103 | + if !self[:name].nil? |
104 | + self[:name] | ||
105 | + else | ||
106 | + self.user ? self.user.login : nil | ||
107 | + end | ||
109 | end | 108 | end |
110 | 109 | ||
111 | has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people' | 110 | has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people' |
app/models/profile.rb
@@ -96,7 +96,7 @@ class Profile < ActiveRecord::Base | @@ -96,7 +96,7 @@ class Profile < ActiveRecord::Base | ||
96 | end | 96 | end |
97 | 97 | ||
98 | validates_presence_of :identifier, :name | 98 | validates_presence_of :identifier, :name |
99 | - validates_format_of :identifier, :with => IDENTIFIER_FORMAT, :message => "Identifier %s is invalid" | 99 | + validates_format_of :identifier, :with => IDENTIFIER_FORMAT |
100 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS | 100 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS |
101 | validates_uniqueness_of :identifier | 101 | validates_uniqueness_of :identifier |
102 | 102 | ||
@@ -121,32 +121,7 @@ class Profile < ActiveRecord::Base | @@ -121,32 +121,7 @@ class Profile < ActiveRecord::Base | ||
121 | true | 121 | true |
122 | end | 122 | end |
123 | 123 | ||
124 | - xss_terminate :only => [ :address, :contact_phone ] | ||
125 | - | ||
126 | - # Returns information about the profile's owner that was made public by | ||
127 | - # him/her. | ||
128 | - # | ||
129 | - # The returned value must be an object that responds to a method "summary", | ||
130 | - # which must return an array in the following format: | ||
131 | - # | ||
132 | - # [ | ||
133 | - # [ 'First Field', first_field_value ], | ||
134 | - # [ 'Second Field', second_field_value ], | ||
135 | - # ] | ||
136 | - # | ||
137 | - # This information shall be used by user interface to present the | ||
138 | - # information. | ||
139 | - # | ||
140 | - # In this class, this method returns nil, what is interpreted as "no | ||
141 | - # information at all". Subclasses must override this method to provide their | ||
142 | - # specific information. | ||
143 | - def info | ||
144 | - nil | ||
145 | - end | ||
146 | - | ||
147 | - def info=(args = {}) | ||
148 | - self.info.attributes = args if self.info | ||
149 | - end | 124 | + xss_terminate :only => [ :name, :address, :contact_phone ] |
150 | 125 | ||
151 | # returns the contact email for this profile. By default returns the the | 126 | # returns the contact email for this profile. By default returns the the |
152 | # e-mail of the owner user. | 127 | # e-mail of the owner user. |
app/views/account/user_info.rhtml
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <h2><%= _('Logged in as %s') % user.identifier %></h2> | 3 | <h2><%= _('Logged in as %s') % user.identifier %></h2> |
4 | 4 | ||
5 | <ul> | 5 | <ul> |
6 | - <li><%= _('User since %{year}/%{month}') % { :year => user.person_info.created_at.year, :month => user.person_info.created_at.month } %></li> | 6 | + <li><%= _('User since %{year}/%{month}') % { :year => user.created_at.year, :month => user.created_at.month } %></li> |
7 | <li><%= link_to_homepage _('Homepage') %></li> | 7 | <li><%= link_to_homepage _('Homepage') %></li> |
8 | </ul> | 8 | </ul> |
9 | 9 |
app/views/enterprise_editor/_form.rhtml
@@ -8,22 +8,22 @@ | @@ -8,22 +8,22 @@ | ||
8 | <%= text_field 'enterprise', 'contact_phone', 'size' => 20 %></p> | 8 | <%= text_field 'enterprise', 'contact_phone', 'size' => 20 %></p> |
9 | 9 | ||
10 | <p class='formfield text_field'><label for="contact_person"><%= _('Contact Person') %></label><br/> | 10 | <p class='formfield text_field'><label for="contact_person"><%= _('Contact Person') %></label><br/> |
11 | -<%= text_field 'organization_info', 'contact_person', 'size' => 20 %></p> | 11 | +<%= text_field 'enterprise', 'contact_person', 'size' => 20 %></p> |
12 | 12 | ||
13 | <p class='formfield text_field'><label for="acronym"><%= _('Acronym') %></label><br/> | 13 | <p class='formfield text_field'><label for="acronym"><%= _('Acronym') %></label><br/> |
14 | -<%= text_field 'organization_info', 'acronym', 'size' => 20 %></p> | 14 | +<%= text_field 'enterprise', 'acronym', 'size' => 20 %></p> |
15 | 15 | ||
16 | <p class='formfield text_field'><label for="foundation_year"><%= _('Foundation Year') %></label><br/> | 16 | <p class='formfield text_field'><label for="foundation_year"><%= _('Foundation Year') %></label><br/> |
17 | -<%= text_field 'organization_info', 'foundation_year', 'size' => 20 %></p> | 17 | +<%= text_field 'enterprise', 'foundation_year', 'size' => 20 %></p> |
18 | 18 | ||
19 | <p class='formfield text_field'><label for="legal_form"><%= _('Legal Form') %></label><br/> | 19 | <p class='formfield text_field'><label for="legal_form"><%= _('Legal Form') %></label><br/> |
20 | -<%= text_field 'organization_info', 'legal_form', 'size' => 20 %></p> | 20 | +<%= text_field 'enterprise', 'legal_form', 'size' => 20 %></p> |
21 | 21 | ||
22 | <p class='formfield text_field'><label for="economic_activity"><%= _('Economic Activity') %></label><br/> | 22 | <p class='formfield text_field'><label for="economic_activity"><%= _('Economic Activity') %></label><br/> |
23 | -<%= text_field 'organization_info', 'economic_activity', 'size' => 20 %></p> | 23 | +<%= text_field 'enterprise', 'economic_activity', 'size' => 20 %></p> |
24 | 24 | ||
25 | <p class='formfield text_area'><label for="management_information"><%= _('Management Information') %></label><br/> | 25 | <p class='formfield text_area'><label for="management_information"><%= _('Management Information') %></label><br/> |
26 | -<%= text_area 'organization_info', 'management_information', 'cols' => 40, 'rows' => 20 %></p> | 26 | +<%= text_area 'enterprise', 'management_information', 'cols' => 40, 'rows' => 20 %></p> |
27 | 27 | ||
28 | <p class='formfield select'><label for="validation_entity"><%= _('Validation Entity') %></label><br/> | 28 | <p class='formfield select'><label for="validation_entity"><%= _('Validation Entity') %></label><br/> |
29 | <%= select 'validation_entity', 'id', @validation_entities.map{|v| [v.name, v.id]}, :include_blank => true %></p> | 29 | <%= select 'validation_entity', 'id', @validation_entities.map{|v| [v.name, v.id]}, :include_blank => true %></p> |
app/views/enterprise_editor/index.rhtml
@@ -5,12 +5,12 @@ | @@ -5,12 +5,12 @@ | ||
5 | <p> <%= _('Identifier:') %> <%= @enterprise.identifier %> </p> | 5 | <p> <%= _('Identifier:') %> <%= @enterprise.identifier %> </p> |
6 | <p> <%= _('Address:') %> <%= @enterprise.address %> </p> | 6 | <p> <%= _('Address:') %> <%= @enterprise.address %> </p> |
7 | <p> <%= _('Contact phone:') %> <%= @enterprise.contact_phone %> </p> | 7 | <p> <%= _('Contact phone:') %> <%= @enterprise.contact_phone %> </p> |
8 | -<p> <%= _('Contact person:') %> <%= @enterprise.organization_info.contact_person %> </p> | ||
9 | -<p> <%= _('Acronym:') %> <%= @enterprise.organization_info.acronym %> </p> | ||
10 | -<p> <%= _('Foundation year:') %> <%= @enterprise.organization_info.foundation_year %> </p> | ||
11 | -<p> <%= _('Legal Form:') %> <%= @enterprise.organization_info.legal_form %> </p> | ||
12 | -<p> <%= _('Economic activity:') %> <%= @enterprise.organization_info.economic_activity %> </p> | ||
13 | -<p> <%= _('Management infomation:') %> <%= @enterprise.organization_info.management_information %> </p> | 8 | +<p> <%= _('Contact person:') %> <%= @enterprise.contact_person %> </p> |
9 | +<p> <%= _('Acronym:') %> <%= @enterprise.acronym %> </p> | ||
10 | +<p> <%= _('Foundation year:') %> <%= @enterprise.foundation_year %> </p> | ||
11 | +<p> <%= _('Legal Form:') %> <%= @enterprise.legal_form %> </p> | ||
12 | +<p> <%= _('Economic activity:') %> <%= @enterprise.economic_activity %> </p> | ||
13 | +<p> <%= _('Management infomation:') %> <%= @enterprise.management_information %> </p> | ||
14 | 14 | ||
15 | <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> | 15 | <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> |
16 | <%= help _('Change the information about the enterprise') %> | 16 | <%= help _('Change the information about the enterprise') %> |
app/views/profile_editor/index.rhtml
@@ -10,8 +10,6 @@ | @@ -10,8 +10,6 @@ | ||
10 | 10 | ||
11 | <%= file_manager_button(_('Change your picture'), profile_icon(@profile, :portrait), :controller => 'profile_editor', :action => 'change_image') %> | 11 | <%= file_manager_button(_('Change your picture'), profile_icon(@profile, :portrait), :controller => 'profile_editor', :action => 'change_image') %> |
12 | 12 | ||
13 | - <%# file_manager_button(_('Edit Profile'), 'icons-app/edit-profile.png', :controller => 'profile_editor', :action => 'edit') %> | ||
14 | - | ||
15 | <%= file_manager_button(_('Pending tasks'), 'icons-app/todo.png', :controller => 'tasks', :action => 'index') %> | 13 | <%= file_manager_button(_('Pending tasks'), 'icons-app/todo.png', :controller => 'tasks', :action => 'index') %> |
16 | 14 | ||
17 | <%= file_manager_button(_('Edit Visual Design'), 'icons-app/design-editor.png', :controller => 'profile_design', :action => 'index') %> | 15 | <%= file_manager_button(_('Edit Visual Design'), 'icons-app/design-editor.png', :controller => 'profile_design', :action => 'index') %> |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +<h1> <%= _('Edit organization info') %> </h1> | ||
2 | + | ||
3 | +<%= error_messages_for :profile %> | ||
4 | + | ||
5 | +<% labelled_form_for :profile_data, @profile do |f| %> | ||
6 | + <%= f.text_field(:contact_person) %> | ||
7 | + <%= f.text_field(:acronym) %> | ||
8 | + <%= f.text_field(:foundation_year) %> | ||
9 | + <%= f.text_field(:legal_form) %> | ||
10 | + <%= f.text_field(:economic_activity) %> | ||
11 | + <%= f.text_area(:management_information, :rows => 5) %> | ||
12 | + <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %> | ||
13 | + <% button_bar do %> | ||
14 | + <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %> | ||
15 | + <% end %> | ||
16 | +<% end %> |
app/views/profile_editor/organization_info.rhtml
@@ -1,18 +0,0 @@ | @@ -1,18 +0,0 @@ | ||
1 | -<h1> <%= _('Edit organization info') %> </h1> | ||
2 | - | ||
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 %> | ||
15 | - <% button_bar do %> | ||
16 | - <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %> | ||
17 | - <% end %> | ||
18 | -<% end %> |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +<h1><%= _('Edit person info') %></h1> | ||
2 | + | ||
3 | +<%= error_messages_for :profile %> | ||
4 | + | ||
5 | +<% labelled_form_for :profile, @profile do |f| %> | ||
6 | + <%= f.text_field(:name) %> | ||
7 | + <%= _('Sex: ') %> | ||
8 | + <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %> | ||
9 | + <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %> | ||
10 | + <%= f.text_field(:city) %> | ||
11 | + <%= f.text_field(:state) %> | ||
12 | + <%= f.text_field(:country) %> | ||
13 | + <% button_bar do %> | ||
14 | + <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> | ||
15 | + <% end %> | ||
16 | + | ||
17 | +<% end %> | ||
18 | + | ||
19 | +<%# = generate_form :info, @info, {...} %> |
app/views/profile_editor/person_info.rhtml
@@ -1,20 +0,0 @@ | @@ -1,20 +0,0 @@ | ||
1 | -<h1><%= _('Edit person info') %></h1> | ||
2 | - | ||
3 | -<%= error_messages_for :info %> | ||
4 | - | ||
5 | -<% labelled_form_for :info, @info do |f| %> | ||
6 | - | ||
7 | - <%= f.text_field(:name) %> | ||
8 | - <%= _('Sex: ') %> | ||
9 | - <%= display_form_field(_('Male'), radio_button(:info, :sex, 'male')) %> | ||
10 | - <%= display_form_field(_('Female'), radio_button(:info, :sex, 'female')) %> | ||
11 | - <%= f.text_field(:city) %> | ||
12 | - <%= f.text_field(:state) %> | ||
13 | - <%= f.text_field(:country) %> | ||
14 | - <% button_bar do %> | ||
15 | - <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> | ||
16 | - <% end %> | ||
17 | - | ||
18 | -<% end %> | ||
19 | - | ||
20 | -<%# = generate_form :info, @info, {...} %> |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + Person.find(:all).each do |i| | ||
4 | + i.name = i.info.name unless i.info.name.nil? | ||
5 | + i.address = i.info.address unless i.info.address.nil? | ||
6 | + for field in [ :photo, :contact_information, :birth_date, :sex, :city, :state, :country ] do | ||
7 | + i.send("#{field}=", i.info.send(field)) | ||
8 | + end | ||
9 | + i.save! | ||
10 | + end | ||
11 | + drop_table :person_infos | ||
12 | + | ||
13 | + Organization.find(:all).each do |i| | ||
14 | + for field in [ :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated ] do | ||
15 | + i.send("#{field}=", i.info.send(field)) | ||
16 | + end | ||
17 | + i.save! | ||
18 | + end | ||
19 | + drop_table :organization_infos | ||
20 | + end | ||
21 | + | ||
22 | + def self.down | ||
23 | + raise "this migration can't be reverted" | ||
24 | + end | ||
25 | +end |
lib/noosfero/constants.rb
test/fixtures/organization_infos.yml
test/fixtures/person_infos.yml
@@ -1,8 +0,0 @@ | @@ -1,8 +0,0 @@ | ||
1 | -person_info_for_ze: | ||
2 | - id: 1 | ||
3 | - person_id: 4 | ||
4 | - name: "Zé, José, Zezinho" | ||
5 | - address: "house of the hat" | ||
6 | - contact_information: "Pavilhão 9, Quadrante 13, Esquina com Avenida das Alamedas, 467, fundos, falar com Dona Ivete após as 16" | ||
7 | - created_at: '2007-12-01' | ||
8 | - |
test/fixtures/profiles.yml
@@ -26,6 +26,12 @@ ze: | @@ -26,6 +26,12 @@ ze: | ||
26 | user_id: 3 | 26 | user_id: 3 |
27 | identifier: ze | 27 | identifier: ze |
28 | environment_id: 1 | 28 | environment_id: 1 |
29 | + data: { | ||
30 | + :person_id: 4, | ||
31 | + :address: "house of the hat", | ||
32 | + :contact_information: "Pavilhão 9, Quadrante 13, Esquina com Avenida das Alamedas, 467, fundos, falar com Dona Ivete após as 16", | ||
33 | + :created_at: '2007-12-01' | ||
34 | + } | ||
29 | colivre: | 35 | colivre: |
30 | id: 5 | 36 | id: 5 |
31 | name: "cooptec_livre" | 37 | name: "cooptec_livre" |
test/functional/enterprise_editor_controller_test.rb
@@ -76,12 +76,12 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase | @@ -76,12 +76,12 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase | ||
76 | user = create_user_with_permission('test_user', 'edit_profile', ent) | 76 | user = create_user_with_permission('test_user', 'edit_profile', ent) |
77 | login_as :test_user | 77 | login_as :test_user |
78 | 78 | ||
79 | - post 'update', :profile => 'test_enterprise', :organization_info => {:acronym => 'bla'} | 79 | + post 'update', :profile => 'test_enterprise', :enterprise => {:acronym => 'bla'} |
80 | 80 | ||
81 | assert_response :redirect | 81 | assert_response :redirect |
82 | assert_redirected_to :action => 'index' | 82 | assert_redirected_to :action => 'index' |
83 | ent.reload | 83 | ent.reload |
84 | - assert_equal 'bla', ent.organization_info.acronym | 84 | + assert_equal 'bla', ent.acronym |
85 | end | 85 | end |
86 | 86 | ||
87 | should 'destroy' do | 87 | should 'destroy' do |
test/functional/profile_editor_controller_test.rb
@@ -24,10 +24,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -24,10 +24,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
24 | 24 | ||
25 | def test_index | 25 | def test_index |
26 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | 26 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
27 | - person.person_info.name = 'a test profile' | ||
28 | - person.person_info.address = 'my address' | ||
29 | - person.person_info.contact_information = 'my contact information' | ||
30 | - person.person_info.save | 27 | + person.name = 'a test profile' |
28 | + person.address = 'my address' | ||
29 | + person.contact_information = 'my contact information' | ||
30 | + person.save! | ||
31 | 31 | ||
32 | get :index, :profile => person.identifier | 32 | get :index, :profile => person.identifier |
33 | assert_template 'index' | 33 | assert_template 'index' |
@@ -57,18 +57,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -57,18 +57,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
57 | 57 | ||
58 | assert person.valid? | 58 | assert person.valid? |
59 | get :edit, :profile => person.identifier | 59 | get :edit, :profile => person.identifier |
60 | - assert_template 'person_info' | ||
61 | assert_response :success | 60 | assert_response :success |
62 | - assert_template 'person_info' | 61 | + assert_template 'person' |
63 | end | 62 | end |
64 | 63 | ||
65 | def test_saving_profile_info | 64 | def test_saving_profile_info |
66 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | 65 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
67 | - person.person_info.address = 'my address' | ||
68 | - person.person_info.contact_information = 'my contact information' | ||
69 | - person.person_info.save! | 66 | + person.address = 'my address' |
67 | + person.contact_information = 'my contact information' | ||
68 | + person.save! | ||
70 | 69 | ||
71 | - post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } | 70 | + post :edit, :profile => 'test_profile', :profile_data => { 'contact_information' => 'new contact information', 'address' => 'new address' } |
72 | 71 | ||
73 | assert_redirected_to :action => 'index' | 72 | assert_redirected_to :action => 'index' |
74 | end | 73 | end |
@@ -102,56 +101,55 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -102,56 +101,55 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
102 | should 'filter html from name when edit person_info' do | 101 | should 'filter html from name when edit person_info' do |
103 | person = create_user('test_profile').person | 102 | person = create_user('test_profile').person |
104 | name = "name <strong id='name_html_test'>with</strong> html" | 103 | name = "name <strong id='name_html_test'>with</strong> html" |
105 | - post :edit, :profile => person.identifier, :profile_data => { :info => { :name => name } } | ||
106 | - assert_sanitized assigns(:profile).info.name | 104 | + post :edit, :profile => person.identifier, :profile_data => { :name => name } |
105 | + assert_sanitized assigns(:profile).name | ||
107 | end | 106 | end |
108 | 107 | ||
109 | should 'filter html from contact_person to organization' do | 108 | should 'filter html from contact_person to organization' do |
110 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 109 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
111 | contact = "name <strong id='name_html_test'>with</strong> html" | 110 | contact = "name <strong id='name_html_test'>with</strong> html" |
112 | - post :edit, :profile => org.identifier, :profile_data => { :info => { :contact_person => contact } } | ||
113 | - assert_sanitized assigns(:profile).info.contact_person | 111 | + post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact } |
112 | + assert_sanitized assigns(:profile).contact_person | ||
114 | end | 113 | end |
115 | 114 | ||
116 | should 'filter html from acronym organization' do | 115 | should 'filter html from acronym organization' do |
117 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 116 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
118 | value = "name <strong id='name_html_test'>with</strong> html" | 117 | value = "name <strong id='name_html_test'>with</strong> html" |
119 | - post :edit, :profile => org.identifier, :profile_data => { :info => { :acronym => value } } | ||
120 | - assert_sanitized assigns(:profile).info.acronym | 118 | + post :edit, :profile => org.identifier, :profile_data => { :acronym => value } |
119 | + assert_sanitized assigns(:profile).acronym | ||
121 | end | 120 | end |
122 | 121 | ||
123 | should 'filter html from legal_form organization' do | 122 | should 'filter html from legal_form organization' do |
124 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 123 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
125 | value = "name <strong id='name_html_test'>with</strong> html" | 124 | value = "name <strong id='name_html_test'>with</strong> html" |
126 | - post :edit, :profile => org.identifier, :profile_data => { :info => { :legal_form => value } } | ||
127 | - assert_sanitized assigns(:profile).info.legal_form | 125 | + post :edit, :profile => org.identifier, :profile_data => { :legal_form => value } |
126 | + assert_sanitized assigns(:profile).legal_form | ||
128 | end | 127 | end |
129 | 128 | ||
130 | should 'filter html from economic_activity organization' do | 129 | should 'filter html from economic_activity organization' do |
131 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 130 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
132 | value = "name <strong id='name_html_test'>with</strong> html" | 131 | value = "name <strong id='name_html_test'>with</strong> html" |
133 | - post :edit, :profile => org.identifier, :profile_data => { :info => { :economic_activity => value } } | ||
134 | - assert_sanitized assigns(:profile).info.economic_activity | 132 | + post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value } |
133 | + assert_sanitized assigns(:profile).economic_activity | ||
135 | end | 134 | end |
136 | 135 | ||
137 | should 'filter html from management_information organization' do | 136 | should 'filter html from management_information organization' do |
138 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 137 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
139 | value = "name <strong id='name_html_test'>with</strong> html" | 138 | value = "name <strong id='name_html_test'>with</strong> html" |
140 | - post :edit, :profile => org.identifier, :profile_data => { :info => { :management_information => value } } | ||
141 | - assert_sanitized assigns(:profile).info.management_information | 139 | + post :edit, :profile => org.identifier, :profile_data => { :management_information => value } |
140 | + assert_sanitized assigns(:profile).management_information | ||
142 | end | 141 | end |
143 | 142 | ||
144 | should 'saving profile organization_info' do | 143 | should 'saving profile organization_info' do |
145 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 144 | 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 | 145 | + post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' } |
146 | + assert_equal 'contact person', Organization.find(org.id).contact_person | ||
149 | end | 147 | end |
150 | 148 | ||
151 | should 'show contact_person field on edit organization' do | 149 | should 'show contact_person field on edit organization' do |
152 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 150 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
153 | get :edit, :profile => org.identifier | 151 | get :edit, :profile => org.identifier |
154 | - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]' } | 152 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]' } |
155 | end | 153 | end |
156 | 154 | ||
157 | should 'save community description' do | 155 | should 'save community description' do |
@@ -174,22 +172,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -174,22 +172,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
174 | 172 | ||
175 | should 'save organization contact_person' do | 173 | should 'save organization contact_person' do |
176 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 174 | 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 | 175 | + post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } |
176 | + assert_equal 'my contact', Organization.find(org.id).contact_person | ||
179 | end | 177 | end |
180 | 178 | ||
181 | should 'save enterprise contact_person' do | 179 | should 'save enterprise contact_person' do |
182 | org = Enterprise.create!(:name => 'test org', :identifier => 'testorg') | 180 | 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 | 181 | + post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } |
182 | + assert_equal 'my contact', Enterprise.find(org.id).contact_person | ||
185 | end | 183 | end |
186 | 184 | ||
187 | should 'show field values on edit organization info' do | 185 | should 'show field values on edit organization info' do |
188 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 186 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') |
189 | - org.info = { :contact_person => 'my contact' } | ||
190 | - org.info.save! | 187 | + org.contact_person = 'my contact' |
188 | + org.save! | ||
191 | get :edit, :profile => 'testorg' | 189 | get :edit, :profile => 'testorg' |
192 | - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' } | 190 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } |
193 | end | 191 | end |
194 | 192 | ||
195 | should 'display profile publication option in edit profile screen' do | 193 | should 'display profile publication option in edit profile screen' do |
@@ -211,4 +209,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -211,4 +209,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
211 | 209 | ||
212 | should 'show error messages for' | 210 | should 'show error messages for' |
213 | 211 | ||
212 | + should 'edit enterprise' do | ||
213 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent') | ||
214 | + get :edit, :profile => 'testent' | ||
215 | + assert_response :success | ||
216 | + end | ||
217 | + | ||
214 | end | 218 | end |
test/integration/editing_person_info_test.rb
@@ -2,7 +2,7 @@ require "#{File.dirname(__FILE__)}/../test_helper" | @@ -2,7 +2,7 @@ require "#{File.dirname(__FILE__)}/../test_helper" | ||
2 | 2 | ||
3 | class EditingPersonInfoTest < ActionController::IntegrationTest | 3 | class EditingPersonInfoTest < ActionController::IntegrationTest |
4 | 4 | ||
5 | - fixtures :users, :profiles, :domains, :environments, :person_infos | 5 | + fixtures :users, :profiles, :domains, :environments |
6 | 6 | ||
7 | should 'allow to edit person info' do | 7 | should 'allow to edit person info' do |
8 | 8 | ||
@@ -13,14 +13,14 @@ class EditingPersonInfoTest < ActionController::IntegrationTest | @@ -13,14 +13,14 @@ class EditingPersonInfoTest < ActionController::IntegrationTest | ||
13 | get '/myprofile/ze' | 13 | get '/myprofile/ze' |
14 | assert_response :success | 14 | assert_response :success |
15 | 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 | 16 | + assert_tag :tag => 'td', :content => profile.name |
17 | + assert_tag :tag => 'td', :content => profile.address | ||
18 | + assert_tag :tag => 'td', :content => profile.contact_information | ||
19 | 19 | ||
20 | get '/myprofile/ze/profile_editor/edit' | 20 | get '/myprofile/ze/profile_editor/edit' |
21 | assert_response :success | 21 | assert_response :success |
22 | 22 | ||
23 | - post '/myprofile/ze/profile_editor/edit', :info => { :address => 'a new address', :contact_information => 'a new contact information' } | 23 | + post '/myprofile/ze/profile_editor/edit', :profile_data => { :address => 'a new address', :contact_information => 'a new contact information' } |
24 | assert_response :redirect | 24 | assert_response :redirect |
25 | 25 | ||
26 | end | 26 | end |
test/unit/community_test.rb
@@ -39,11 +39,9 @@ class CommunityTest < Test::Unit::TestCase | @@ -39,11 +39,9 @@ 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 | 42 | + should 'have contact_person' do |
43 | + community = Community.new(:name => 'my new community') | ||
44 | + assert_respond_to community, :contact_person | ||
47 | end | 45 | end |
48 | 46 | ||
49 | end | 47 | end |
test/unit/organization_info_test.rb
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
2 | - | ||
3 | -class OrganizationInfoTest < Test::Unit::TestCase | ||
4 | - fixtures :organization_infos | ||
5 | - | ||
6 | - def test_numericality_year | ||
7 | - count = OrganizationInfo.count | ||
8 | - | ||
9 | - oi = OrganizationInfo.new | ||
10 | - oi.foundation_year = 'xxxx' | ||
11 | - oi.valid? | ||
12 | - assert oi.errors.invalid?(:foundation_year) | ||
13 | - | ||
14 | - oi.foundation_year = 20.07 | ||
15 | - oi.valid? | ||
16 | - assert oi.errors.invalid?(:foundation_year) | ||
17 | - | ||
18 | - oi.foundation_year = 2007 | ||
19 | - oi.valid? | ||
20 | - assert ! oi.errors.invalid?(:foundation_year) | ||
21 | - end | ||
22 | -end |
test/unit/organization_test.rb
@@ -25,13 +25,10 @@ class OrganizationTest < Test::Unit::TestCase | @@ -25,13 +25,10 @@ class OrganizationTest < Test::Unit::TestCase | ||
25 | end | 25 | end |
26 | 26 | ||
27 | 27 | ||
28 | - should 'reference organization info' do | 28 | + should 'not reference organization info' do |
29 | org = Organization.new | 29 | org = Organization.new |
30 | - assert_raise ActiveRecord::AssociationTypeMismatch do | ||
31 | - org.organization_info = 1 | ||
32 | - end | ||
33 | - assert_nothing_raised do | ||
34 | - org.organization_info = OrganizationInfo.new | 30 | + assert_raise NoMethodError do |
31 | + org.organization_info | ||
35 | end | 32 | end |
36 | end | 33 | end |
37 | 34 | ||
@@ -75,11 +72,9 @@ class OrganizationTest < Test::Unit::TestCase | @@ -75,11 +72,9 @@ class OrganizationTest < Test::Unit::TestCase | ||
75 | assert_equal 'something', org.validation_restrictions | 72 | assert_equal 'something', org.validation_restrictions |
76 | end | 73 | end |
77 | 74 | ||
78 | - should 'override contact_email to get it from organization_info' do | 75 | + should 'have contact_email' do |
79 | org = Organization.new | 76 | org = Organization.new |
80 | - assert_nil org.contact_email | ||
81 | - org.organization_info = OrganizationInfo.new(:contact_email => 'test@example.com') | ||
82 | - assert_equal 'test@example.com', org.contact_email | 77 | + assert_respond_to org, :contact_email |
83 | end | 78 | end |
84 | 79 | ||
85 | should 'list pending enterprise validations' do | 80 | should 'list pending enterprise validations' do |
@@ -124,11 +119,41 @@ class OrganizationTest < Test::Unit::TestCase | @@ -124,11 +119,41 @@ class OrganizationTest < Test::Unit::TestCase | ||
124 | assert_equal true, Organization.new.has_members? | 119 | assert_equal true, Organization.new.has_members? |
125 | end | 120 | end |
126 | 121 | ||
127 | - should 'update organization_info' do | 122 | + should 'update contact_person' do |
128 | org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 123 | 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 | 124 | + assert_nil org.contact_person |
125 | + org.contact_person = 'person' | ||
126 | + assert_not_nil org.contact_person | ||
127 | + end | ||
128 | + | ||
129 | + should 'numericality year' do | ||
130 | + count = Organization.count | ||
131 | + | ||
132 | + org = Organization.new | ||
133 | + org.foundation_year = 'xxxx' | ||
134 | + org.valid? | ||
135 | + assert org.errors.invalid?(:foundation_year) | ||
136 | + | ||
137 | + org.foundation_year = 20.07 | ||
138 | + org.valid? | ||
139 | + assert org.errors.invalid?(:foundation_year) | ||
140 | + | ||
141 | + org.foundation_year = 2007 | ||
142 | + org.valid? | ||
143 | + assert ! org.errors.invalid?(:foundation_year) | ||
144 | + end | ||
145 | + | ||
146 | + should 'provide needed information in summary' do | ||
147 | + organization = Organization.new | ||
148 | + | ||
149 | + organization.acronym = 'organization acronym' | ||
150 | + organization.foundation_year = '2007' | ||
151 | + organization.contact_email = 'my contact email' | ||
152 | + | ||
153 | + summary = organization.summary | ||
154 | + assert(summary.any? { |line| line[1] == 'organization acronym' }) | ||
155 | + assert(summary.any? { |line| line[1] == '2007' }) | ||
156 | + assert(summary.any? { |line| line[1] == 'my contact email' }) | ||
132 | end | 157 | end |
133 | 158 | ||
134 | end | 159 | end |
test/unit/person_info_test.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
2 | - | ||
3 | -class PersonInfoTest < Test::Unit::TestCase | ||
4 | - | ||
5 | - should 'provide desired fields' do | ||
6 | - info = PersonInfo.new | ||
7 | - | ||
8 | - assert info.respond_to?(:photo) | ||
9 | - assert info.respond_to?(:address) | ||
10 | - assert info.respond_to?(:contact_information) | ||
11 | - end | ||
12 | - | ||
13 | - should 'provide needed information in summary' do | ||
14 | - person_info = PersonInfo.new | ||
15 | - | ||
16 | - person_info.name = 'person name' | ||
17 | - person_info.address = 'my address' | ||
18 | - person_info.contact_information = 'my contact information' | ||
19 | - | ||
20 | - summary = person_info.summary | ||
21 | - assert(summary.any? { |line| line[1] == 'person name' }) | ||
22 | - assert(summary.any? { |line| line[1] == 'my address' }) | ||
23 | - assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'") | ||
24 | - end | ||
25 | - | ||
26 | -end |
test/unit/person_test.rb
@@ -43,8 +43,8 @@ class PersonTest < Test::Unit::TestCase | @@ -43,8 +43,8 @@ class PersonTest < Test::Unit::TestCase | ||
43 | 43 | ||
44 | assert p.community_memberships.include?(c), "Community should add a new member" | 44 | assert p.community_memberships.include?(c), "Community should add a new member" |
45 | end | 45 | end |
46 | - | ||
47 | - def test_can_have_user | 46 | + |
47 | + should 'can have user' do | ||
48 | u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') | 48 | u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') |
49 | p = Person.new(:name => 'John', :identifier => 'john') | 49 | p = Person.new(:name => 'John', :identifier => 'john') |
50 | u.person = p | 50 | u.person = p |
@@ -53,7 +53,7 @@ class PersonTest < Test::Unit::TestCase | @@ -53,7 +53,7 @@ class PersonTest < Test::Unit::TestCase | ||
53 | assert_equal 'John', u.person.name | 53 | assert_equal 'John', u.person.name |
54 | end | 54 | end |
55 | 55 | ||
56 | - def test_only_one_person_per_user | 56 | + should 'only one person per user' do |
57 | u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') | 57 | u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') |
58 | assert u.save | 58 | assert u.save |
59 | 59 | ||
@@ -66,14 +66,18 @@ class PersonTest < Test::Unit::TestCase | @@ -66,14 +66,18 @@ class PersonTest < Test::Unit::TestCase | ||
66 | assert p2.errors.invalid?(:user_id) | 66 | assert p2.errors.invalid?(:user_id) |
67 | end | 67 | end |
68 | 68 | ||
69 | - should "have person info" do | 69 | + should "have person info fields" do |
70 | p = Person.new | 70 | p = Person.new |
71 | - assert_kind_of PersonInfo, p.person_info | 71 | + [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country ].each do |i| |
72 | + assert_respond_to p, i | ||
73 | + end | ||
72 | end | 74 | end |
73 | 75 | ||
74 | - should 'return person_info as info' do | 76 | + should 'not have person_info class' do |
75 | p = Person.new | 77 | p = Person.new |
76 | - assert_equal p.person_info, p.info | 78 | + assert_raise NoMethodError do |
79 | + p.person_info | ||
80 | + end | ||
77 | end | 81 | end |
78 | 82 | ||
79 | should 'change the roles of the user' do | 83 | should 'change the roles of the user' do |
@@ -204,14 +208,14 @@ class PersonTest < Test::Unit::TestCase | @@ -204,14 +208,14 @@ class PersonTest < Test::Unit::TestCase | ||
204 | 208 | ||
205 | should 'return info name instead of name when info is setted' do | 209 | should 'return info name instead of name when info is setted' do |
206 | p = create_user('ze_maria').person | 210 | p = create_user('ze_maria').person |
207 | - p.person_info = PersonInfo.create!(:name => 'José') | ||
208 | - | 211 | + assert_equal 'ze_maria', p.name |
212 | + p.name = 'José' | ||
209 | assert_equal 'José', p.name | 213 | assert_equal 'José', p.name |
210 | end | 214 | end |
211 | 215 | ||
212 | should 'fallback to login when person_info is not present' do | 216 | should 'fallback to login when person_info is not present' do |
213 | p = create_user('randomhacker').person | 217 | p = create_user('randomhacker').person |
214 | - p.person_info = nil | 218 | + p.name = nil |
215 | assert_equal 'randomhacker', p.name | 219 | assert_equal 'randomhacker', p.name |
216 | end | 220 | end |
217 | 221 | ||
@@ -224,11 +228,31 @@ class PersonTest < Test::Unit::TestCase | @@ -224,11 +228,31 @@ class PersonTest < Test::Unit::TestCase | ||
224 | assert_includes Person.find(p.id).favorite_enterprises, e | 228 | assert_includes Person.find(p.id).favorite_enterprises, e |
225 | end | 229 | end |
226 | 230 | ||
227 | - should 'save info' do | 231 | + should 'save info contact_information field' do |
228 | person = create_user('new_person').person | 232 | person = create_user('new_person').person |
229 | - person.info = {:contact_information => 'my contact'} | 233 | + person.contact_information = 'my contact' |
230 | person.save! | 234 | person.save! |
231 | - assert_equal 'my contact', person.info.contact_information | 235 | + assert_equal 'my contact', person.contact_information |
236 | + end | ||
237 | + | ||
238 | + should 'provide desired info fields' do | ||
239 | + p = Person.new | ||
240 | + assert p.respond_to?(:photo) | ||
241 | + assert p.respond_to?(:address) | ||
242 | + assert p.respond_to?(:contact_information) | ||
243 | + end | ||
244 | + | ||
245 | + should 'provide needed information in summary' do | ||
246 | + person = Person.new | ||
247 | + | ||
248 | + person.name = 'person name' | ||
249 | + person.address = 'my address' | ||
250 | + person.contact_information = 'my contact information' | ||
251 | + | ||
252 | + summary = person.summary | ||
253 | + assert(summary.any? { |line| line[1] == 'person name' }) | ||
254 | + assert(summary.any? { |line| line[1] == 'my address' }) | ||
255 | + assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'") | ||
232 | end | 256 | end |
233 | 257 | ||
234 | end | 258 | end |
test/unit/profile_helper_test.rb
@@ -9,16 +9,7 @@ class ProfileHelperTest < Test::Unit::TestCase | @@ -9,16 +9,7 @@ class ProfileHelperTest < Test::Unit::TestCase | ||
9 | end | 9 | end |
10 | attr_reader :profile, :helper | 10 | attr_reader :profile, :helper |
11 | 11 | ||
12 | - def test_should_ignore_nil | ||
13 | - profile.expects(:info).returns(nil) | ||
14 | - | ||
15 | - helper.expects(:content_tag) | ||
16 | - helper.expects(:_) | ||
17 | - | ||
18 | - helper.display_profile_info(profile) | ||
19 | - end | ||
20 | - | ||
21 | - def test_should_display_info | 12 | + should 'display info' do |
22 | f1 = 'Field 1' | 13 | f1 = 'Field 1' |
23 | v1 = 'value 1' | 14 | v1 = 'value 1' |
24 | f2 = 'Field 2' | 15 | f2 = 'Field 2' |
@@ -27,24 +18,19 @@ class ProfileHelperTest < Test::Unit::TestCase | @@ -27,24 +18,19 @@ class ProfileHelperTest < Test::Unit::TestCase | ||
27 | [ f1, v1 ], | 18 | [ f1, v1 ], |
28 | [ f2, v2 ] | 19 | [ f2, v2 ] |
29 | ] | 20 | ] |
30 | - info = mock | ||
31 | - info.expects(:summary).returns(array) | ||
32 | - profile.stubs(:info).returns(info) | 21 | + profile.expects(:summary).returns(array) |
33 | 22 | ||
34 | helper.expects(:content_tag).returns('').at_least_once | 23 | helper.expects(:content_tag).returns('').at_least_once |
35 | 24 | ||
36 | helper.expects(:_).with('edit your information').returns('edit your information') | 25 | helper.expects(:_).with('edit your information').returns('edit your information') |
37 | helper.expects(:button).with(:edit, 'edit your information', :controller => 'profile_editor', :action => 'edit').returns("BUTTON") | 26 | helper.expects(:button).with(:edit, 'edit your information', :controller => 'profile_editor', :action => 'edit').returns("BUTTON") |
38 | 27 | ||
39 | - | ||
40 | helper.display_profile_info(profile) | 28 | helper.display_profile_info(profile) |
41 | end | 29 | end |
42 | 30 | ||
43 | - def test_should_call_blocks | 31 | + should 'call blocks' do |
44 | myproc = lambda { content_tag('div', 'lalala') } | 32 | myproc = lambda { content_tag('div', 'lalala') } |
45 | - info = mock | ||
46 | - info.expects(:summary).returns([['f1', myproc ]]) | ||
47 | - profile.stubs(:info).returns(info) | 33 | + profile.expects(:summary).returns([['f1', myproc ]]) |
48 | helper.stubs(:content_tag).returns('') | 34 | helper.stubs(:content_tag).returns('') |
49 | 35 | ||
50 | helper.expects(:instance_eval).with(myproc) | 36 | helper.expects(:instance_eval).with(myproc) |
test/unit/profile_test.rb
@@ -114,10 +114,6 @@ class ProfileTest < Test::Unit::TestCase | @@ -114,10 +114,6 @@ class ProfileTest < Test::Unit::TestCase | ||
114 | assert_equal total - mine, Article.count | 114 | assert_equal total - mine, Article.count |
115 | end | 115 | end |
116 | 116 | ||
117 | - def test_should_define_info | ||
118 | - assert_nil Profile.new.info | ||
119 | - end | ||
120 | - | ||
121 | def test_should_avoid_reserved_identifiers | 117 | def test_should_avoid_reserved_identifiers |
122 | assert_invalid_identifier 'admin' | 118 | assert_invalid_identifier 'admin' |
123 | assert_invalid_identifier 'system' | 119 | assert_invalid_identifier 'system' |