From 0ba97d3054159c5a4d734ee9715f383d5d63703d Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 12 Dec 2008 20:20:53 -0300 Subject: [PATCH] ActionItem833: port unifreire-specific changes as configuration into master branch --- app/controllers/admin/features_controller.rb | 36 ++++++++++++++++++++++++++++++++++++ app/controllers/public/account_controller.rb | 6 +++++- app/helpers/application_helper.rb | 40 ++++++++++++++++++++++++++++------------ app/helpers/categories_helper.rb | 3 ++- app/helpers/profile_editor_helper.rb | 362 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/community.rb | 27 +++++++++++++++++++++++++++ app/models/enterprise.rb | 34 ++++++++++++++++++++++++++++++++++ app/models/environment.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/organization.rb | 23 +++++++++++++++++++++++ app/models/person.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/user.rb | 7 +++++++ app/views/account/_signup_form.rhtml | 26 +++++++++++++++----------- app/views/admin_panel/index.rhtml | 2 ++ app/views/categories/_form.rhtml | 8 ++++++-- app/views/features/_manage_community_fields.rhtml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ app/views/features/_manage_enterprise_fields.rhtml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ app/views/features/_manage_person_fields.rhtml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ app/views/features/manage_fields.rhtml | 5 +++++ app/views/profile_editor/_community_fields.rhtml | 2 ++ app/views/profile_editor/_enterprise_fields.rhtml | 11 +++++++++++ app/views/profile_editor/_organization.rhtml | 15 ++++++++++----- app/views/profile_editor/_person.rhtml | 5 ++++- app/views/profile_editor/_person_form.rhtml | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- app/views/profile_editor/edit.rhtml | 4 ++-- public/stylesheets/person_data.css | 10 ++++++++++ test/functional/account_controller_test.rb | 6 ++++++ test/functional/categories_controller_test.rb | 37 +++++++++++++++++++++++++++++++++++++ test/functional/features_controller_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/functional/profile_editor_controller_test.rb | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- test/unit/application_helper_test.rb | 32 ++++++++++++++++++++++++++++++++ test/unit/categories_helper_test.rb | 33 +++++++++++++++++++++++++++++++++ test/unit/community_test.rb | 46 +++++++++++++++++++++++++++++++++++++--------- test/unit/enterprise_test.rb | 33 +++++++++++++++++++++++++++++++-- test/unit/environment_test.rb | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/friendship_test.rb | 4 ++-- test/unit/person_test.rb | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 36 files changed, 1538 insertions(+), 107 deletions(-) create mode 100644 app/helpers/profile_editor_helper.rb create mode 100644 app/views/features/_manage_community_fields.rhtml create mode 100644 app/views/features/_manage_enterprise_fields.rhtml create mode 100644 app/views/features/_manage_person_fields.rhtml create mode 100644 app/views/features/manage_fields.rhtml create mode 100644 app/views/profile_editor/_community_fields.rhtml create mode 100644 app/views/profile_editor/_enterprise_fields.rhtml create mode 100644 public/stylesheets/person_data.css create mode 100644 test/unit/categories_helper_test.rb diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb index 54cb27d..8135b70 100644 --- a/app/controllers/admin/features_controller.rb +++ b/app/controllers/admin/features_controller.rb @@ -15,4 +15,40 @@ class FeaturesController < AdminController end end + def manage_fields + @person_fields = Person.fields + @enterprise_fields = Enterprise.fields + @community_fields = Community.fields + end + + def manage_person_fields + environment.custom_person_fields = params[:person_fields] + if environment.save! + flash[:notice] = _('Custom person fields updated successfully.') + else + flash[:error] = _('Custom person fields not updated successfully.') + end + redirect_to :action => 'manage_fields' + end + + def manage_enterprise_fields + environment.custom_enterprise_fields = params[:enterprise_fields] + if environment.save! + flash[:notice] = _('Custom enterprise fields updated successfully.') + else + flash[:error] = _('Custom enterprise fields not updated successfully.') + end + redirect_to :action => 'manage_fields' + end + + def manage_community_fields + environment.custom_community_fields = params[:community_fields] + if environment.save! + flash[:notice] = _('Custom community fields updated successfully.') + else + flash[:error] = _('Custom community fields not updated successfully.') + end + redirect_to :action => 'manage_fields' + end + end diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 627f96b..5dd5c37 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -14,6 +14,7 @@ class AccountController < ApplicationController # action to perform login to the application def login @user = User.new + @person = @user.build_person return unless request.post? self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] if logged_in? @@ -46,8 +47,10 @@ class AccountController < ApplicationController @user.terms_of_use = environment.terms_of_use @user.environment = environment @terms_of_use = environment.terms_of_use + @person = @user.build_person(params[:profile_data]) + @person.environment = @user.environment if request.post? && params[self.icaptcha_field].blank? - @user.save! + @user.signup! self.current_user = @user owner_role = Role.find_by_name('owner') @user.person.affiliate(@user.person, [owner_role]) if owner_role @@ -55,6 +58,7 @@ class AccountController < ApplicationController flash[:notice] = _("Thanks for signing up!") end rescue ActiveRecord::RecordInvalid + @person.valid? render :action => 'signup' end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 849e79e..22b5dc7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,7 +19,9 @@ module ApplicationHelper include DatesHelper include FolderHelper - + + include ProfileEditorHelper + # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this # method. *Note*: the block is ignored if content is not @@ -289,7 +291,6 @@ module ApplicationHelper @controller.send(:user) end - def stylesheet_import(*sources) options = sources.last.is_a?(Hash) ? sources.pop : { } themed_source = options.delete(:themed_source) @@ -378,16 +379,14 @@ module ApplicationHelper end def profile_sex_icon( profile ) - if profile.class == Person - sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) - title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) - sex = content_tag 'span', - content_tag( 'span', sex ), - :class => 'sex-'+sex, - :title => title - else - sex = '' - end + return '' unless profile.is_a?(Person) + return '' unless !environment.enabled?('disable_gender_icon') + sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) + title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) + sex = content_tag 'span', + content_tag( 'span', sex ), + :class => 'sex-'+sex, + :title => title sex end @@ -692,6 +691,23 @@ module ApplicationHelper form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) end + def custom_field(profile, name, field_html, options = {}) + result = "" + if (controller.action_name == 'signup') + if profile.signup_fields.include?(name) + result = field_html + end + else + if profile.active_fields.include?(name) + result = field_html + end + end + if profile.required_fields.include?(name) + result = required(result) + end + result + end + def search_page_title(title, options={}) title = "

" + title + "

" title += "

" + _("Searched for '%s'") % options[:query] + "

