mpog_software_plugin_controller_test.rb
5.71 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
require File.dirname(__FILE__) + '/../../../../test/test_helper'
require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller'
class MpogSoftwarePluginController; def rescue_action(e) raise e end; end
class MpogSoftwarePluginControllerTest < ActionController::TestCase
def setup
admin = create_user("adminuser").person
admin.stubs(:has_permission?).returns("true")
@environment = Environment.default
@environment.enabled_plugins = ['MpogSoftwarePlugin']
@environment.add_admin(admin)
@environment.save
@govPower = GovernmentalPower.create(:name=>"Some Gov Power")
@govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
@response = ActionController::TestResponse.new
@institution_list = []
@institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere)
@institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", @govPower, @govSphere)
end
should "Search for institution with acronym" do
xhr :get, :get_institutions, :query=>"TRU"
json_response = ActiveSupport::JSON.decode(@response.body)
assert_equal "Tribunal Regional da Uniao", json_response[0]["value"]
end
should "Search for institution with name" do
xhr :get, :get_institutions, :query=>"Minis"
json_response = ActiveSupport::JSON.decode(@response.body)
assert_equal "Ministerio Publico da Uniao", json_response[0]["value"]
end
should "search with name or acronym and return a list with institutions" do
xhr :get, :get_institutions, :query=>"uni"
json_response = ActiveSupport::JSON.decode(@response.body)
assert_equal "Ministerio Publico da Uniao", json_response[0]["value"]
assert_equal "Tribunal Regional da Uniao", json_response[1]["value"]
end
should "method create_institution return the html for modal" do
xhr :get, :create_institution
assert_template 'create_institution'
end
should "create new institution with ajax" do
@controller.stubs(:verify_recaptcha).returns(true)
xhr :get, :new_institution,
:authenticity_token=>"dsa45a6das52sd",
:community=>{:name=>"foo bar"},
:institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"},
:governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
:recaptcha_response_field=>''
json_response = ActiveSupport::JSON.decode(@response.body)
assert json_response["success"]
end
should "not create a institution that already exists" do
@controller.stubs(:verify_recaptcha).returns(true)
xhr :get, :new_institution,
:authenticity_token=>"dsa45a6das52sd",
:community=>{:name=>"Ministerio Publico da Uniao"},
:institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"},
:governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
:recaptcha_response_field=>''
json_response = ActiveSupport::JSON.decode(@response.body)
assert !json_response["success"]
end
should "set the environment admin as institution community admin" do
@controller.stubs(:verify_recaptcha).returns(true)
xhr :get, :new_institution,
:authenticity_token=>"dsa45a6das52sd",
:community=>{:name=>"Another instituon community"},
:institution => {:cnpj=>"10.254.577/8910-12", :acronym=>"aic", :type=>"PublicInstitution"},
:governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
:recaptcha_response_field=>''
json_response = ActiveSupport::JSON.decode(@response.body)
assert json_response["success"]
assert Community.last.admins.include?(@environment.admins.first)
assert_equal Community.last.name, "Another instituon community"
end
should "verify if institution name already exists" do
xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao"
assert_equal "true", @response.body
xhr :get, :institution_already_exists, :name=>"Another name here"
assert_equal "false", @response.body
end
should "response as XML to export softwares" do
get :download, :format => 'xml'
assert_equal 'text/xml', @response.content_type
end
should "response as CSV to export softwares" do
get :download, :format => 'csv'
assert_equal 'text/csv', @response.content_type
assert_equal "name;acronym;demonstration_url;e_arq;e_mag;e_ping;features;icp_brasil;objectives;operating_platform\n", @response.body
end
should "hide registration incomplete message" do
xhr :get, :hide_registration_incomplete_percentage, :hide=>true
assert_equal "true", @response.body
end
should "not hide registration incomplete message" do
xhr :get, :hide_registration_incomplete_percentage, :hide=>false
assert_equal "false", @response.body
end
should "update institution date_modification in your creation" do
@controller.stubs(:verify_recaptcha).returns(true)
xhr :get, :new_institution,
:authenticity_token=>"dsa45a6das52sd",
:community=>{:name=>"foo bar"},
:institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"},
:governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
:recaptcha_response_field=>''
date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s
assert_equal date, Institution.last.date_modification
end
private
def create_public_institution name, acronym, gov_p, gov_s
institution_community = Community::new :name=>name
institution = PublicInstitution.new
institution.community = institution_community
institution.name = name
institution.acronym = acronym
institution.governmental_power = gov_p
institution.governmental_sphere = gov_s
institution.save
institution
end
end