Commit e22aa922dcfdeb7042f569910ffaa571043747b8
1 parent
a2e3c514
Exists in
staging
and in
42 other branches
Fix mock abused test
Showing
4 changed files
with
57 additions
and
69 deletions
Show diff stats
app/controllers/my_profile/enterprise_validation_controller.rb
| 1 | 1 | class EnterpriseValidationController < MyProfileController |
| 2 | 2 | |
| 3 | 3 | protect 'validate_enterprise', :profile |
| 4 | - | |
| 4 | + | |
| 5 | 5 | def index |
| 6 | 6 | @pending_validations = profile.pending_validations |
| 7 | 7 | end |
| ... | ... | @@ -27,7 +27,7 @@ class EnterpriseValidationController < MyProfileController |
| 27 | 27 | post_only :reject |
| 28 | 28 | def reject |
| 29 | 29 | @pending = profile.find_pending_validation(params[:id]) |
| 30 | - if @pending | |
| 30 | + if @pending | |
| 31 | 31 | @pending.reject_explanation = params[:reject_explanation] |
| 32 | 32 | begin |
| 33 | 33 | @pending.reject | ... | ... |
app/models/validation_info.rb
| ... | ... | @@ -2,9 +2,10 @@ class ValidationInfo < ActiveRecord::Base |
| 2 | 2 | |
| 3 | 3 | attr_accessible :validation_methodology, :restrictions, :organization |
| 4 | 4 | |
| 5 | - validates_presence_of :validation_methodology | |
| 6 | - | |
| 7 | 5 | belongs_to :organization |
| 8 | 6 | |
| 7 | + validates_presence_of :organization | |
| 8 | + validates_presence_of :validation_methodology | |
| 9 | + | |
| 9 | 10 | xss_terminate :only => [ :validation_methodology, :restrictions ], :on => 'validation' |
| 10 | 11 | end | ... | ... |
test/functional/enterprise_validation_controller_test.rb
| ... | ... | @@ -12,126 +12,109 @@ class EnterpriseValidationControllerTest < ActionController::TestCase |
| 12 | 12 | @controller = EnterpriseValidationController.new |
| 13 | 13 | @request = ActionController::TestRequest.new |
| 14 | 14 | @response = ActionController::TestResponse.new |
| 15 | - | |
| 15 | + | |
| 16 | 16 | login_as 'ze' |
| 17 | - @org = Organization.create!(:identifier => 'myorg', :name => "My Org") | |
| 17 | + @user = Profile['ze'] | |
| 18 | + @org = Organization.create!(identifier: 'myorg', name: "My Org") | |
| 18 | 19 | give_permission('ze', 'validate_enterprise', @org) |
| 19 | - Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once | |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | should 'list pending validations on index' do |
| 23 | - empty = [] | |
| 24 | - @org.expects(:pending_validations).returns(empty) | |
| 25 | - get :index, :profile => 'myorg' | |
| 26 | - assert_equal empty, assigns(:pending_validations) | |
| 23 | + get :index, profile: 'myorg' | |
| 24 | + assert_equal [], assigns(:pending_validations) | |
| 27 | 25 | assert_template 'index' |
| 28 | 26 | end |
| 29 | 27 | |
| 30 | 28 | should 'display details and prompt for needed data when approving or rejecting enterprise' do |
| 31 | - validating = CreateEnterprise.new | |
| 32 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validating) | |
| 33 | - | |
| 34 | - get :details, :profile => 'myorg', :id => 'kakakaka' | |
| 35 | - assert_same validating, assigns(:pending) | |
| 29 | + code = 'kakakaka' | |
| 30 | + @org.validations.create! code: code, name: 'test', identifier: 'test', requestor: @user, target: @org | |
| 31 | + get :details, profile: 'myorg', id: code | |
| 32 | + assert_equal @org.find_pending_validation(code), assigns(:pending) | |
| 36 | 33 | end |
| 37 | 34 | |
| 38 | 35 | should 'refuse to validate unexisting request' do |
| 39 | - @org.expects(:find_pending_validation).with('kakakaka').returns(nil) | |
| 40 | - get :details , :profile => 'myorg', :id => 'kakakaka' | |
| 36 | + get :details, profile: 'myorg', id: 'kakakaka' | |
| 41 | 37 | assert_response 404 |
| 42 | 38 | end |
| 43 | 39 | |
| 44 | 40 | should 'be able to actually validate enterprise on request' do |
| 45 | - validation = CreateEnterprise.new | |
| 46 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | |
| 47 | - validation.expects(:approve) | |
| 48 | - validation.expects(:code).returns('kakakaka') | |
| 49 | - post :approve, :profile => 'myorg', :id => 'kakakaka' | |
| 50 | - assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | |
| 41 | + code = 'kakakaka' | |
| 42 | + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org | |
| 43 | + post :approve, profile: 'myorg', id: code | |
| 44 | + assert_redirected_to action: 'view_processed', id: code | |
| 51 | 45 | end |
| 52 | 46 | |
| 53 | 47 | should 'be able to reject an enterprise' do |
| 54 | - validation = CreateEnterprise.new | |
| 55 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | |
| 56 | - validation.expects(:reject) | |
| 57 | - validation.expects(:code).returns('kakakaka') | |
| 58 | - post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise' | |
| 59 | - assert_redirected_to :action => 'view_processed', :id => 'kakakaka' | |
| 48 | + code = 'kakakaka' | |
| 49 | + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org | |
| 50 | + post :reject, profile: 'myorg', id: code, reject_explanation: 'this is not a solidarity economy enterprise' | |
| 51 | + assert_redirected_to action: 'view_processed', id: code | |
| 60 | 52 | end |
| 61 | 53 | |
| 62 | 54 | should 'require the user to fill in the explanation for an rejection' do |
| 63 | - validation = CreateEnterprise.new | |
| 64 | - validation.stubs(:environment).returns(Environment.default) | |
| 65 | - @org.expects(:find_pending_validation).with('kakakaka').returns(validation) | |
| 66 | - | |
| 67 | - # FIXME: this is not working, but should. Anyway the assert_response and | |
| 68 | - # assert_template below in some test some things we need. But the | |
| 69 | - # expectation below must be put to work. | |
| 70 | - # | |
| 71 | - #validation.expects(:reject).raises(ActiveRecord::RecordInvalid) | |
| 55 | + code = 'kakakaka' | |
| 56 | + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org | |
| 72 | 57 | |
| 73 | - post :reject, :profile => 'myorg', :id => 'kakakaka' | |
| 58 | + post :reject, profile: 'myorg', id: code | |
| 74 | 59 | assert_response :success |
| 75 | 60 | assert_template 'details' |
| 76 | 61 | end |
| 77 | 62 | |
| 78 | 63 | should 'list validations already processed' do |
| 79 | - processed_validations = [CreateEnterprise.new] | |
| 80 | - @org.expects(:processed_validations).returns(processed_validations) | |
| 81 | - | |
| 82 | - get :list_processed, :profile => 'myorg' | |
| 64 | + v = @org.validations.create! code: 'kakakaka', name: 'test2', identifier: 'test2', requestor: @user, target: @org | |
| 65 | + v.perform | |
| 83 | 66 | |
| 84 | - assert_equal processed_validations, assigns(:processed_validations) | |
| 67 | + get :list_processed, profile: 'myorg' | |
| 68 | + | |
| 69 | + assert_equal @org.processed_validations, assigns(:processed_validations) | |
| 85 | 70 | |
| 86 | 71 | assert_response :success |
| 87 | 72 | assert_template 'list_processed' |
| 88 | 73 | end |
| 89 | - | |
| 74 | + | |
| 90 | 75 | should 'be able to display a validation that was already processed' do |
| 91 | - validation = CreateEnterprise.new | |
| 92 | - @org.expects(:find_processed_validation).with('kakakaka').returns(validation) | |
| 93 | - get :view_processed, :profile => 'myorg', :id => 'kakakaka' | |
| 94 | - assert_same validation, assigns(:processed) | |
| 76 | + code = 'kakakaka' | |
| 77 | + v = @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org | |
| 78 | + v.perform | |
| 79 | + | |
| 80 | + get :view_processed, profile: 'myorg', id: code | |
| 81 | + assert_same @org.processed_validations.first, assigns(:processed) | |
| 95 | 82 | end |
| 96 | 83 | |
| 97 | 84 | should 'display a form for editing the validation info' do |
| 98 | - info = ValidationInfo.new(:validation_methodology => 'none') | |
| 99 | - @org.expects(:validation_info).returns(info) | |
| 100 | - get :edit_validation_info, :profile => 'myorg' | |
| 85 | + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org | |
| 86 | + get :edit_validation_info, profile: 'myorg' | |
| 101 | 87 | assert_response :success |
| 102 | 88 | assert_equal info, assigns(:info) |
| 103 | 89 | end |
| 104 | 90 | |
| 105 | 91 | should 'save an alteration of the validation info' do |
| 106 | - info = ValidationInfo.new(:validation_methodology => 'none') | |
| 107 | - @org.expects(:validation_info).returns(info) | |
| 108 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'} | |
| 109 | - | |
| 92 | + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org | |
| 93 | + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new methodology'} | |
| 94 | + | |
| 110 | 95 | assert_response :redirect |
| 111 | - assert_redirected_to :action => 'index' | |
| 112 | - assert_equal info, assigns(:info) | |
| 96 | + assert_redirected_to action: 'index' | |
| 97 | + info.reload | |
| 98 | + assert_equal info.reload, assigns(:info) | |
| 113 | 99 | end |
| 114 | 100 | |
| 115 | 101 | should 'not save an empaty validation mthodology' do |
| 116 | - info = ValidationInfo.new(:validation_methodology => 'none') | |
| 117 | - @org.expects(:validation_info).returns(info) | |
| 118 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => ''} | |
| 119 | - | |
| 102 | + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org | |
| 103 | + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: ''} | |
| 104 | + | |
| 120 | 105 | assert_response :success |
| 121 | 106 | assert_equal info, assigns(:info) |
| 122 | 107 | end |
| 123 | 108 | |
| 124 | 109 | should 'filter html from methodology of the validation info' do |
| 125 | - info = ValidationInfo.new(:validation_methodology => 'none') | |
| 126 | - @org.expects(:validation_info).returns(info) | |
| 127 | - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new <b>methodology</b>'} | |
| 110 | + @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org | |
| 111 | + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new <b>methodology</b>'} | |
| 128 | 112 | assert_sanitized assigns(:info).validation_methodology |
| 129 | 113 | end |
| 130 | 114 | |
| 131 | 115 | should 'filter html from restrictions of the validation info' do |
| 132 | - info = ValidationInfo.new(:validation_methodology => 'none') | |
| 133 | - @org.expects(:validation_info).returns(info) | |
| 134 | - post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new <b>methodology</b>'} | |
| 116 | + @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org | |
| 117 | + post :edit_validation_info, profile: 'myorg', info: {restrictions: 'new <b>methodology</b>'} | |
| 135 | 118 | assert_sanitized assigns(:info).restrictions |
| 136 | 119 | end |
| 137 | 120 | ... | ... |
test/integration/routing_test.rb
| ... | ... | @@ -27,6 +27,10 @@ class RoutingTest < ActionController::IntegrationTest |
| 27 | 27 | assert_routing('/account/new_password/90dfhga7sadgd0as6saas', :controller => 'account', :action => 'new_password', :code => '90dfhga7sadgd0as6saas') |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | + should 'ignore case for profiles' do | |
| 31 | + assert_routing '/myprofile/ZE/cms', profile: 'ZE', controller: 'cms', action: 'index' | |
| 32 | + end | |
| 33 | + | |
| 30 | 34 | def test_cms |
| 31 | 35 | assert_routing('/myprofile/ze/cms', :profile => 'ze', :controller => 'cms', :action => 'index') |
| 32 | 36 | end | ... | ... |