" if !options[:query].blank? diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 78ad950..d2a2972 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -35,7 +35,8 @@ module CategoriesHelper def select_category_type(field) value = params[field] - labelled_form_field(_('Type of category'), select_tag('type', options_for_select(CategoriesHelper::TYPES, value))) + types = TYPES.select { |title,typename| environment.category_types.include?(typename) } + labelled_form_field(_('Type of category'), select_tag('type', options_for_select(types, value))) end end diff --git a/app/helpers/profile_editor_helper.rb b/app/helpers/profile_editor_helper.rb new file mode 100644 index 0000000..77628d9 --- /dev/null +++ b/app/helpers/profile_editor_helper.rb @@ -0,0 +1,362 @@ +module ProfileEditorHelper + + include GetText + + AREAS_OF_STUDY = [ + N_('Agrometeorology'), + N_('Agronomy'), + N_('Foods'), + N_('Anthropology'), + N_('Architecture'), + N_('Arts'), + N_('Astronomy'), + N_('Librarianship'), + N_('Biosciences'), + N_('Biophysics'), + N_('Biology'), + N_('Biotechnology'), + N_('Botany'), + N_('Science Politics'), + N_('Accounting and Actuarial Science'), + N_('Morphologic Sciences'), + N_('Computation'), + N_('Rural Development'), + N_('Law'), + N_('Ecology'), + N_('Economy'), + N_('Education'), + N_('Long-distance Education'), + N_('Physical Education'), + N_('Professional Education'), + N_('Nursing'), + N_('Engineerings'), + N_('Basic and Average education'), + N_('Statistics'), + N_('Stratigraphy'), + N_('Pharmacy'), + N_('Pharmacology'), + N_('Philosophy'), + N_('Physics'), + N_('Plant Protection'), + N_('Genetics'), + N_('Geosciences'), + N_('Geography'), + N_('Geology'), + N_('Hydrology'), + N_('Hydromechanics'), + N_('History'), + N_('Horticulture'), + N_('Informatics'), + N_('Interdisciplinary'), + N_('Journalism'), + N_('Letters'), + N_('Languages'), + N_('Mathematics'), + N_('Medicines'), + N_('Medicine'), + N_('Metallurgy'), + N_('Microbiology'), + N_('Mineralogy'), + N_('Music'), + N_('Nutrition'), + N_('Odontology'), + N_('Paleontology'), + N_('Petrology'), + N_('Production'), + N_('Psychology'), + N_('Psychiatry'), + N_('Quality'), + N_('Chemistry'), + N_('Health'), + N_('Remote Sensing'), + N_('Forestry'), + N_('Sociology'), + N_('Ground'), + N_('Theater'), + N_('Transport'), + N_('Urbanism'), + N_('Veterinary Medicine'), + N_('Zoology'), + N_('Zootecnia'), + N_('Others') + ] + + COUNTRIES = [ + ("Afeganistão (افغانستان)"), + ("África do Sul (South Africa)"), + ("Albânia (Shqipëria)"), + ("Alemanha (Deutschland)"), + ("Andorra"), + ("Angola"), + ("Anguila (Anguilla)"), + ("Antártica (Antarctica)"), + ("Antígua e Barbuda (Antigua and Barbuda)"), + ("Antilhas Holandesas (Netherlands Antilles)"), + ("Arábia Saudita (العربية السعودية)"), + ("Argélia (الجمهورية الجزائرية)"), + ("Argentina"), + ("Armênia (Հայաստան)"), + ("Aruba"), + ("Austrália (Australia)"), + ("Áustria (Österreich)"), + ("Azerbaijão (Azərbaycan)"), + ("Bahamas"), + ("Bangladesh (বাংলাদেশ)"), + ("Barbados"), + ("Barein (بحرين)"), + ("Bélgica (België)"), + ("Belize"), + ("Benin (Bénin)"), + ("Bermudas (Bermuda)"), + ("Bielo-Rússia (Белару́сь)"), + ("Bolívia (Bolivia)"), + ("Bósnia-Herzegovina (Bosna i Hercegovina)"), + ("Botsuana (Botswana)"), + ("Brasil"), + ("Brunei (Brunei Darussalam)"), + ("Bulgária (България)"), + ("Burkina Fasso (Burkina Faso)"), + ("Burundi (Uburundi)"), + ("Butão (འབྲུག་ཡུལ)"), + ("Cabo Verde"), + ("Camarões (Cameroun)"), + ("Camboja (Kampuchea)"), + ("Canadá (Canada)"), + ("Catar (قطر)"), + ("Cazaquistão (Қазақстан)"), + ("Chade (Tchad)"), + ("Chile"), + ("China (中国)"), + ("Chipre (Κυπρος)"), + ("Cidade do Vaticano (Città del Vaticano)"), + ("Cingapura (Singapura)"), + ("Colômbia (Colombia)"), + ("Comores"), + ("Congo"), + ("Congo, República democrática do (Congo, Democratic Republic of the)"), + ("Coréia do Norte (조선)"), + ("Coréia do Sul (한국)"), + ("Costa do Marfim (Côte d'Ivoire)"), + ("Costa Rica"), + ("Croácia (Hrvatska)"), + ("Cuba"), + ("Dinamarca (Danmark)"), + ("Djibuti (Djibouti)"), + ("Dominica"), + ("Egito (مصر)"), + ("El Salvador"), + ("Emirados Árabes Unidos (الإمارات العربيّة المتّحد)"), + ("Equador (Ecuador)"), + ("Eritréia (Ertra)"), + ("Eslováquia (Slovensko)"), + ("Eslovênia (Slovenija)"), + ("Espanha (España)"), + ("Estados Unidos (United States)"), + ("Estônia (Eesti)"), + ("Etiópia (Ityop'iya)"), + ("Fiji"), + ("Filipinas (Pilipinas)"), + ("Finlândia (Suomi)"), + ("França (France)"), + ("Gabão (Gabon)"), + ("Gâmbia (Gambia)"), + ("Gana (Ghana)"), + ("Geórgia (საქართველო)"), + ("Geórgia do Sul e Ilhas Sandwich do Sul (South Georgia and the South Sandwich Islands)"), + ("Gibraltar"), + ("Granada (Grenada)"), + ("Grécia (Eλλας)"), + ("Groenlândia (Greenland)"), + ("Guadalupe (Guadeloupe)"), + ("Guam"), + ("Guatemala"), + ("Guernsey"), + ("Guiana (Guyana)"), + ("Guiana Francesa (French Guiana)"), + ("Guiné (Guinée)"), + ("Guiné-Bissau"), + ("Guiné Equatorial (Guinea Ecuatorial)"), + ("Haiti (Haïti)"), + ("Holanda (Nederland)"), + ("Honduras"), + ("Hong Kong"), + ("Hungria (Magyarország)"), + ("Iêmen (اليمن)"), + ("Ilha Aland (Aland Islands)"), + ("Ilha Bouvet (Bouvet Island)"), + ("Ilha Christmas (Christmas Island)"), + ("Ilha de Man (Isle of Man)"), + ("Ilha Norfolk (Norfolk Island)"), + ("Ilhas Cayman (Cayman Islands)"), + ("Ilhas Cocos (Keeling) (Cocos Islands)"), + ("Ilhas Cook (Cook Islands)"), + ("Ilhas Falkland (Malvinas) (Falkland Islands)"), + ("Ilhas Faroé (Faroe Islands)"), + ("Ilhas Heard e McDonald (Heard Island and McDonald Islands)"), + ("Ilhas Marianas do Norte (Northern Mariana Islands)"), + ("Ilhas Marshall (Marshall Islands)"), + ("Ilhas Maurício (Mauritius)"), + ("Ilhas Reunião (Reunion)"), + ("Ilhas Salomão (Solomon Islands)"), + ("Ilhas Svalbard e Jan Mayen (Svalbard and Jan Mayen)"), + ("Ilhas Tokelau (Tokelau)"), + ("Ilhas Turks e Caicos (Turks and Caicos Islands)"), + ("Ilhas Virgens, Britânicas (Virgin Islands, British)"), + ("Ilhas Virgens, EUA (Virgin Islands, U.S.)"), + ("Ilhas Wallis e Futuna (Wallis and Futuna)"), + ("Índia (India)"), + ("Indonésia (Indonesia)"), + ("Irã (ایران)"), + ("Iraque (العراق)"), + ("Irlanda (Ireland)"), + ("Islândia (Ísland)"), + ("Israel (ישראל)"), + ("Itália (Italia)"), + ("Jamaica"), + ("Japão (日本)"), + ("Jordânia (الارد)"), + ("Kiribati"), + ("Kuwait (الكويت)"), + ("Laos (ນລາວ)"), + ("Lesoto (Lesotho)"), + ("Letônia (Latvija)"), + ("Líbano (لبنان)"), + ("Libéria (Liberia)"), + ("Líbia (ليبية)"), + ("Liechtenstein"), + ("Lituânia (Lietuva)"), + ("Luxemburgo (Lëtzebuerg)"), + ("Macau (Macao)"), + ("Macedônia (Македонија)"), + ("Madagáscar (Madagasikara)"), + ("Maiote (Mayotte)"), + ("Malásia (Malaysia)"), + ("Malavi (Malawi)"), + ("Maldivas (ގުޖޭއްރާ ޔާއްރިހޫމްޖ)"), + ("Mali"), + ("Malta"), + ("Marrocos (مغرب)"), + ("Martinica (Martinique)"), + ("Mauritânia (موريتانية)"), + ("México"), + ("Micronésia (Micronesia)"), + ("Moçambique"), + ("Moldávia (Moldova)"), + ("Mônaco (Monaco)"), + ("Mongólia (Монгол Улс)"), + ("Montserrat"), + ("Myanmar (Լեռնային Ղարաբաղ)"), + ("Namíbia (Namibia)"), + ("Nauru (Naoero)"), + ("Nepal (नेपाल)"), + ("Nicarágua (Nicaragua)"), + ("Níger (Niger)"), + ("Nigéria (Nigeria)"), + ("Niue"), + ("Noruega (Norge)"), + ("Nova Caledônia (New Caledonia)"), + ("Nova Jérsei (Jersey)"), + ("Nova Zelândia (New Zealand)"), + ("Omã (عمان)"), + ("Palau (Belau)"), + ("Palestina (Palestine)"), + ("Panamá"), + ("Papua-Nova Guiné (Papua New Guinea)"), + ("Paquistão (پاکستان)"), + ("Paraguai (Paraguay)"), + ("Peru (Perú)"), + ("Pitcairn"), + ("Polinésia Francesa (French Polynesia)"), + ("Polônia (Polska)"), + ("Porto Rico (Puerto Rico)"), + ("Portugal"), + ("Quênia (Kenya)"), + ("Quirquistão (Кыргызстан)"), + ("Reino Unido (United Kingdom)"), + ("República Centro-Africana (République Centrafricaine)"), + ("República Dominicana (Dominican Republic)"), + ("República Tcheca (Česko)"), + ("Romênia (România)"), + ("Ruanda (Rwanda)"), + ("Rússia (Россия)"), + ("Saara Ocidental (صحراوية)"), + ("Samoa"), + ("Samoa Americana (American Samoa)"), + ("San Marino"), + ("Santa Helena (Saint Helena)"), + ("Santa Lúcia (Saint Lucia)"), + ("São Cristóvão e Névis (Saint Kitts and Nevis)"), + ("São Pierre e Miquelon (Saint Pierre and Miquelon)"), + ("São Tomé e Príncipe (São Tomé and Príncipe)"), + ("São Vincente e Granadinas (Saint Vincent and the Grenadines)"), + ("Seicheles (Seychelles)"), + ("Senegal (Sénégal)"), + ("Serra Leoa (Sierra Leone)"), + ("Sérvia e Montenegro (Србија и Црна Гора)"), + ("Síria (سورية)"), + ("Somália (Soomaaliya)"), + ("Sri Lanka"), + ("Suazilândia (Swaziland)"), + ("Sudão (السودان)"), + ("Suécia (Sverige)"), + ("Suíça (Schweiz)"), + ("Suriname"), + ("Tailândia (ราชอาณาจักรไทย)"), + ("Taiwan (台灣)"), + ("Tajiquistão (Тоҷикистон)"), + ("Tanzânia (Tanzania)"), + ("Território Britânico do Oceano Índico (British Indian Ocean Territory)"), + ("Territórios Franceses do Sul (French Southern Territories)"), + ("Territórios Insulares dos Estados Unidos (United States minor outlying islands)"), + ("Timor Leste (Timor-Leste)"), + ("Togo"), + ("Tonga"), + ("Trinidad e Tobago (Trinidad and Tobago)"), + ("Tunísia (تونس)"), + ("Turcomenistão (Türkmenistan)"), + ("Turquia (Türkiye)"), + ("Tuvalu"), + ("Ucrânia (Україна)"), + ("Uganda"), + ("Uruguai (Uruguay)"), + ("Uzbequistão (O'zbekiston)"), + ("Vanuatu"), + ("Venezuela"), + ("Vietnã (Việt Nam)"), + ("Zâmbia (Zambia)"), + ("Zimbábue (Zimbabwe)") + ] + + SCHOOLING = [ + N_('Post-Doctoral'), + N_('Ph.D.'), + N_('Masters'), + N_('Undergraduate'), + N_('Graduate'), + N_('High School'), + N_('Elementary School') + ] + + SCHOOLING_STATUS = [ + N_('Concluded'), + N_('Incomplete'), + N_('Ongoing') + ] + + def select_area(title, object, method, options) + labelled_form_field(title, select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::AREAS_OF_STUDY.map{|s| [gettext(s), s]}, {}, options)) + end + + def select_country(title, object, method, options) + labelled_form_field(title, select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::COUNTRIES.map{|s| [s]}, {}, options)) + end + + def select_schooling(object, method, options) + select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::SCHOOLING.map{|s| [gettext(s), s]}, {}, options) + end + + def select_schooling_status(object, method, options) + select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::SCHOOLING_STATUS.map{|s| [gettext(s), s]}, {}, options) + end + +end diff --git a/app/models/community.rb b/app/models/community.rb index c6d099c..77510d9 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -1,10 +1,37 @@ class Community < Organization N_('Community') + N_('Language') settings_items :description + settings_items :language xss_terminate :only => [ :name, :address, :contact_phone, :description ] + FIELDS = %w[ + description + language + ] + + def self.fields + super + FIELDS + end + + def validate + self.required_fields.each do |field| + if self.send(field).blank? + self.errors.add(field, _('%{fn} is mandatory')) + end + end + end + + def active_fields + environment ? environment.active_community_fields : [] + end + + def required_fields + environment ? environment.required_community_fields : [] + end + def name=(value) super(value) self.identifier = value.to_slug diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 9418ce0..af5fed7 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -8,6 +8,40 @@ class Enterprise < Organization extra_data_for_index :product_categories + N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') + + settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country + + FIELDS = %w[ + zip_code + city + state + country + organization_website + historic_and_current_context + activities_short_description + ] + + def self.fields + super + FIELDS + end + + def validate + self.required_fields.each do |field| + if self.send(field).blank? + self.errors.add(field, _('%{fn} is mandatory')) + end + end + end + + def active_fields + environment ? environment.active_enterprise_fields : [] + end + + def required_fields + environment ? environment.required_enterprise_fields : [] + end + def product_categories products.map{|p| p.category_full_name}.compact end diff --git a/app/models/environment.rb b/app/models/environment.rb index 9c24f25..13acfde 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -32,6 +32,8 @@ class Environment < ActiveRecord::Base 'disable_categories' => _('Disable categories'), 'disable_cms' => _('Disable CMS'), 'disable_header_and_footer' => _('Disable header/footer editing by users'), + 'disable_gender_icon' => _('Disable gender icon'), + 'disable_categories_menu' => _('Disable the categories menu'), } end @@ -231,6 +233,109 @@ class Environment < ActiveRecord::Base end end + def custom_person_fields + self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields] + end + + def custom_person_fields=(values) + if values['schooling'] && values['schooling']['active'] == 'true' + schooling_status = values['schooling'] + end + self.settings[:custom_person_fields] = values.delete_if { |key, value| ! Person.fields.include?(key)} + if schooling_status + self.settings[:custom_person_fields]['schooling_status'] = schooling_status + end + end + + def custom_person_field(field, status) + if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') + return true + end + false + end + + def active_person_fields + (custom_person_fields.delete_if { |key, value| !custom_person_field(key, 'active')}).keys || [] + end + + def required_person_fields + required_fields = [] + active_person_fields.each do |field| + required_fields << field if custom_person_fields[field]['required'] == 'true' + end + required_fields + end + + def signup_person_fields + signup_fields = [] + active_person_fields.each do |field| + signup_fields << field if custom_person_fields[field]['signup'] == 'true' + end + signup_fields + end + + def custom_enterprise_fields + self.settings[:custom_enterprise_fields].nil? ? {} : self.settings[:custom_enterprise_fields] + end + + def custom_enterprise_fields=(values) + self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| ! Enterprise.fields.include?(key)} + end + + def custom_enterprise_field(field, status) + if (custom_enterprise_fields[field] && custom_enterprise_fields[field][status] == 'true') + return true + end + false + end + + def active_enterprise_fields + (custom_enterprise_fields.delete_if { |key, value| !custom_enterprise_field(key, 'active')}).keys || [] + end + + def required_enterprise_fields + required_fields = [] + active_enterprise_fields.each do |field| + required_fields << field if custom_enterprise_fields[field]['required'] == 'true' + end + required_fields + end + + def custom_community_fields + self.settings[:custom_community_fields].nil? ? {} : self.settings[:custom_community_fields] + end + + def custom_community_fields=(values) + self.settings[:custom_community_fields] = values.delete_if { |key, value| ! Community.fields.include?(key)} + end + + def custom_community_field(field, status) + if (custom_community_fields[field] && custom_community_fields[field][status] == 'true') + return true + end + false + end + + def active_community_fields + (custom_community_fields.delete_if { |key, value| !custom_community_field(key, 'active')}).keys + end + + def required_community_fields + required_fields = [] + active_community_fields.each do |field| + required_fields << field if custom_community_fields[field]['required'] == 'true' + end + required_fields + end + + def category_types + self.settings[:category_types].nil? ? ['Category'] : self.settings[:category_types] + end + + def category_types=(values) + self.settings[:category_types] = values + end + # Whether this environment should force having 'www.' in its domain name or # not. Defauls to false. # diff --git a/app/models/organization.rb b/app/models/organization.rb index e3cf621..ee0a22a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -43,6 +43,29 @@ class Organization < Profile !self.validation_info.nil? end + FIELDS = %w[ + nickname + contact_person + contact_phone + contact_email + legal_form + economic_activity + management_information + address + ] + + def self.fields + FIELDS + end + + def required_fields + [] + end + + def active_fields + [] + end + N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Validated') settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj diff --git a/app/models/person.rb b/app/models/person.rb index bd039b3..ae9b2be 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -41,6 +41,70 @@ class Person < Profile friends.delete(friend) end + FIELDS = %w[ + nickname + sex + address + zip_code + city + state + country + nationality + birth_date + cell_phone + comercial_phone + schooling + professional_activity + organization + organization_website + area_of_study + custom_area_of_study + formation + custom_formation + contact_phone + contact_information + ] + + def self.fields + FIELDS + end + + def validate + self.required_fields.each do |field| + if self.send(field).blank? + unless (field == 'custom_area_of_study' && self.area_of_study != 'Others') || (field == 'custom_formation' && self.formation != 'Others') + self.errors.add(field, _('%{fn} is mandatory')) + end + end + end + end + + before_save do |person| + person.custom_formation = nil if (! person.formation.nil? && person.formation != 'Others') + person.custom_area_of_study = nil if (! person.area_of_study.nil? && person.area_of_study != 'Others') + end + + def active_fields + environment ? environment.active_person_fields : [] + end + + def required_fields + environment ? environment.required_person_fields : [] + end + + def signup_fields + environment ? environment.signup_person_fields : [] + end + + N_('Cell phone'); N_('Comercial phone'); N_('Nationality'); N_('Schooling'); N_('Area of study'); N_('Professional activity'); N_('Organization'); N_('Organization website'); + settings_items :cell_phone, :comercial_phone, :nationality, :schooling, :area_of_study, :professional_activity, :organization, :organization_website + + N_('Schooling status') + settings_items :schooling_status + + N_('Formation'); N_('Custom formation'); N_('Custom area of study'); + settings_items :formation, :custom_formation, :custom_area_of_study + N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code') settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country, :zip_code diff --git a/app/models/user.rb b/app/models/user.rb index 473cb87..05381cb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -28,6 +28,13 @@ class User < ActiveRecord::Base user.person.name ||= user.login user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) end + + def signup! + User.transaction do + self.save! + self.person.save! + end + end has_one :person, :dependent => :destroy belongs_to :environment diff --git a/app/views/account/_signup_form.rhtml b/app/views/account/_signup_form.rhtml index 781eed2..4d7215e 100644 --- a/app/views/account/_signup_form.rhtml +++ b/app/views/account/_signup_form.rhtml @@ -1,4 +1,14 @@ -<%= error_messages_for :user %> +<%= error_messages_for :user, :person %> + +<% if ! defined? hidden_atention || ! hidden_atention %> +

