Commit ac4008f740e0ed151032ff648af58be94810c116
1 parent
44854faa
Exists in
staging
and in
42 other branches
ActionItem629: renaming controller the right way
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2455 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
149 additions
and
149 deletions
Show diff stats
test/functional/enterprise_validation_controller_test.rb
0 → 100644
| @@ -0,0 +1,149 @@ | @@ -0,0 +1,149 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | +require 'enterprise_validation_controller' | ||
| 3 | + | ||
| 4 | +# Re-raise errors caught by the controller. | ||
| 5 | +class EnterpriseValidationController; def rescue_action(e) raise e end; end | ||
| 6 | + | ||
| 7 | +class EnterpriseValidationControllerTest < Test::Unit::TestCase | ||
| 8 | + | ||
| 9 | + all_fixtures | ||
| 10 | + | ||
| 11 | + def setup | ||
| 12 | + @controller = EnterpriseValidationController.new | ||
| 13 | + @request = ActionController::TestRequest.new | ||
| 14 | + @response = ActionController::TestResponse.new | ||
| 15 | + | ||
| 16 | + login_as 'ze' | ||
| 17 | + @org = Organization.create!(:identifier => 'myorg', :name => "My Org") | ||
| 18 | + give_permission('ze', 'validate_enterprise', @org) | ||
| 19 | + Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + def test_local_files_reference | ||
| 23 | + assert_local_files_reference :get, :index, :profile => 'myorg' | ||
| 24 | + end | ||
| 25 | + | ||
| 26 | + def test_valid_xhtml | ||
| 27 | + | ||
| 28 | + # FIXME remove this after enable assert_valid_xhtml | ||
| 29 | + Profile.find_by_identifier('myorg') | ||
| 30 | + | ||
| 31 | + assert_valid_xhtml :get, :index, :profile => 'myorg' | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + should 'list pending validations on index' do | ||
| 35 | + empty = [] | ||
| 36 | + @org.expects(:pending_validations).returns(empty) | ||
| 37 | + get :index, :profile => 'myorg' | ||
| 38 | + assert_same empty, assigns(:pending_validations) | ||
| 39 | + assert_template 'index' | ||
| 40 | + end | ||
| 41 | + | ||
| 42 | + should 'display details and prompt for needed data when approving or rejecting enterprise' do | ||
| 43 | + validating = CreateEnterprise.new | ||
| 44 | + @org.expects(:find_pending_validation).with('kakakaka').returns(validating) | ||
| 45 | + | ||
| 46 | + get :details, :profile => 'myorg', :id => 'kakakaka' | ||
| 47 | + assert_same validating, assigns(:pending) | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + should 'refuse to validate unexisting request' do | ||
| 51 | + @org.expects(:find_pending_validation).with('kakakaka').returns(nil) | ||
| 52 | + get :details , :profile => 'myorg', :id => 'kakakaka' | ||
| 53 | + assert_response 404 | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + should 'be able to actually validate enterprise on request' do | ||
| 57 | + validation = CreateEnterprise.new | ||
| 58 | + @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 59 | + validation.expects(:approve) | ||
| 60 | + validation.expects(:code).returns('kakakaka') | ||
| 61 | + post :approve, :profile => 'myorg', :id => 'kakakaka' | ||
| 62 | + assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | + should 'be able to reject an enterprise' do | ||
| 66 | + validation = CreateEnterprise.new | ||
| 67 | + @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 68 | + validation.expects(:reject) | ||
| 69 | + validation.expects(:code).returns('kakakaka') | ||
| 70 | + post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise' | ||
| 71 | + assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | ||
| 72 | + end | ||
| 73 | + | ||
| 74 | + should 'require the user to fill in the explanation for an rejection' do | ||
| 75 | + validation = CreateEnterprise.new | ||
| 76 | + @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 77 | + | ||
| 78 | + # FIXME: this is not working, but should. Anyway the assert_response and | ||
| 79 | + # assert_template below in some test some things we need. But the | ||
| 80 | + # expectation below must be put to work. | ||
| 81 | + # | ||
| 82 | + #validation.expects(:reject).raises(ActiveRecord::RecordInvalid) | ||
| 83 | + | ||
| 84 | + post :reject, :profile => 'myorg', :id => 'kakakaka' | ||
| 85 | + assert_response :success | ||
| 86 | + assert_template 'details' | ||
| 87 | + end | ||
| 88 | + | ||
| 89 | + should 'list validations already processed' do | ||
| 90 | + processed_validations = [CreateEnterprise.new] | ||
| 91 | + @org.expects(:processed_validations).returns(processed_validations) | ||
| 92 | + | ||
| 93 | + get :list_processed, :profile => 'myorg' | ||
| 94 | + | ||
| 95 | + assert_same processed_validations, assigns(:processed_validations) | ||
| 96 | + | ||
| 97 | + assert_response :success | ||
| 98 | + assert_template 'list_processed' | ||
| 99 | + end | ||
| 100 | + | ||
| 101 | + should 'be able to display a validation that was already processed' do | ||
| 102 | + validation = CreateEnterprise.new | ||
| 103 | + @org.expects(:find_processed_validation).with('kakakaka').returns(validation) | ||
| 104 | + get :view_processed, :profile => 'myorg', :id => 'kakakaka' | ||
| 105 | + assert_same validation, assigns(:processed) | ||
| 106 | + end | ||
| 107 | + | ||
| 108 | + should 'display a form for editing the validation info' do | ||
| 109 | + info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 110 | + @org.expects(:validation_info).returns(info) | ||
| 111 | + get :edit_validation_info, :profile => 'myorg' | ||
| 112 | + assert_response :success | ||
| 113 | + assert_equal info, assigns(:info) | ||
| 114 | + end | ||
| 115 | + | ||
| 116 | + should 'save an alteration of the validation info' do | ||
| 117 | + info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 118 | + @org.expects(:validation_info).returns(info) | ||
| 119 | + post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'} | ||
| 120 | + | ||
| 121 | + assert_response :redirect | ||
| 122 | + assert_redirected_to :action => 'index' | ||
| 123 | + assert_equal info, assigns(:info) | ||
| 124 | + end | ||
| 125 | + | ||
| 126 | + should 'not save an empaty validation mthodology' do | ||
| 127 | + info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 128 | + @org.expects(:validation_info).returns(info) | ||
| 129 | + post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => ''} | ||
| 130 | + | ||
| 131 | + assert_response :success | ||
| 132 | + assert_equal info, assigns(:info) | ||
| 133 | + end | ||
| 134 | + | ||
| 135 | + should 'filter html from methodology of the validation info' do | ||
| 136 | + info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 137 | + @org.expects(:validation_info).returns(info) | ||
| 138 | + post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new <b>methodology</b>'} | ||
| 139 | + assert_sanitized assigns(:info).validation_methodology | ||
| 140 | + end | ||
| 141 | + | ||
| 142 | + should 'filter html from restrictions of the validation info' do | ||
| 143 | + info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 144 | + @org.expects(:validation_info).returns(info) | ||
| 145 | + post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new <b>methodology</b>'} | ||
| 146 | + assert_sanitized assigns(:info).restrictions | ||
| 147 | + end | ||
| 148 | + | ||
| 149 | +end |
test/functional/enterprise_validation_test.rb
| @@ -1,149 +0,0 @@ | @@ -1,149 +0,0 @@ | ||
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | -require 'enterprise_validation_controller' | ||
| 3 | - | ||
| 4 | -# Re-raise errors caught by the controller. | ||
| 5 | -class EnterpriseValidationController; def rescue_action(e) raise e end; end | ||
| 6 | - | ||
| 7 | -class EnterpriseValidationControllerTest < Test::Unit::TestCase | ||
| 8 | - | ||
| 9 | - all_fixtures | ||
| 10 | - | ||
| 11 | - def setup | ||
| 12 | - @controller = EnterpriseValidationController.new | ||
| 13 | - @request = ActionController::TestRequest.new | ||
| 14 | - @response = ActionController::TestResponse.new | ||
| 15 | - | ||
| 16 | - login_as 'ze' | ||
| 17 | - @org = Organization.create!(:identifier => 'myorg', :name => "My Org") | ||
| 18 | - give_permission('ze', 'validate_enterprise', @org) | ||
| 19 | - Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once | ||
| 20 | - end | ||
| 21 | - | ||
| 22 | - def test_local_files_reference | ||
| 23 | - assert_local_files_reference :get, :index, :profile => 'myorg' | ||
| 24 | - end | ||
| 25 | - | ||
| 26 | - def test_valid_xhtml | ||
| 27 | - | ||
| 28 | - # FIXME remove this after enable assert_valid_xhtml | ||
| 29 | - Profile.find_by_identifier('myorg') | ||
| 30 | - | ||
| 31 | - assert_valid_xhtml :get, :index, :profile => 'myorg' | ||
| 32 | - end | ||
| 33 | - | ||
| 34 | - should 'list pending validations on index' do | ||
| 35 | - empty = [] | ||
| 36 | - @org.expects(:pending_validations).returns(empty) | ||
| 37 | - get :index, :profile => 'myorg' | ||
| 38 | - assert_same empty, assigns(:pending_validations) | ||
| 39 | - assert_template 'index' | ||
| 40 | - end | ||
| 41 | - | ||
| 42 | - should 'display details and prompt for needed data when approving or rejecting enterprise' do | ||
| 43 | - validating = CreateEnterprise.new | ||
| 44 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validating) | ||
| 45 | - | ||
| 46 | - get :details, :profile => 'myorg', :id => 'kakakaka' | ||
| 47 | - assert_same validating, assigns(:pending) | ||
| 48 | - end | ||
| 49 | - | ||
| 50 | - should 'refuse to validate unexisting request' do | ||
| 51 | - @org.expects(:find_pending_validation).with('kakakaka').returns(nil) | ||
| 52 | - get :details , :profile => 'myorg', :id => 'kakakaka' | ||
| 53 | - assert_response 404 | ||
| 54 | - end | ||
| 55 | - | ||
| 56 | - should 'be able to actually validate enterprise on request' do | ||
| 57 | - validation = CreateEnterprise.new | ||
| 58 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 59 | - validation.expects(:approve) | ||
| 60 | - validation.expects(:code).returns('kakakaka') | ||
| 61 | - post :approve, :profile => 'myorg', :id => 'kakakaka' | ||
| 62 | - assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | ||
| 63 | - end | ||
| 64 | - | ||
| 65 | - should 'be able to reject an enterprise' do | ||
| 66 | - validation = CreateEnterprise.new | ||
| 67 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 68 | - validation.expects(:reject) | ||
| 69 | - validation.expects(:code).returns('kakakaka') | ||
| 70 | - post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise' | ||
| 71 | - assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | ||
| 72 | - end | ||
| 73 | - | ||
| 74 | - should 'require the user to fill in the explanation for an rejection' do | ||
| 75 | - validation = CreateEnterprise.new | ||
| 76 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | ||
| 77 | - | ||
| 78 | - # FIXME: this is not working, but should. Anyway the assert_response and | ||
| 79 | - # assert_template below in some test some things we need. But the | ||
| 80 | - # expectation below must be put to work. | ||
| 81 | - # | ||
| 82 | - #validation.expects(:reject).raises(ActiveRecord::RecordInvalid) | ||
| 83 | - | ||
| 84 | - post :reject, :profile => 'myorg', :id => 'kakakaka' | ||
| 85 | - assert_response :success | ||
| 86 | - assert_template 'details' | ||
| 87 | - end | ||
| 88 | - | ||
| 89 | - should 'list validations already processed' do | ||
| 90 | - processed_validations = [CreateEnterprise.new] | ||
| 91 | - @org.expects(:processed_validations).returns(processed_validations) | ||
| 92 | - | ||
| 93 | - get :list_processed, :profile => 'myorg' | ||
| 94 | - | ||
| 95 | - assert_same processed_validations, assigns(:processed_validations) | ||
| 96 | - | ||
| 97 | - assert_response :success | ||
| 98 | - assert_template 'list_processed' | ||
| 99 | - end | ||
| 100 | - | ||
| 101 | - should 'be able to display a validation that was already processed' do | ||
| 102 | - validation = CreateEnterprise.new | ||
| 103 | - @org.expects(:find_processed_validation).with('kakakaka').returns(validation) | ||
| 104 | - get :view_processed, :profile => 'myorg', :id => 'kakakaka' | ||
| 105 | - assert_same validation, assigns(:processed) | ||
| 106 | - end | ||
| 107 | - | ||
| 108 | - should 'display a form for editing the validation info' do | ||
| 109 | - info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 110 | - @org.expects(:validation_info).returns(info) | ||
| 111 | - get :edit_validation_info, :profile => 'myorg' | ||
| 112 | - assert_response :success | ||
| 113 | - assert_equal info, assigns(:info) | ||
| 114 | - end | ||
| 115 | - | ||
| 116 | - should 'save an alteration of the validation info' do | ||
| 117 | - info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 118 | - @org.expects(:validation_info).returns(info) | ||
| 119 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'} | ||
| 120 | - | ||
| 121 | - assert_response :redirect | ||
| 122 | - assert_redirected_to :action => 'index' | ||
| 123 | - assert_equal info, assigns(:info) | ||
| 124 | - end | ||
| 125 | - | ||
| 126 | - should 'not save an empaty validation mthodology' do | ||
| 127 | - info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 128 | - @org.expects(:validation_info).returns(info) | ||
| 129 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => ''} | ||
| 130 | - | ||
| 131 | - assert_response :success | ||
| 132 | - assert_equal info, assigns(:info) | ||
| 133 | - end | ||
| 134 | - | ||
| 135 | - should 'filter html from methodology of the validation info' do | ||
| 136 | - info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 137 | - @org.expects(:validation_info).returns(info) | ||
| 138 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new <b>methodology</b>'} | ||
| 139 | - assert_sanitized assigns(:info).validation_methodology | ||
| 140 | - end | ||
| 141 | - | ||
| 142 | - should 'filter html from restrictions of the validation info' do | ||
| 143 | - info = ValidationInfo.new(:validation_methodology => 'none') | ||
| 144 | - @org.expects(:validation_info).returns(info) | ||
| 145 | - post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new <b>methodology</b>'} | ||
| 146 | - assert_sanitized assigns(:info).restrictions | ||
| 147 | - end | ||
| 148 | - | ||
| 149 | -end |