Commit ab552d41ad9a2d265dde6360cd3e8ae3f4ee07ab
Committed by
Macartur Sousa
1 parent
e40dac3d
Exists in
elasticsearch_categories
Adds tests for the category filter
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com>
Showing
1 changed file
with
17 additions
and
3 deletions
Show diff stats
plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb
@@ -24,11 +24,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -24,11 +24,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
24 | end | 24 | end |
25 | 25 | ||
26 | def create_visible_models | 26 | def create_visible_models |
27 | + categories = [] | ||
27 | 5.times do | index | | 28 | 5.times do | index | |
29 | + categories[index] = fast_create Category, name: "Category#{index}", id: index+1 | ||
28 | create_user "person #{index}" | 30 | create_user "person #{index}" |
29 | end | 31 | end |
32 | + | ||
30 | 6.times do | index | | 33 | 6.times do | index | |
31 | - fast_create Community, name: "community #{index}", created_at: Date.new | 34 | + community = fast_create Community, name: "community #{index}", created_at: Date.new |
35 | + if categories[index] | ||
36 | + community.categories.push categories[index] | ||
37 | + community.save | ||
38 | + end | ||
32 | end | 39 | end |
33 | end | 40 | end |
34 | 41 | ||
@@ -45,7 +52,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -45,7 +52,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
45 | create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) | 52 | create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person) |
46 | create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) | 53 | create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person) |
47 | create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) | 54 | create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) |
48 | - | ||
49 | end | 55 | end |
50 | 56 | ||
51 | def create_private_article model,options = {} | 57 | def create_private_article model,options = {} |
@@ -142,7 +148,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -142,7 +148,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
142 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params | 148 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params |
143 | end | 149 | end |
144 | 150 | ||
145 | - | ||
146 | should 'filter community by default environment' do | 151 | should 'filter community by default environment' do |
147 | get :index, { "selected_type" => :community} | 152 | get :index, { "selected_type" => :community} |
148 | assert_response :success | 153 | assert_response :success |
@@ -173,4 +178,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -173,4 +178,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
173 | assert_select ".search-item", 0 | 178 | assert_select ".search-item", 0 |
174 | end | 179 | end |
175 | 180 | ||
181 | + should 'filter by selected categories' do | ||
182 | + get :index, { "categories" => "1,2,3" } | ||
183 | + assert_response :success | ||
184 | + assert_select ".search-item", 3 | ||
185 | + get :index, { "categories" => "5" } | ||
186 | + assert_response :success | ||
187 | + assert_select ".search-item", 1 | ||
188 | + end | ||
189 | + | ||
176 | end | 190 | end |