Commit cd103fdc63a0b66ba029c83b87e13f2ce823e0cf
1 parent
37845587
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
22 additions
and
1 deletions
Show diff stats
plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb
@@ -23,6 +23,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -23,6 +23,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
23 | end | 23 | end |
24 | 24 | ||
25 | def create_instances_environment | 25 | def create_instances_environment |
26 | + create_categories | ||
26 | create_people | 27 | create_people |
27 | create_communities | 28 | create_communities |
28 | end | 29 | end |
@@ -34,8 +35,19 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -34,8 +35,19 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
34 | end | 35 | end |
35 | 36 | ||
36 | def create_communities | 37 | def create_communities |
38 | + categories = [Category.find(1), Category.find(2), Category.find(3), Category.find(4), Category.find(5)] | ||
37 | 6.times do | index | | 39 | 6.times do | index | |
38 | - fast_create Community, name: "community #{index}", created_at: Date.new | 40 | + community = fast_create Community, name: "community #{index}", created_at: Date.new |
41 | + if categories[index] | ||
42 | + community.categories.push categories[index] | ||
43 | + community.save | ||
44 | + end | ||
45 | + end | ||
46 | + end | ||
47 | + | ||
48 | + def create_categories | ||
49 | + 5.times do | index | | ||
50 | + fast_create Category, name: "category#{index}", id: index+1 | ||
39 | end | 51 | end |
40 | end | 52 | end |
41 | 53 | ||
@@ -140,4 +152,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -140,4 +152,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
140 | assert_select ".search-item", 5 | 152 | assert_select ".search-item", 5 |
141 | end | 153 | end |
142 | 154 | ||
155 | + should 'filter by selected categories' do | ||
156 | + get :index, { "categories" => "1,2,3" } | ||
157 | + assert_response :success | ||
158 | + assert_select ".search-item", 3 | ||
159 | + get :index, { "categories" => "5" } | ||
160 | + assert_response :success | ||
161 | + assert_select ".search-item", 1 | ||
162 | + end | ||
163 | + | ||
143 | end | 164 | end |