Commit 4521fc48d44e418667f5cd3873e34f7da7b0d3fc
1 parent
b0f1226f
Exists in
master
and in
79 other branches
Add functional test to person and software search
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
1 changed file
with
173 additions
and
17 deletions
Show diff stats
test/functional/search_controller_test.rb
@@ -31,49 +31,191 @@ class SearchControllerTest < ActionController::TestCase | @@ -31,49 +31,191 @@ class SearchControllerTest < ActionController::TestCase | ||
31 | software_database = SoftwareDatabase.new(version: "1.0", operating_system: "windows") | 31 | software_database = SoftwareDatabase.new(version: "1.0", operating_system: "windows") |
32 | software_database.database_description = DatabaseDescription.last | 32 | software_database.database_description = DatabaseDescription.last |
33 | software_database.save! | 33 | software_database.save! |
34 | + | ||
34 | end | 35 | end |
35 | 36 | ||
36 | should "search for people by name" do | 37 | should "search for people by name" do |
37 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | 38 | + p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person |
38 | 39 | ||
39 | - get :people, :query => "user_1" | 40 | + get :people, :query => "user_1" |
40 | 41 | ||
41 | - assert_includes assigns(:searches)[:people][:results], p1 | 42 | + assert_includes assigns(:searches)[:people][:results], p1 |
42 | end | 43 | end |
43 | 44 | ||
44 | should "search for people by state" do | 45 | should "search for people by state" do |
45 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | 46 | + p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person |
46 | 47 | ||
47 | - get :people, :state => "DF" | 48 | + get :people, :state => "DF" |
48 | 49 | ||
49 | - assert_includes assigns(:searches)[:people][:results], p1 | 50 | + assert_includes assigns(:searches)[:people][:results], p1 |
50 | end | 51 | end |
51 | 52 | ||
52 | should "search for people by city" do | 53 | should "search for people by city" do |
53 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | 54 | + p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person |
54 | 55 | ||
55 | - get :people, :city => "Gama" | 56 | + get :people, :city => "Gama" |
56 | 57 | ||
57 | - assert_includes assigns(:searches)[:people][:results], p1 | 58 | + assert_includes assigns(:searches)[:people][:results], p1 |
58 | end | 59 | end |
59 | 60 | ||
60 | should "search for people by email" do | 61 | should "search for people by email" do |
61 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | 62 | + p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person |
63 | + | ||
64 | + get :people, :email => "user_1@user.com" | ||
65 | + | ||
66 | + assert_includes assigns(:searches)[:people][:results], p1 | ||
67 | + end | ||
68 | + | ||
69 | + | ||
70 | + should "search for software by name" do | ||
71 | + software = create_software("beautiful") | ||
72 | + | ||
73 | + params = {"type"=>"Software", "query"=>"", "name"=>"beautiful", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"} | ||
74 | + get :communities, params | ||
75 | + | ||
76 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
77 | + end | ||
78 | + | ||
79 | + should "search for software by database" do | ||
80 | + software = create_software("beautiful") | ||
81 | + software.software_databases.clear() | ||
82 | + software.software_databases << SoftwareDatabase.last | ||
83 | + software.save! | ||
84 | + | ||
85 | + params = {"type"=>"Software", "query"=>"", "name"=>"", | ||
86 | + "database_description"=>{"id"=>SoftwareDatabase.last.database_description.id}, | ||
87 | + "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "controlled_vocabulary"=>"", | ||
88 | + "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
89 | + "commit"=>"Search"} | ||
90 | + get :communities, params | ||
91 | + | ||
92 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
93 | + end | ||
94 | + | ||
95 | + should "search for software by programming language" do | ||
96 | + software = create_software("beautiful") | ||
97 | + software.software_languages.clear() | ||
98 | + software.software_languages << SoftwareLanguage.last | ||
99 | + software.save! | ||
100 | + | ||
101 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
102 | + "programming_language"=>{"id"=>SoftwareLanguage.last.programming_language.id}, | ||
103 | + "operating_system"=>{"id"=>""}, "controlled_vocabulary"=>"", | ||
104 | + "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
105 | + "commit"=>"Search"} | ||
106 | + get :communities, params | ||
107 | + | ||
108 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
109 | + end | ||
110 | + | ||
111 | + should "search for software by operating system" do | ||
112 | + software = create_software("beautiful") | ||
113 | + software.operating_systems.clear() | ||
114 | + software.operating_systems << OperatingSystem.last | ||
115 | + software.save! | ||
116 | + | ||
117 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
118 | + "programming_language"=>{"id"=>""}, | ||
119 | + "operating_system"=>{"id"=>OperatingSystem.last.id}, | ||
120 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
121 | + "commit"=>"Search"} | ||
122 | + get :communities, params | ||
123 | + | ||
124 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
125 | + end | ||
126 | + | ||
127 | + should "search for software by controlled vocabulary" do | ||
128 | + software = create_software("beautiful") | ||
129 | + software.controlled_vocabulary.habitation = true | ||
130 | + software.controlled_vocabulary.save! | ||
62 | 131 | ||
63 | - get :people, :email => "user_1@user.com" | 132 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, |
133 | + "programming_language"=>{"id"=>""}, | ||
134 | + "operating_system"=>{"id"=>""}, | ||
135 | + "controlled_vocabulary"=>"habitation", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
136 | + "commit"=>"Search"} | ||
137 | + get :communities, params | ||
64 | 138 | ||
65 | - assert_includes assigns(:searches)[:people][:results], p1 | 139 | + assert_includes assigns(:searches)[:communities][:results], software.community |
66 | end | 140 | end |
67 | 141 | ||
142 | + should "search for software by license info" do | ||
143 | + software = create_software("beautiful") | ||
144 | + software.license_info = LicenseInfo.last | ||
145 | + software.save! | ||
68 | 146 | ||
69 | - # should "search for software by name" do | ||
70 | - # software = create_software("software") | 147 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, |
148 | + "programming_language"=>{"id"=>""}, | ||
149 | + "operating_system"=>{"id"=>""}, | ||
150 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>LicenseInfo.last.id}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
151 | + "commit"=>"Search"} | ||
152 | + get :communities, params | ||
71 | 153 | ||
72 | - # get :communities, :type => "Software", :query => "", :name => "software", :database_description => {:id => ""}, :programming_language => {:id=>""}, :operating_system => {:id => ""}, :controlled_vocabulary => "", :license_info => {:id => ""}, :e_ping => "", :e_mag => "", :icp_brasil => "", :e_arq => "", :internacionalizable => "" | 154 | + assert_includes assigns(:searches)[:communities][:results], software.community |
155 | + end | ||
156 | + | ||
157 | + | ||
158 | + should "search for software by e_mag" do | ||
159 | + software = create_software("beautiful") | ||
160 | + software.e_mag = true | ||
161 | + software.save! | ||
162 | + | ||
163 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
164 | + "programming_language"=>{"id"=>""}, | ||
165 | + "operating_system"=>{"id"=>""}, | ||
166 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"true", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
167 | + "commit"=>"Search"} | ||
168 | + get :communities, params | ||
169 | + | ||
170 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
171 | + end | ||
172 | + | ||
173 | + | ||
174 | + should "search for software by e_ping" do | ||
175 | + software = create_software("beautiful") | ||
176 | + software.e_ping = true | ||
177 | + software.save! | ||
178 | + | ||
179 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
180 | + "programming_language"=>{"id"=>""}, | ||
181 | + "operating_system"=>{"id"=>""}, | ||
182 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"true", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", | ||
183 | + "commit"=>"Search"} | ||
184 | + get :communities, params | ||
185 | + | ||
186 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
187 | + end | ||
73 | 188 | ||
74 | - # assert_includes assigns(:searches)[:communities][:results], software.community | ||
75 | - # end | ||
76 | 189 | ||
190 | + should "search for software by icp_brasil" do | ||
191 | + software = create_software("beautiful") | ||
192 | + software.icp_brasil = true | ||
193 | + software.save! | ||
194 | + | ||
195 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
196 | + "programming_language"=>{"id"=>""}, | ||
197 | + "operating_system"=>{"id"=>""}, | ||
198 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"true", "e_arq"=>"", "internacionalizable"=>"", | ||
199 | + "commit"=>"Search"} | ||
200 | + get :communities, params | ||
201 | + | ||
202 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
203 | + end | ||
204 | + | ||
205 | + should "search for software by e_arq" do | ||
206 | + software = create_software("beautiful") | ||
207 | + software.e_arq = true | ||
208 | + software.save! | ||
209 | + | ||
210 | + params = {"type"=>"Software", "query"=>"", "name"=>"", "database_description"=>{"id"=>""}, | ||
211 | + "programming_language"=>{"id"=>""}, | ||
212 | + "operating_system"=>{"id"=>""}, | ||
213 | + "controlled_vocabulary"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"true", "internacionalizable"=>"", | ||
214 | + "commit"=>"Search"} | ||
215 | + get :communities, params | ||
216 | + | ||
217 | + assert_includes assigns(:searches)[:communities][:results], software.community | ||
218 | + end | ||
77 | protected | 219 | protected |
78 | 220 | ||
79 | def create_user name, state, city, email | 221 | def create_user name, state, city, email |
@@ -94,6 +236,20 @@ class SearchControllerTest < ActionController::TestCase | @@ -94,6 +236,20 @@ class SearchControllerTest < ActionController::TestCase | ||
94 | software_info.software_languages << SoftwareLanguage.last | 236 | software_info.software_languages << SoftwareLanguage.last |
95 | software_info.software_databases << SoftwareDatabase.last | 237 | software_info.software_databases << SoftwareDatabase.last |
96 | software_info.operating_systems << OperatingSystem.last | 238 | software_info.operating_systems << OperatingSystem.last |
239 | + software_info.license_info = LicenseInfo.last | ||
240 | + | ||
241 | + | ||
242 | + cv = ControlledVocabulary.new() | ||
243 | + cv.attributes.each do |key| | ||
244 | + if(key.first == 'id' || key.first == 'software_info_id') | ||
245 | + next | ||
246 | + end | ||
247 | + cv.update_attribute(key.first, false) | ||
248 | + end | ||
249 | + cv.save! | ||
250 | + | ||
251 | + software_info.controlled_vocabulary = cv | ||
252 | + | ||
97 | software_info.save! | 253 | software_info.save! |
98 | 254 | ||
99 | community.save! | 255 | community.save! |