From ec0761a4546cf4ebf56538d75d3fc67d6f65930f Mon Sep 17 00:00:00 2001
From: JoenioCosta
Date: Fri, 16 May 2008 14:23:25 +0000
Subject: [PATCH] ActionItem380: moving all fields from PersonInfo and OrganizationInfo to profile using settings_items
---
app/controllers/my_profile/enterprise_editor_controller.rb | 2 +-
app/controllers/my_profile/profile_editor_controller.rb | 5 ++---
app/helpers/profile_helper.rb | 45 ++++++++++++++++++++-------------------------
app/models/create_enterprise.rb | 4 ++--
app/models/organization.rb | 27 ++++++++++++++-------------
app/models/organization_info.rb | 16 ----------------
app/models/person.rb | 27 +++++++++++++--------------
app/models/profile.rb | 29 ++---------------------------
app/views/account/user_info.rhtml | 2 +-
app/views/enterprise_editor/_form.rhtml | 12 ++++++------
app/views/enterprise_editor/index.rhtml | 12 ++++++------
app/views/profile_editor/index.rhtml | 2 --
app/views/profile_editor/organization.rhtml | 16 ++++++++++++++++
app/views/profile_editor/organization_info.rhtml | 18 ------------------
app/views/profile_editor/person.rhtml | 19 +++++++++++++++++++
app/views/profile_editor/person_info.rhtml | 20 --------------------
db/migrate/033_destroy_organization_and_person_infos.rb | 25 +++++++++++++++++++++++++
lib/noosfero/constants.rb | 1 +
test/fixtures/organization_infos.yml | 6 ------
test/fixtures/person_infos.yml | 8 --------
test/fixtures/profiles.yml | 6 ++++++
test/functional/enterprise_editor_controller_test.rb | 4 ++--
test/functional/profile_editor_controller_test.rb | 70 +++++++++++++++++++++++++++++++++++++---------------------------------
test/integration/editing_person_info_test.rb | 10 +++++-----
test/unit/community_test.rb | 8 +++-----
test/unit/organization_info_test.rb | 22 ----------------------
test/unit/organization_test.rb | 53 +++++++++++++++++++++++++++++++++++++++--------------
test/unit/person_info_test.rb | 26 --------------------------
test/unit/person_test.rb | 50 +++++++++++++++++++++++++++++++++++++-------------
test/unit/profile_helper_test.rb | 22 ++++------------------
test/unit/profile_test.rb | 4 ----
31 files changed, 261 insertions(+), 310 deletions(-)
delete mode 100644 app/models/organization_info.rb
create mode 100644 app/views/profile_editor/organization.rhtml
delete mode 100644 app/views/profile_editor/organization_info.rhtml
create mode 100644 app/views/profile_editor/person.rhtml
delete mode 100644 app/views/profile_editor/person_info.rhtml
create mode 100644 db/migrate/033_destroy_organization_and_person_infos.rb
delete mode 100644 test/fixtures/organization_infos.yml
delete mode 100644 test/fixtures/person_infos.yml
delete mode 100644 test/unit/organization_info_test.rb
delete mode 100644 test/unit/person_info_test.rb
diff --git a/app/controllers/my_profile/enterprise_editor_controller.rb b/app/controllers/my_profile/enterprise_editor_controller.rb
index 1bcbf23..acf1e65 100644
--- a/app/controllers/my_profile/enterprise_editor_controller.rb
+++ b/app/controllers/my_profile/enterprise_editor_controller.rb
@@ -16,7 +16,7 @@ class EnterpriseEditorController < MyProfileController
# Saves the changes made in an enterprise
def update
- if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info])
+ if @enterprise.update_attributes(params[:enterprise])
redirect_to :action => 'index'
else
flash[:notice] = _('Could not update the enterprise')
diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index 122344c..3965dcf 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -11,12 +11,11 @@ class ProfileEditorController < MyProfileController
# edits the profile info (posts back)
def edit
if request.post?
- if profile.update_attributes(params[:profile_data]) and profile.info.save
+ if profile.update_attributes(params[:profile_data])
redirect_to :action => 'index'
end
else
- @info = profile.info
- render :action => @info.class.name.underscore
+ render :action => profile.class.name.underscore
end
end
diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb
index e1fc993..c2df978 100644
--- a/app/helpers/profile_helper.rb
+++ b/app/helpers/profile_helper.rb
@@ -1,33 +1,28 @@
module ProfileHelper
def display_profile_info(profile)
- info = profile.info
- if info.nil?
- content_tag('div', _('This profile does not have any public information'))
- else
- table_rows = content_tag( 'tr',
- content_tag( 'th',
- "\n" +
- button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) +
- "\n",
- :colspan => 2, :class => 'header' )
- ) + "\n"
- info.summary.each do |item|
- name = item[0]
- value = item[1]
- if value.is_a?(Proc)
- value = self.instance_eval(value)
- end
- table_rows << content_tag('tr', content_tag('th', name) + content_tag('td', value))
- table_rows << "\n"
+ table_rows = content_tag( 'tr',
+ content_tag( 'th',
+ "\n" +
+ button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) +
+ "\n",
+ :colspan => 2, :class => 'header' )
+ ) + "\n"
+ profile.summary.each do |item|
+ name = item[0]
+ value = item[1]
+ if value.is_a?(Proc)
+ value = self.instance_eval(value)
end
-
- content_tag(
- 'table',
- table_rows,
- :class => 'profile_info'
- )
+ table_rows << content_tag('tr', content_tag('th', _(name)) + content_tag('td', value))
+ table_rows << "\n"
end
+
+ content_tag(
+ 'table',
+ table_rows,
+ :class => 'profile_info'
+ )
end
end
diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb
index 3d606dc..4c0b7e8 100644
--- a/app/models/create_enterprise.rb
+++ b/app/models/create_enterprise.rb
@@ -112,13 +112,13 @@ class CreateEnterprise < Task
enterprise.send("#{field}=", self.send(field))
end
- organization_info_data = self.data.reject do |key,value|
+ organization_data = self.data.reject do |key,value|
profile_fields.include?(key.to_s)
end
enterprise.user = self.requestor.user
- enterprise.organization_info = OrganizationInfo.new(organization_info_data)
+ enterprise.update_attributes(organization_data)
enterprise.save!
end
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 9fa9878..6573cac 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -1,22 +1,12 @@
-# Represents any organization of the system and has an organization_info object to hold its info
+# Represents any organization of the system
class Organization < Profile
- has_one :organization_info
-
belongs_to :region
has_one :validation_info
has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id
- after_create do |org|
- OrganizationInfo.create!(:organization_id => org.id)
- end
-
- def contact_email
- self.organization_info ? self.organization_info.contact_email : nil
- end
-
def validation_methodology
self.validation_info ? self.validation_info.validation_methodology : nil
end
@@ -45,8 +35,19 @@ class Organization < Profile
!self.validation_info.nil?
end
- def info
- organization_info
+ settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated
+
+ validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT, :if => (lambda { |org| ! org.foundation_year.nil? })
+
+ validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| ! org.contact_email.nil? })
+
+ xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ]
+
+ def summary
+ # FIXME diplays too few fields
+ ['acronym', 'foundation_year', 'contact_email'].map do |col|
+ [ col.humanize, self.send(col) ]
+ end
end
# Yes, organizations have members.
diff --git a/app/models/organization_info.rb b/app/models/organization_info.rb
deleted file mode 100644
index c44750f..0000000
--- a/app/models/organization_info.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-class OrganizationInfo < ActiveRecord::Base
- belongs_to :organization
-
- validates_numericality_of :foundation_year, :only_integer => true, :allow_nil => true
-
- validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |info| ! info.contact_email.nil? })
-
- xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ]
-
- def summary
- # FIXME diplays too few fields
- [ 'acronym', 'foundation_year', 'contact_email'].map do |col|
- [ OrganizationInfo.columns_hash[col].human_name, self.send(col) ]
- end
- end
-end
diff --git a/app/models/person.rb b/app/models/person.rb
index d51c1cf..5afac75 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -21,8 +21,14 @@ class Person < Profile
def remove_friend(friend)
friends.delete(friend)
end
-
- has_one :person_info
+
+ settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country
+
+ def summary
+ ['name', 'contact_information', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col|
+ [ col.humanize, self.send(col) ]
+ end
+ end
def self.conditions_for_profiles(conditions, person)
new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person])
@@ -50,20 +56,9 @@ class Person < Profile
alias :communities :community_memberships
-
- def info
- person_info
- end
-
validates_presence_of :user_id
validates_uniqueness_of :user_id
- def initialize(*args)
- super(*args)
- self.person_info ||= PersonInfo.new
- self.person_info.person = self
- end
-
def email
self.user.nil? ? nil : self.user.email
end
@@ -105,7 +100,11 @@ class Person < Profile
hacked_after_create :insert_default_homepage_and_feed
def name
- person_info.nil? ? self[:name] : (person_info.name || self[:name])
+ if !self[:name].nil?
+ self[:name]
+ else
+ self.user ? self.user.login : nil
+ end
end
has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people'
diff --git a/app/models/profile.rb b/app/models/profile.rb
index aa4228e..9186e45 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -96,7 +96,7 @@ class Profile < ActiveRecord::Base
end
validates_presence_of :identifier, :name
- validates_format_of :identifier, :with => IDENTIFIER_FORMAT, :message => "Identifier %s is invalid"
+ validates_format_of :identifier, :with => IDENTIFIER_FORMAT
validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS
validates_uniqueness_of :identifier
@@ -121,32 +121,7 @@ class Profile < ActiveRecord::Base
true
end
- xss_terminate :only => [ :address, :contact_phone ]
-
- # Returns information about the profile's owner that was made public by
- # him/her.
- #
- # The returned value must be an object that responds to a method "summary",
- # which must return an array in the following format:
- #
- # [
- # [ 'First Field', first_field_value ],
- # [ 'Second Field', second_field_value ],
- # ]
- #
- # This information shall be used by user interface to present the
- # information.
- #
- # In this class, this method returns nil, what is interpreted as "no
- # information at all". Subclasses must override this method to provide their
- # specific information.
- def info
- nil
- end
-
- def info=(args = {})
- self.info.attributes = args if self.info
- end
+ xss_terminate :only => [ :name, :address, :contact_phone ]
# returns the contact email for this profile. By default returns the the
# e-mail of the owner user.
diff --git a/app/views/account/user_info.rhtml b/app/views/account/user_info.rhtml
index c7aef94..cf12b13 100644
--- a/app/views/account/user_info.rhtml
+++ b/app/views/account/user_info.rhtml
@@ -3,7 +3,7 @@
<%= _('Logged in as %s') % user.identifier %>
- - <%= _('User since %{year}/%{month}') % { :year => user.person_info.created_at.year, :month => user.person_info.created_at.month } %>
+ - <%= _('User since %{year}/%{month}') % { :year => user.created_at.year, :month => user.created_at.month } %>
- <%= link_to_homepage _('Homepage') %>
diff --git a/app/views/enterprise_editor/_form.rhtml b/app/views/enterprise_editor/_form.rhtml
index f2435b6..5fc5889 100644
--- a/app/views/enterprise_editor/_form.rhtml
+++ b/app/views/enterprise_editor/_form.rhtml
@@ -8,22 +8,22 @@
<%= text_field 'enterprise', 'contact_phone', 'size' => 20 %>
-<%= text_field 'organization_info', 'contact_person', 'size' => 20 %>
+<%= text_field 'enterprise', 'contact_person', 'size' => 20 %>
-<%= text_field 'organization_info', 'acronym', 'size' => 20 %>
+<%= text_field 'enterprise', 'acronym', 'size' => 20 %>
-<%= text_field 'organization_info', 'foundation_year', 'size' => 20 %>
+<%= text_field 'enterprise', 'foundation_year', 'size' => 20 %>
-<%= text_field 'organization_info', 'legal_form', 'size' => 20 %>
+<%= text_field 'enterprise', 'legal_form', 'size' => 20 %>
-<%= text_field 'organization_info', 'economic_activity', 'size' => 20 %>
+<%= text_field 'enterprise', 'economic_activity', 'size' => 20 %>
-<%= text_area 'organization_info', 'management_information', 'cols' => 40, 'rows' => 20 %>
+<%= text_area 'enterprise', 'management_information', 'cols' => 40, 'rows' => 20 %>
<%= select 'validation_entity', 'id', @validation_entities.map{|v| [v.name, v.id]}, :include_blank => true %>
diff --git a/app/views/enterprise_editor/index.rhtml b/app/views/enterprise_editor/index.rhtml
index 233fde9..f98034c 100644
--- a/app/views/enterprise_editor/index.rhtml
+++ b/app/views/enterprise_editor/index.rhtml
@@ -5,12 +5,12 @@
<%= _('Identifier:') %> <%= @enterprise.identifier %>
<%= _('Address:') %> <%= @enterprise.address %>
<%= _('Contact phone:') %> <%= @enterprise.contact_phone %>
- <%= _('Contact person:') %> <%= @enterprise.organization_info.contact_person %>
- <%= _('Acronym:') %> <%= @enterprise.organization_info.acronym %>
- <%= _('Foundation year:') %> <%= @enterprise.organization_info.foundation_year %>
- <%= _('Legal Form:') %> <%= @enterprise.organization_info.legal_form %>
- <%= _('Economic activity:') %> <%= @enterprise.organization_info.economic_activity %>
- <%= _('Management infomation:') %> <%= @enterprise.organization_info.management_information %>
+ <%= _('Contact person:') %> <%= @enterprise.contact_person %>
+ <%= _('Acronym:') %> <%= @enterprise.acronym %>
+ <%= _('Foundation year:') %> <%= @enterprise.foundation_year %>
+ <%= _('Legal Form:') %> <%= @enterprise.legal_form %>
+ <%= _('Economic activity:') %> <%= @enterprise.economic_activity %>
+ <%= _('Management infomation:') %> <%= @enterprise.management_information %>
<%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %>
<%= help _('Change the information about the enterprise') %>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 197ecf7..d887639 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -10,8 +10,6 @@
<%= file_manager_button(_('Change your picture'), profile_icon(@profile, :portrait), :controller => 'profile_editor', :action => 'change_image') %>
- <%# file_manager_button(_('Edit Profile'), 'icons-app/edit-profile.png', :controller => 'profile_editor', :action => 'edit') %>
-
<%= file_manager_button(_('Pending tasks'), 'icons-app/todo.png', :controller => 'tasks', :action => 'index') %>
<%= file_manager_button(_('Edit Visual Design'), 'icons-app/design-editor.png', :controller => 'profile_design', :action => 'index') %>
diff --git a/app/views/profile_editor/organization.rhtml b/app/views/profile_editor/organization.rhtml
new file mode 100644
index 0000000..1d6633b
--- /dev/null
+++ b/app/views/profile_editor/organization.rhtml
@@ -0,0 +1,16 @@
+ <%= _('Edit organization info') %>
+
+<%= error_messages_for :profile %>
+
+<% labelled_form_for :profile_data, @profile 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, :rows => 5) %>
+ <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %>
+ <% button_bar do %>
+ <%= submit_button('save' , _('Save'), :cancel => {:action => 'index'}) %>
+ <% end %>
+<% end %>
diff --git a/app/views/profile_editor/organization_info.rhtml b/app/views/profile_editor/organization_info.rhtml
deleted file mode 100644
index e6901a6..0000000
--- a/app/views/profile_editor/organization_info.rhtml
+++ /dev/null
@@ -1,18 +0,0 @@
- <%= _('Edit organization info') %>
-
-<%= 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 %>
-<% end %>
diff --git a/app/views/profile_editor/person.rhtml b/app/views/profile_editor/person.rhtml
new file mode 100644
index 0000000..e9361ff
--- /dev/null
+++ b/app/views/profile_editor/person.rhtml
@@ -0,0 +1,19 @@
+<%= _('Edit person info') %>
+
+<%= error_messages_for :profile %>
+
+<% labelled_form_for :profile, @profile do |f| %>
+ <%= f.text_field(:name) %>
+ <%= _('Sex: ') %>
+ <%= display_form_field(_('Male'), radio_button(:profile, :sex, 'male')) %>
+ <%= display_form_field(_('Female'), radio_button(:profile, :sex, 'female')) %>
+ <%= f.text_field(:city) %>
+ <%= f.text_field(:state) %>
+ <%= f.text_field(:country) %>
+ <% button_bar do %>
+ <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %>
+ <% end %>
+
+<% end %>
+
+<%# = generate_form :info, @info, {...} %>
diff --git a/app/views/profile_editor/person_info.rhtml b/app/views/profile_editor/person_info.rhtml
deleted file mode 100644
index e10cb4c..0000000
--- a/app/views/profile_editor/person_info.rhtml
+++ /dev/null
@@ -1,20 +0,0 @@
-<%= _('Edit person info') %>
-
-<%= error_messages_for :info %>
-
-<% labelled_form_for :info, @info do |f| %>
-
- <%= f.text_field(:name) %>
- <%= _('Sex: ') %>
- <%= display_form_field(_('Male'), radio_button(:info, :sex, 'male')) %>
- <%= display_form_field(_('Female'), radio_button(:info, :sex, 'female')) %>
- <%= f.text_field(:city) %>
- <%= f.text_field(:state) %>
- <%= f.text_field(:country) %>
- <% button_bar do %>
- <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %>
- <% end %>
-
-<% end %>
-
-<%# = generate_form :info, @info, {...} %>
diff --git a/db/migrate/033_destroy_organization_and_person_infos.rb b/db/migrate/033_destroy_organization_and_person_infos.rb
new file mode 100644
index 0000000..3738475
--- /dev/null
+++ b/db/migrate/033_destroy_organization_and_person_infos.rb
@@ -0,0 +1,25 @@
+class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration
+ def self.up
+ Person.find(:all).each do |i|
+ i.name = i.info.name unless i.info.name.nil?
+ i.address = i.info.address unless i.info.address.nil?
+ for field in [ :photo, :contact_information, :birth_date, :sex, :city, :state, :country ] do
+ i.send("#{field}=", i.info.send(field))
+ end
+ i.save!
+ end
+ drop_table :person_infos
+
+ Organization.find(:all).each do |i|
+ for field in [ :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated ] do
+ i.send("#{field}=", i.info.send(field))
+ end
+ i.save!
+ end
+ drop_table :organization_infos
+ end
+
+ def self.down
+ raise "this migration can't be reverted"
+ end
+end
diff --git a/lib/noosfero/constants.rb b/lib/noosfero/constants.rb
index 4c0fe80..036492a 100644
--- a/lib/noosfero/constants.rb
+++ b/lib/noosfero/constants.rb
@@ -1,3 +1,4 @@
module Noosfero::Constants
EMAIL_FORMAT = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
+ INTEGER_FORMAT = /\A\d+\Z/i
end
diff --git a/test/fixtures/organization_infos.yml b/test/fixtures/organization_infos.yml
deleted file mode 100644
index a0604ed..0000000
--- a/test/fixtures/organization_infos.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
- organization_id: 5
-two:
- id: 2
diff --git a/test/fixtures/person_infos.yml b/test/fixtures/person_infos.yml
deleted file mode 100644
index 8ed3f60..0000000
--- a/test/fixtures/person_infos.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-person_info_for_ze:
- id: 1
- person_id: 4
- name: "Zé, José, Zezinho"
- address: "house of the hat"
- contact_information: "Pavilhão 9, Quadrante 13, Esquina com Avenida das Alamedas, 467, fundos, falar com Dona Ivete após as 16"
- created_at: '2007-12-01'
-
diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml
index 8cbd8b6..4bc6e24 100644
--- a/test/fixtures/profiles.yml
+++ b/test/fixtures/profiles.yml
@@ -26,6 +26,12 @@ ze:
user_id: 3
identifier: ze
environment_id: 1
+ data: {
+ :person_id: 4,
+ :address: "house of the hat",
+ :contact_information: "Pavilhão 9, Quadrante 13, Esquina com Avenida das Alamedas, 467, fundos, falar com Dona Ivete após as 16",
+ :created_at: '2007-12-01'
+ }
colivre:
id: 5
name: "cooptec_livre"
diff --git a/test/functional/enterprise_editor_controller_test.rb b/test/functional/enterprise_editor_controller_test.rb
index d2c30b6..7bceee6 100644
--- a/test/functional/enterprise_editor_controller_test.rb
+++ b/test/functional/enterprise_editor_controller_test.rb
@@ -76,12 +76,12 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase
user = create_user_with_permission('test_user', 'edit_profile', ent)
login_as :test_user
- post 'update', :profile => 'test_enterprise', :organization_info => {:acronym => 'bla'}
+ post 'update', :profile => 'test_enterprise', :enterprise => {:acronym => 'bla'}
assert_response :redirect
assert_redirected_to :action => 'index'
ent.reload
- assert_equal 'bla', ent.organization_info.acronym
+ assert_equal 'bla', ent.acronym
end
should 'destroy' do
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 2bae683..d74880d 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -24,10 +24,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
def test_index
person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
- person.person_info.name = 'a test profile'
- person.person_info.address = 'my address'
- person.person_info.contact_information = 'my contact information'
- person.person_info.save
+ person.name = 'a test profile'
+ person.address = 'my address'
+ person.contact_information = 'my contact information'
+ person.save!
get :index, :profile => person.identifier
assert_template 'index'
@@ -57,18 +57,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
assert person.valid?
get :edit, :profile => person.identifier
- assert_template 'person_info'
assert_response :success
- assert_template 'person_info'
+ assert_template 'person'
end
def test_saving_profile_info
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.address = 'my address'
+ person.contact_information = 'my contact information'
+ person.save!
- post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' }
+ post :edit, :profile => 'test_profile', :profile_data => { 'contact_information' => 'new contact information', 'address' => 'new address' }
assert_redirected_to :action => 'index'
end
@@ -102,56 +101,55 @@ 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, :profile_data => { :info => { :name => name } }
- assert_sanitized assigns(:profile).info.name
+ post :edit, :profile => person.identifier, :profile_data => { :name => name }
+ assert_sanitized assigns(:profile).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, :profile_data => { :info => { :contact_person => contact } }
- assert_sanitized assigns(:profile).info.contact_person
+ post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact }
+ assert_sanitized assigns(:profile).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, :profile_data => { :info => { :acronym => value } }
- assert_sanitized assigns(:profile).info.acronym
+ post :edit, :profile => org.identifier, :profile_data => { :acronym => value }
+ assert_sanitized assigns(:profile).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, :profile_data => { :info => { :legal_form => value } }
- assert_sanitized assigns(:profile).info.legal_form
+ post :edit, :profile => org.identifier, :profile_data => { :legal_form => value }
+ assert_sanitized assigns(:profile).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, :profile_data => { :info => { :economic_activity => value } }
- assert_sanitized assigns(:profile).info.economic_activity
+ post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value }
+ assert_sanitized assigns(:profile).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, :profile_data => { :info => { :management_information => value } }
- assert_sanitized assigns(:profile).info.management_information
+ post :edit, :profile => org.identifier, :profile_data => { :management_information => value }
+ assert_sanitized assigns(:profile).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
+ post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' }
+ assert_equal 'contact person', Organization.find(org.id).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]' }
+ assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]' }
end
should 'save community description' do
@@ -174,22 +172,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
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
+ post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' }
+ assert_equal 'my contact', Organization.find(org.id).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
+ post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' }
+ assert_equal 'my contact', Enterprise.find(org.id).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!
+ org.contact_person = 'my contact'
+ org.save!
get :edit, :profile => 'testorg'
- assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' }
+ assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' }
end
should 'display profile publication option in edit profile screen' do
@@ -211,4 +209,10 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
should 'show error messages for'
+ should 'edit enterprise' do
+ ent = Enterprise.create!(:name => 'test org', :identifier => 'testent')
+ get :edit, :profile => 'testent'
+ assert_response :success
+ end
+
end
diff --git a/test/integration/editing_person_info_test.rb b/test/integration/editing_person_info_test.rb
index c2f2c4e..96fba9e 100644
--- a/test/integration/editing_person_info_test.rb
+++ b/test/integration/editing_person_info_test.rb
@@ -2,7 +2,7 @@ require "#{File.dirname(__FILE__)}/../test_helper"
class EditingPersonInfoTest < ActionController::IntegrationTest
- fixtures :users, :profiles, :domains, :environments, :person_infos
+ fixtures :users, :profiles, :domains, :environments
should 'allow to edit person info' do
@@ -13,14 +13,14 @@ class EditingPersonInfoTest < ActionController::IntegrationTest
get '/myprofile/ze'
assert_response :success
- assert_tag :tag => 'td', :content => profile.person_info.name
- assert_tag :tag => 'td', :content => profile.person_info.address
- assert_tag :tag => 'td', :content => profile.person_info.contact_information
+ assert_tag :tag => 'td', :content => profile.name
+ assert_tag :tag => 'td', :content => profile.address
+ assert_tag :tag => 'td', :content => profile.contact_information
get '/myprofile/ze/profile_editor/edit'
assert_response :success
- post '/myprofile/ze/profile_editor/edit', :info => { :address => 'a new address', :contact_information => 'a new contact information' }
+ post '/myprofile/ze/profile_editor/edit', :profile_data => { :address => 'a new address', :contact_information => 'a new contact information' }
assert_response :redirect
end
diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb
index d678187..5a9e2cc 100644
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -39,11 +39,9 @@ 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
+ should 'have contact_person' do
+ community = Community.new(:name => 'my new community')
+ assert_respond_to community, :contact_person
end
end
diff --git a/test/unit/organization_info_test.rb b/test/unit/organization_info_test.rb
deleted file mode 100644
index b4f4734..0000000
--- a/test/unit/organization_info_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class OrganizationInfoTest < Test::Unit::TestCase
- fixtures :organization_infos
-
- def test_numericality_year
- count = OrganizationInfo.count
-
- oi = OrganizationInfo.new
- oi.foundation_year = 'xxxx'
- oi.valid?
- assert oi.errors.invalid?(:foundation_year)
-
- oi.foundation_year = 20.07
- oi.valid?
- assert oi.errors.invalid?(:foundation_year)
-
- oi.foundation_year = 2007
- oi.valid?
- assert ! oi.errors.invalid?(:foundation_year)
- end
-end
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index 4ad5295..b96fc68 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -25,13 +25,10 @@ class OrganizationTest < Test::Unit::TestCase
end
- should 'reference organization info' do
+ should 'not reference organization info' do
org = Organization.new
- assert_raise ActiveRecord::AssociationTypeMismatch do
- org.organization_info = 1
- end
- assert_nothing_raised do
- org.organization_info = OrganizationInfo.new
+ assert_raise NoMethodError do
+ org.organization_info
end
end
@@ -75,11 +72,9 @@ class OrganizationTest < Test::Unit::TestCase
assert_equal 'something', org.validation_restrictions
end
- should 'override contact_email to get it from organization_info' do
+ should 'have contact_email' do
org = Organization.new
- assert_nil org.contact_email
- org.organization_info = OrganizationInfo.new(:contact_email => 'test@example.com')
- assert_equal 'test@example.com', org.contact_email
+ assert_respond_to org, :contact_email
end
should 'list pending enterprise validations' do
@@ -124,11 +119,41 @@ class OrganizationTest < Test::Unit::TestCase
assert_equal true, Organization.new.has_members?
end
- should 'update organization_info' do
+ should 'update contact_person' 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
+ assert_nil org.contact_person
+ org.contact_person = 'person'
+ assert_not_nil org.contact_person
+ end
+
+ should 'numericality year' do
+ count = Organization.count
+
+ org = Organization.new
+ org.foundation_year = 'xxxx'
+ org.valid?
+ assert org.errors.invalid?(:foundation_year)
+
+ org.foundation_year = 20.07
+ org.valid?
+ assert org.errors.invalid?(:foundation_year)
+
+ org.foundation_year = 2007
+ org.valid?
+ assert ! org.errors.invalid?(:foundation_year)
+ end
+
+ should 'provide needed information in summary' do
+ organization = Organization.new
+
+ organization.acronym = 'organization acronym'
+ organization.foundation_year = '2007'
+ organization.contact_email = 'my contact email'
+
+ summary = organization.summary
+ assert(summary.any? { |line| line[1] == 'organization acronym' })
+ assert(summary.any? { |line| line[1] == '2007' })
+ assert(summary.any? { |line| line[1] == 'my contact email' })
end
end
diff --git a/test/unit/person_info_test.rb b/test/unit/person_info_test.rb
deleted file mode 100644
index 7a67d7e..0000000
--- a/test/unit/person_info_test.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class PersonInfoTest < Test::Unit::TestCase
-
- should 'provide desired fields' do
- info = PersonInfo.new
-
- assert info.respond_to?(:photo)
- assert info.respond_to?(:address)
- assert info.respond_to?(:contact_information)
- end
-
- should 'provide needed information in summary' do
- person_info = PersonInfo.new
-
- person_info.name = 'person name'
- person_info.address = 'my address'
- person_info.contact_information = 'my contact information'
-
- summary = person_info.summary
- assert(summary.any? { |line| line[1] == 'person name' })
- assert(summary.any? { |line| line[1] == 'my address' })
- assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'")
- end
-
-end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index 72cb732..4787628 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -43,8 +43,8 @@ class PersonTest < Test::Unit::TestCase
assert p.community_memberships.include?(c), "Community should add a new member"
end
-
- def test_can_have_user
+
+ should 'can have user' do
u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
p = Person.new(:name => 'John', :identifier => 'john')
u.person = p
@@ -53,7 +53,7 @@ class PersonTest < Test::Unit::TestCase
assert_equal 'John', u.person.name
end
- def test_only_one_person_per_user
+ should 'only one person per user' do
u = User.new(:login => 'john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe')
assert u.save
@@ -66,14 +66,18 @@ class PersonTest < Test::Unit::TestCase
assert p2.errors.invalid?(:user_id)
end
- should "have person info" do
+ should "have person info fields" do
p = Person.new
- assert_kind_of PersonInfo, p.person_info
+ [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country ].each do |i|
+ assert_respond_to p, i
+ end
end
- should 'return person_info as info' do
+ should 'not have person_info class' do
p = Person.new
- assert_equal p.person_info, p.info
+ assert_raise NoMethodError do
+ p.person_info
+ end
end
should 'change the roles of the user' do
@@ -204,14 +208,14 @@ class PersonTest < Test::Unit::TestCase
should 'return info name instead of name when info is setted' do
p = create_user('ze_maria').person
- p.person_info = PersonInfo.create!(:name => 'José')
-
+ assert_equal 'ze_maria', p.name
+ p.name = 'José'
assert_equal 'José', p.name
end
should 'fallback to login when person_info is not present' do
p = create_user('randomhacker').person
- p.person_info = nil
+ p.name = nil
assert_equal 'randomhacker', p.name
end
@@ -224,11 +228,31 @@ class PersonTest < Test::Unit::TestCase
assert_includes Person.find(p.id).favorite_enterprises, e
end
- should 'save info' do
+ should 'save info contact_information field' do
person = create_user('new_person').person
- person.info = {:contact_information => 'my contact'}
+ person.contact_information = 'my contact'
person.save!
- assert_equal 'my contact', person.info.contact_information
+ assert_equal 'my contact', person.contact_information
+ end
+
+ should 'provide desired info fields' do
+ p = Person.new
+ assert p.respond_to?(:photo)
+ assert p.respond_to?(:address)
+ assert p.respond_to?(:contact_information)
+ end
+
+ should 'provide needed information in summary' do
+ person = Person.new
+
+ person.name = 'person name'
+ person.address = 'my address'
+ person.contact_information = 'my contact information'
+
+ summary = person.summary
+ assert(summary.any? { |line| line[1] == 'person name' })
+ assert(summary.any? { |line| line[1] == 'my address' })
+ assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'")
end
end
diff --git a/test/unit/profile_helper_test.rb b/test/unit/profile_helper_test.rb
index 7e658a1..9797e47 100644
--- a/test/unit/profile_helper_test.rb
+++ b/test/unit/profile_helper_test.rb
@@ -9,16 +9,7 @@ class ProfileHelperTest < Test::Unit::TestCase
end
attr_reader :profile, :helper
- def test_should_ignore_nil
- profile.expects(:info).returns(nil)
-
- helper.expects(:content_tag)
- helper.expects(:_)
-
- helper.display_profile_info(profile)
- end
-
- def test_should_display_info
+ should 'display info' do
f1 = 'Field 1'
v1 = 'value 1'
f2 = 'Field 2'
@@ -27,24 +18,19 @@ class ProfileHelperTest < Test::Unit::TestCase
[ f1, v1 ],
[ f2, v2 ]
]
- info = mock
- info.expects(:summary).returns(array)
- profile.stubs(:info).returns(info)
+ profile.expects(:summary).returns(array)
helper.expects(:content_tag).returns('').at_least_once
helper.expects(:_).with('edit your information').returns('edit your information')
helper.expects(:button).with(:edit, 'edit your information', :controller => 'profile_editor', :action => 'edit').returns("BUTTON")
-
helper.display_profile_info(profile)
end
- def test_should_call_blocks
+ should 'call blocks' do
myproc = lambda { content_tag('div', 'lalala') }
- info = mock
- info.expects(:summary).returns([['f1', myproc ]])
- profile.stubs(:info).returns(info)
+ profile.expects(:summary).returns([['f1', myproc ]])
helper.stubs(:content_tag).returns('')
helper.expects(:instance_eval).with(myproc)
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 9ee0c8d..29c3897 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -114,10 +114,6 @@ class ProfileTest < Test::Unit::TestCase
assert_equal total - mine, Article.count
end
- def test_should_define_info
- assert_nil Profile.new.info
- end
-
def test_should_avoid_reserved_identifiers
assert_invalid_identifier 'admin'
assert_invalid_identifier 'system'
--
libgit2 0.21.2