Commit 0ba97d3054159c5a4d734ee9715f383d5d63703d
1 parent
20541556
Exists in
master
and in
29 other branches
ActionItem833: port unifreire-specific changes as configuration into master branch
* making fields appear on signup form * environment has a list of Category subclasses that must be available for users; if there is only one category type available, no need of asking for category type * environment has a setting categories_menu which enables/disables the category menu. If it is disabled, then no need to ask for a color in the menu * add a configuration to the environment called disable_gender_icon. When it is false, don't display gender icons. * adding css for profile_data * adding required on label for schooling fixing javascript * adding fields on signup and option to admin manage * adding required message on required fields * adding partials for person/enterprise/community fields * adding methods for person/community/enterprise custom_fields * adding option to admin manage person fields
Showing
36 changed files
with
1538 additions
and
107 deletions
Show diff stats
app/controllers/admin/features_controller.rb
| @@ -15,4 +15,40 @@ class FeaturesController < AdminController | @@ -15,4 +15,40 @@ class FeaturesController < AdminController | ||
| 15 | end | 15 | end |
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | + def manage_fields | ||
| 19 | + @person_fields = Person.fields | ||
| 20 | + @enterprise_fields = Enterprise.fields | ||
| 21 | + @community_fields = Community.fields | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + def manage_person_fields | ||
| 25 | + environment.custom_person_fields = params[:person_fields] | ||
| 26 | + if environment.save! | ||
| 27 | + flash[:notice] = _('Custom person fields updated successfully.') | ||
| 28 | + else | ||
| 29 | + flash[:error] = _('Custom person fields not updated successfully.') | ||
| 30 | + end | ||
| 31 | + redirect_to :action => 'manage_fields' | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + def manage_enterprise_fields | ||
| 35 | + environment.custom_enterprise_fields = params[:enterprise_fields] | ||
| 36 | + if environment.save! | ||
| 37 | + flash[:notice] = _('Custom enterprise fields updated successfully.') | ||
| 38 | + else | ||
| 39 | + flash[:error] = _('Custom enterprise fields not updated successfully.') | ||
| 40 | + end | ||
| 41 | + redirect_to :action => 'manage_fields' | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + def manage_community_fields | ||
| 45 | + environment.custom_community_fields = params[:community_fields] | ||
| 46 | + if environment.save! | ||
| 47 | + flash[:notice] = _('Custom community fields updated successfully.') | ||
| 48 | + else | ||
| 49 | + flash[:error] = _('Custom community fields not updated successfully.') | ||
| 50 | + end | ||
| 51 | + redirect_to :action => 'manage_fields' | ||
| 52 | + end | ||
| 53 | + | ||
| 18 | end | 54 | end |
app/controllers/public/account_controller.rb
| @@ -14,6 +14,7 @@ class AccountController < ApplicationController | @@ -14,6 +14,7 @@ class AccountController < ApplicationController | ||
| 14 | # action to perform login to the application | 14 | # action to perform login to the application |
| 15 | def login | 15 | def login |
| 16 | @user = User.new | 16 | @user = User.new |
| 17 | + @person = @user.build_person | ||
| 17 | return unless request.post? | 18 | return unless request.post? |
| 18 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] | 19 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] |
| 19 | if logged_in? | 20 | if logged_in? |
| @@ -46,8 +47,10 @@ class AccountController < ApplicationController | @@ -46,8 +47,10 @@ class AccountController < ApplicationController | ||
| 46 | @user.terms_of_use = environment.terms_of_use | 47 | @user.terms_of_use = environment.terms_of_use |
| 47 | @user.environment = environment | 48 | @user.environment = environment |
| 48 | @terms_of_use = environment.terms_of_use | 49 | @terms_of_use = environment.terms_of_use |
| 50 | + @person = @user.build_person(params[:profile_data]) | ||
| 51 | + @person.environment = @user.environment | ||
| 49 | if request.post? && params[self.icaptcha_field].blank? | 52 | if request.post? && params[self.icaptcha_field].blank? |
| 50 | - @user.save! | 53 | + @user.signup! |
| 51 | self.current_user = @user | 54 | self.current_user = @user |
| 52 | owner_role = Role.find_by_name('owner') | 55 | owner_role = Role.find_by_name('owner') |
| 53 | @user.person.affiliate(@user.person, [owner_role]) if owner_role | 56 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
| @@ -55,6 +58,7 @@ class AccountController < ApplicationController | @@ -55,6 +58,7 @@ class AccountController < ApplicationController | ||
| 55 | flash[:notice] = _("Thanks for signing up!") | 58 | flash[:notice] = _("Thanks for signing up!") |
| 56 | end | 59 | end |
| 57 | rescue ActiveRecord::RecordInvalid | 60 | rescue ActiveRecord::RecordInvalid |
| 61 | + @person.valid? | ||
| 58 | render :action => 'signup' | 62 | render :action => 'signup' |
| 59 | end | 63 | end |
| 60 | end | 64 | end |
app/helpers/application_helper.rb
| @@ -19,7 +19,9 @@ module ApplicationHelper | @@ -19,7 +19,9 @@ module ApplicationHelper | ||
| 19 | include DatesHelper | 19 | include DatesHelper |
| 20 | 20 | ||
| 21 | include FolderHelper | 21 | include FolderHelper |
| 22 | - | 22 | + |
| 23 | + include ProfileEditorHelper | ||
| 24 | + | ||
| 23 | # Displays context help. You can pass the content of the help message as the | 25 | # Displays context help. You can pass the content of the help message as the |
| 24 | # first parameter or using template code inside a block passed to this | 26 | # first parameter or using template code inside a block passed to this |
| 25 | # method. *Note*: the block is ignored if <tt>content</tt> is not | 27 | # method. *Note*: the block is ignored if <tt>content</tt> is not |
| @@ -289,7 +291,6 @@ module ApplicationHelper | @@ -289,7 +291,6 @@ module ApplicationHelper | ||
| 289 | @controller.send(:user) | 291 | @controller.send(:user) |
| 290 | end | 292 | end |
| 291 | 293 | ||
| 292 | - | ||
| 293 | def stylesheet_import(*sources) | 294 | def stylesheet_import(*sources) |
| 294 | options = sources.last.is_a?(Hash) ? sources.pop : { } | 295 | options = sources.last.is_a?(Hash) ? sources.pop : { } |
| 295 | themed_source = options.delete(:themed_source) | 296 | themed_source = options.delete(:themed_source) |
| @@ -378,16 +379,14 @@ module ApplicationHelper | @@ -378,16 +379,14 @@ module ApplicationHelper | ||
| 378 | end | 379 | end |
| 379 | 380 | ||
| 380 | def profile_sex_icon( profile ) | 381 | def profile_sex_icon( profile ) |
| 381 | - if profile.class == Person | ||
| 382 | - sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) | ||
| 383 | - title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) | ||
| 384 | - sex = content_tag 'span', | ||
| 385 | - content_tag( 'span', sex ), | ||
| 386 | - :class => 'sex-'+sex, | ||
| 387 | - :title => title | ||
| 388 | - else | ||
| 389 | - sex = '' | ||
| 390 | - end | 382 | + return '' unless profile.is_a?(Person) |
| 383 | + return '' unless !environment.enabled?('disable_gender_icon') | ||
| 384 | + sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) | ||
| 385 | + title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) | ||
| 386 | + sex = content_tag 'span', | ||
| 387 | + content_tag( 'span', sex ), | ||
| 388 | + :class => 'sex-'+sex, | ||
| 389 | + :title => title | ||
| 391 | sex | 390 | sex |
| 392 | end | 391 | end |
| 393 | 392 | ||
| @@ -692,6 +691,23 @@ module ApplicationHelper | @@ -692,6 +691,23 @@ module ApplicationHelper | ||
| 692 | form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) | 691 | form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) |
| 693 | end | 692 | end |
| 694 | 693 | ||
| 694 | + def custom_field(profile, name, field_html, options = {}) | ||
| 695 | + result = "" | ||
| 696 | + if (controller.action_name == 'signup') | ||
| 697 | + if profile.signup_fields.include?(name) | ||
| 698 | + result = field_html | ||
| 699 | + end | ||
| 700 | + else | ||
| 701 | + if profile.active_fields.include?(name) | ||
| 702 | + result = field_html | ||
| 703 | + end | ||
| 704 | + end | ||
| 705 | + if profile.required_fields.include?(name) | ||
| 706 | + result = required(result) | ||
| 707 | + end | ||
| 708 | + result | ||
| 709 | + end | ||
| 710 | + | ||
| 695 | def search_page_title(title, options={}) | 711 | def search_page_title(title, options={}) |
| 696 | title = "<h1>" + title + "</h1>" | 712 | title = "<h1>" + title + "</h1>" |
| 697 | title += "<h2 align='center'>" + _("Searched for '%s'") % options[:query] + "</h2>" if !options[:query].blank? | 713 | title += "<h2 align='center'>" + _("Searched for '%s'") % options[:query] + "</h2>" if !options[:query].blank? |
app/helpers/categories_helper.rb
| @@ -35,7 +35,8 @@ module CategoriesHelper | @@ -35,7 +35,8 @@ module CategoriesHelper | ||
| 35 | 35 | ||
| 36 | def select_category_type(field) | 36 | def select_category_type(field) |
| 37 | value = params[field] | 37 | value = params[field] |
| 38 | - labelled_form_field(_('Type of category'), select_tag('type', options_for_select(CategoriesHelper::TYPES, value))) | 38 | + types = TYPES.select { |title,typename| environment.category_types.include?(typename) } |
| 39 | + labelled_form_field(_('Type of category'), select_tag('type', options_for_select(types, value))) | ||
| 39 | end | 40 | end |
| 40 | 41 | ||
| 41 | end | 42 | end |
| @@ -0,0 +1,362 @@ | @@ -0,0 +1,362 @@ | ||
| 1 | +module ProfileEditorHelper | ||
| 2 | + | ||
| 3 | + include GetText | ||
| 4 | + | ||
| 5 | + AREAS_OF_STUDY = [ | ||
| 6 | + N_('Agrometeorology'), | ||
| 7 | + N_('Agronomy'), | ||
| 8 | + N_('Foods'), | ||
| 9 | + N_('Anthropology'), | ||
| 10 | + N_('Architecture'), | ||
| 11 | + N_('Arts'), | ||
| 12 | + N_('Astronomy'), | ||
| 13 | + N_('Librarianship'), | ||
| 14 | + N_('Biosciences'), | ||
| 15 | + N_('Biophysics'), | ||
| 16 | + N_('Biology'), | ||
| 17 | + N_('Biotechnology'), | ||
| 18 | + N_('Botany'), | ||
| 19 | + N_('Science Politics'), | ||
| 20 | + N_('Accounting and Actuarial Science'), | ||
| 21 | + N_('Morphologic Sciences'), | ||
| 22 | + N_('Computation'), | ||
| 23 | + N_('Rural Development'), | ||
| 24 | + N_('Law'), | ||
| 25 | + N_('Ecology'), | ||
| 26 | + N_('Economy'), | ||
| 27 | + N_('Education'), | ||
| 28 | + N_('Long-distance Education'), | ||
| 29 | + N_('Physical Education'), | ||
| 30 | + N_('Professional Education'), | ||
| 31 | + N_('Nursing'), | ||
| 32 | + N_('Engineerings'), | ||
| 33 | + N_('Basic and Average education'), | ||
| 34 | + N_('Statistics'), | ||
| 35 | + N_('Stratigraphy'), | ||
| 36 | + N_('Pharmacy'), | ||
| 37 | + N_('Pharmacology'), | ||
| 38 | + N_('Philosophy'), | ||
| 39 | + N_('Physics'), | ||
| 40 | + N_('Plant Protection'), | ||
| 41 | + N_('Genetics'), | ||
| 42 | + N_('Geosciences'), | ||
| 43 | + N_('Geography'), | ||
| 44 | + N_('Geology'), | ||
| 45 | + N_('Hydrology'), | ||
| 46 | + N_('Hydromechanics'), | ||
| 47 | + N_('History'), | ||
| 48 | + N_('Horticulture'), | ||
| 49 | + N_('Informatics'), | ||
| 50 | + N_('Interdisciplinary'), | ||
| 51 | + N_('Journalism'), | ||
| 52 | + N_('Letters'), | ||
| 53 | + N_('Languages'), | ||
| 54 | + N_('Mathematics'), | ||
| 55 | + N_('Medicines'), | ||
| 56 | + N_('Medicine'), | ||
| 57 | + N_('Metallurgy'), | ||
| 58 | + N_('Microbiology'), | ||
| 59 | + N_('Mineralogy'), | ||
| 60 | + N_('Music'), | ||
| 61 | + N_('Nutrition'), | ||
| 62 | + N_('Odontology'), | ||
| 63 | + N_('Paleontology'), | ||
| 64 | + N_('Petrology'), | ||
| 65 | + N_('Production'), | ||
| 66 | + N_('Psychology'), | ||
| 67 | + N_('Psychiatry'), | ||
| 68 | + N_('Quality'), | ||
| 69 | + N_('Chemistry'), | ||
| 70 | + N_('Health'), | ||
| 71 | + N_('Remote Sensing'), | ||
| 72 | + N_('Forestry'), | ||
| 73 | + N_('Sociology'), | ||
| 74 | + N_('Ground'), | ||
| 75 | + N_('Theater'), | ||
| 76 | + N_('Transport'), | ||
| 77 | + N_('Urbanism'), | ||
| 78 | + N_('Veterinary Medicine'), | ||
| 79 | + N_('Zoology'), | ||
| 80 | + N_('Zootecnia'), | ||
| 81 | + N_('Others') | ||
| 82 | + ] | ||
| 83 | + | ||
| 84 | + COUNTRIES = [ | ||
| 85 | + ("Afeganistão (افغانستان)"), | ||
| 86 | + ("África do Sul (South Africa)"), | ||
| 87 | + ("Albânia (Shqipëria)"), | ||
| 88 | + ("Alemanha (Deutschland)"), | ||
| 89 | + ("Andorra"), | ||
| 90 | + ("Angola"), | ||
| 91 | + ("Anguila (Anguilla)"), | ||
| 92 | + ("Antártica (Antarctica)"), | ||
| 93 | + ("Antígua e Barbuda (Antigua and Barbuda)"), | ||
| 94 | + ("Antilhas Holandesas (Netherlands Antilles)"), | ||
| 95 | + ("Arábia Saudita (العربية السعودية)"), | ||
| 96 | + ("Argélia (الجمهورية الجزائرية)"), | ||
| 97 | + ("Argentina"), | ||
| 98 | + ("Armênia (Հայաստան)"), | ||
| 99 | + ("Aruba"), | ||
| 100 | + ("Austrália (Australia)"), | ||
| 101 | + ("Áustria (Österreich)"), | ||
| 102 | + ("Azerbaijão (Azərbaycan)"), | ||
| 103 | + ("Bahamas"), | ||
| 104 | + ("Bangladesh (বাংলাদেশ)"), | ||
| 105 | + ("Barbados"), | ||
| 106 | + ("Barein (بحرين)"), | ||
| 107 | + ("Bélgica (België)"), | ||
| 108 | + ("Belize"), | ||
| 109 | + ("Benin (Bénin)"), | ||
| 110 | + ("Bermudas (Bermuda)"), | ||
| 111 | + ("Bielo-Rússia (Белару́сь)"), | ||
| 112 | + ("Bolívia (Bolivia)"), | ||
| 113 | + ("Bósnia-Herzegovina (Bosna i Hercegovina)"), | ||
| 114 | + ("Botsuana (Botswana)"), | ||
| 115 | + ("Brasil"), | ||
| 116 | + ("Brunei (Brunei Darussalam)"), | ||
| 117 | + ("Bulgária (България)"), | ||
| 118 | + ("Burkina Fasso (Burkina Faso)"), | ||
| 119 | + ("Burundi (Uburundi)"), | ||
| 120 | + ("Butão (འབྲུག་ཡུལ)"), | ||
| 121 | + ("Cabo Verde"), | ||
| 122 | + ("Camarões (Cameroun)"), | ||
| 123 | + ("Camboja (Kampuchea)"), | ||
| 124 | + ("Canadá (Canada)"), | ||
| 125 | + ("Catar (قطر)"), | ||
| 126 | + ("Cazaquistão (Қазақстан)"), | ||
| 127 | + ("Chade (Tchad)"), | ||
| 128 | + ("Chile"), | ||
| 129 | + ("China (中国)"), | ||
| 130 | + ("Chipre (Κυπρος)"), | ||
| 131 | + ("Cidade do Vaticano (Città del Vaticano)"), | ||
| 132 | + ("Cingapura (Singapura)"), | ||
| 133 | + ("Colômbia (Colombia)"), | ||
| 134 | + ("Comores"), | ||
| 135 | + ("Congo"), | ||
| 136 | + ("Congo, República democrática do (Congo, Democratic Republic of the)"), | ||
| 137 | + ("Coréia do Norte (조선)"), | ||
| 138 | + ("Coréia do Sul (한국)"), | ||
| 139 | + ("Costa do Marfim (Côte d'Ivoire)"), | ||
| 140 | + ("Costa Rica"), | ||
| 141 | + ("Croácia (Hrvatska)"), | ||
| 142 | + ("Cuba"), | ||
| 143 | + ("Dinamarca (Danmark)"), | ||
| 144 | + ("Djibuti (Djibouti)"), | ||
| 145 | + ("Dominica"), | ||
| 146 | + ("Egito (مصر)"), | ||
| 147 | + ("El Salvador"), | ||
| 148 | + ("Emirados Árabes Unidos (الإمارات العربيّة المتّحد)"), | ||
| 149 | + ("Equador (Ecuador)"), | ||
| 150 | + ("Eritréia (Ertra)"), | ||
| 151 | + ("Eslováquia (Slovensko)"), | ||
| 152 | + ("Eslovênia (Slovenija)"), | ||
| 153 | + ("Espanha (España)"), | ||
| 154 | + ("Estados Unidos (United States)"), | ||
| 155 | + ("Estônia (Eesti)"), | ||
| 156 | + ("Etiópia (Ityop'iya)"), | ||
| 157 | + ("Fiji"), | ||
| 158 | + ("Filipinas (Pilipinas)"), | ||
| 159 | + ("Finlândia (Suomi)"), | ||
| 160 | + ("França (France)"), | ||
| 161 | + ("Gabão (Gabon)"), | ||
| 162 | + ("Gâmbia (Gambia)"), | ||
| 163 | + ("Gana (Ghana)"), | ||
| 164 | + ("Geórgia (საქართველო)"), | ||
| 165 | + ("Geórgia do Sul e Ilhas Sandwich do Sul (South Georgia and the South Sandwich Islands)"), | ||
| 166 | + ("Gibraltar"), | ||
| 167 | + ("Granada (Grenada)"), | ||
| 168 | + ("Grécia (Eλλας)"), | ||
| 169 | + ("Groenlândia (Greenland)"), | ||
| 170 | + ("Guadalupe (Guadeloupe)"), | ||
| 171 | + ("Guam"), | ||
| 172 | + ("Guatemala"), | ||
| 173 | + ("Guernsey"), | ||
| 174 | + ("Guiana (Guyana)"), | ||
| 175 | + ("Guiana Francesa (French Guiana)"), | ||
| 176 | + ("Guiné (Guinée)"), | ||
| 177 | + ("Guiné-Bissau"), | ||
| 178 | + ("Guiné Equatorial (Guinea Ecuatorial)"), | ||
| 179 | + ("Haiti (Haïti)"), | ||
| 180 | + ("Holanda (Nederland)"), | ||
| 181 | + ("Honduras"), | ||
| 182 | + ("Hong Kong"), | ||
| 183 | + ("Hungria (Magyarország)"), | ||
| 184 | + ("Iêmen (اليمن)"), | ||
| 185 | + ("Ilha Aland (Aland Islands)"), | ||
| 186 | + ("Ilha Bouvet (Bouvet Island)"), | ||
| 187 | + ("Ilha Christmas (Christmas Island)"), | ||
| 188 | + ("Ilha de Man (Isle of Man)"), | ||
| 189 | + ("Ilha Norfolk (Norfolk Island)"), | ||
| 190 | + ("Ilhas Cayman (Cayman Islands)"), | ||
| 191 | + ("Ilhas Cocos (Keeling) (Cocos Islands)"), | ||
| 192 | + ("Ilhas Cook (Cook Islands)"), | ||
| 193 | + ("Ilhas Falkland (Malvinas) (Falkland Islands)"), | ||
| 194 | + ("Ilhas Faroé (Faroe Islands)"), | ||
| 195 | + ("Ilhas Heard e McDonald (Heard Island and McDonald Islands)"), | ||
| 196 | + ("Ilhas Marianas do Norte (Northern Mariana Islands)"), | ||
| 197 | + ("Ilhas Marshall (Marshall Islands)"), | ||
| 198 | + ("Ilhas Maurício (Mauritius)"), | ||
| 199 | + ("Ilhas Reunião (Reunion)"), | ||
| 200 | + ("Ilhas Salomão (Solomon Islands)"), | ||
| 201 | + ("Ilhas Svalbard e Jan Mayen (Svalbard and Jan Mayen)"), | ||
| 202 | + ("Ilhas Tokelau (Tokelau)"), | ||
| 203 | + ("Ilhas Turks e Caicos (Turks and Caicos Islands)"), | ||
| 204 | + ("Ilhas Virgens, Britânicas (Virgin Islands, British)"), | ||
| 205 | + ("Ilhas Virgens, EUA (Virgin Islands, U.S.)"), | ||
| 206 | + ("Ilhas Wallis e Futuna (Wallis and Futuna)"), | ||
| 207 | + ("Índia (India)"), | ||
| 208 | + ("Indonésia (Indonesia)"), | ||
| 209 | + ("Irã (ایران)"), | ||
| 210 | + ("Iraque (العراق)"), | ||
| 211 | + ("Irlanda (Ireland)"), | ||
| 212 | + ("Islândia (Ísland)"), | ||
| 213 | + ("Israel (ישראל)"), | ||
| 214 | + ("Itália (Italia)"), | ||
| 215 | + ("Jamaica"), | ||
| 216 | + ("Japão (日本)"), | ||
| 217 | + ("Jordânia (الارد)"), | ||
| 218 | + ("Kiribati"), | ||
| 219 | + ("Kuwait (الكويت)"), | ||
| 220 | + ("Laos (ນລາວ)"), | ||
| 221 | + ("Lesoto (Lesotho)"), | ||
| 222 | + ("Letônia (Latvija)"), | ||
| 223 | + ("Líbano (لبنان)"), | ||
| 224 | + ("Libéria (Liberia)"), | ||
| 225 | + ("Líbia (ليبية)"), | ||
| 226 | + ("Liechtenstein"), | ||
| 227 | + ("Lituânia (Lietuva)"), | ||
| 228 | + ("Luxemburgo (Lëtzebuerg)"), | ||
| 229 | + ("Macau (Macao)"), | ||
| 230 | + ("Macedônia (Македонија)"), | ||
| 231 | + ("Madagáscar (Madagasikara)"), | ||
| 232 | + ("Maiote (Mayotte)"), | ||
| 233 | + ("Malásia (Malaysia)"), | ||
| 234 | + ("Malavi (Malawi)"), | ||
| 235 | + ("Maldivas (ގުޖޭއްރާ ޔާއްރިހޫމްޖ)"), | ||
| 236 | + ("Mali"), | ||
| 237 | + ("Malta"), | ||
| 238 | + ("Marrocos (مغرب)"), | ||
| 239 | + ("Martinica (Martinique)"), | ||
| 240 | + ("Mauritânia (موريتانية)"), | ||
| 241 | + ("México"), | ||
| 242 | + ("Micronésia (Micronesia)"), | ||
| 243 | + ("Moçambique"), | ||
| 244 | + ("Moldávia (Moldova)"), | ||
| 245 | + ("Mônaco (Monaco)"), | ||
| 246 | + ("Mongólia (Монгол Улс)"), | ||
| 247 | + ("Montserrat"), | ||
| 248 | + ("Myanmar (Լեռնային Ղարաբաղ)"), | ||
| 249 | + ("Namíbia (Namibia)"), | ||
| 250 | + ("Nauru (Naoero)"), | ||
| 251 | + ("Nepal (नेपाल)"), | ||
| 252 | + ("Nicarágua (Nicaragua)"), | ||
| 253 | + ("Níger (Niger)"), | ||
| 254 | + ("Nigéria (Nigeria)"), | ||
| 255 | + ("Niue"), | ||
| 256 | + ("Noruega (Norge)"), | ||
| 257 | + ("Nova Caledônia (New Caledonia)"), | ||
| 258 | + ("Nova Jérsei (Jersey)"), | ||
| 259 | + ("Nova Zelândia (New Zealand)"), | ||
| 260 | + ("Omã (عمان)"), | ||
| 261 | + ("Palau (Belau)"), | ||
| 262 | + ("Palestina (Palestine)"), | ||
| 263 | + ("Panamá"), | ||
| 264 | + ("Papua-Nova Guiné (Papua New Guinea)"), | ||
| 265 | + ("Paquistão (پاکستان)"), | ||
| 266 | + ("Paraguai (Paraguay)"), | ||
| 267 | + ("Peru (Perú)"), | ||
| 268 | + ("Pitcairn"), | ||
| 269 | + ("Polinésia Francesa (French Polynesia)"), | ||
| 270 | + ("Polônia (Polska)"), | ||
| 271 | + ("Porto Rico (Puerto Rico)"), | ||
| 272 | + ("Portugal"), | ||
| 273 | + ("Quênia (Kenya)"), | ||
| 274 | + ("Quirquistão (Кыргызстан)"), | ||
| 275 | + ("Reino Unido (United Kingdom)"), | ||
| 276 | + ("República Centro-Africana (République Centrafricaine)"), | ||
| 277 | + ("República Dominicana (Dominican Republic)"), | ||
| 278 | + ("República Tcheca (Česko)"), | ||
| 279 | + ("Romênia (România)"), | ||
| 280 | + ("Ruanda (Rwanda)"), | ||
| 281 | + ("Rússia (Россия)"), | ||
| 282 | + ("Saara Ocidental (صحراوية)"), | ||
| 283 | + ("Samoa"), | ||
| 284 | + ("Samoa Americana (American Samoa)"), | ||
| 285 | + ("San Marino"), | ||
| 286 | + ("Santa Helena (Saint Helena)"), | ||
| 287 | + ("Santa Lúcia (Saint Lucia)"), | ||
| 288 | + ("São Cristóvão e Névis (Saint Kitts and Nevis)"), | ||
| 289 | + ("São Pierre e Miquelon (Saint Pierre and Miquelon)"), | ||
| 290 | + ("São Tomé e Príncipe (São Tomé and Príncipe)"), | ||
| 291 | + ("São Vincente e Granadinas (Saint Vincent and the Grenadines)"), | ||
| 292 | + ("Seicheles (Seychelles)"), | ||
| 293 | + ("Senegal (Sénégal)"), | ||
| 294 | + ("Serra Leoa (Sierra Leone)"), | ||
| 295 | + ("Sérvia e Montenegro (Србија и Црна Гора)"), | ||
| 296 | + ("Síria (سورية)"), | ||
| 297 | + ("Somália (Soomaaliya)"), | ||
| 298 | + ("Sri Lanka"), | ||
| 299 | + ("Suazilândia (Swaziland)"), | ||
| 300 | + ("Sudão (السودان)"), | ||
| 301 | + ("Suécia (Sverige)"), | ||
| 302 | + ("Suíça (Schweiz)"), | ||
| 303 | + ("Suriname"), | ||
| 304 | + ("Tailândia (ราชอาณาจักรไทย)"), | ||
| 305 | + ("Taiwan (台灣)"), | ||
| 306 | + ("Tajiquistão (Тоҷикистон)"), | ||
| 307 | + ("Tanzânia (Tanzania)"), | ||
| 308 | + ("Território Britânico do Oceano Índico (British Indian Ocean Territory)"), | ||
| 309 | + ("Territórios Franceses do Sul (French Southern Territories)"), | ||
| 310 | + ("Territórios Insulares dos Estados Unidos (United States minor outlying islands)"), | ||
| 311 | + ("Timor Leste (Timor-Leste)"), | ||
| 312 | + ("Togo"), | ||
| 313 | + ("Tonga"), | ||
| 314 | + ("Trinidad e Tobago (Trinidad and Tobago)"), | ||
| 315 | + ("Tunísia (تونس)"), | ||
| 316 | + ("Turcomenistão (Türkmenistan)"), | ||
| 317 | + ("Turquia (Türkiye)"), | ||
| 318 | + ("Tuvalu"), | ||
| 319 | + ("Ucrânia (Україна)"), | ||
| 320 | + ("Uganda"), | ||
| 321 | + ("Uruguai (Uruguay)"), | ||
| 322 | + ("Uzbequistão (O'zbekiston)"), | ||
| 323 | + ("Vanuatu"), | ||
| 324 | + ("Venezuela"), | ||
| 325 | + ("Vietnã (Việt Nam)"), | ||
| 326 | + ("Zâmbia (Zambia)"), | ||
| 327 | + ("Zimbábue (Zimbabwe)") | ||
| 328 | + ] | ||
| 329 | + | ||
| 330 | + SCHOOLING = [ | ||
| 331 | + N_('Post-Doctoral'), | ||
| 332 | + N_('Ph.D.'), | ||
| 333 | + N_('Masters'), | ||
| 334 | + N_('Undergraduate'), | ||
| 335 | + N_('Graduate'), | ||
| 336 | + N_('High School'), | ||
| 337 | + N_('Elementary School') | ||
| 338 | + ] | ||
| 339 | + | ||
| 340 | + SCHOOLING_STATUS = [ | ||
| 341 | + N_('Concluded'), | ||
| 342 | + N_('Incomplete'), | ||
| 343 | + N_('Ongoing') | ||
| 344 | + ] | ||
| 345 | + | ||
| 346 | + def select_area(title, object, method, options) | ||
| 347 | + labelled_form_field(title, select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::AREAS_OF_STUDY.map{|s| [gettext(s), s]}, {}, options)) | ||
| 348 | + end | ||
| 349 | + | ||
| 350 | + def select_country(title, object, method, options) | ||
| 351 | + labelled_form_field(title, select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::COUNTRIES.map{|s| [s]}, {}, options)) | ||
| 352 | + end | ||
| 353 | + | ||
| 354 | + def select_schooling(object, method, options) | ||
| 355 | + select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::SCHOOLING.map{|s| [gettext(s), s]}, {}, options) | ||
| 356 | + end | ||
| 357 | + | ||
| 358 | + def select_schooling_status(object, method, options) | ||
| 359 | + select(object, method, [[_('[Select ...]'), nil]] + ProfileEditorHelper::SCHOOLING_STATUS.map{|s| [gettext(s), s]}, {}, options) | ||
| 360 | + end | ||
| 361 | + | ||
| 362 | +end |
app/models/community.rb
| 1 | class Community < Organization | 1 | class Community < Organization |
| 2 | N_('Community') | 2 | N_('Community') |
| 3 | + N_('Language') | ||
| 3 | 4 | ||
| 4 | settings_items :description | 5 | settings_items :description |
| 6 | + settings_items :language | ||
| 5 | 7 | ||
| 6 | xss_terminate :only => [ :name, :address, :contact_phone, :description ] | 8 | xss_terminate :only => [ :name, :address, :contact_phone, :description ] |
| 7 | 9 | ||
| 10 | + FIELDS = %w[ | ||
| 11 | + description | ||
| 12 | + language | ||
| 13 | + ] | ||
| 14 | + | ||
| 15 | + def self.fields | ||
| 16 | + super + FIELDS | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + def validate | ||
| 20 | + self.required_fields.each do |field| | ||
| 21 | + if self.send(field).blank? | ||
| 22 | + self.errors.add(field, _('%{fn} is mandatory')) | ||
| 23 | + end | ||
| 24 | + end | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def active_fields | ||
| 28 | + environment ? environment.active_community_fields : [] | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + def required_fields | ||
| 32 | + environment ? environment.required_community_fields : [] | ||
| 33 | + end | ||
| 34 | + | ||
| 8 | def name=(value) | 35 | def name=(value) |
| 9 | super(value) | 36 | super(value) |
| 10 | self.identifier = value.to_slug | 37 | self.identifier = value.to_slug |
app/models/enterprise.rb
| @@ -8,6 +8,40 @@ class Enterprise < Organization | @@ -8,6 +8,40 @@ class Enterprise < Organization | ||
| 8 | 8 | ||
| 9 | extra_data_for_index :product_categories | 9 | extra_data_for_index :product_categories |
| 10 | 10 | ||
| 11 | + N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') | ||
| 12 | + | ||
| 13 | + settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country | ||
| 14 | + | ||
| 15 | + FIELDS = %w[ | ||
| 16 | + zip_code | ||
| 17 | + city | ||
| 18 | + state | ||
| 19 | + country | ||
| 20 | + organization_website | ||
| 21 | + historic_and_current_context | ||
| 22 | + activities_short_description | ||
| 23 | + ] | ||
| 24 | + | ||
| 25 | + def self.fields | ||
| 26 | + super + FIELDS | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + def validate | ||
| 30 | + self.required_fields.each do |field| | ||
| 31 | + if self.send(field).blank? | ||
| 32 | + self.errors.add(field, _('%{fn} is mandatory')) | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | + def active_fields | ||
| 38 | + environment ? environment.active_enterprise_fields : [] | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | + def required_fields | ||
| 42 | + environment ? environment.required_enterprise_fields : [] | ||
| 43 | + end | ||
| 44 | + | ||
| 11 | def product_categories | 45 | def product_categories |
| 12 | products.map{|p| p.category_full_name}.compact | 46 | products.map{|p| p.category_full_name}.compact |
| 13 | end | 47 | end |
app/models/environment.rb
| @@ -32,6 +32,8 @@ class Environment < ActiveRecord::Base | @@ -32,6 +32,8 @@ class Environment < ActiveRecord::Base | ||
| 32 | 'disable_categories' => _('Disable categories'), | 32 | 'disable_categories' => _('Disable categories'), |
| 33 | 'disable_cms' => _('Disable CMS'), | 33 | 'disable_cms' => _('Disable CMS'), |
| 34 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), | 34 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), |
| 35 | + 'disable_gender_icon' => _('Disable gender icon'), | ||
| 36 | + 'disable_categories_menu' => _('Disable the categories menu'), | ||
| 35 | } | 37 | } |
| 36 | end | 38 | end |
| 37 | 39 | ||
| @@ -231,6 +233,109 @@ class Environment < ActiveRecord::Base | @@ -231,6 +233,109 @@ class Environment < ActiveRecord::Base | ||
| 231 | end | 233 | end |
| 232 | end | 234 | end |
| 233 | 235 | ||
| 236 | + def custom_person_fields | ||
| 237 | + self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields] | ||
| 238 | + end | ||
| 239 | + | ||
| 240 | + def custom_person_fields=(values) | ||
| 241 | + if values['schooling'] && values['schooling']['active'] == 'true' | ||
| 242 | + schooling_status = values['schooling'] | ||
| 243 | + end | ||
| 244 | + self.settings[:custom_person_fields] = values.delete_if { |key, value| ! Person.fields.include?(key)} | ||
| 245 | + if schooling_status | ||
| 246 | + self.settings[:custom_person_fields]['schooling_status'] = schooling_status | ||
| 247 | + end | ||
| 248 | + end | ||
| 249 | + | ||
| 250 | + def custom_person_field(field, status) | ||
| 251 | + if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') | ||
| 252 | + return true | ||
| 253 | + end | ||
| 254 | + false | ||
| 255 | + end | ||
| 256 | + | ||
| 257 | + def active_person_fields | ||
| 258 | + (custom_person_fields.delete_if { |key, value| !custom_person_field(key, 'active')}).keys || [] | ||
| 259 | + end | ||
| 260 | + | ||
| 261 | + def required_person_fields | ||
| 262 | + required_fields = [] | ||
| 263 | + active_person_fields.each do |field| | ||
| 264 | + required_fields << field if custom_person_fields[field]['required'] == 'true' | ||
| 265 | + end | ||
| 266 | + required_fields | ||
| 267 | + end | ||
| 268 | + | ||
| 269 | + def signup_person_fields | ||
| 270 | + signup_fields = [] | ||
| 271 | + active_person_fields.each do |field| | ||
| 272 | + signup_fields << field if custom_person_fields[field]['signup'] == 'true' | ||
| 273 | + end | ||
| 274 | + signup_fields | ||
| 275 | + end | ||
| 276 | + | ||
| 277 | + def custom_enterprise_fields | ||
| 278 | + self.settings[:custom_enterprise_fields].nil? ? {} : self.settings[:custom_enterprise_fields] | ||
| 279 | + end | ||
| 280 | + | ||
| 281 | + def custom_enterprise_fields=(values) | ||
| 282 | + self.settings[:custom_enterprise_fields] = values.delete_if { |key, value| ! Enterprise.fields.include?(key)} | ||
| 283 | + end | ||
| 284 | + | ||
| 285 | + def custom_enterprise_field(field, status) | ||
| 286 | + if (custom_enterprise_fields[field] && custom_enterprise_fields[field][status] == 'true') | ||
| 287 | + return true | ||
| 288 | + end | ||
| 289 | + false | ||
| 290 | + end | ||
| 291 | + | ||
| 292 | + def active_enterprise_fields | ||
| 293 | + (custom_enterprise_fields.delete_if { |key, value| !custom_enterprise_field(key, 'active')}).keys || [] | ||
| 294 | + end | ||
| 295 | + | ||
| 296 | + def required_enterprise_fields | ||
| 297 | + required_fields = [] | ||
| 298 | + active_enterprise_fields.each do |field| | ||
| 299 | + required_fields << field if custom_enterprise_fields[field]['required'] == 'true' | ||
| 300 | + end | ||
| 301 | + required_fields | ||
| 302 | + end | ||
| 303 | + | ||
| 304 | + def custom_community_fields | ||
| 305 | + self.settings[:custom_community_fields].nil? ? {} : self.settings[:custom_community_fields] | ||
| 306 | + end | ||
| 307 | + | ||
| 308 | + def custom_community_fields=(values) | ||
| 309 | + self.settings[:custom_community_fields] = values.delete_if { |key, value| ! Community.fields.include?(key)} | ||
| 310 | + end | ||
| 311 | + | ||
| 312 | + def custom_community_field(field, status) | ||
| 313 | + if (custom_community_fields[field] && custom_community_fields[field][status] == 'true') | ||
| 314 | + return true | ||
| 315 | + end | ||
| 316 | + false | ||
| 317 | + end | ||
| 318 | + | ||
| 319 | + def active_community_fields | ||
| 320 | + (custom_community_fields.delete_if { |key, value| !custom_community_field(key, 'active')}).keys | ||
| 321 | + end | ||
| 322 | + | ||
| 323 | + def required_community_fields | ||
| 324 | + required_fields = [] | ||
| 325 | + active_community_fields.each do |field| | ||
| 326 | + required_fields << field if custom_community_fields[field]['required'] == 'true' | ||
| 327 | + end | ||
| 328 | + required_fields | ||
| 329 | + end | ||
| 330 | + | ||
| 331 | + def category_types | ||
| 332 | + self.settings[:category_types].nil? ? ['Category'] : self.settings[:category_types] | ||
| 333 | + end | ||
| 334 | + | ||
| 335 | + def category_types=(values) | ||
| 336 | + self.settings[:category_types] = values | ||
| 337 | + end | ||
| 338 | + | ||
| 234 | # Whether this environment should force having 'www.' in its domain name or | 339 | # Whether this environment should force having 'www.' in its domain name or |
| 235 | # not. Defauls to false. | 340 | # not. Defauls to false. |
| 236 | # | 341 | # |
app/models/organization.rb
| @@ -43,6 +43,29 @@ class Organization < Profile | @@ -43,6 +43,29 @@ class Organization < Profile | ||
| 43 | !self.validation_info.nil? | 43 | !self.validation_info.nil? |
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | + FIELDS = %w[ | ||
| 47 | + nickname | ||
| 48 | + contact_person | ||
| 49 | + contact_phone | ||
| 50 | + contact_email | ||
| 51 | + legal_form | ||
| 52 | + economic_activity | ||
| 53 | + management_information | ||
| 54 | + address | ||
| 55 | + ] | ||
| 56 | + | ||
| 57 | + def self.fields | ||
| 58 | + FIELDS | ||
| 59 | + end | ||
| 60 | + | ||
| 61 | + def required_fields | ||
| 62 | + [] | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | + def active_fields | ||
| 66 | + [] | ||
| 67 | + end | ||
| 68 | + | ||
| 46 | N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Validated') | 69 | N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Validated') |
| 47 | settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj | 70 | settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj |
| 48 | 71 |
app/models/person.rb
| @@ -41,6 +41,70 @@ class Person < Profile | @@ -41,6 +41,70 @@ class Person < Profile | ||
| 41 | friends.delete(friend) | 41 | friends.delete(friend) |
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | + FIELDS = %w[ | ||
| 45 | + nickname | ||
| 46 | + sex | ||
| 47 | + address | ||
| 48 | + zip_code | ||
| 49 | + city | ||
| 50 | + state | ||
| 51 | + country | ||
| 52 | + nationality | ||
| 53 | + birth_date | ||
| 54 | + cell_phone | ||
| 55 | + comercial_phone | ||
| 56 | + schooling | ||
| 57 | + professional_activity | ||
| 58 | + organization | ||
| 59 | + organization_website | ||
| 60 | + area_of_study | ||
| 61 | + custom_area_of_study | ||
| 62 | + formation | ||
| 63 | + custom_formation | ||
| 64 | + contact_phone | ||
| 65 | + contact_information | ||
| 66 | + ] | ||
| 67 | + | ||
| 68 | + def self.fields | ||
| 69 | + FIELDS | ||
| 70 | + end | ||
| 71 | + | ||
| 72 | + def validate | ||
| 73 | + self.required_fields.each do |field| | ||
| 74 | + if self.send(field).blank? | ||
| 75 | + unless (field == 'custom_area_of_study' && self.area_of_study != 'Others') || (field == 'custom_formation' && self.formation != 'Others') | ||
| 76 | + self.errors.add(field, _('%{fn} is mandatory')) | ||
| 77 | + end | ||
| 78 | + end | ||
| 79 | + end | ||
| 80 | + end | ||
| 81 | + | ||
| 82 | + before_save do |person| | ||
| 83 | + person.custom_formation = nil if (! person.formation.nil? && person.formation != 'Others') | ||
| 84 | + person.custom_area_of_study = nil if (! person.area_of_study.nil? && person.area_of_study != 'Others') | ||
| 85 | + end | ||
| 86 | + | ||
| 87 | + def active_fields | ||
| 88 | + environment ? environment.active_person_fields : [] | ||
| 89 | + end | ||
| 90 | + | ||
| 91 | + def required_fields | ||
| 92 | + environment ? environment.required_person_fields : [] | ||
| 93 | + end | ||
| 94 | + | ||
| 95 | + def signup_fields | ||
| 96 | + environment ? environment.signup_person_fields : [] | ||
| 97 | + end | ||
| 98 | + | ||
| 99 | + N_('Cell phone'); N_('Comercial phone'); N_('Nationality'); N_('Schooling'); N_('Area of study'); N_('Professional activity'); N_('Organization'); N_('Organization website'); | ||
| 100 | + settings_items :cell_phone, :comercial_phone, :nationality, :schooling, :area_of_study, :professional_activity, :organization, :organization_website | ||
| 101 | + | ||
| 102 | + N_('Schooling status') | ||
| 103 | + settings_items :schooling_status | ||
| 104 | + | ||
| 105 | + N_('Formation'); N_('Custom formation'); N_('Custom area of study'); | ||
| 106 | + settings_items :formation, :custom_formation, :custom_area_of_study | ||
| 107 | + | ||
| 44 | N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code') | 108 | N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code') |
| 45 | settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country, :zip_code | 109 | settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country, :zip_code |
| 46 | 110 |
app/models/user.rb
| @@ -28,6 +28,13 @@ class User < ActiveRecord::Base | @@ -28,6 +28,13 @@ class User < ActiveRecord::Base | ||
| 28 | user.person.name ||= user.login | 28 | user.person.name ||= user.login |
| 29 | user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) | 29 | user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) |
| 30 | end | 30 | end |
| 31 | + | ||
| 32 | + def signup! | ||
| 33 | + User.transaction do | ||
| 34 | + self.save! | ||
| 35 | + self.person.save! | ||
| 36 | + end | ||
| 37 | + end | ||
| 31 | 38 | ||
| 32 | has_one :person, :dependent => :destroy | 39 | has_one :person, :dependent => :destroy |
| 33 | belongs_to :environment | 40 | belongs_to :environment |
app/views/account/_signup_form.rhtml
| 1 | -<%= error_messages_for :user %> | 1 | +<%= error_messages_for :user, :person %> |
| 2 | + | ||
| 3 | +<% if ! defined? hidden_atention || ! hidden_atention %> | ||
| 4 | +<p/> | ||
| 5 | +<div class="atention"> | ||
| 6 | +<%= _('Dear user, welcome to the %s network. To start your participation | ||
| 7 | +in this space, fill in the fields below. After this operation, your login and | ||
| 8 | +password will be registered, allowing you to create communities and enterprises | ||
| 9 | +in this environment.') % environment.name %> | ||
| 10 | +</div> | ||
| 11 | +<% end %> | ||
| 2 | 12 | ||
| 3 | <% labelled_form_for :user, @user, | 13 | <% labelled_form_for :user, @user, |
| 4 | :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)'), :id => 'profile-data' | 14 | :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)'), :id => 'profile-data' |
| @@ -22,6 +32,10 @@ | @@ -22,6 +32,10 @@ | ||
| 22 | :help => help=_('To confirm, repeat your password.')) %> | 32 | :help => help=_('To confirm, repeat your password.')) %> |
| 23 | <small><%= help %></small> | 33 | <small><%= help %></small> |
| 24 | 34 | ||
| 35 | +<% labelled_fields_for :profile_data, @person do |f| %> | ||
| 36 | + <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> | ||
| 37 | +<% end %> | ||
| 38 | + | ||
| 25 | <%= icaptcha_field() %> | 39 | <%= icaptcha_field() %> |
| 26 | 40 | ||
| 27 | <% if @terms_of_use %> | 41 | <% if @terms_of_use %> |
| @@ -41,16 +55,6 @@ | @@ -41,16 +55,6 @@ | ||
| 41 | <%= hidden_field_tag :new_user, true %> | 55 | <%= hidden_field_tag :new_user, true %> |
| 42 | <% end %> | 56 | <% end %> |
| 43 | 57 | ||
| 44 | -<% if ! defined? hidden_atention || ! hidden_atention %> | ||
| 45 | -<p/> | ||
| 46 | -<div class="atention"> | ||
| 47 | -<%= _('Dear user, welcome to the %s network. To start your participation | ||
| 48 | -in this space, fill in the fields below. After this operation, your login and | ||
| 49 | -password will be registered, allowing you to create communities and enterprises | ||
| 50 | -in this environment.') % environment.name %> | ||
| 51 | -</div> | ||
| 52 | -<% end %> | ||
| 53 | - | ||
| 54 | <% button_bar do %> | 58 | <% button_bar do %> |
| 55 | <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> | 59 | <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> |
| 56 | <% end %> | 60 | <% end %> |
app/views/admin_panel/index.rhtml
| @@ -11,4 +11,6 @@ | @@ -11,4 +11,6 @@ | ||
| 11 | <li><%= link_to _('Manage User roles'), :controller => 'role' %></li> | 11 | <li><%= link_to _('Manage User roles'), :controller => 'role' %></li> |
| 12 | <li><%= link_to _('Manage Validators by region'), :controller => 'region_validators' %></li> | 12 | <li><%= link_to _('Manage Validators by region'), :controller => 'region_validators' %></li> |
| 13 | <li><%= link_to _('Manage Templates'), :action => 'manage_templates' %></li> | 13 | <li><%= link_to _('Manage Templates'), :action => 'manage_templates' %></li> |
| 14 | + <li><%= link_to _('Edit Templates'), :action => 'edit_templates' %></li> | ||
| 15 | + <li><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></li> | ||
| 14 | </ul> | 16 | </ul> |
app/views/categories/_form.rhtml
| @@ -9,11 +9,15 @@ | @@ -9,11 +9,15 @@ | ||
| 9 | <%= hidden_field_tag('parent_id', @category.parent.id) %> | 9 | <%= hidden_field_tag('parent_id', @category.parent.id) %> |
| 10 | <%= hidden_field_tag('type', @category.parent.class.name) %> | 10 | <%= hidden_field_tag('type', @category.parent.class.name) %> |
| 11 | <% else %> | 11 | <% else %> |
| 12 | - <%= select_category_type :type %> | 12 | + <% if environment.category_types.length > 1 %> |
| 13 | + <%= select_category_type :type %> | ||
| 14 | + <% else %> | ||
| 15 | + <%= hidden_field_tag('type', environment.category_types.to_s) %> | ||
| 16 | + <% end%> | ||
| 13 | <% end %> | 17 | <% end %> |
| 14 | <% end %> | 18 | <% end %> |
| 15 | 19 | ||
| 16 | - <%= select_color_for_category %> | 20 | + <%= select_color_for_category if !environment.enabled?('disable_categories_menu') %> |
| 17 | 21 | ||
| 18 | <%= required f.text_field('name') %> | 22 | <%= required f.text_field('name') %> |
| 19 | 23 |
| @@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
| 1 | +<h2><%= _('Manage community fields') %></h2> | ||
| 2 | + | ||
| 3 | +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_community_fields'}) do |f| %> | ||
| 4 | + | ||
| 5 | +<table id='community_fields_conf'> | ||
| 6 | + <tr> | ||
| 7 | + <th><%= _('Field') %></th> | ||
| 8 | + <th><%= _('Active') %></th> | ||
| 9 | + <th><%= _('Required') %></th> | ||
| 10 | + </tr> | ||
| 11 | + <% @community_fields.each do |field| %> | ||
| 12 | + <tr> | ||
| 13 | + <td><label for="community_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> | ||
| 14 | + <td> | ||
| 15 | + <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "$('community_fields[#{field}][required]').disabled=!this.checked" %> | ||
| 16 | + <%= hidden_field_tag "community_fields[#{field}][active]", false %> | ||
| 17 | + </td> | ||
| 18 | + <td> | ||
| 19 | + <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required') %> | ||
| 20 | + <%= hidden_field_tag "community_fields[#{field}][required]", false %> | ||
| 21 | + </td> | ||
| 22 | + </tr> | ||
| 23 | + <% end %> | ||
| 24 | +</table> | ||
| 25 | + | ||
| 26 | +<script type='text/javascript'> | ||
| 27 | + var trs = $$('#community_fields_conf tr'); | ||
| 28 | + var tr, td2; | ||
| 29 | + for ( var i=0; tr=trs[i]; i++ ) { | ||
| 30 | + if ( td2 = tr.getElementsByTagName('td')[1] ) { | ||
| 31 | + td2.getElementsByTagName('input')[0].onclick(); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | +</script> | ||
| 35 | + | ||
| 36 | +<div> | ||
| 37 | + <% button_bar do %> | ||
| 38 | + <%= submit_button('save', _('Save changes')) %> | ||
| 39 | + <% end %> | ||
| 40 | +</div> | ||
| 41 | + | ||
| 42 | +<% end %> | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + |
| @@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
| 1 | +<h2><%= _('Manage enterprise fields') %></h2> | ||
| 2 | + | ||
| 3 | +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_enterprise_fields'}) do |f| %> | ||
| 4 | + | ||
| 5 | +<table id='enterprise_fields_conf'> | ||
| 6 | + <tr> | ||
| 7 | + <th><%= _('Field') %></th> | ||
| 8 | + <th><%= _('Active') %></th> | ||
| 9 | + <th><%= _('Required') %></th> | ||
| 10 | + </tr> | ||
| 11 | + <% @enterprise_fields.each do |field| %> | ||
| 12 | + <tr> | ||
| 13 | + <td><label for="enterprise_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> | ||
| 14 | + <td> | ||
| 15 | + <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "$('enterprise_fields[#{field}][required]').disabled=!this.checked" %> | ||
| 16 | + <%= hidden_field_tag "enterprise_fields[#{field}][active]", false %> | ||
| 17 | + </td> | ||
| 18 | + <td> | ||
| 19 | + <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required') %> | ||
| 20 | + <%= hidden_field_tag "enterprise_fields[#{field}][required]", false %> | ||
| 21 | + </td> | ||
| 22 | + </tr> | ||
| 23 | + <% end %> | ||
| 24 | +</table> | ||
| 25 | + | ||
| 26 | +<script type='text/javascript'> | ||
| 27 | + var trs = $$('#enterprise_fields_conf tr'); | ||
| 28 | + var tr, td2; | ||
| 29 | + for ( var i=0; tr=trs[i]; i++ ) { | ||
| 30 | + if ( td2 = tr.getElementsByTagName('td')[1] ) { | ||
| 31 | + td2.getElementsByTagName('input')[0].onclick(); | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | +</script> | ||
| 35 | + | ||
| 36 | +<div> | ||
| 37 | + <% button_bar do %> | ||
| 38 | + <%= submit_button('save', _('Save changes')) %> | ||
| 39 | + <% end %> | ||
| 40 | +</div> | ||
| 41 | + | ||
| 42 | +<% end %> | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + |
| @@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
| 1 | +<h2><%= _('Manage person fields') %></h2> | ||
| 2 | + | ||
| 3 | +<% labelled_form_for(:environment, @environment, :url => {:action => 'manage_person_fields'}) do |f| %> | ||
| 4 | + | ||
| 5 | +<table id='person_fields_conf'> | ||
| 6 | + <tr> | ||
| 7 | + <th><%= _('Field') %></th> | ||
| 8 | + <th><%= _('Active') %></th> | ||
| 9 | + <th><%= _('Required') %></th> | ||
| 10 | + <th><%= _('Display on signup?') %></th> | ||
| 11 | + </tr> | ||
| 12 | + <% @person_fields.each do |field| %> | ||
| 13 | + <tr> | ||
| 14 | + <td><label for="person_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> | ||
| 15 | + <td> | ||
| 16 | + <%= 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" %> | ||
| 17 | + <%= hidden_field_tag "person_fields[#{field}][active]", false %> | ||
| 18 | + </td> | ||
| 19 | + <td> | ||
| 20 | + <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required') %> | ||
| 21 | + <%= hidden_field_tag "person_fields[#{field}][required]", false %> | ||
| 22 | + </td> | ||
| 23 | + <td> | ||
| 24 | + <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup') %> | ||
| 25 | + <%= hidden_field_tag "person_fields[#{field}][signup]", false %> | ||
| 26 | + </td> | ||
| 27 | + </tr> | ||
| 28 | + <% end %> | ||
| 29 | +</table> | ||
| 30 | + | ||
| 31 | +<script type='text/javascript'>// <!-- | ||
| 32 | + var trs = $$('#person_fields_conf tr'); | ||
| 33 | + var tr, td2; | ||
| 34 | + for ( var i=0; tr=trs[i]; i++ ) { | ||
| 35 | + if ( td2 = tr.getElementsByTagName('td')[1] ) { | ||
| 36 | + td2.getElementsByTagName('input')[0].onclick(); | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + // --> | ||
| 40 | +</script> | ||
| 41 | + | ||
| 42 | +<div> | ||
| 43 | + <% button_bar do %> | ||
| 44 | + <%= submit_button('save', _('Save changes')) %> | ||
| 45 | + <% end %> | ||
| 46 | +</div> | ||
| 47 | + | ||
| 48 | +<% end %> | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + |
| @@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
| 1 | +<%= custom_field(@profile, 'contact_phone', f.text_field(:contact_phone)) %> | ||
| 2 | +<%= custom_field(@profile, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address))) %> | ||
| 3 | + | ||
| 4 | +<%= custom_field(@profile, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code))) %> | ||
| 5 | +<%= custom_field(@profile, 'city', f.text_field(:city)) %> | ||
| 6 | +<%= custom_field(@profile, 'state', f.text_field(:state)) %> | ||
| 7 | +<%= custom_field(@profile, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> | ||
| 8 | +<%= custom_field(@profile, 'organization_website', f.text_field(:organization_website)) %> | ||
| 9 | +<%= custom_field(@profile, 'historic_and_current_context', f.text_area(:historic_and_current_context, :rows => 5)) %> | ||
| 10 | +<%= custom_field(@profile, 'activities_short_description', f.text_area(:activities_short_description, :rows => 5)) %> | ||
| 11 | +<%= custom_field(@profile, 'management_information', f.text_area(:management_information, :rows => 5)) %> |
app/views/profile_editor/_organization.rhtml
| 1 | <h2><%= _('General information') %></h2> | 1 | <h2><%= _('General information') %></h2> |
| 2 | 2 | ||
| 3 | + <%= required_fields_message if @profile.required_fields.any? %> | ||
| 4 | + | ||
| 3 | <div class="formfieldline"> | 5 | <div class="formfieldline"> |
| 4 | <label class="formlabel" for="profile_data_nickname"><%= _('Display name') %></label> | 6 | <label class="formlabel" for="profile_data_nickname"><%= _('Display name') %></label> |
| 5 | <div class="formfield type-text"> | 7 | <div class="formfield type-text"> |
| @@ -9,13 +11,16 @@ | @@ -9,13 +11,16 @@ | ||
| 9 | 11 | ||
| 10 | </div> | 12 | </div> |
| 11 | <%= f.text_field(:acronym) %> | 13 | <%= f.text_field(:acronym) %> |
| 12 | - <%= f.text_field(:address, 'size' => 50) if @profile.enterprise? %> | ||
| 13 | <%= f.text_field(:foundation_year) %> | 14 | <%= f.text_field(:foundation_year) %> |
| 14 | - <%= f.text_field(:contact_person) %> | ||
| 15 | - <%= f.text_field(:contact_email) %> | ||
| 16 | - <%= f.text_field(:economic_activity) %> | ||
| 17 | - <%= f.text_area(:description, :rows => 5) if @profile.community? %> | 15 | + <%= custom_field(@profile, 'contact_person', f.text_field(:contact_person)) %> |
| 16 | + <%= custom_field(@profile, 'contact_email', f.text_field(:contact_email)) %> | ||
| 17 | + <%= custom_field(@profile, 'economic_activity', f.text_field(:economic_activity)) %> | ||
| 18 | + <%= custom_field(@profile, 'description', f.text_area(:description, :rows => 5)) if @profile.community? %> | ||
| 18 | <%= f.check_box(:enable_contact_us) if @profile.enterprise? %> | 19 | <%= f.check_box(:enable_contact_us) if @profile.enterprise? %> |
| 20 | + | ||
| 21 | + <%= render :partial => 'community_fields', :locals => { :f => f } if @profile.community? %> | ||
| 22 | + <%= render :partial => 'enterprise_fields', :locals => { :f => f } if @profile.enterprise? %> | ||
| 23 | + | ||
| 19 | <h1><%= _('Moderation options') %></h1> | 24 | <h1><%= _('Moderation options') %></h1> |
| 20 | <div style='margin-bottom: 1em'> | 25 | <div style='margin-bottom: 1em'> |
| 21 | <%= _('New members must be approved:')%> | 26 | <%= _('New members must be approved:')%> |
app/views/profile_editor/_person.rhtml
| 1 | <h2><%= _('Personal information') %></h2> | 1 | <h2><%= _('Personal information') %></h2> |
| 2 | 2 | ||
| 3 | - <%= f.text_field(:email)%> | 3 | + <%= required_fields_message %> |
| 4 | + | ||
| 5 | + <%= required f.text_field(:email)%> | ||
| 6 | + <%= labelled_form_field _('Full name'), text_field(:profile_data, :name) %> | ||
| 4 | 7 | ||
| 5 | <%= render :partial => 'person_form', :locals => {:f => f} %> | 8 | <%= render :partial => 'person_form', :locals => {:f => f} %> |
app/views/profile_editor/_person_form.rhtml
| 1 | -<%= f.text_field(:nickname, :maxlength => 16, :size => 30) %> | ||
| 2 | -<div> | ||
| 3 | - <small><em><%= _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') %></em></small> | ||
| 4 | -</div> | ||
| 5 | - | ||
| 6 | -<%= f.text_field(:name) %> | ||
| 7 | -<%= f.text_field(:contact_information) %> | ||
| 8 | -<%= f.text_field(:contact_phone) %> | ||
| 9 | -<%# use :size => 3 if you want 3 radios by line %> | ||
| 10 | -<%= f.radio_group :profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ] %> | ||
| 11 | -<%= f.text_field(:birth_date) %> | ||
| 12 | -<%= labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address)) %> | ||
| 13 | -<%= labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code)) %> | ||
| 14 | -<%= f.text_field(:city) %> | ||
| 15 | -<%= f.text_field(:state) %> | ||
| 16 | -<%= f.text_field(:country) %> | 1 | +<% @person ||= @profile %> |
| 2 | + | ||
| 3 | +<%= custom_field(@person, 'nickname', f.text_field(:nickname, :maxlength => 16, :size => 30)) %> | ||
| 4 | + | ||
| 5 | +<% nickname_tip = "<div><small><em>" + _('A short name by which you like to be known. Will be used in friends listings, community member listings etc.') + "</em></small></div>" %> | ||
| 6 | +<% if controller.action_name == 'signup' %> | ||
| 7 | + <% if @person.signup_fields.include?('nickname') %> | ||
| 8 | + <%= nickname_tip %> | ||
| 9 | + <% end%> | ||
| 10 | +<% elsif @person.active_fields.include?('nickname') %> | ||
| 11 | + <%= nickname_tip %> | ||
| 12 | +<% end %> | ||
| 13 | + | ||
| 14 | +<%= custom_field(@person, 'contact_information', f.text_field(:contact_information)) %> | ||
| 15 | +<%= custom_field(@person, 'contact_phone', labelled_form_field(_('Home phone'), text_field(:profile_data, :contact_phone))) %> | ||
| 16 | +<%= custom_field(@person, 'cell_phone', f.text_field(:cell_phone)) %> | ||
| 17 | +<%= custom_field(@person, 'comercial_phone', f.text_field(:comercial_phone)) %> | ||
| 18 | +<%= custom_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> | ||
| 19 | +<%= custom_field(@person, 'birth_date', f.text_field(:birth_date)) %> | ||
| 20 | +<%= custom_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address))) %> | ||
| 21 | +<%= custom_field(@person, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code))) %> | ||
| 22 | +<%= custom_field(@person, 'city', f.text_field(:city)) %> | ||
| 23 | +<%= custom_field(@person, 'state', f.text_field(:state)) %> | ||
| 24 | +<%= custom_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> | ||
| 25 | +<%= custom_field(@person, 'nationality', f.text_field(:nationality)) %> | ||
| 26 | + | ||
| 27 | +<% if @person.active_fields.include?('schooling') %> | ||
| 28 | + <% schooling_label = "<label class='formlabel' for='profile_data_schooling'>#{_('Schooling')}</label>" %> | ||
| 29 | + <div class="formfieldline"><%= @person.required_fields.include?('schooling') ? required(schooling_label) : schooling_label %> | ||
| 30 | + <div class="formfield type-select"> | ||
| 31 | + <%= custom_field(@person, 'schooling', select_schooling('profile_data', 'schooling', {:class => 'select-schooling'})) %> | ||
| 32 | + <%= custom_field(@person, 'schooling_status', select_schooling_status('profile_data', 'schooling_status', {:class => 'select-schooling'})) %> | ||
| 33 | + </div> | ||
| 34 | + </div> | ||
| 35 | +<% end %> | ||
| 36 | + | ||
| 37 | +<script type='text/javascript'> | ||
| 38 | + function toggle_text_field(id, span_id) { | ||
| 39 | + if ($(id).value == "Others") { | ||
| 40 | + $(span_id).show(); return false; | ||
| 41 | + } else { | ||
| 42 | + $(span_id).hide(); return false; | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | +</script> | ||
| 46 | + | ||
| 47 | +<%= custom_field(@person, 'formation', select_area(_('Formation'), 'profile_data', 'formation', {:class => 'type-select-full-line'})) %> | ||
| 48 | + | ||
| 49 | +<span id='profile_data_custom_formation_span' <%= "style='display:none'" if ! ['Others', nil].include?(@person.formation) %> > | ||
| 50 | + <%= custom_field(@person, 'custom_formation', f.text_field(:custom_formation)) %> | ||
| 51 | +</span> | ||
| 52 | +<%= observe_field 'profile_data_formation', :function =>'toggle_text_field("profile_data_formation", "profile_data_custom_formation_span")' %> | ||
| 53 | + | ||
| 54 | +<%= custom_field(@person, 'area_of_study', select_area(_('Area of study'), 'profile_data', 'area_of_study', {:class => 'type-select-full-line'})) %> | ||
| 55 | + | ||
| 56 | +<span id='profile_data_custom_area_of_study_span' <%= "style='display:none'" if ! ['Others', nil].include?(@person.area_of_study) %> > | ||
| 57 | + <%= custom_field(@person, 'custom_area_of_study', f.text_field(:custom_area_of_study)) %> | ||
| 58 | +</span> | ||
| 59 | +<%= observe_field 'profile_data_area_of_study', :function =>'toggle_text_field("profile_data_area_of_study", "profile_data_custom_area_of_study_span")' %> | ||
| 60 | + | ||
| 61 | +<%= custom_field(@person, 'professional_activity', f.text_field(:professional_activity)) %> | ||
| 62 | +<%= custom_field(@person, 'organization', f.text_field(:organization)) %> | ||
| 63 | +<%= custom_field(@person, 'organization_website', f.text_field(:organization_website)) %> | ||
| 64 | + |
app/views/profile_editor/edit.rhtml
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | <%= error_messages_for :profile %> | 3 | <%= error_messages_for :profile %> |
| 4 | 4 | ||
| 5 | -<% labelled_form_for :profile_data, @profile, :html => { :multipart => true } do |f| %> | 5 | +<% labelled_form_for :profile_data, @profile, :html => { :id => 'profile-data', :multipart => true } do |f| %> |
| 6 | 6 | ||
| 7 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> | 7 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> |
| 8 | 8 | ||
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | <%= _('This profile is:') %> | 18 | <%= _('This profile is:') %> |
| 19 | </p> | 19 | </p> |
| 20 | 20 | ||
| 21 | - <% if profile.kind_of?(Person) %> | 21 | + <% if profile.person? %> |
| 22 | <table> | 22 | <table> |
| 23 | <tr> | 23 | <tr> |
| 24 | <th></th> | 24 | <th></th> |
test/functional/account_controller_test.rb
| @@ -594,6 +594,12 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -594,6 +594,12 @@ class AccountControllerTest < Test::Unit::TestCase | ||
| 594 | assert_no_tag :tag => 'form', :attributes => { :action => /^https:\/\// } | 594 | assert_no_tag :tag => 'form', :attributes => { :action => /^https:\/\// } |
| 595 | end | 595 | end |
| 596 | 596 | ||
| 597 | + should 'render person partial' do | ||
| 598 | + Environment.any_instance.expects(:signup_person_fields).returns(['contact_phone']).at_least_once | ||
| 599 | + get :signup | ||
| 600 | + assert_tag :tag => 'input', :attributes => { :name => "profile_data[contact_phone]" } | ||
| 601 | + end | ||
| 602 | + | ||
| 597 | protected | 603 | protected |
| 598 | def new_user(options = {}, extra_options ={}) | 604 | def new_user(options = {}, extra_options ={}) |
| 599 | data = {:profile_data => person_data} | 605 | data = {:profile_data => person_data} |
test/functional/categories_controller_test.rb
| @@ -137,4 +137,41 @@ class CategoriesControllerTest < Test::Unit::TestCase | @@ -137,4 +137,41 @@ class CategoriesControllerTest < Test::Unit::TestCase | ||
| 137 | post :new, :category => { :display_in_menu => '1' } | 137 | post :new, :category => { :display_in_menu => '1' } |
| 138 | end | 138 | end |
| 139 | 139 | ||
| 140 | + should 'not display color selection if environment.categories_menu is false' do | ||
| 141 | + env.enable('disable_categories_menu') | ||
| 142 | + env.save! | ||
| 143 | + get :new | ||
| 144 | + | ||
| 145 | + assert_no_tag :tag => 'select', :attributes => { :name => "category[display_color]" } | ||
| 146 | + end | ||
| 147 | + | ||
| 148 | + should 'display color selection if environment.categories_menu is true' do | ||
| 149 | + env.disable('disable_categories_menu') | ||
| 150 | + env.save! | ||
| 151 | + get :new | ||
| 152 | + | ||
| 153 | + assert_tag :tag => 'select', :attributes => { :name => "category[display_color]" } | ||
| 154 | + end | ||
| 155 | + | ||
| 156 | + should 'not display category_type if only one category is available' do | ||
| 157 | + env.category_types = ['Category'] | ||
| 158 | + get :new | ||
| 159 | + | ||
| 160 | + assert_no_tag :tag => 'select', :attributes => { :name => "type" } | ||
| 161 | + end | ||
| 162 | + | ||
| 163 | + should 'have hidden_tag type if only one category is available' do | ||
| 164 | + env.category_types = ['Category'] | ||
| 165 | + env.save! | ||
| 166 | + get :new | ||
| 167 | + | ||
| 168 | + assert_tag :tag => 'input', :attributes => { :name => 'type', :value => "Category", :type => 'hidden' } | ||
| 169 | + end | ||
| 170 | + | ||
| 171 | + should 'display category_type if more than one category is available' do | ||
| 172 | + env.category_types = 'Category', 'ProductCategory' | ||
| 173 | + get :new | ||
| 174 | + | ||
| 175 | + assert_tag :tag => 'select', :attributes => { :name => "type" } | ||
| 176 | + end | ||
| 140 | end | 177 | end |
test/functional/features_controller_test.rb
| @@ -76,8 +76,78 @@ class FeaturesControllerTest < Test::Unit::TestCase | @@ -76,8 +76,78 @@ class FeaturesControllerTest < Test::Unit::TestCase | ||
| 76 | post :index | 76 | post :index |
| 77 | 77 | ||
| 78 | assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } } | 78 | assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } } |
| 79 | + end | ||
| 80 | + | ||
| 81 | + should 'list possible person fields' do | ||
| 82 | + uses_host 'anhetegua.net' | ||
| 83 | + Person.expects(:fields).returns(['cell_phone', 'comercial_phone']).at_least_once | ||
| 84 | + get :manage_fields | ||
| 85 | + assert_template 'manage_fields' | ||
| 86 | + Person.fields.each do |field| | ||
| 87 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][active]"}) | ||
| 88 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][required]"}) | ||
| 89 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "person_fields[#{field}][signup]"}) | ||
| 90 | + end | ||
| 91 | + end | ||
| 92 | + | ||
| 93 | + should 'update custom_person_fields' do | ||
| 94 | + uses_host 'anhetegua.net' | ||
| 95 | + e = Environment.find(2) | ||
| 96 | + Person.expects(:fields).returns(['cell_phone', 'comercial_phone']).at_least_once | ||
| 97 | + | ||
| 98 | + post :manage_person_fields, :person_fields => { :cell_phone => {:active => true, :required => true }} | ||
| 99 | + assert_redirected_to :action => 'manage_fields' | ||
| 100 | + e.reload | ||
| 101 | + assert_equal true, e.custom_person_fields['cell_phone']['active'] | ||
| 102 | + assert_equal true, e.custom_person_fields['cell_phone']['required'] | ||
| 103 | + end | ||
| 79 | 104 | ||
| 105 | + should 'disable check_box for required if active is not checked' | ||
| 106 | + | ||
| 107 | + should 'list possible enterprise fields' do | ||
| 108 | + uses_host 'anhetegua.net' | ||
| 109 | + Enterprise.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once | ||
| 110 | + get :manage_fields | ||
| 111 | + assert_template 'manage_fields' | ||
| 112 | + Enterprise.fields.each do |field| | ||
| 113 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "enterprise_fields[#{field}][active]"}) | ||
| 114 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "enterprise_fields[#{field}][required]"}) | ||
| 115 | + end | ||
| 116 | + end | ||
| 117 | + | ||
| 118 | + should 'update custom_enterprise_fields' do | ||
| 119 | + uses_host 'anhetegua.net' | ||
| 120 | + e = Environment.find(2) | ||
| 121 | + Enterprise.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once | ||
| 122 | + | ||
| 123 | + post :manage_enterprise_fields, :enterprise_fields => { :contact_person => {:active => true, :required => true }} | ||
| 124 | + assert_redirected_to :action => 'manage_fields' | ||
| 125 | + e.reload | ||
| 126 | + assert_equal true, e.custom_enterprise_fields['contact_person']['active'] | ||
| 127 | + assert_equal true, e.custom_enterprise_fields['contact_person']['required'] | ||
| 128 | + end | ||
| 129 | + | ||
| 130 | + should 'list possible community fields' do | ||
| 131 | + uses_host 'anhetegua.net' | ||
| 132 | + Community.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once | ||
| 133 | + get :manage_fields | ||
| 134 | + assert_template 'manage_fields' | ||
| 135 | + Community.fields.each do |field| | ||
| 136 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "community_fields[#{field}][active]"}) | ||
| 137 | + assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "community_fields[#{field}][required]"}) | ||
| 138 | + end | ||
| 139 | + end | ||
| 140 | + | ||
| 141 | + should 'update custom_community_fields' do | ||
| 142 | + uses_host 'anhetegua.net' | ||
| 143 | + e = Environment.find(2) | ||
| 144 | + Community.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once | ||
| 80 | 145 | ||
| 146 | + post :manage_community_fields, :community_fields => { :contact_person => {:active => true, :required => true }} | ||
| 147 | + assert_redirected_to :action => 'manage_fields' | ||
| 148 | + e.reload | ||
| 149 | + assert_equal true, e.custom_community_fields['contact_person']['active'] | ||
| 150 | + assert_equal true, e.custom_community_fields['contact_person']['required'] | ||
| 81 | end | 151 | end |
| 82 | 152 | ||
| 83 | end | 153 | end |
test/functional/profile_editor_controller_test.rb
| @@ -105,66 +105,68 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -105,66 +105,68 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 105 | end | 105 | end |
| 106 | 106 | ||
| 107 | should 'filter html from contact_person to organization' do | 107 | should 'filter html from contact_person to organization' do |
| 108 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 108 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 109 | contact = "name <strong id='name_html_test'>with</strong> html" | 109 | contact = "name <strong id='name_html_test'>with</strong> html" |
| 110 | post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact } | 110 | post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact } |
| 111 | assert_sanitized assigns(:profile).contact_person | 111 | assert_sanitized assigns(:profile).contact_person |
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | should 'filter html from acronym organization' do | 114 | should 'filter html from acronym organization' do |
| 115 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 115 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 116 | value = "name <strong id='name_html_test'>with</strong> html" | 116 | value = "name <strong id='name_html_test'>with</strong> html" |
| 117 | post :edit, :profile => org.identifier, :profile_data => { :acronym => value } | 117 | post :edit, :profile => org.identifier, :profile_data => { :acronym => value } |
| 118 | assert_sanitized assigns(:profile).acronym | 118 | assert_sanitized assigns(:profile).acronym |
| 119 | end | 119 | end |
| 120 | 120 | ||
| 121 | should 'filter html from legal_form organization' do | 121 | should 'filter html from legal_form organization' do |
| 122 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 122 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 123 | value = "name <strong id='name_html_test'>with</strong> html" | 123 | value = "name <strong id='name_html_test'>with</strong> html" |
| 124 | post :edit, :profile => org.identifier, :profile_data => { :legal_form => value } | 124 | post :edit, :profile => org.identifier, :profile_data => { :legal_form => value } |
| 125 | assert_sanitized assigns(:profile).legal_form | 125 | assert_sanitized assigns(:profile).legal_form |
| 126 | end | 126 | end |
| 127 | 127 | ||
| 128 | should 'filter html from economic_activity organization' do | 128 | should 'filter html from economic_activity organization' do |
| 129 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 129 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 130 | value = "name <strong id='name_html_test'>with</strong> html" | 130 | value = "name <strong id='name_html_test'>with</strong> html" |
| 131 | post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value } | 131 | post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value } |
| 132 | assert_sanitized assigns(:profile).economic_activity | 132 | assert_sanitized assigns(:profile).economic_activity |
| 133 | end | 133 | end |
| 134 | 134 | ||
| 135 | should 'filter html from management_information organization' do | 135 | should 'filter html from management_information organization' do |
| 136 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 136 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 137 | value = "name <strong id='name_html_test'>with</strong> html" | 137 | value = "name <strong id='name_html_test'>with</strong> html" |
| 138 | post :edit, :profile => org.identifier, :profile_data => { :management_information => value } | 138 | post :edit, :profile => org.identifier, :profile_data => { :management_information => value } |
| 139 | assert_sanitized assigns(:profile).management_information | 139 | assert_sanitized assigns(:profile).management_information |
| 140 | end | 140 | end |
| 141 | 141 | ||
| 142 | should 'saving profile organization_info' do | 142 | should 'saving profile organization_info' do |
| 143 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 143 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 144 | post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' } | 144 | post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' } |
| 145 | assert_equal 'contact person', Organization.find(org.id).contact_person | 145 | assert_equal 'contact person', Organization.find(org.id).contact_person |
| 146 | end | 146 | end |
| 147 | 147 | ||
| 148 | - should 'show contact_person field on edit organization' do | ||
| 149 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 148 | + should 'show contact_phone field on edit enterprise' do |
| 149 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) | ||
| 150 | + Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once | ||
| 150 | get :edit, :profile => org.identifier | 151 | get :edit, :profile => org.identifier |
| 151 | - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]' } | 152 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } |
| 152 | end | 153 | end |
| 153 | 154 | ||
| 154 | should 'save community description' do | 155 | should 'save community description' do |
| 155 | - org = Community.create!(:name => 'test org', :identifier => 'testorg') | 156 | + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 156 | post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } | 157 | post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } |
| 157 | assert_equal 'my description', Organization.find(org.id).description | 158 | assert_equal 'my description', Organization.find(org.id).description |
| 158 | end | 159 | end |
| 159 | 160 | ||
| 160 | should 'show community description' do | 161 | should 'show community description' do |
| 161 | - org = Community.create!(:name => 'test org', :identifier => 'testorg') | 162 | + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 163 | + Community.any_instance.expects(:active_fields).returns(['description']).at_least_once | ||
| 162 | get :edit, :profile => 'testorg' | 164 | get :edit, :profile => 'testorg' |
| 163 | assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } | 165 | assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } |
| 164 | end | 166 | end |
| 165 | 167 | ||
| 166 | - should 'not show organization description' do | ||
| 167 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 168 | + should 'not show enterprise description' do |
| 169 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) | ||
| 168 | get :edit, :profile => 'testorg' | 170 | get :edit, :profile => 'testorg' |
| 169 | assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } | 171 | assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } |
| 170 | end | 172 | end |
| @@ -176,13 +178,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -176,13 +178,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 176 | end | 178 | end |
| 177 | 179 | ||
| 178 | should 'save enterprise contact_person' do | 180 | should 'save enterprise contact_person' do |
| 179 | - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg') | 181 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 180 | post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } | 182 | post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } |
| 181 | assert_equal 'my contact', Enterprise.find(org.id).contact_person | 183 | assert_equal 'my contact', Enterprise.find(org.id).contact_person |
| 182 | end | 184 | end |
| 183 | 185 | ||
| 184 | - should 'show field values on edit organization info' do | ||
| 185 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 186 | + should 'show field values on edit community info' do |
| 187 | + Community.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once | ||
| 188 | + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) | ||
| 189 | + org.contact_person = 'my contact' | ||
| 190 | + org.save! | ||
| 191 | + get :edit, :profile => 'testorg' | ||
| 192 | + assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } | ||
| 193 | + end | ||
| 194 | + | ||
| 195 | + should 'show field values on edit enterprise info' do | ||
| 196 | + Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once | ||
| 197 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) | ||
| 186 | org.contact_person = 'my contact' | 198 | org.contact_person = 'my contact' |
| 187 | org.save! | 199 | org.save! |
| 188 | get :edit, :profile => 'testorg' | 200 | get :edit, :profile => 'testorg' |
| @@ -214,20 +226,27 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -214,20 +226,27 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 214 | end | 226 | end |
| 215 | 227 | ||
| 216 | should 'show error messages for invalid foundation_year' do | 228 | should 'show error messages for invalid foundation_year' do |
| 217 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg') | 229 | + org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) |
| 218 | post :edit, :profile => 'testorg', :profile_data => { :foundation_year => 'aaa' } | 230 | post :edit, :profile => 'testorg', :profile_data => { :foundation_year => 'aaa' } |
| 219 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } | 231 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } |
| 220 | end | 232 | end |
| 221 | 233 | ||
| 222 | should 'edit enterprise' do | 234 | should 'edit enterprise' do |
| 223 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent') | 235 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :environment => Environment.default) |
| 224 | get :edit, :profile => 'testent' | 236 | get :edit, :profile => 'testent' |
| 225 | assert_response :success | 237 | assert_response :success |
| 226 | end | 238 | end |
| 227 | 239 | ||
| 228 | - should 'back when update organization info fail' do | ||
| 229 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') | ||
| 230 | - Organization.any_instance.stubs(:update_attributes).returns(false) | 240 | + should 'back when update community info fail' do |
| 241 | + org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) | ||
| 242 | + Community.any_instance.stubs(:update_attributes).returns(false) | ||
| 243 | + post :edit, :profile => 'testorg' | ||
| 244 | + assert_template 'edit' | ||
| 245 | + end | ||
| 246 | + | ||
| 247 | + should 'back when update enterprise info fail' do | ||
| 248 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) | ||
| 249 | + Enterprise.any_instance.stubs(:update_attributes).returns(false) | ||
| 231 | post :edit, :profile => 'testorg' | 250 | post :edit, :profile => 'testorg' |
| 232 | assert_template 'edit' | 251 | assert_template 'edit' |
| 233 | end | 252 | end |
| @@ -259,9 +278,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -259,9 +278,22 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 259 | end | 278 | end |
| 260 | 279 | ||
| 261 | should 'render person partial' do | 280 | should 'render person partial' do |
| 281 | + person = create_user('test_profile', :environment => Environment.default).person | ||
| 282 | + Person.any_instance.expects(:active_fields).returns(['contact_phone', 'birth_date', 'address']).at_least_once | ||
| 283 | + get :edit, :profile => person.identifier | ||
| 284 | + person.active_fields.each do |field| | ||
| 285 | + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } | ||
| 286 | + end | ||
| 287 | + end | ||
| 288 | + | ||
| 289 | + should 'display only active person fields' do | ||
| 290 | + Person.any_instance.expects(:active_fields).returns(['cell_phone']).at_least_once | ||
| 262 | person = create_user('test_profile').person | 291 | person = create_user('test_profile').person |
| 292 | + | ||
| 263 | get :edit, :profile => person.identifier | 293 | get :edit, :profile => person.identifier |
| 264 | - assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } | 294 | + |
| 295 | + assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" } | ||
| 296 | + assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" } | ||
| 265 | end | 297 | end |
| 266 | 298 | ||
| 267 | should 'be able to upload an image' do | 299 | should 'be able to upload an image' do |
| @@ -271,8 +303,16 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -271,8 +303,16 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 271 | assert_not_nil assigns(:profile).image | 303 | assert_not_nil assigns(:profile).image |
| 272 | end | 304 | end |
| 273 | 305 | ||
| 306 | + should 'display closed attribute for enterprise when it is set' do | ||
| 307 | + org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default) | ||
| 308 | + get :edit, :profile => 'testorg' | ||
| 309 | + | ||
| 310 | + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } | ||
| 311 | + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } | ||
| 312 | + end | ||
| 313 | + | ||
| 274 | should 'display closed attribute for organizations when it is set' do | 314 | should 'display closed attribute for organizations when it is set' do |
| 275 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) | 315 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default) |
| 276 | get :edit, :profile => 'testorg' | 316 | get :edit, :profile => 'testorg' |
| 277 | 317 | ||
| 278 | assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } | 318 | assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } |
| @@ -311,7 +351,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -311,7 +351,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 311 | 351 | ||
| 312 | should 'display manage members options if has permission' do | 352 | should 'display manage members options if has permission' do |
| 313 | profile = Profile['ze'] | 353 | profile = Profile['ze'] |
| 314 | - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') | 354 | + community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) |
| 315 | @controller.stubs(:user).returns(profile) | 355 | @controller.stubs(:user).returns(profile) |
| 316 | @controller.stubs(:profile).returns(community) | 356 | @controller.stubs(:profile).returns(community) |
| 317 | profile.stubs(:has_permission?).returns(true) | 357 | profile.stubs(:has_permission?).returns(true) |
| @@ -321,7 +361,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -321,7 +361,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 321 | 361 | ||
| 322 | should 'not display manage members options if has no permission' do | 362 | should 'not display manage members options if has no permission' do |
| 323 | profile = Profile['ze'] | 363 | profile = Profile['ze'] |
| 324 | - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') | 364 | + community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) |
| 325 | @controller.stubs(:user).returns(profile) | 365 | @controller.stubs(:user).returns(profile) |
| 326 | @controller.stubs(:profile).returns(community) | 366 | @controller.stubs(:profile).returns(community) |
| 327 | profile.stubs(:has_permission?).returns(false) | 367 | profile.stubs(:has_permission?).returns(false) |
| @@ -329,6 +369,24 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -329,6 +369,24 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 329 | assert_no_tag :tag => 'a', :content => 'Manage Members' | 369 | assert_no_tag :tag => 'a', :content => 'Manage Members' |
| 330 | end | 370 | end |
| 331 | 371 | ||
| 372 | + should 'render enterprise partial' do | ||
| 373 | + ent = Enterprise.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) | ||
| 374 | + Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once | ||
| 375 | + get :edit, :profile => ent.identifier | ||
| 376 | + ent.active_fields.each do |field| | ||
| 377 | + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } | ||
| 378 | + end | ||
| 379 | + end | ||
| 380 | + | ||
| 381 | + should 'render community partial' do | ||
| 382 | + community = Community.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) | ||
| 383 | + Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once | ||
| 384 | + get :edit, :profile => community.identifier | ||
| 385 | + community.active_fields.each do |field| | ||
| 386 | + assert_tag :tag => 'input', :attributes => { :name => "profile_data[#{field}]" } | ||
| 387 | + end | ||
| 388 | + end | ||
| 389 | + | ||
| 332 | should 'show task if user has permission' do | 390 | should 'show task if user has permission' do |
| 333 | user1 = create_user('userone').person | 391 | user1 = create_user('userone').person |
| 334 | user2 = create_user('usertwo').person | 392 | user2 = create_user('usertwo').person |
| @@ -385,13 +443,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -385,13 +443,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 385 | end | 443 | end |
| 386 | 444 | ||
| 387 | should 'link to enable enterprise' do | 445 | should 'link to enable enterprise' do |
| 388 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) | 446 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) |
| 389 | get :index, :profile => 'testent' | 447 | get :index, :profile => 'testent' |
| 390 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } | 448 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } |
| 391 | end | 449 | end |
| 392 | 450 | ||
| 393 | should 'link to disable enterprise' do | 451 | should 'link to disable enterprise' do |
| 394 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) | 452 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) |
| 395 | get :index, :profile => 'testent' | 453 | get :index, :profile => 'testent' |
| 396 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } | 454 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } |
| 397 | end | 455 | end |
| @@ -403,31 +461,31 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -403,31 +461,31 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 403 | end | 461 | end |
| 404 | 462 | ||
| 405 | should 'request enable enterprise confirmation' do | 463 | should 'request enable enterprise confirmation' do |
| 406 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) | 464 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) |
| 407 | get :enable, :profile => 'testent' | 465 | get :enable, :profile => 'testent' |
| 408 | assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } | 466 | assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } |
| 409 | end | 467 | end |
| 410 | 468 | ||
| 411 | should 'enable enterprise after confirmation' do | 469 | should 'enable enterprise after confirmation' do |
| 412 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) | 470 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) |
| 413 | post :enable, :profile => 'testent', :confirmation => 1 | 471 | post :enable, :profile => 'testent', :confirmation => 1 |
| 414 | assert assigns(:to_enable).enabled? | 472 | assert assigns(:to_enable).enabled? |
| 415 | end | 473 | end |
| 416 | 474 | ||
| 417 | should 'not enable enterprise without confirmation' do | 475 | should 'not enable enterprise without confirmation' do |
| 418 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) | 476 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) |
| 419 | post :enable, :profile => 'testent' | 477 | post :enable, :profile => 'testent' |
| 420 | assert !assigns(:to_enable).enabled? | 478 | assert !assigns(:to_enable).enabled? |
| 421 | end | 479 | end |
| 422 | 480 | ||
| 423 | should 'disable enterprise after confirmation' do | 481 | should 'disable enterprise after confirmation' do |
| 424 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) | 482 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) |
| 425 | post :disable, :profile => 'testent', :confirmation => 1 | 483 | post :disable, :profile => 'testent', :confirmation => 1 |
| 426 | assert !assigns(:to_disable).enabled? | 484 | assert !assigns(:to_disable).enabled? |
| 427 | end | 485 | end |
| 428 | 486 | ||
| 429 | should 'not disable enterprise without confirmation' do | 487 | should 'not disable enterprise without confirmation' do |
| 430 | - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) | 488 | + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) |
| 431 | post :disable, :profile => 'testent' | 489 | post :disable, :profile => 'testent' |
| 432 | assert assigns(:to_disable).enabled? | 490 | assert assigns(:to_disable).enabled? |
| 433 | end | 491 | end |
test/unit/application_helper_test.rb
| @@ -231,6 +231,38 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -231,6 +231,38 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 231 | assert_tag_in_string meta_tags_for_article(b), :tag => 'link', :attributes => {:type => 'application/rss+xml', :title => 'feed'} | 231 | assert_tag_in_string meta_tags_for_article(b), :tag => 'link', :attributes => {:type => 'application/rss+xml', :title => 'feed'} |
| 232 | end | 232 | end |
| 233 | 233 | ||
| 234 | + should 'provide sex icon for males' do | ||
| 235 | + stubs(:environment).returns(Environment.default) | ||
| 236 | + expects(:content_tag).with(anything, 'male').returns('MALE!!') | ||
| 237 | + expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL") | ||
| 238 | + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => 'male')) | ||
| 239 | + end | ||
| 240 | + | ||
| 241 | + should 'provide sex icon for females' do | ||
| 242 | + stubs(:environment).returns(Environment.default) | ||
| 243 | + expects(:content_tag).with(anything, 'female').returns('FEMALE!!') | ||
| 244 | + expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL") | ||
| 245 | + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => 'female')) | ||
| 246 | + end | ||
| 247 | + | ||
| 248 | + should 'provide undef sex icon' do | ||
| 249 | + stubs(:environment).returns(Environment.default) | ||
| 250 | + expects(:content_tag).with(anything, 'undef').returns('UNDEF!!') | ||
| 251 | + expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL") | ||
| 252 | + assert_equal "FINAL", profile_sex_icon(Person.new(:sex => nil)) | ||
| 253 | + end | ||
| 254 | + | ||
| 255 | + should 'not draw sex icon for non-person profiles' do | ||
| 256 | + assert_equal '', profile_sex_icon(Community.new) | ||
| 257 | + end | ||
| 258 | + | ||
| 259 | + should 'not draw sex icon when disabled in the environment' do | ||
| 260 | + env = Environment.create!(:name => 'env test') | ||
| 261 | + env.expects(:enabled?).with('disable_gender_icon').returns(true) | ||
| 262 | + stubs(:environment).returns(env) | ||
| 263 | + assert_equal '', profile_sex_icon(Person.new(:sex => 'male')) | ||
| 264 | + end | ||
| 265 | + | ||
| 234 | protected | 266 | protected |
| 235 | 267 | ||
| 236 | def url_for(args = {}) | 268 | def url_for(args = {}) |
| @@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class CategoriesHelperTest < Test::Unit::TestCase | ||
| 4 | + | ||
| 5 | + include CategoriesHelper | ||
| 6 | + | ||
| 7 | + def setup | ||
| 8 | + @environment = Environment.default | ||
| 9 | + end | ||
| 10 | + attr_reader :environment | ||
| 11 | + def _(s); s; end | ||
| 12 | + | ||
| 13 | + should 'generate list of category types for selection' do | ||
| 14 | + environment.category_types = ['Category', 'ProductCategory', 'Region'] | ||
| 15 | + expects(:params).returns({'fieldname' => 'fieldvalue'}) | ||
| 16 | + expects(:options_for_select).with([['General Category', 'Category'],[ 'Product Category', 'ProductCategory'],[ 'Region', 'Region' ]], 'fieldvalue').returns('OPTIONS') | ||
| 17 | + expects(:select_tag).with('type', 'OPTIONS').returns('TAG') | ||
| 18 | + expects(:labelled_form_field).with(anything, 'TAG').returns('RESULT') | ||
| 19 | + | ||
| 20 | + assert_equal 'RESULT', select_category_type('fieldname') | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | + should 'only list the available types' do | ||
| 24 | + environment.category_types = ['Category'] | ||
| 25 | + expects(:params).returns({'fieldname' => 'fieldvalue'}) | ||
| 26 | + expects(:options_for_select).with([['General Category', 'Category']], 'fieldvalue').returns('OPTIONS') | ||
| 27 | + expects(:select_tag).with('type', 'OPTIONS').returns('TAG') | ||
| 28 | + expects(:labelled_form_field).with(anything, 'TAG').returns('RESULT') | ||
| 29 | + | ||
| 30 | + assert_equal 'RESULT', select_category_type('fieldname') | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | +end |
test/unit/community_test.rb
| @@ -7,19 +7,19 @@ class CommunityTest < Test::Unit::TestCase | @@ -7,19 +7,19 @@ class CommunityTest < Test::Unit::TestCase | ||
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | should 'convert name into identifier' do | 9 | should 'convert name into identifier' do |
| 10 | - c = Community.new(:name =>'My shiny new Community') | 10 | + c = Community.new(:environment => Environment.default, :name =>'My shiny new Community') |
| 11 | assert_equal 'My shiny new Community', c.name | 11 | assert_equal 'My shiny new Community', c.name |
| 12 | assert_equal 'my-shiny-new-community', c.identifier | 12 | assert_equal 'my-shiny-new-community', c.identifier |
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | should 'have a description attribute' do | 15 | should 'have a description attribute' do |
| 16 | - c = Community.new | 16 | + c = Community.new(:environment => Environment.default) |
| 17 | c.description = 'the description of the community' | 17 | c.description = 'the description of the community' |
| 18 | assert_equal 'the description of the community', c.description | 18 | assert_equal 'the description of the community', c.description |
| 19 | end | 19 | end |
| 20 | 20 | ||
| 21 | should 'create default set of blocks' do | 21 | should 'create default set of blocks' do |
| 22 | - c = Community.create!(:name => 'my new community') | 22 | + c = Community.create!(:environment => Environment.default, :name => 'my new community') |
| 23 | 23 | ||
| 24 | assert c.boxes[0].blocks.map(&:class).include?(MainBlock) | 24 | assert c.boxes[0].blocks.map(&:class).include?(MainBlock) |
| 25 | 25 | ||
| @@ -33,19 +33,19 @@ class CommunityTest < Test::Unit::TestCase | @@ -33,19 +33,19 @@ class CommunityTest < Test::Unit::TestCase | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | should 'get a default home page and RSS feed' do | 35 | should 'get a default home page and RSS feed' do |
| 36 | - community = Community.create!(:name => 'my new community') | 36 | + community = Community.create!(:environment => Environment.default, :name => 'my new community') |
| 37 | 37 | ||
| 38 | assert_kind_of Article, community.home_page | 38 | assert_kind_of Article, community.home_page |
| 39 | assert_kind_of RssFeed, community.articles.find_by_path('feed') | 39 | assert_kind_of RssFeed, community.articles.find_by_path('feed') |
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | should 'have contact_person' do | 42 | should 'have contact_person' do |
| 43 | - community = Community.new(:name => 'my new community') | 43 | + community = Community.new(:environment => Environment.default, :name => 'my new community') |
| 44 | assert_respond_to community, :contact_person | 44 | assert_respond_to community, :contact_person |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | should 'allow to add new members' do | 47 | should 'allow to add new members' do |
| 48 | - c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 48 | + c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') |
| 49 | p = create_user('mytestuser').person | 49 | p = create_user('mytestuser').person |
| 50 | 50 | ||
| 51 | c.add_member(p) | 51 | c.add_member(p) |
| @@ -54,7 +54,7 @@ class CommunityTest < Test::Unit::TestCase | @@ -54,7 +54,7 @@ class CommunityTest < Test::Unit::TestCase | ||
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | should 'allow to remove members' do | 56 | should 'allow to remove members' do |
| 57 | - c = Community.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | 57 | + c = Community.create!(:environment => Environment.default, :name => 'my other test profile', :identifier => 'myothertestprofile') |
| 58 | p = create_user('myothertestuser').person | 58 | p = create_user('myothertestuser').person |
| 59 | 59 | ||
| 60 | c.add_member(p) | 60 | c.add_member(p) |
| @@ -65,7 +65,7 @@ class CommunityTest < Test::Unit::TestCase | @@ -65,7 +65,7 @@ class CommunityTest < Test::Unit::TestCase | ||
| 65 | end | 65 | end |
| 66 | 66 | ||
| 67 | should 'clear relationships after destroy' do | 67 | should 'clear relationships after destroy' do |
| 68 | - c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 68 | + c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') |
| 69 | member = create_user('memberuser').person | 69 | member = create_user('memberuser').person |
| 70 | admin = create_user('adminuser').person | 70 | admin = create_user('adminuser').person |
| 71 | moderator = create_user('moderatoruser').person | 71 | moderator = create_user('moderatoruser').person |
| @@ -85,8 +85,36 @@ class CommunityTest < Test::Unit::TestCase | @@ -85,8 +85,36 @@ class CommunityTest < Test::Unit::TestCase | ||
| 85 | 85 | ||
| 86 | should 'have a community template' do | 86 | should 'have a community template' do |
| 87 | env = Environment.create!(:name => 'test env') | 87 | env = Environment.create!(:name => 'test env') |
| 88 | - p = Community.create!(:name => 'test_com', :identifier => 'test_com', :environment => env) | 88 | + p = Community.create!(:environment => Environment.default, :name => 'test_com', :identifier => 'test_com', :environment => env) |
| 89 | assert_kind_of Community, p.template | 89 | assert_kind_of Community, p.template |
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | + should 'return active_community_fields' do | ||
| 93 | + e = Environment.default | ||
| 94 | + e.expects(:active_community_fields).returns(['contact_phone', 'contact_email']).at_least_once | ||
| 95 | + ent = Community.new(:environment => e) | ||
| 96 | + | ||
| 97 | + assert_equal e.active_community_fields, ent.active_fields | ||
| 98 | + end | ||
| 99 | + | ||
| 100 | + should 'return required_community_fields' do | ||
| 101 | + e = Environment.default | ||
| 102 | + e.expects(:required_community_fields).returns(['contact_phone', 'contact_email']).at_least_once | ||
| 103 | + community = Community.new(:environment => e) | ||
| 104 | + | ||
| 105 | + assert_equal e.required_community_fields, community.required_fields | ||
| 106 | + end | ||
| 107 | + | ||
| 108 | + should 'require fields if community needs' do | ||
| 109 | + e = Environment.default | ||
| 110 | + e.expects(:required_community_fields).returns(['contact_phone']).at_least_once | ||
| 111 | + community = Community.new(:environment => e) | ||
| 112 | + assert ! community.valid? | ||
| 113 | + assert community.errors.invalid?(:contact_phone) | ||
| 114 | + | ||
| 115 | + community.contact_phone = '99999' | ||
| 116 | + community.valid? | ||
| 117 | + assert ! community.errors.invalid?(:contact_phone) | ||
| 118 | + end | ||
| 119 | + | ||
| 92 | end | 120 | end |
test/unit/enterprise_test.rb
| @@ -174,7 +174,7 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -174,7 +174,7 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 174 | ent.reload | 174 | ent.reload |
| 175 | assert_equal 1, ent.boxes.size | 175 | assert_equal 1, ent.boxes.size |
| 176 | assert_equal 1, ent.boxes[0].blocks.size | 176 | assert_equal 1, ent.boxes[0].blocks.size |
| 177 | - end | 177 | + end |
| 178 | 178 | ||
| 179 | should 'not replace template if environment doesnt allow' do | 179 | should 'not replace template if environment doesnt allow' do |
| 180 | template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) | 180 | template = Enterprise.create!(:name => 'template enteprise', :identifier => 'template_enterprise', :enabled => false) |
| @@ -195,7 +195,8 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -195,7 +195,8 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 195 | assert_equal 1, ent.boxes.size | 195 | assert_equal 1, ent.boxes.size |
| 196 | assert_equal 1, ent.boxes[0].blocks.size | 196 | assert_equal 1, ent.boxes[0].blocks.size |
| 197 | end | 197 | end |
| 198 | - should 'create EnterpriseActivation task when creating with enabled = false' do | 198 | + |
| 199 | + should 'create EnterpriseActivation task when creating with enabled = false' do | ||
| 199 | EnterpriseActivation.delete_all | 200 | EnterpriseActivation.delete_all |
| 200 | ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | 201 | ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) |
| 201 | assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise) | 202 | assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise) |
| @@ -256,4 +257,32 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -256,4 +257,32 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 256 | assert e.enable_contact_us | 257 | assert e.enable_contact_us |
| 257 | end | 258 | end |
| 258 | 259 | ||
| 260 | + should 'return active_enterprise_fields' do | ||
| 261 | + e = Environment.default | ||
| 262 | + e.expects(:active_enterprise_fields).returns(['contact_phone', 'contact_email']).at_least_once | ||
| 263 | + ent = Enterprise.new(:environment => e) | ||
| 264 | + | ||
| 265 | + assert_equal e.active_enterprise_fields, ent.active_fields | ||
| 266 | + end | ||
| 267 | + | ||
| 268 | + should 'return required_enterprise_fields' do | ||
| 269 | + e = Environment.default | ||
| 270 | + e.expects(:required_enterprise_fields).returns(['contact_phone', 'contact_email']).at_least_once | ||
| 271 | + enterprise = Enterprise.new(:environment => e) | ||
| 272 | + | ||
| 273 | + assert_equal e.required_enterprise_fields, enterprise.required_fields | ||
| 274 | + end | ||
| 275 | + | ||
| 276 | + should 'require fields if enterprise needs' do | ||
| 277 | + e = Environment.default | ||
| 278 | + e.expects(:required_enterprise_fields).returns(['contact_phone']).at_least_once | ||
| 279 | + enterprise = Enterprise.new(:environment => e) | ||
| 280 | + assert ! enterprise.valid? | ||
| 281 | + assert enterprise.errors.invalid?(:contact_phone) | ||
| 282 | + | ||
| 283 | + enterprise.contact_phone = '99999' | ||
| 284 | + enterprise.valid? | ||
| 285 | + assert ! enterprise.errors.invalid?(:contact_phone) | ||
| 286 | + end | ||
| 287 | + | ||
| 259 | end | 288 | end |
test/unit/environment_test.rb
| @@ -532,4 +532,153 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -532,4 +532,153 @@ class EnvironmentTest < Test::Unit::TestCase | ||
| 532 | assert_equal false, Environment.new.replace_enterprise_template_when_enable | 532 | assert_equal false, Environment.new.replace_enterprise_template_when_enable |
| 533 | end | 533 | end |
| 534 | 534 | ||
| 535 | + should 'set custom_person_fields' do | ||
| 536 | + env = Environment.new | ||
| 537 | + env.custom_person_fields = {'cell_phone' => {'required' => 'true', 'active' => 'true'},'comercial_phone'=> {'required' => 'true', 'active' => 'true'}} | ||
| 538 | + | ||
| 539 | + assert_equal({'cell_phone' => {'required' => 'true', 'active' => 'true'},'comercial_phone'=> {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) | ||
| 540 | + end | ||
| 541 | + | ||
| 542 | + should 'have no custom_person_fields by default' do | ||
| 543 | + assert_equal({}, Environment.new.custom_person_fields) | ||
| 544 | + end | ||
| 545 | + | ||
| 546 | + should 'not set in custom_person_fields if not in person.fields' do | ||
| 547 | + env = Environment.default | ||
| 548 | + Person.stubs(:fields).returns(['cell_phone', 'comercial_phone']) | ||
| 549 | + | ||
| 550 | + env.custom_person_fields = { 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'true'}} | ||
| 551 | + assert_equal({'cell_phone' => {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) | ||
| 552 | + assert ! env.custom_person_fields.keys.include?('birth_date') | ||
| 553 | + end | ||
| 554 | + | ||
| 555 | + should 'add schooling_status if custom_person_fields has schooling' do | ||
| 556 | + env = Environment.default | ||
| 557 | + Person.stubs(:fields).returns(['cell_phone', 'schooling']) | ||
| 558 | + | ||
| 559 | + env.custom_person_fields = { 'schooling' => {'required' => 'true', 'active' => 'true'}} | ||
| 560 | + assert_equal({'schooling' => {'required' => 'true', 'active' => 'true'}, 'schooling_status' => {'required' => 'true', 'active' => 'true'}}, env.custom_person_fields) | ||
| 561 | + assert ! env.custom_person_fields.keys.include?('birth_date') | ||
| 562 | + end | ||
| 563 | + | ||
| 564 | + should 'return person_fields status' do | ||
| 565 | + env = Environment.default | ||
| 566 | + | ||
| 567 | + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 568 | + | ||
| 569 | + assert_equal true, env.custom_person_field('birth_date', 'required') | ||
| 570 | + assert_equal false, env.custom_person_field('birth_date', 'active') | ||
| 571 | + end | ||
| 572 | + | ||
| 573 | + should 'select active fields from person' do | ||
| 574 | + env = Environment.default | ||
| 575 | + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 576 | + | ||
| 577 | + assert_equal ['birth_date'], env.active_person_fields | ||
| 578 | + end | ||
| 579 | + | ||
| 580 | + should 'select required fields from person' do | ||
| 581 | + env = Environment.default | ||
| 582 | + env.expects(:custom_person_fields).returns({ 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'false', 'active' => 'true'}}).at_least_once | ||
| 583 | + | ||
| 584 | + assert_equal ['birth_date'], env.required_person_fields | ||
| 585 | + end | ||
| 586 | + | ||
| 587 | + should 'set custom_enterprises_fields' do | ||
| 588 | + env = Environment.new | ||
| 589 | + env.custom_enterprise_fields = {'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}} | ||
| 590 | + | ||
| 591 | + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}}, env.custom_enterprise_fields) | ||
| 592 | + end | ||
| 593 | + | ||
| 594 | + should 'have no custom_enterprise_fields by default' do | ||
| 595 | + assert_equal({}, Environment.new.custom_enterprise_fields) | ||
| 596 | + end | ||
| 597 | + | ||
| 598 | + should 'not set in custom_enterprise_fields if not in enterprise.fields' do | ||
| 599 | + env = Environment.default | ||
| 600 | + Enterprise.stubs(:fields).returns(['contact_person', 'comercial_phone']) | ||
| 601 | + | ||
| 602 | + env.custom_enterprise_fields = { 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'true'}} | ||
| 603 | + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'}}, env.custom_enterprise_fields) | ||
| 604 | + assert ! env.custom_enterprise_fields.keys.include?('contact_email') | ||
| 605 | + end | ||
| 606 | + | ||
| 607 | + should 'return enteprise_fields status' do | ||
| 608 | + env = Environment.default | ||
| 609 | + | ||
| 610 | + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 611 | + | ||
| 612 | + assert_equal true, env.custom_enterprise_field('contact_email', 'required') | ||
| 613 | + assert_equal false, env.custom_enterprise_field('contact_email', 'active') | ||
| 614 | + end | ||
| 615 | + | ||
| 616 | + should 'select active fields from enterprise' do | ||
| 617 | + env = Environment.default | ||
| 618 | + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 619 | + | ||
| 620 | + assert_equal ['contact_email'], env.active_enterprise_fields | ||
| 621 | + end | ||
| 622 | + | ||
| 623 | + should 'select required fields from enterprise' do | ||
| 624 | + env = Environment.default | ||
| 625 | + env.expects(:custom_enterprise_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'false', 'active' => 'true'}}).at_least_once | ||
| 626 | + | ||
| 627 | + assert_equal ['contact_email'], env.required_enterprise_fields | ||
| 628 | + end | ||
| 629 | + | ||
| 630 | + should 'set custom_communitys_fields' do | ||
| 631 | + env = Environment.new | ||
| 632 | + env.custom_community_fields = {'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}} | ||
| 633 | + | ||
| 634 | + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'},'contact_email'=> {'required' => 'true', 'active' => 'true'}}, env.custom_community_fields) | ||
| 635 | + end | ||
| 636 | + | ||
| 637 | + should 'have no custom_community_fields by default' do | ||
| 638 | + assert_equal({}, Environment.new.custom_community_fields) | ||
| 639 | + end | ||
| 640 | + | ||
| 641 | + should 'not set in custom_community_fields if not in community.fields' do | ||
| 642 | + env = Environment.default | ||
| 643 | + Community.stubs(:fields).returns(['contact_person', 'comercial_phone']) | ||
| 644 | + | ||
| 645 | + env.custom_community_fields = { 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'true'}} | ||
| 646 | + assert_equal({'contact_person' => {'required' => 'true', 'active' => 'true'}}, env.custom_community_fields) | ||
| 647 | + assert ! env.custom_community_fields.keys.include?('contact_email') | ||
| 648 | + end | ||
| 649 | + | ||
| 650 | + should 'return community_fields status' do | ||
| 651 | + env = Environment.default | ||
| 652 | + | ||
| 653 | + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 654 | + | ||
| 655 | + assert_equal true, env.custom_community_field('contact_email', 'required') | ||
| 656 | + assert_equal false, env.custom_community_field('contact_email', 'active') | ||
| 657 | + end | ||
| 658 | + | ||
| 659 | + should 'select active fields from community' do | ||
| 660 | + env = Environment.default | ||
| 661 | + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'true', 'active' => 'false'}}).at_least_once | ||
| 662 | + | ||
| 663 | + assert_equal ['contact_email'], env.active_community_fields | ||
| 664 | + end | ||
| 665 | + | ||
| 666 | + should 'select required fields from community' do | ||
| 667 | + env = Environment.default | ||
| 668 | + env.expects(:custom_community_fields).returns({ 'contact_email' => {'required' => 'true', 'active' => 'true'}, 'contact_person' => {'required' => 'false', 'active' => 'true'}}).at_least_once | ||
| 669 | + | ||
| 670 | + assert_equal ['contact_email'], env.required_community_fields | ||
| 671 | + end | ||
| 672 | + | ||
| 673 | + should 'set category_types' do | ||
| 674 | + env = Environment.new | ||
| 675 | + env.category_types = ['Category', 'ProductCategory'] | ||
| 676 | + | ||
| 677 | + assert_equal ['Category', 'ProductCategory'], env.category_types | ||
| 678 | + end | ||
| 679 | + | ||
| 680 | + should 'have type /Category/ on category_types by default' do | ||
| 681 | + assert_equal ['Category'], Environment.new.category_types | ||
| 682 | + end | ||
| 683 | + | ||
| 535 | end | 684 | end |
test/unit/friendship_test.rb
| @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
| 3 | class FriendshipTest < Test::Unit::TestCase | 3 | class FriendshipTest < Test::Unit::TestCase |
| 4 | 4 | ||
| 5 | should 'connect a person to another' do | 5 | should 'connect a person to another' do |
| 6 | - p1 = Person.new | ||
| 7 | - p2 = Person.new | 6 | + p1 = Person.new(:environment => Environment.default) |
| 7 | + p2 = Person.new(:environment => Environment.default) | ||
| 8 | 8 | ||
| 9 | f = Friendship.new | 9 | f = Friendship.new |
| 10 | assert_raise ActiveRecord::AssociationTypeMismatch do | 10 | assert_raise ActiveRecord::AssociationTypeMismatch do |
test/unit/person_test.rb
| @@ -4,7 +4,7 @@ class PersonTest < Test::Unit::TestCase | @@ -4,7 +4,7 @@ class PersonTest < Test::Unit::TestCase | ||
| 4 | fixtures :profiles, :users, :environments | 4 | fixtures :profiles, :users, :environments |
| 5 | 5 | ||
| 6 | def test_person_must_come_form_the_cration_of_an_user | 6 | def test_person_must_come_form_the_cration_of_an_user |
| 7 | - p = Person.new(:name => 'John', :identifier => 'john') | 7 | + p = Person.new(:environment => Environment.default, :name => 'John', :identifier => 'john') |
| 8 | assert !p.valid? | 8 | assert !p.valid? |
| 9 | p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') | 9 | p.user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') |
| 10 | assert !p.valid? | 10 | assert !p.valid? |
| @@ -59,21 +59,21 @@ class PersonTest < Test::Unit::TestCase | @@ -59,21 +59,21 @@ class PersonTest < Test::Unit::TestCase | ||
| 59 | p1 = u.person | 59 | p1 = u.person |
| 60 | assert_equal u, p1.user | 60 | assert_equal u, p1.user |
| 61 | 61 | ||
| 62 | - p2 = Person.new | 62 | + p2 = Person.new(:environment => Environment.default) |
| 63 | p2.user = u | 63 | p2.user = u |
| 64 | assert !p2.valid? | 64 | assert !p2.valid? |
| 65 | assert p2.errors.invalid?(:user_id) | 65 | assert p2.errors.invalid?(:user_id) |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | should "have person info fields" do | 68 | should "have person info fields" do |
| 69 | - p = Person.new | 69 | + p = Person.new(:environment => Environment.default) |
| 70 | [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code ].each do |i| | 70 | [ :name, :photo, :contact_information, :birth_date, :sex, :address, :city, :state, :country, :zip_code ].each do |i| |
| 71 | assert_respond_to p, i | 71 | assert_respond_to p, i |
| 72 | end | 72 | end |
| 73 | end | 73 | end |
| 74 | 74 | ||
| 75 | should 'not have person_info class' do | 75 | should 'not have person_info class' do |
| 76 | - p = Person.new | 76 | + p = Person.new(:environment => Environment.default) |
| 77 | assert_raise NoMethodError do | 77 | assert_raise NoMethodError do |
| 78 | p.person_info | 78 | p.person_info |
| 79 | end | 79 | end |
| @@ -108,7 +108,7 @@ class PersonTest < Test::Unit::TestCase | @@ -108,7 +108,7 @@ class PersonTest < Test::Unit::TestCase | ||
| 108 | end | 108 | end |
| 109 | 109 | ||
| 110 | should 'get no email address when there is no associated user' do | 110 | should 'get no email address when there is no associated user' do |
| 111 | - p = Person.new | 111 | + p = Person.new(:environment => Environment.default) |
| 112 | assert_nil p.email | 112 | assert_nil p.email |
| 113 | end | 113 | end |
| 114 | 114 | ||
| @@ -173,12 +173,12 @@ class PersonTest < Test::Unit::TestCase | @@ -173,12 +173,12 @@ class PersonTest < Test::Unit::TestCase | ||
| 173 | end | 173 | end |
| 174 | 174 | ||
| 175 | should 'suggest default friend groups list' do | 175 | should 'suggest default friend groups list' do |
| 176 | - p = Person.new | 176 | + p = Person.new(:environment => Environment.default) |
| 177 | assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups | 177 | assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups |
| 178 | end | 178 | end |
| 179 | 179 | ||
| 180 | should 'suggest current groups as well' do | 180 | should 'suggest current groups as well' do |
| 181 | - p = Person.new | 181 | + p = Person.new(:environment => Environment.default) |
| 182 | p.expects(:friend_groups).returns(['group1', 'group2']) | 182 | p.expects(:friend_groups).returns(['group1', 'group2']) |
| 183 | assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups | 183 | assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups |
| 184 | end | 184 | end |
| @@ -264,14 +264,14 @@ class PersonTest < Test::Unit::TestCase | @@ -264,14 +264,14 @@ class PersonTest < Test::Unit::TestCase | ||
| 264 | end | 264 | end |
| 265 | 265 | ||
| 266 | should 'provide desired info fields' do | 266 | should 'provide desired info fields' do |
| 267 | - p = Person.new | 267 | + p = Person.new(:environment => Environment.default) |
| 268 | assert p.respond_to?(:photo) | 268 | assert p.respond_to?(:photo) |
| 269 | assert p.respond_to?(:address) | 269 | assert p.respond_to?(:address) |
| 270 | assert p.respond_to?(:contact_information) | 270 | assert p.respond_to?(:contact_information) |
| 271 | end | 271 | end |
| 272 | 272 | ||
| 273 | should 'required name' do | 273 | should 'required name' do |
| 274 | - person = Person.new | 274 | + person = Person.new(:environment => Environment.default) |
| 275 | assert !person.valid? | 275 | assert !person.valid? |
| 276 | assert person.errors.invalid?(:name) | 276 | assert person.errors.invalid?(:name) |
| 277 | end | 277 | end |
| @@ -285,7 +285,7 @@ class PersonTest < Test::Unit::TestCase | @@ -285,7 +285,7 @@ class PersonTest < Test::Unit::TestCase | ||
| 285 | 285 | ||
| 286 | should 'have e-mail addresses' do | 286 | should 'have e-mail addresses' do |
| 287 | env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) | 287 | env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) |
| 288 | - person = Person.new(:identifier => 'testuser') | 288 | + person = Person.new(:environment => env, :identifier => 'testuser') |
| 289 | person.expects(:environment).returns(env) | 289 | person.expects(:environment).returns(env) |
| 290 | 290 | ||
| 291 | assert_equal ['testuser@somedomain.com'], person.email_addresses | 291 | assert_equal ['testuser@somedomain.com'], person.email_addresses |
| @@ -295,7 +295,7 @@ class PersonTest < Test::Unit::TestCase | @@ -295,7 +295,7 @@ class PersonTest < Test::Unit::TestCase | ||
| 295 | env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) | 295 | env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) |
| 296 | env.force_www = true | 296 | env.force_www = true |
| 297 | env.save | 297 | env.save |
| 298 | - person = Person.new(:identifier => 'testuser') | 298 | + person = Person.new(:environment => env, :identifier => 'testuser') |
| 299 | person.expects(:environment).returns(env) | 299 | person.expects(:environment).returns(env) |
| 300 | 300 | ||
| 301 | assert_equal ['testuser@somedomain.com'], person.email_addresses | 301 | assert_equal ['testuser@somedomain.com'], person.email_addresses |
| @@ -387,4 +387,76 @@ class PersonTest < Test::Unit::TestCase | @@ -387,4 +387,76 @@ class PersonTest < Test::Unit::TestCase | ||
| 387 | assert_equal 'pt_BR', Person['user_lang_test'].last_lang | 387 | assert_equal 'pt_BR', Person['user_lang_test'].last_lang |
| 388 | end | 388 | end |
| 389 | 389 | ||
| 390 | + should 'return active_person_fields' do | ||
| 391 | + e = Environment.default | ||
| 392 | + e.expects(:active_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once | ||
| 393 | + person = Person.new(:environment => e) | ||
| 394 | + | ||
| 395 | + assert_equal e.active_person_fields, person.active_fields | ||
| 396 | + end | ||
| 397 | + | ||
| 398 | + should 'return required_person_fields' do | ||
| 399 | + e = Environment.default | ||
| 400 | + e.expects(:required_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once | ||
| 401 | + person = Person.new(:environment => e) | ||
| 402 | + | ||
| 403 | + assert_equal e.required_person_fields, person.required_fields | ||
| 404 | + end | ||
| 405 | + | ||
| 406 | + should 'require fields if person needs' do | ||
| 407 | + e = Environment.default | ||
| 408 | + e.expects(:required_person_fields).returns(['cell_phone']).at_least_once | ||
| 409 | + person = Person.new(:environment => e) | ||
| 410 | + assert ! person.valid? | ||
| 411 | + assert person.errors.invalid?(:cell_phone) | ||
| 412 | + | ||
| 413 | + person.cell_phone = '99999' | ||
| 414 | + person.valid? | ||
| 415 | + assert ! person.errors.invalid?(:cell_phone) | ||
| 416 | + end | ||
| 417 | + | ||
| 418 | + should 'require custom_area_of_study if area_of_study is others' do | ||
| 419 | + e = Environment.default | ||
| 420 | + e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once | ||
| 421 | + | ||
| 422 | + person = Person.new(:environment => e, :area_of_study => 'Others') | ||
| 423 | + assert !person.valid? | ||
| 424 | + assert person.errors.invalid?(:custom_area_of_study) | ||
| 425 | + | ||
| 426 | + person.custom_area_of_study = 'Customized area of study' | ||
| 427 | + person.valid? | ||
| 428 | + assert ! person.errors.invalid?(:custom_area_of_study) | ||
| 429 | + end | ||
| 430 | + | ||
| 431 | + should 'not require custom_area_of_study if area_of_study is not others' do | ||
| 432 | + e = Environment.default | ||
| 433 | + e.expects(:required_person_fields).returns(['area_of_study']).at_least_once | ||
| 434 | + | ||
| 435 | + person = Person.new(:environment => e, :area_of_study => 'Agrometeorology') | ||
| 436 | + person.valid? | ||
| 437 | + assert ! person.errors.invalid?(:custom_area_of_study) | ||
| 438 | + end | ||
| 439 | + | ||
| 440 | + should 'require custom_formation if formation is others' do | ||
| 441 | + e = Environment.default | ||
| 442 | + e.expects(:required_person_fields).returns(['formation', 'custom_formation']).at_least_once | ||
| 443 | + | ||
| 444 | + person = Person.new(:environment => e, :formation => 'Others') | ||
| 445 | + assert !person.valid? | ||
| 446 | + assert person.errors.invalid?(:custom_formation) | ||
| 447 | + | ||
| 448 | + person.custom_formation = 'Customized formation' | ||
| 449 | + person.valid? | ||
| 450 | + assert ! person.errors.invalid?(:custom_formation) | ||
| 451 | + end | ||
| 452 | + | ||
| 453 | + should 'not require custom_formation if formation is not others' do | ||
| 454 | + e = Environment.default | ||
| 455 | + e.expects(:required_person_fields).returns(['formation']).at_least_once | ||
| 456 | + | ||
| 457 | + person = Person.new(:environment => e, :formation => 'Agrometeorology') | ||
| 458 | + assert !person.valid? | ||
| 459 | + assert ! person.errors.invalid?(:custom_formation) | ||
| 460 | + end | ||
| 461 | + | ||
| 390 | end | 462 | end |