Commit 8ac01fe0561e4afa989befb7176b02e5c174a32f

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent a6fdacba

ActionItem833: adding tests to custom_field

test/functional/features_controller_test.rb
... ... @@ -102,8 +102,6 @@ class FeaturesControllerTest < Test::Unit::TestCase
102 102 assert_equal true, e.custom_person_fields['cell_phone']['required']
103 103 end
104 104  
105   - should 'disable check_box for required if active is not checked'
106   -
107 105 should 'list possible enterprise fields' do
108 106 uses_host 'anhetegua.net'
109 107 Enterprise.expects(:fields).returns(['contact_person', 'contact_email']).at_least_once
... ...
test/unit/application_helper_test.rb
... ... @@ -263,6 +263,73 @@ class ApplicationHelperTest < Test::Unit::TestCase
263 263 assert_equal '', profile_sex_icon(Person.new(:sex => 'male'))
264 264 end
265 265  
  266 + should 'display field on signup' do
  267 + env = Environment.create!(:name => 'env test')
  268 + stubs(:environment).returns(env)
  269 +
  270 + controller = mock
  271 + stubs(:controller).returns(controller)
  272 + controller.expects(:action_name).returns('signup')
  273 +
  274 + profile = Person.new
  275 + profile.expects(:signup_fields).returns(['field'])
  276 + assert_equal 'SIGNUP_FIELD', custom_field(profile, 'field', 'SIGNUP_FIELD')
  277 + end
  278 +
  279 + should 'not display field on signup' do
  280 + env = Environment.create!(:name => 'env test')
  281 + stubs(:environment).returns(env)
  282 +
  283 + controller = mock
  284 + stubs(:controller).returns(controller)
  285 + controller.expects(:action_name).returns('signup')
  286 +
  287 + profile = Person.new
  288 + profile.expects(:signup_fields).returns([])
  289 + assert_equal '', custom_field(profile, 'field', 'SIGNUP_FIELD')
  290 + end
  291 +
  292 + should 'display active fields' do
  293 + env = Environment.create!(:name => 'env test')
  294 + stubs(:environment).returns(env)
  295 +
  296 + controller = mock
  297 + stubs(:controller).returns(controller)
  298 + controller.expects(:action_name).returns('edit')
  299 +
  300 + profile = Person.new
  301 + profile.expects(:active_fields).returns(['field'])
  302 + assert_equal 'SIGNUP_FIELD', custom_field(profile, 'field', 'SIGNUP_FIELD')
  303 + end
  304 +
  305 + should 'not display active fields' do
  306 + env = Environment.create!(:name => 'env test')
  307 + stubs(:environment).returns(env)
  308 +
  309 + controller = mock
  310 + stubs(:controller).returns(controller)
  311 + controller.expects(:action_name).returns('edit')
  312 +
  313 + profile = Person.new
  314 + profile.expects(:active_fields).returns([])
  315 + assert_equal '', custom_field(profile, 'field', 'SIGNUP_FIELD')
  316 + end
  317 +
  318 + should 'display required fields' do
  319 + env = Environment.create!(:name => 'env test')
  320 + stubs(:environment).returns(env)
  321 +
  322 + controller = mock
  323 + stubs(:controller).returns(controller)
  324 + controller.expects(:action_name).returns('edit')
  325 +
  326 + stubs(:required).with('SIGNUP_FIELD').returns('<span>SIGNUP_FIELD</span>')
  327 + profile = Person.new
  328 + profile.expects(:active_fields).returns(['field'])
  329 + profile.expects(:required_fields).returns(['field'])
  330 + assert_equal '<span>SIGNUP_FIELD</span>', custom_field(profile, 'field', 'SIGNUP_FIELD')
  331 + end
  332 +
266 333 protected
267 334  
268 335 def url_for(args = {})
... ...