search_controller_test.rb
4.52 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
require File.dirname(__FILE__) + '/../../../../test/test_helper'
require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
require(
File.dirname(__FILE__) +
'/../../../../app/controllers/public/search_controller'
)
class SearchController; def rescue_action(e) raise e end; end
class SearchControllerTest < ActionController::TestCase
include PluginTestHelper
def setup
@environment = Environment.default
@environment.enabled_plugins = ['MpogSoftwarePlugin']
@environment.save
@controller = SearchController.new
@request = ActionController::TestRequest.new
@request.stubs(:ssl?).returns(:false)
@response = ActionController::TestResponse.new
create_software_categories
end
should "communities searches don't have software or institution" do
community = create_community("New Community")
software = create_software_info("New Software")
institution = create_private_institution(
"New Private Institution",
"NPI" ,
"Brazil",
"DF",
"Gama",
"66.544.314/0001-63"
)
get :communities, :query => "New"
assert_includes assigns(:searches)[:communities][:results], community
assert_not_includes assigns(:searches)[:communities][:results], software
assert_not_includes assigns(:searches)[:communities][:results], institution
end
should "software_infos search don't have community or institution" do
community = create_community("New Community")
software = create_software_info("New Software")
institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
software.license_info = LicenseInfo.create :version=>"GPL - 1.0"
software.save!
get :software_infos, :query => "New"
assert_includes assigns(:searches)[:software_infos][:results], software.community
assert_not_includes assigns(:searches)[:software_infos][:results], community
assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
end
should "Don't found template in communities search" do
community = create_community("New Community")
software = create_software_info("New Software")
software.license_info = LicenseInfo.create(:version => "GPL")
software.save!
institution = create_private_institution(
"New Private Institution",
"NPI" ,
"Brazil",
"DF",
"Gama",
"66.544.314/0001-63"
)
community_template = create_community("New Community Template")
community_template.is_template = true
community_template.save!
get :communities, :query => "New"
assert_not_includes(
assigns(:searches)[:communities][:results],
community_template
)
end
should "institutions_search don't have community or software" do
community = create_community("New Community")
software = create_software_info("New Software")
institution = create_private_institution(
"New Private Institution",
"NPI" ,
"Brazil",
"DF",
"Gama",
"66.544.314/0001-63"
)
get :institutions, :query => "New"
assert_includes(
assigns(:searches)[:institutions][:results],
institution.community
)
assert_not_includes assigns(:searches)[:institutions][:results], community
assert_not_includes(
assigns(:searches)[:institutions][:results],
software.community
)
end
should "software_infos search by category" do
software_one = create_software_info("Software One")
software_two = create_software_info("Software Two")
software_one.community.categories << Category.first
software_two.community.categories << Category.last
software_one.license_info = LicenseInfo.create :version=>"GPL - 1.0"
software_two.license_info = LicenseInfo.create :version=>"GPL - 1.0"
software_one.save!
software_two.save!
get(
:software_infos,
:query => "",
:selected_categories => [Category.first.id]
)
assert_includes assigns(:searches)[:software_infos][:results], software_one.community
assert_not_includes assigns(:searches)[:software_infos][:results], software_two.community
end
private
def create_software_categories
category_software = Category.create!(
:name => "Software",
:environment => @environment
)
Category.create(
:name => "Category One",
:environment => @environment,
:parent => category_software
)
Category.create(
:name => "Category Two",
:environment => @environment,
:parent => category_software
)
end
end