cirandas.net

ref: master

test/functional/enterprise_validation_controller_test.rb


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require_relative '../test_helper'

class EnterpriseValidationControllerTest < ActionController::TestCase

  all_fixtures

  def setup
    @controller = EnterpriseValidationController.new

    login_as 'ze'
    @user = Profile['ze']
    @org = Organization.create!(identifier: 'myorg', name: "My Org")
    give_permission('ze', 'validate_enterprise', @org)
  end

  should 'list pending validations on index' do
    get :index, profile: 'myorg'
    assert_equal [], assigns(:pending_validations)
    assert_template 'index'
  end

  should 'display details and prompt for needed data when approving or rejecting enterprise' do
    code = 'kakakaka'
    @org.validations.create! code: code, name: 'test', identifier: 'test', requestor: @user, target: @org
    get :details, profile: 'myorg', id: code
    assert_equal @org.find_pending_validation(code), assigns(:pending)
  end

  should 'refuse to validate unexisting request' do
    get :details, profile: 'myorg', id: 'kakakaka'
    assert_response 404
  end

  should 'be able to actually validate enterprise on request' do
    code = 'kakakaka'
    @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
    post :approve, profile: 'myorg', id: code
    assert_redirected_to action: 'view_processed', id: code
  end

  should 'be able to reject an enterprise' do
    code = 'kakakaka'
    @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
    post :reject, profile: 'myorg', id: code, reject_explanation: 'this is not a solidarity economy enterprise'
    assert_redirected_to action: 'view_processed', id: code
  end

  should 'require the user to fill in the explanation for an rejection' do
    code = 'kakakaka'
    @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org

    post :reject, profile: 'myorg', id: code
    assert_response :success
    assert_template 'details'
  end

  should 'list validations already processed' do
    v = @org.validations.create! code: 'kakakaka', name: 'test2', identifier: 'test2', requestor: @user, target: @org
    v.perform

    get :list_processed, profile: 'myorg'

    assert_equal @org.processed_validations, assigns(:processed_validations)

    assert_response :success
    assert_template 'list_processed'
  end

  should 'be able to display a validation that was already processed' do
    code = 'kakakaka'
    v = @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
    v.perform

    get :view_processed, profile: 'myorg', id: code
    assert_same @org.processed_validations.first, assigns(:processed)
  end

  should 'display a form for editing the validation info' do
    info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
    get :edit_validation_info, profile: 'myorg'
    assert_response :success
    assert_equal info, assigns(:info)
  end

  should 'save an alteration of the validation info' do
    info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
    post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new methodology'}

    assert_response :redirect
    assert_redirected_to action: 'index'
    info.reload
    assert_equal info.reload, assigns(:info)
  end

  should 'not save an empaty validation mthodology' do
    info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
    post :edit_validation_info, profile: 'myorg', info: {validation_methodology: ''}

    assert_response :success
    assert_equal info, assigns(:info)
  end

  should 'filter html from methodology of the validation info' do
    @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
    post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new <b>methodology</b>'}
    assert_sanitized assigns(:info).validation_methodology
  end

  should 'filter html from restrictions of the validation info' do
    @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
    post :edit_validation_info, profile: 'myorg', info: {restrictions: 'new <b>methodology</b>'}
    assert_sanitized assigns(:info).restrictions
  end

end