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