Commit 34de9463151b7f959addd9ba3dab4f1e1fa77638

Authored by Antonio Terceiro
1 parent 3a69faf1

Rename test file

plugins/stoa/test/functional/profile_editor_controller.rb
@@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller'  
3 -  
4 -# Re-raise errors caught by the controller.  
5 -class ProfileEditorController; def rescue_action(e) raise e end; end  
6 -  
7 -class ProfileEditorTest < ActionController::TestCase  
8 -  
9 - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt']  
10 -  
11 - def setup  
12 - @controller = ProfileEditorController.new  
13 - @request = ActionController::TestRequest.new  
14 - @response = ActionController::TestResponse.new  
15 - @person = User.create(:login => 'test_user', :email => 'test_user@example.com', :password => 'test', :password_confirmation => 'test').person  
16 - login_as(@person.identifier)  
17 - Environment.default.enable_plugin(StoaPlugin.name)  
18 - db = Tempfile.new('stoa-test')  
19 - ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => db.path}  
20 - end  
21 -  
22 - attr_accessor :person  
23 -  
24 - should 'show usp_id field if person did not filled it' do  
25 - get :edit, :profile => person.identifier  
26 - assert_match /USP number/, @response.body  
27 - end  
28 -  
29 - should 'not show usp_id field if person already filled it' do  
30 - person.usp_id = 12345  
31 - person.save  
32 - get :edit, :profile => person.identifier  
33 - assert_no_match /USP number/, @response.body  
34 - end  
35 -  
36 - should 'not display field if profile is an organization' do  
37 - organization = fast_create(Organization)  
38 - get :edit, :profile => organization.identifier  
39 - assert_no_match /USP number/, @response.body  
40 - end  
41 -  
42 - should 'display error if usp_id does not match with supplied confirmation' do  
43 - StoaPlugin::UspUser.stubs(:matches?).returns(false)  
44 - post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999  
45 - assert assigns(:profile_data).errors.invalid?(:usp_id)  
46 - end  
47 -  
48 - should 'save usp_id if everyhtings is ok' do  
49 - StoaPlugin::UspUser.stubs(:matches?).returns(true)  
50 - post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999  
51 - person.reload  
52 - assert_equal '12345678', person.usp_id  
53 - end  
54 -  
55 -end  
plugins/stoa/test/functional/profile_editor_controller_test.rb 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class ProfileEditorController; def rescue_action(e) raise e end; end
  6 +
  7 +class StoaPluginProfileEditorControllerTest < ActionController::TestCase
  8 +
  9 + SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt']
  10 +
  11 + def setup
  12 + @controller = ProfileEditorController.new
  13 + @request = ActionController::TestRequest.new
  14 + @response = ActionController::TestResponse.new
  15 + @person = User.create(:login => 'test_user', :email => 'test_user@example.com', :password => 'test', :password_confirmation => 'test').person
  16 + login_as(@person.identifier)
  17 + Environment.default.enable_plugin(StoaPlugin.name)
  18 + db = Tempfile.new('stoa-test')
  19 + ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => db.path}
  20 + end
  21 +
  22 + attr_accessor :person
  23 +
  24 + should 'show usp_id field if person did not filled it' do
  25 + get :edit, :profile => person.identifier
  26 + assert_match /USP number/, @response.body
  27 + end
  28 +
  29 + should 'not show usp_id field if person already filled it' do
  30 + person.usp_id = 12345
  31 + person.save
  32 + get :edit, :profile => person.identifier
  33 + assert_no_match /USP number/, @response.body
  34 + end
  35 +
  36 + should 'not display field if profile is an organization' do
  37 + organization = fast_create(Organization)
  38 + get :edit, :profile => organization.identifier
  39 + assert_no_match /USP number/, @response.body
  40 + end
  41 +
  42 + should 'display error if usp_id does not match with supplied confirmation' do
  43 + StoaPlugin::UspUser.stubs(:matches?).returns(false)
  44 + post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999
  45 + assert assigns(:profile_data).errors.invalid?(:usp_id)
  46 + end
  47 +
  48 + should 'save usp_id if everyhtings is ok' do
  49 + StoaPlugin::UspUser.stubs(:matches?).returns(true)
  50 + post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999
  51 + person.reload
  52 + assert_equal '12345678', person.usp_id
  53 + end
  54 +
  55 +end