Commit 1110c0124def61533d8a0631fb589ee00eaedbba

Authored by Dylan Guedes
Committed by Macartur Sousa
1 parent cebb76c4
Exists in fix_sign_up_form

Elasticsearch: Adds tests for the category

* Adds filter tests for controller
* Adds categories tests for the api

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com>
plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb
... ... @@ -57,8 +57,13 @@ class ElasticsearchPluginApiTest &lt; ActiveSupport::TestCase
57 57 end
58 58  
59 59 def create_instances
  60 + 5.times.each {|index| fast_create Category, name: "category#{index}", id: index+1 }
60 61 7.times.each {|index| create_user "person #{index}"}
61   - 4.times.each {|index| fast_create Community, name: "community #{index}" }
  62 + 4.times.each do |index|
  63 + community = fast_create Community, name: "community #{index}"
  64 + community.categories.push Category.find(index+1)
  65 + community.save
  66 + end
62 67 end
63 68  
64 69 should 'show all types avaliable in /search/types endpoint' do
... ... @@ -110,4 +115,11 @@ class ElasticsearchPluginApiTest &lt; ActiveSupport::TestCase
110 115 assert_equal 7, json["results"].count
111 116 end
112 117  
  118 + should 'respond with only the correct categories' do
  119 + get "/api/v1/search?categories=1,2,3"
  120 + json = JSON.parse(last_response.body)
  121 + assert_equal 200, last_response.status
  122 + assert_equal 3, json["results"].count
  123 + end
  124 +
113 125 end
... ...
plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb
... ... @@ -24,11 +24,18 @@ class ElasticsearchPluginControllerTest &lt; ActionController::TestCase
24 24 end
25 25  
26 26 def create_visible_models
  27 + categories = []
27 28 5.times do | index |
  29 + categories[index] = fast_create Category, name: "Category#{index}", id: index+1
28 30 create_user "person #{index}"
29 31 end
  32 +
30 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 39 end
33 40 end
34 41  
... ... @@ -45,7 +52,6 @@ class ElasticsearchPluginControllerTest &lt; ActionController::TestCase
45 52 create_private_article(TextArticle,public_person: User.first.person, private_person: invisible_user.person)
46 53 create_private_article(UploadedFile,public_person: User.first.person, private_person: invisible_user.person)
47 54 create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person)
48   -
49 55 end
50 56  
51 57 def create_private_article model,options = {}
... ... @@ -142,7 +148,6 @@ class ElasticsearchPluginControllerTest &lt; ActionController::TestCase
142 148 assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params
143 149 end
144 150  
145   -
146 151 should 'filter community by default environment' do
147 152 get :index, { "selected_type" => :community}
148 153 assert_response :success
... ... @@ -173,4 +178,13 @@ class ElasticsearchPluginControllerTest &lt; ActionController::TestCase
173 178 assert_select ".search-item", 0
174 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 190 end
... ...