+

+<%= _('Dear user, welcome to the %s network. To start your participation +in this space, fill in the fields below. After this operation, your login and +password will be registered, allowing you to create communities and enterprises +in this environment.') % environment.name %> +
+<% end %> <% labelled_form_for :user, @user, :html => { :help=>_('Fill all this fields to join in this environment.

If you forgot your password, do not create a new account, click on the "I forgot my password!" link. ;-)'), :id => 'profile-data' @@ -22,6 +32,10 @@ :help => help=_('To confirm, repeat your password.')) %> <%= help %> +<% labelled_fields_for :profile_data, @person do |f| %> + <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> +<% end %> + <%= icaptcha_field() %> <% if @terms_of_use %> @@ -41,16 +55,6 @@ <%= hidden_field_tag :new_user, true %> <% end %> -<% if ! defined? hidden_atention || ! hidden_atention %> -

-

-<%= _('Dear user, welcome to the %s network. To start your participation -in this space, fill in the fields below. After this operation, your login and -password will be registered, allowing you to create communities and enterprises -in this environment.') % environment.name %> -
-<% end %> - <% button_bar do %> <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> <% end %> diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml index ab666d0..63ee4bf 100644 --- a/app/views/admin_panel/index.rhtml +++ b/app/views/admin_panel/index.rhtml @@ -11,4 +11,6 @@
  • <%= link_to _('Manage User roles'), :controller => 'role' %>
  • <%= link_to _('Manage Validators by region'), :controller => 'region_validators' %>
  • <%= link_to _('Manage Templates'), :action => 'manage_templates' %>
  • +
  • <%= link_to _('Edit Templates'), :action => 'edit_templates' %>
  • +
  • <%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %>
  • diff --git a/app/views/categories/_form.rhtml b/app/views/categories/_form.rhtml index 90b5b4d..5320797 100644 --- a/app/views/categories/_form.rhtml +++ b/app/views/categories/_form.rhtml @@ -9,11 +9,15 @@ <%= hidden_field_tag('parent_id', @category.parent.id) %> <%= hidden_field_tag('type', @category.parent.class.name) %> <% else %> - <%= select_category_type :type %> + <% if environment.category_types.length > 1 %> + <%= select_category_type :type %> + <% else %> + <%= hidden_field_tag('type', environment.category_types.to_s) %> + <% end%> <% end %> <% end %> - <%= select_color_for_category %> + <%= select_color_for_category if !environment.enabled?('disable_categories_menu') %> <%= required f.text_field('name') %> diff --git a/app/views/features/_manage_community_fields.rhtml b/app/views/features/_manage_community_fields.rhtml new file mode 100644 index 0000000..0d18e3e --- /dev/null +++ b/app/views/features/_manage_community_fields.rhtml @@ -0,0 +1,46 @@ +

    <%= _('Manage community fields') %>

    + +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_community_fields'}) do |f| %> + + + + + + + + <% @community_fields.each do |field| %> + + + + + + <% end %> +
    <%= _('Field') %><%= _('Active') %><%= _('Required') %>
    + <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "$('community_fields[#{field}][required]').disabled=!this.checked" %> + <%= hidden_field_tag "community_fields[#{field}][active]", false %> + + <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required') %> + <%= hidden_field_tag "community_fields[#{field}][required]", false %> +
    + + + +
    + <% button_bar do %> + <%= submit_button('save', _('Save changes')) %> + <% end %> +
    + +<% end %> + + + + diff --git a/app/views/features/_manage_enterprise_fields.rhtml b/app/views/features/_manage_enterprise_fields.rhtml new file mode 100644 index 0000000..55ee75c --- /dev/null +++ b/app/views/features/_manage_enterprise_fields.rhtml @@ -0,0 +1,46 @@ +

    <%= _('Manage enterprise fields') %>

    + +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_enterprise_fields'}) do |f| %> + + + + + + + + <% @enterprise_fields.each do |field| %> + + + + + + <% end %> +
    <%= _('Field') %><%= _('Active') %><%= _('Required') %>
    + <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "$('enterprise_fields[#{field}][required]').disabled=!this.checked" %> + <%= hidden_field_tag "enterprise_fields[#{field}][active]", false %> + + <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required') %> + <%= hidden_field_tag "enterprise_fields[#{field}][required]", false %> +
    + + + +
    + <% button_bar do %> + <%= submit_button('save', _('Save changes')) %> + <% end %> +
    + +<% end %> + + + + diff --git a/app/views/features/_manage_person_fields.rhtml b/app/views/features/_manage_person_fields.rhtml new file mode 100644 index 0000000..8b1f1d7 --- /dev/null +++ b/app/views/features/_manage_person_fields.rhtml @@ -0,0 +1,52 @@ +

    <%= _('Manage person fields') %>

    + +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_person_fields'}) do |f| %> + + + + + + + + + <% @person_fields.each do |field| %> + + + + + + + <% end %> +
    <%= _('Field') %><%= _('Active') %><%= _('Required') %><%= _('Display on signup?') %>
    + <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "$('person_fields[#{field}][required]').disabled=$('person_fields[#{field}][signup]').disabled=!this.checked" %> + <%= hidden_field_tag "person_fields[#{field}][active]", false %> + + <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required') %> + <%= hidden_field_tag "person_fields[#{field}][required]", false %> + + <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup') %> + <%= hidden_field_tag "person_fields[#{field}][signup]", false %> +
    + + + +
    + <% button_bar do %> + <%= submit_button('save', _('Save changes')) %> + <% end %> +
    + +<% end %> + + + + diff --git a/app/views/features/manage_fields.rhtml b/app/views/features/manage_fields.rhtml new file mode 100644 index 0000000..70c8d16 --- /dev/null +++ b/app/views/features/manage_fields.rhtml @@ -0,0 +1,5 @@ +<%= render :partial => 'manage_person_fields' %> + +<%= render :partial => 'manage_enterprise_fields' %> + +<%= render :partial => 'manage_community_fields' %> diff --git a/app/views/profile_editor/_community_fields.rhtml b/app/views/profile_editor/_community_fields.rhtml new file mode 100644 index 0000000..a126b05 --- /dev/null +++ b/app/views/profile_editor/_community_fields.rhtml @@ -0,0 +1,2 @@ +<%= custom_field(@profile, 'language', f.text_field(:language)) %> +<%= custom_field(@profile, 'description', f.text_area(:description, :rows => 5)) %> diff --git a/app/views/profile_editor/_enterprise_fields.rhtml b/app/views/profile_editor/_enterprise_fields.rhtml new file mode 100644 index 0000000..be4b4d4 --- /dev/null +++ b/app/views/profile_editor/_enterprise_fields.rhtml @@ -0,0 +1,11 @@ +<%= custom_field(@profile, 'contact_phone', f.text_field(:contact_phone)) %> +<%= custom_field(@profile, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address))) %> + +<%= custom_field(@profile, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code))) %> +<%= custom_field(@profile, 'city', f.text_field(:city)) %> +<%= custom_field(@profile, 'state', f.text_field(:state)) %> +<%= custom_field(@profile, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> +<%= custom_field(@profile, 'organization_website', f.text_field(:organization_website)) %> +<%= custom_field(@profile, 'historic_and_current_context', f.text_area(:historic_and_current_context, :rows => 5)) %> +<%= custom_field(@profile, 'activities_short_description', f.text_area(:activities_short_description, :rows => 5)) %> +<%= custom_field(@profile, 'management_information', f.text_area(:management_information, :rows => 5)) %> diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml index 51342e5..d734df6 100644 --- a/app/views/profile_editor/_organization.rhtml +++ b/app/views/profile_editor/_organization.rhtml @@ -1,5 +1,7 @@

    <%= _('General information') %>

    + <%= required_fields_message if @profile.required_fields.any? %> +
    @@ -9,13 +11,16 @@
    <%= f.text_field(:acronym) %> - <%= f.text_field(:address, 'size' => 50) if @profile.enterprise? %> <%= f.text_field(:foundation_year) %> - <%= f.text_field(:contact_person) %> - <%= f.text_field(:contact_email) %> - <%= f.text_field(:economic_activity) %> - <%= f.text_area(:description, :rows => 5) if @profile.community? %> + <%= custom_field(@profile, 'contact_person', f.text_field(:contact_person)) %> + <%= custom_field(@profile, 'contact_email', f.text_field(:contact_email)) %> + <%= custom_field(@profile, 'economic_activity', f.text_field(:economic_activity)) %> + <%= custom_field(@profile, 'description', f.text_area(:description, :rows => 5)) if @profile.community? %> <%= f.check_box(:enable_contact_us) if @profile.enterprise? %> + + <%= render :partial => 'community_fields', :locals => { :f => f } if @profile.community? %> + <%= render :partial => 'enterprise_fields', :locals => { :f => f } if @profile.enterprise? %> +

    <%= _('Moderation options') %>

    <%= _('New members must be approved:')%> diff --git a/app/views/profile_editor/_person.rhtml b/app/views/profile_editor/_person.rhtml index 8d748c9..4e8ad40 100644 --- a/app/views/profile_editor/_person.rhtml +++ b/app/views/profile_editor/_person.rhtml @@ -1,5 +1,8 @@

    <%= _('Personal information') %>

    - <%= f.text_field(:email)%> + <%= required_fields_message %> + + <%= required f.text_field(:email)%> + <%= labelled_form_field _('Full name'), text_field(:profile_data, :name) %> <%= render :partial => 'person_form', :locals => {:f => f} %> diff --git a/app/views/profile_editor/_person_form.rhtml b/app/views/profile_editor/_person_form.rhtml index df6682a..8d1da03 100644 --- a/app/views/profile_editor/_person_form.rhtml +++ b/app/views/profile_editor/_person_form.rhtml @@ -1,16 +1,64 @@ -<%= f.text_field(:nickname, :maxlength => 16, :size => 30) %> -
    - <%= _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') %> -
    - -<%= f.text_field(:name) %> -<%= f.text_field(:contact_information) %> -<%= f.text_field(:contact_phone) %> -<%# use :size => 3 if you want 3 radios by line %> -<%= f.radio_group :profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ] %> -<%= f.text_field(:birth_date) %> -<%= labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address)) %> -<%= labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code)) %> -<%= f.text_field(:city) %> -<%= f.text_field(:state) %> -<%= f.text_field(:country) %> +<% @person ||= @profile %> + +<%= custom_field(@person, 'nickname', f.text_field(:nickname, :maxlength => 16, :size => 30)) %> + +<% nickname_tip = "
    " + _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') + "
    " %> +<% if controller.action_name == 'signup' %> + <% if @person.signup_fields.include?('nickname') %> + <%= nickname_tip %> + <% end%> +<% elsif @person.active_fields.include?('nickname') %> + <%= nickname_tip %> +<% end %> + +<%= custom_field(@person, 'contact_information', f.text_field(:contact_information)) %> +<%= custom_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone))) %> +<%= custom_field(@person, 'cell_phone', f.text_field(:cell_phone)) %> +<%= custom_field(@person, 'comercial_phone', f.text_field(:comercial_phone)) %> +<%= custom_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> +<%= custom_field(@person, 'birth_date', f.text_field(:birth_date)) %> +<%= custom_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address))) %> +<%= custom_field(@person, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code))) %> +<%= custom_field(@person, 'city', f.text_field(:city)) %> +<%= custom_field(@person, 'state', f.text_field(:state)) %> +<%= custom_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> +<%= custom_field(@person, 'nationality', f.text_field(:nationality)) %> + +<% if @person.active_fields.include?('schooling') %> + <% schooling_label = "" %> +
    <%= @person.required_fields.include?('schooling') ? required(schooling_label) : schooling_label %> +
    + <%= custom_field(@person, 'schooling', select_schooling('profile_data', 'schooling', {:class => 'select-schooling'})) %> + <%= custom_field(@person, 'schooling_status', select_schooling_status('profile_data', 'schooling_status', {:class => 'select-schooling'})) %> +
    +
    +<% end %> + + + +<%= custom_field(@person, 'formation', select_area(_('Formation'), 'profile_data', 'formation', {:class => 'type-select-full-line'})) %> + + > + <%= custom_field(@person, 'custom_formation', f.text_field(:custom_formation)) %> + +<%= observe_field 'profile_data_formation', :function =>'toggle_text_field("profile_data_formation", "profile_data_custom_formation_span")' %> + +<%= custom_field(@person, 'area_of_study', select_area(_('Area of study'), 'profile_data', 'area_of_study', {:class => 'type-select-full-line'})) %> + + > + <%= custom_field(@person, 'custom_area_of_study', f.text_field(:custom_area_of_study)) %> + +<%= observe_field 'profile_data_area_of_study', :function =>'toggle_text_field("profile_data_area_of_study", "profile_data_custom_area_of_study_span")' %> + +<%= custom_field(@person, 'professional_activity', f.text_field(:professional_activity)) %> +<%= custom_field(@person, 'organization', f.text_field(:organization)) %> +<%= custom_field(@person, 'organization_website', f.text_field(:organization_website)) %> + diff --git a/app/views/profile_editor/edit.rhtml b/app/views/profile_editor/edit.rhtml index 169fae6..7db58a1 100644 --- a/app/views/profile_editor/edit.rhtml +++ b/app/views/profile_editor/edit.rhtml @@ -2,7 +2,7 @@ <%= error_messages_for :profile %> -<% labelled_form_for :profile_data, @profile, :html => { :multipart => true } do |f| %> +<% labelled_form_for :profile_data, @profile, :html => { :id => 'profile-data', :multipart => true } do |f| %> <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> @@ -18,7 +18,7 @@ <%= _('This profile is:') %>

    - <% if profile.kind_of?(Person) %> + <% if profile.person? %> diff --git a/public/stylesheets/person_data.css b/public/stylesheets/person_data.css new file mode 100644 index 0000000..dc343a6 --- /dev/null +++ b/public/stylesheets/person_data.css @@ -0,0 +1,10 @@ +#profile-data .type-text input, +#profile-data .type-password input, +#profile-data .type-select select { + width: 220px +} + +#profile-data .type-select select.select-schooling { + width: 108px; +} + diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 1f8cb8b..b872721 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -594,6 +594,12 @@ class AccountControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'form', :attributes => { :action => /^https:\/\// } end + should 'render person partial' do + Environment.any_instance.expects(:signup_person_fields).returns(['contact_phone']).at_least_once + get :signup + assert_tag :tag => 'input', :attributes => { :name => "profile_data[contact_phone]" } + end + protected def new_user(options = {}, extra_options ={}) data = {:profile_data => person_data} diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index c165810..1122be7 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -137,4 +137,41 @@ class CategoriesControllerTest < Test::Unit::TestCase post :new, :category => { :display_in_menu => '1' } end + should 'not display color selection if environment.categories_menu is false' do + env.enable('disable_categories_menu') + env.save! + get :new + + assert_no_tag :tag => 'select', :attributes => { :name => "category[display_color]" } + end + + should 'display color selection if environment.categories_menu is true' do + env.disable('disable_categories_menu') + env.save! + get :new + + assert_tag :tag => 'select', :attributes => { :name => "category[display_color]" } + end + + should 'not display category_type if only one category is available' do + env.category_types = ['Category'] + get :new + + assert_no_tag :tag => 'select', :attributes => { :name => "type" } + end + + should 'have hidden_tag type if only one category is available' do + env.category_types = ['Category'] + env.save! + get :new + + assert_tag :tag => 'input', :attributes => { :name => 'type', :value => "Category", :type => 'hidden' } + end + + should 'display category_type if more than one category is available' do + env.category_types = 'Category', 'ProductCategory' + get :new + + assert_tag :tag => 'select', :attributes => { :name => "type" } + end end diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index a0e682c..f788708 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -76,8 +76,78 @@ class FeaturesControllerTest < Test::Unit::TestCase post :index assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } } + end + + should 'list possible person fields' do + uses_host 'anhetegua.net' + Person.expects(:fields).returns(['cell_phone', 'comercial_phone']).at_least_once + get :manage_fields + assert_template 'manage_fields' + Person.fields.each do |field| + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][active]"}) + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][required]"}) + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][signup]"}) + end + end + + should 'update custom_person_fields' do + uses_host 'anhetegua.net' + e = Environment.find(2) + Person.expects(:fields).returns(['cell_phone', 'comercial_phone']).at_least_once + + post :manage_person_fields, :person_fields => { :cell_phone => {:active => true, :required => true }} + assert_redirected_to :action => 'manage_fields' + e.reload + assert_equal true, e.custom_person_fields['cell_phone']['active'] + assert_equal true, e.custom_person_fields['cell_phone']['required'] + end + should 'disable check_box for required if active is not checked' + + should 'list possible enterprise fields' do + uses_host 'anhetegua.net' + Enterprise.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once + get :manage_fields + assert_template 'manage_fields' + Enterprise.fields.each do |field| + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "enterprise_fields[#{field}][active]"}) + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "enterprise_fields[#{field}][required]"}) + end + end + + should 'update custom_enterprise_fields' do + uses_host 'anhetegua.net' + e = Environment.find(2) + Enterprise.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once + + post :manage_enterprise_fields, :enterprise_fields => { :contact_person => {:active => true, :required => true }} + assert_redirected_to :action => 'manage_fields' + e.reload + assert_equal true, e.custom_enterprise_fields['contact_person']['active'] + assert_equal true, e.custom_enterprise_fields['contact_person']['required'] + end + + should 'list possible community fields' do + uses_host 'anhetegua.net' + Community.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once + get :manage_fields + assert_template 'manage_fields' + Community.fields.each do |field| + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "community_fields[#{field}][active]"}) + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "community_fields[#{field}][required]"}) + end + end + + should 'update custom_community_fields' do + uses_host 'anhetegua.net' + e = Environment.find(2) + Community.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once + post :manage_community_fields, :community_fields => { :contact_person => {:active => true, :required => true }} + assert_redirected_to :action => 'manage_fields' + e.reload + assert_equal true, e.custom_community_fields['contact_person']['active'] + assert_equal true, e.custom_community_fields['contact_person']['required'] end end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index cba9c8e..d801f1c 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -105,66 +105,68 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'filter html from contact_person to organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) contact = "name with html" 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') + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) value = "name with html" 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') + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) value = "name with html" 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') + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) value = "name with html" 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') + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) value = "name with html" 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.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 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') + should 'show contact_phone field on edit enterprise' do + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once get :edit, :profile => org.identifier - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]' } + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } end should 'save community description' do - org = Community.create!(:name => 'test org', :identifier => 'testorg') + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } assert_equal 'my description', Organization.find(org.id).description end should 'show community description' do - org = Community.create!(:name => 'test org', :identifier => 'testorg') + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + Community.any_instance.expects(:active_fields).returns(['description']).at_least_once get :edit, :profile => 'testorg' assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } end - should 'not show organization description' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + should 'not show enterprise description' do + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) get :edit, :profile => 'testorg' assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } end @@ -176,13 +178,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'save enterprise contact_person' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg') + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 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') + should 'show field values on edit community info' do + Community.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + org.contact_person = 'my contact' + org.save! + get :edit, :profile => 'testorg' + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } + end + + should 'show field values on edit enterprise info' do + Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) org.contact_person = 'my contact' org.save! get :edit, :profile => 'testorg' @@ -214,20 +226,27 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'show error messages for invalid foundation_year' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) post :edit, :profile => 'testorg', :profile_data => { :foundation_year => 'aaa' } assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } end should 'edit enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent') + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :environment => Environment.default) get :edit, :profile => 'testent' assert_response :success end - should 'back when update organization info fail' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') - Organization.any_instance.stubs(:update_attributes).returns(false) + should 'back when update community info fail' do + org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + Community.any_instance.stubs(:update_attributes).returns(false) + post :edit, :profile => 'testorg' + assert_template 'edit' + end + + should 'back when update enterprise info fail' do + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + Enterprise.any_instance.stubs(:update_attributes).returns(false) post :edit, :profile => 'testorg' assert_template 'edit' end @@ -259,9 +278,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'render person partial' do + person = create_user('test_profile', :environment => Environment.default).person + Person.any_instance.expects(:active_fields).returns(['contact_phone', 'birth_date', 'address']).at_least_once + get :edit, :profile => person.identifier + person.active_fields.each do |field| + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } + end + end + + should 'display only active person fields' do + Person.any_instance.expects(:active_fields).returns(['cell_phone']).at_least_once person = create_user('test_profile').person + get :edit, :profile => person.identifier - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } + + assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" } + assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" } end should 'be able to upload an image' do @@ -271,8 +303,16 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_not_nil assigns(:profile).image end + should 'display closed attribute for enterprise when it is set' do + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default) + get :edit, :profile => 'testorg' + + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } + end + should 'display closed attribute for organizations when it is set' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default) get :edit, :profile => 'testorg' assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } @@ -311,7 +351,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'display manage members options if has permission' do profile = Profile['ze'] - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') + community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) @controller.stubs(:user).returns(profile) @controller.stubs(:profile).returns(community) profile.stubs(:has_permission?).returns(true) @@ -321,7 +361,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'not display manage members options if has no permission' do profile = Profile['ze'] - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') + community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) @controller.stubs(:user).returns(profile) @controller.stubs(:profile).returns(community) profile.stubs(:has_permission?).returns(false) @@ -329,6 +369,24 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :content => 'Manage Members' end + should 'render enterprise partial' do + ent = Enterprise.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) + Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once + get :edit, :profile => ent.identifier + ent.active_fields.each do |field| + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } + end + end + + should 'render community partial' do + community = Community.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) + Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once + get :edit, :profile => community.identifier + community.active_fields.each do |field| + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } + end + end + should 'show task if user has permission' do user1 = create_user('userone').person user2 = create_user('usertwo').person @@ -385,13 +443,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'link to enable enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) get :index, :profile => 'testent' assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } end should 'link to disable enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) get :index, :profile => 'testent' assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } end @@ -403,31 +461,31 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'request enable enterprise confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) get :enable, :profile => 'testent' assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } end should 'enable enterprise after confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) post :enable, :profile => 'testent', :confirmation => 1 assert assigns(:to_enable).enabled? end should 'not enable enterprise without confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) post :enable, :profile => 'testent' assert !assigns(:to_enable).enabled? end should 'disable enterprise after confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) post :disable, :profile => 'testent', :confirmation => 1 assert !assigns(:to_disable).enabled? end should 'not disable enterprise without confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) post :disable, :profile => 'testent' assert assigns(:to_disable).enabled? end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 841be9d..e0733ba 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -231,6 +231,38 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_tag_in_string meta_tags_for_article(b), :tag => 'link', :attributes => {:type => 'application/rss+xml', :title => 'feed'} end + should 'provide sex icon for males' do + stubs(:environment).returns(Environment.default) + expects(:content_tag).with(anything, 'male').returns('MALE!!') + expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL") + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => 'male')) + end + + should 'provide sex icon for females' do + stubs(:environment).returns(Environment.default) + expects(:content_tag).with(anything, 'female').returns('FEMALE!!') + expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL") + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => 'female')) + end + + should 'provide undef sex icon' do + stubs(:environment).returns(Environment.default) + expects(:content_tag).with(anything, 'undef').returns('UNDEF!!') + expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL") + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => nil)) + end + + should 'not draw sex icon for non-person profiles' do + assert_equal '', profile_sex_icon(Community.new) + end + + should 'not draw sex icon when disabled in the environment' do + env = Environment.create!(:name => 'env test') + env.expects(:enabled?).with('disable_gender_icon').returns(true) + stubs(:environment).returns(env) + assert_equal '', profile_sex_icon(Person.new(:sex => 'male')) + end + protected def url_for(args = {}) diff --git a/test/unit/categories_helper_test.rb b/test/unit/categories_helper_test.rb new file mode 100644 index 0000000..cb62749 --- /dev/null +++ b/test/unit/categories_helper_test.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class CategoriesHelperTest < Test::Unit::TestCase + + include CategoriesHelper + + def setup + @environment = Environment.default + end + attr_reader :environment + def _(s); s; end + + should 'generate list of category types for selection' do + environment.category_types = ['Category', 'ProductCategory', 'Region'] + expects(:params).returns({'fieldname' => 'fieldvalue'}) + expects(:options_for_select).with([['General Category', 'Category'],[ 'Product Category', 'ProductCategory'],[ 'Region', 'Region' ]], 'fieldvalue').returns('OPTIONS') + expects(:select_tag).with('type', 'OPTIONS').returns('TAG') + expects(:labelled_form_field).with(anything, 'TAG').returns('RESULT') + + assert_equal 'RESULT', select_category_type('fieldname') + end + + should 'only list the available types' do + environment.category_types = ['Category'] + expects(:params).returns({'fieldname' => 'fieldvalue'}) + expects(:options_for_select).with([['General Category', 'Category']], 'fieldvalue').returns('OPTIONS') + expects(:select_tag).with('type', 'OPTIONS').returns('TAG') + expects(:labelled_form_field).with(anything, 'TAG').returns('RESULT') + + assert_equal 'RESULT', select_category_type('fieldname') + end + +end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 03fabda..34f876c 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -7,19 +7,19 @@ class CommunityTest < Test::Unit::TestCase end should 'convert name into identifier' do - c = Community.new(:name =>'My shiny new Community') + c = Community.new(:environment => Environment.default, :name =>'My shiny new Community') assert_equal 'My shiny new Community', c.name assert_equal 'my-shiny-new-community', c.identifier end should 'have a description attribute' do - c = Community.new + c = Community.new(:environment => Environment.default) c.description = 'the description of the community' assert_equal 'the description of the community', c.description end should 'create default set of blocks' do - c = Community.create!(:name => 'my new community') + c = Community.create!(:environment => Environment.default, :name => 'my new community') assert c.boxes[0].blocks.map(&:class).include?(MainBlock) @@ -33,19 +33,19 @@ class CommunityTest < Test::Unit::TestCase end should 'get a default home page and RSS feed' do - community = Community.create!(:name => 'my new community') + community = Community.create!(:environment => Environment.default, :name => 'my new community') assert_kind_of Article, community.home_page assert_kind_of RssFeed, community.articles.find_by_path('feed') end should 'have contact_person' do - community = Community.new(:name => 'my new community') + community = Community.new(:environment => Environment.default, :name => 'my new community') assert_respond_to community, :contact_person end should 'allow to add new members' do - c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') + c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') p = create_user('mytestuser').person c.add_member(p) @@ -54,7 +54,7 @@ class CommunityTest < Test::Unit::TestCase end should 'allow to remove members' do - c = Community.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + c = Community.create!(:environment => Environment.default, :name => 'my other test profile', :identifier => 'myothertestprofile') p = create_user('myothertestuser').person c.add_member(p) @@ -65,7 +65,7 @@ class CommunityTest < Test::Unit::TestCase end should 'clear relationships after destroy' do - c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') + c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') member = create_user('memberuser').person admin = create_user('adminuser').person moderator = create_user('moderatoruser').person @@ -85,8 +85,36 @@ class CommunityTest < Test::Unit::TestCase should 'have a community template' do env = Environment.create!(:name => 'test env') - p = Community.create!(:name => 'test_com', :identifier => 'test_com', :environment => env) + p = Community.create!(:environment => Environment.default, :name => 'test_com', :identifier => 'test_com', :environment => env) assert_kind_of Community, p.template end + should 'return active_community_fields' do + e = Environment.default + e.expects(:active_community_fields).returns(['contact_phone', 'contact_email']).at_least_once + ent = Community.new(:environment => e) + + assert_equal e.active_community_fields, ent.active_fields + end + + should 'return required_community_fields' do + e = Environment.default + e.expects(:required_community_fields).returns(['contact_phone', 'contact_email']).at_least_once + community = Community.new(:environment => e) + + assert_equal e.required_community_fields, community.required_fields + end + + should 'require fields if community needs' do + e = Environment.default + e.expects(:required_community_fields).returns(['contact_phone']).at_least_once + community = Community.new(:environment => e) + assert ! community.valid? + assert community.errors.invalid?(:contact_phone) + + community.contact_phone = '99999' + community.valid? + assert ! community.errors.invalid?(:contact_phone) + end + end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 6809f36..f50b369 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -174,7 +174,7 @@ class EnterpriseTest < Test::Unit::TestCase ent.reload assert_equal 1, ent.boxes.size assert_equal 1, ent.boxes[0].blocks.size - end + end should 'not replace template if environment doesnt allow' do template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) @@ -195,7 +195,8 @@ class EnterpriseTest < Test::Unit::TestCase assert_equal 1, ent.boxes.size assert_equal 1, ent.boxes[0].blocks.size end - should 'create EnterpriseActivation task when creating with enabled = false' do + + should 'create EnterpriseActivation task when creating with enabled = false' do EnterpriseActivation.delete_all ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise) @@ -256,4 +257,32 @@ class EnterpriseTest < Test::Unit::TestCase assert e.enable_contact_us end + should 'return active_enterprise_fields' do + e = Environment.default + e.expects(:active_enterprise_fields).returns(['contact_phone', 'contact_email']).at_least_once + ent = Enterprise.new(:environment => e) + + assert_equal e.active_enterprise_fields, ent.active_fields + end + + should 'return required_enterprise_fields' do + e = Environment.default + e.expects(:required_enterprise_fields).returns(['contact_phone', 'contact_email']).at_least_once + enterprise = Enterprise.new(:environment => e) + + assert_equal e.required_enterprise_fields, enterprise.required_fields + end + + should 'require fields if enterprise needs' do + e = Environment.default + e.expects(:required_enterprise_fields).returns(['contact_phone']).at_least_once + enterprise = Enterprise.new(:environment => e) + assert ! enterprise.valid? + assert enterprise.errors.invalid?(:contact_phone) + + enterprise.contact_phone = '99999' + enterprise.valid? + assert ! enterprise.errors.invalid?(:contact_phone) + end + end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 6ae758e..e74df78 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -532,4 +532,153 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal false, Environment.new.replace_enterprise_template_when_enable end + should 'set custom_person_fields' do + env = Environment.new + env.custom_person_fields = {'cell_phone' => {'required' => 'true', 'active' => 'true'},'comercial_phone'=> {'required' => 'true', 'active' => 'true'}} + + assert_equal({'cell_phone' => {'required' => 'true', 'active' => 'true'},'comercial_phone'=> {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) + end + + should 'have no custom_person_fields by default' do + assert_equal({}, Environment.new.custom_person_fields) + end + + should 'not set in custom_person_fields if not in person.fields' do + env = Environment.default + Person.stubs(:fields).returns(['cell_phone', 'comercial_phone']) + + env.custom_person_fields = { 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'true'}} + assert_equal({'cell_phone' => {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) + assert ! env.custom_person_fields.keys.include?('birth_date') + end + + should 'add schooling_status if custom_person_fields has schooling' do + env = Environment.default + Person.stubs(:fields).returns(['cell_phone', 'schooling']) + + env.custom_person_fields = { 'schooling' => {'required' => 'true', 'active' => 'true'}} + assert_equal({'schooling' => {'required' => 'true', 'active' => 'true'}, 'schooling_status' => {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) + assert ! env.custom_person_fields.keys.include?('birth_date') + end + + should 'return person_fields status' do + env = Environment.default + + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal true, env.custom_person_field('birth_date', 'required') + assert_equal false, env.custom_person_field('birth_date', 'active') + end + + should 'select active fields from person' do + env = Environment.default + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal ['birth_date'], env.active_person_fields + end + + should 'select required fields from person' do + env = Environment.default + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'false', 'active' => 'true'}}).at_least_once + + assert_equal ['birth_date'], env.required_person_fields + end + + should 'set custom_enterprises_fields' do + env = Environment.new + env.custom_enterprise_fields = {'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}} + + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}}, env.custom_enterprise_fields) + end + + should 'have no custom_enterprise_fields by default' do + assert_equal({}, Environment.new.custom_enterprise_fields) + end + + should 'not set in custom_enterprise_fields if not in enterprise.fields' do + env = Environment.default + Enterprise.stubs(:fields).returns(['contact_person', 'comercial_phone']) + + env.custom_enterprise_fields = { 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'true'}} + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'}}, env.custom_enterprise_fields) + assert ! env.custom_enterprise_fields.keys.include?('contact_email') + end + + should 'return enteprise_fields status' do + env = Environment.default + + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal true, env.custom_enterprise_field('contact_email', 'required') + assert_equal false, env.custom_enterprise_field('contact_email', 'active') + end + + should 'select active fields from enterprise' do + env = Environment.default + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal ['contact_email'], env.active_enterprise_fields + end + + should 'select required fields from enterprise' do + env = Environment.default + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'false', 'active' => 'true'}}).at_least_once + + assert_equal ['contact_email'], env.required_enterprise_fields + end + + should 'set custom_communitys_fields' do + env = Environment.new + env.custom_community_fields = {'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}} + + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}}, env.custom_community_fields) + end + + should 'have no custom_community_fields by default' do + assert_equal({}, Environment.new.custom_community_fields) + end + + should 'not set in custom_community_fields if not in community.fields' do + env = Environment.default + Community.stubs(:fields).returns(['contact_person', 'comercial_phone']) + + env.custom_community_fields = { 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'true'}} + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'}}, env.custom_community_fields) + assert ! env.custom_community_fields.keys.include?('contact_email') + end + + should 'return community_fields status' do + env = Environment.default + + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal true, env.custom_community_field('contact_email', 'required') + assert_equal false, env.custom_community_field('contact_email', 'active') + end + + should 'select active fields from community' do + env = Environment.default + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'false'}}).at_least_once + + assert_equal ['contact_email'], env.active_community_fields + end + + should 'select required fields from community' do + env = Environment.default + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'false', 'active' => 'true'}}).at_least_once + + assert_equal ['contact_email'], env.required_community_fields + end + + should 'set category_types' do + env = Environment.new + env.category_types = ['Category', 'ProductCategory'] + + assert_equal ['Category', 'ProductCategory'], env.category_types + end + + should 'have type /Category/ on category_types by default' do + assert_equal ['Category'], Environment.new.category_types + end + end diff --git a/test/unit/friendship_test.rb b/test/unit/friendship_test.rb index ac0605f..f1b52da 100644 --- a/test/unit/friendship_test.rb +++ b/test/unit/friendship_test.rb @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' class FriendshipTest < Test::Unit::TestCase should 'connect a person to another' do - p1 = Person.new - p2 = Person.new + p1 = Person.new(:environment => Environment.default) + p2 = Person.new(:environment => Environment.default) f = Friendship.new assert_raise ActiveRecord::AssociationTypeMismatch do diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index ea1cba4..4220f88 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -4,7 +4,7 @@ class PersonTest < Test::Unit::TestCase fixtures :profiles, :users, :environments def test_person_must_come_form_the_cration_of_an_user - p = Person.new(:name => 'John', :identifier => 'john') + p = Person.new(:environment => Environment.default, :name => 'John', :identifier => 'john') assert !p.valid? p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') assert !p.valid? @@ -59,21 +59,21 @@ class PersonTest < Test::Unit::TestCase p1 = u.person assert_equal u, p1.user - p2 = Person.new + p2 = Person.new(:environment => Environment.default) p2.user = u assert !p2.valid? assert p2.errors.invalid?(:user_id) end should "have person info fields" do - p = Person.new + p = Person.new(:environment => Environment.default) [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code ].each do |i| assert_respond_to p, i end end should 'not have person_info class' do - p = Person.new + p = Person.new(:environment => Environment.default) assert_raise NoMethodError do p.person_info end @@ -108,7 +108,7 @@ class PersonTest < Test::Unit::TestCase end should 'get no email address when there is no associated user' do - p = Person.new + p = Person.new(:environment => Environment.default) assert_nil p.email end @@ -173,12 +173,12 @@ class PersonTest < Test::Unit::TestCase end should 'suggest default friend groups list' do - p = Person.new + p = Person.new(:environment => Environment.default) assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups end should 'suggest current groups as well' do - p = Person.new + p = Person.new(:environment => Environment.default) p.expects(:friend_groups).returns(['group1', 'group2']) assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups end @@ -264,14 +264,14 @@ class PersonTest < Test::Unit::TestCase end should 'provide desired info fields' do - p = Person.new + p = Person.new(:environment => Environment.default) assert p.respond_to?(:photo) assert p.respond_to?(:address) assert p.respond_to?(:contact_information) end should 'required name' do - person = Person.new + person = Person.new(:environment => Environment.default) assert !person.valid? assert person.errors.invalid?(:name) end @@ -285,7 +285,7 @@ class PersonTest < Test::Unit::TestCase should 'have e-mail addresses' do env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) - person = Person.new(:identifier => 'testuser') + person = Person.new(:environment => env, :identifier => 'testuser') person.expects(:environment).returns(env) assert_equal ['testuser@somedomain.com'], person.email_addresses @@ -295,7 +295,7 @@ class PersonTest < Test::Unit::TestCase env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) env.force_www = true env.save - person = Person.new(:identifier => 'testuser') + person = Person.new(:environment => env, :identifier => 'testuser') person.expects(:environment).returns(env) assert_equal ['testuser@somedomain.com'], person.email_addresses @@ -387,4 +387,76 @@ class PersonTest < Test::Unit::TestCase assert_equal 'pt_BR', Person['user_lang_test'].last_lang end + should 'return active_person_fields' do + e = Environment.default + e.expects(:active_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once + person = Person.new(:environment => e) + + assert_equal e.active_person_fields, person.active_fields + end + + should 'return required_person_fields' do + e = Environment.default + e.expects(:required_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once + person = Person.new(:environment => e) + + assert_equal e.required_person_fields, person.required_fields + end + + should 'require fields if person needs' do + e = Environment.default + e.expects(:required_person_fields).returns(['cell_phone']).at_least_once + person = Person.new(:environment => e) + assert ! person.valid? + assert person.errors.invalid?(:cell_phone) + + person.cell_phone = '99999' + person.valid? + assert ! person.errors.invalid?(:cell_phone) + end + + should 'require custom_area_of_study if area_of_study is others' do + e = Environment.default + e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once + + person = Person.new(:environment => e, :area_of_study => 'Others') + assert !person.valid? + assert person.errors.invalid?(:custom_area_of_study) + + person.custom_area_of_study = 'Customized area of study' + person.valid? + assert ! person.errors.invalid?(:custom_area_of_study) + end + + should 'not require custom_area_of_study if area_of_study is not others' do + e = Environment.default + e.expects(:required_person_fields).returns(['area_of_study']).at_least_once + + person = Person.new(:environment => e, :area_of_study => 'Agrometeorology') + person.valid? + assert ! person.errors.invalid?(:custom_area_of_study) + end + + should 'require custom_formation if formation is others' do + e = Environment.default + e.expects(:required_person_fields).returns(['formation', 'custom_formation']).at_least_once + + person = Person.new(:environment => e, :formation => 'Others') + assert !person.valid? + assert person.errors.invalid?(:custom_formation) + + person.custom_formation = 'Customized formation' + person.valid? + assert ! person.errors.invalid?(:custom_formation) + end + + should 'not require custom_formation if formation is not others' do + e = Environment.default + e.expects(:required_person_fields).returns(['formation']).at_least_once + + person = Person.new(:environment => e, :formation => 'Agrometeorology') + assert !person.valid? + assert ! person.errors.invalid?(:custom_formation) + end + end -- libgit2 0.21.2