enterprise_validation_controller_test.rb
5.29 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require_relative "../test_helper"
require 'enterprise_validation_controller'
# Re-raise errors caught by the controller.
class EnterpriseValidationController; def rescue_action(e) raise e end; end
class EnterpriseValidationControllerTest < ActionController::TestCase
all_fixtures
def setup
@controller = EnterpriseValidationController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
login_as 'ze'
@org = Organization.create!(:identifier => 'myorg', :name => "My Org")
give_permission('ze', 'validate_enterprise', @org)
Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
end
should 'list pending validations on index' do
empty = []
@org.expects(:pending_validations).returns(empty)
get :index, :profile => 'myorg'
assert_equal empty, assigns(:pending_validations)
assert_template 'index'
end
should 'display details and prompt for needed data when approving or rejecting enterprise' do
validating = CreateEnterprise.new
@org.expects(:find_pending_validation).with('kakakaka').returns(validating)
get :details, :profile => 'myorg', :id => 'kakakaka'
assert_same validating, assigns(:pending)
end
should 'refuse to validate unexisting request' do
@org.expects(:find_pending_validation).with('kakakaka').returns(nil)
get :details , :profile => 'myorg', :id => 'kakakaka'
assert_response 404
end
should 'be able to actually validate enterprise on request' do
validation = CreateEnterprise.new
@org.expects(:find_pending_validation).with('kakakaka').returns(validation)
validation.expects(:approve)
validation.expects(:code).returns('kakakaka')
post :approve, :profile => 'myorg', :id => 'kakakaka'
assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
end
should 'be able to reject an enterprise' do
validation = CreateEnterprise.new
@org.expects(:find_pending_validation).with('kakakaka').returns(validation)
validation.expects(:reject)
validation.expects(:code).returns('kakakaka')
post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise'
assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
end
should 'require the user to fill in the explanation for an rejection' do
validation = CreateEnterprise.new
validation.stubs(:environment).returns(Environment.default)
@org.expects(:find_pending_validation).with('kakakaka').returns(validation)
# FIXME: this is not working, but should. Anyway the assert_response and
# assert_template below in some test some things we need. But the
# expectation below must be put to work.
#
#validation.expects(:reject).raises(ActiveRecord::RecordInvalid)
post :reject, :profile => 'myorg', :id => 'kakakaka'
assert_response :success
assert_template 'details'
end
should 'list validations already processed' do
processed_validations = [CreateEnterprise.new]
@org.expects(:processed_validations).returns(processed_validations)
get :list_processed, :profile => 'myorg'
assert_equal 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
validation = CreateEnterprise.new
@org.expects(:find_processed_validation).with('kakakaka').returns(validation)
get :view_processed, :profile => 'myorg', :id => 'kakakaka'
assert_same validation, assigns(:processed)
end
should 'display a form for editing the validation info' do
info = ValidationInfo.new(:validation_methodology => 'none')
@org.expects(:validation_info).returns(info)
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 = ValidationInfo.new(:validation_methodology => 'none')
@org.expects(:validation_info).returns(info)
post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'}
assert_response :redirect
assert_redirected_to :action => 'index'
assert_equal info, assigns(:info)
end
should 'not save an empaty validation mthodology' do
info = ValidationInfo.new(:validation_methodology => 'none')
@org.expects(:validation_info).returns(info)
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
info = ValidationInfo.new(:validation_methodology => 'none')
@org.expects(:validation_info).returns(info)
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
info = ValidationInfo.new(:validation_methodology => 'none')
@org.expects(:validation_info).returns(info)
post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new <b>methodology</b>'}
assert_sanitized assigns(:info).restrictions
end
end