Commit e1d27af8f46aea28b5f4db587993fdcf8f629de0
1 parent
24f9fb1f
Exists in
elasticsearch_filter
and in
1 other branch
Adding private itens to be filtered into tests
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
1 changed file
with
62 additions
and
29 deletions
Show diff stats
plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb
@@ -5,7 +5,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -5,7 +5,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
5 | include ElasticsearchTestHelper | 5 | include ElasticsearchTestHelper |
6 | 6 | ||
7 | def indexed_models | 7 | def indexed_models |
8 | - [Community, Person] | 8 | + [Person,TextArticle,UploadedFile,Community,Event] |
9 | end | 9 | end |
10 | 10 | ||
11 | def create_instances | 11 | def create_instances |
@@ -14,31 +14,51 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -14,31 +14,51 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
14 | end | 14 | end |
15 | 15 | ||
16 | def create_instances_environment2 | 16 | def create_instances_environment2 |
17 | - 5.times do |index| | ||
18 | - create_user "Sample User Environment 2", environment:Environment.second | ||
19 | - end | ||
20 | - 6.times do |index| | ||
21 | - fast_create Community, name:"Sample Community Environment 2", created_at: Date.new, environment_id: Environment.second.id | ||
22 | - end | 17 | + create_user "Sample User Environment 2", environment:Environment.second |
18 | + fast_create Community, name:"Sample Community Environment 2", created_at: Date.new, environment_id: Environment.second.id | ||
23 | end | 19 | end |
24 | 20 | ||
25 | def create_instances_environment | 21 | def create_instances_environment |
26 | - create_people | ||
27 | - create_communities | 22 | + create_visible_models |
23 | + create_private_models | ||
28 | end | 24 | end |
29 | 25 | ||
30 | - def create_people | 26 | + def create_visible_models |
31 | 5.times do | index | | 27 | 5.times do | index | |
32 | create_user "person #{index}" | 28 | create_user "person #{index}" |
33 | end | 29 | end |
34 | - end | ||
35 | - | ||
36 | - def create_communities | ||
37 | 6.times do | index | | 30 | 6.times do | index | |
38 | fast_create Community, name: "community #{index}", created_at: Date.new | 31 | fast_create Community, name: "community #{index}", created_at: Date.new |
39 | end | 32 | end |
40 | end | 33 | end |
41 | 34 | ||
35 | + def create_private_models | ||
36 | + secret_user = create_user("Secret Person") | ||
37 | + fast_update(secret_user.person, secret: true, visible: true) | ||
38 | + | ||
39 | + invisible_user= create_user("Invisible Person") | ||
40 | + fast_update(invisible_user.person, secret: false, visible: false, public_profile: false) | ||
41 | + | ||
42 | + fast_create(Community, name: "secret community", secret: true, visible: true) | ||
43 | + fast_create(Community, name: "invisible community", secret: false, visible: false) | ||
44 | + | ||
45 | + 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) | ||
47 | + create_private_article(Event,public_person: User.first.person, private_person: invisible_user.person) | ||
48 | + | ||
49 | + end | ||
50 | + | ||
51 | + def create_private_article model,options = {} | ||
52 | + public_person = options[:public_person] | ||
53 | + private_person = options[:private_person] | ||
54 | + | ||
55 | + fast_create(model, name: "#{model.to_s.underscore} not advertise", advertise: false, published: true, profile_id: public_person, created_at: Time.now) | ||
56 | + fast_create(model, name: "#{model.to_s.underscore} not published", advertise: true, published: false, profile_id: public_person, created_at: Time.now) | ||
57 | + fast_create(model, name: "#{model.to_s.underscore} with not visible profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) | ||
58 | + fast_create(model, name: "#{model.to_s.underscore} with not public_profile", advertise: true, published: true, profile_id: private_person, created_at: Time.now) | ||
59 | + end | ||
60 | + | ||
61 | + | ||
42 | should 'work and uses control filter variables' do | 62 | should 'work and uses control filter variables' do |
43 | get :index | 63 | get :index |
44 | assert_response :success | 64 | assert_response :success |
@@ -74,18 +94,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -74,18 +94,18 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
74 | assert_template partial: '_person_display' | 94 | assert_template partial: '_person_display' |
75 | end | 95 | end |
76 | 96 | ||
77 | - should 'return results filtered by query with uppercase' do | ||
78 | - get :index, {'query' => "PERSON 1"} | ||
79 | - assert_response :success | ||
80 | - assert_template partial: '_person_display' | ||
81 | - assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
82 | - end | 97 | + should 'return results filtered by query with uppercase' do |
98 | + get :index, {'query' => "PERSON 1"} | ||
99 | + assert_response :success | ||
100 | + assert_template partial: '_person_display' | ||
101 | + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
102 | + end | ||
83 | 103 | ||
84 | - should 'return results filtered by query with downcase' do | ||
85 | - get :index, {'query' => "person 1"} | ||
86 | - assert_response :success | ||
87 | - assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
88 | - end | 104 | + should 'return results filtered by query with downcase' do |
105 | + get :index, {'query' => "person 1"} | ||
106 | + assert_response :success | ||
107 | + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
108 | + end | ||
89 | 109 | ||
90 | should 'return new community indexed' do | 110 | should 'return new community indexed' do |
91 | get :index, { "selected_type" => :community} | 111 | get :index, { "selected_type" => :community} |
@@ -122,11 +142,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -122,11 +142,6 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
122 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params | 142 | assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params |
123 | end | 143 | end |
124 | 144 | ||
125 | - should 'pass params to elastic search controller' do | ||
126 | - get 'index', { query: 'community' } | ||
127 | - assert_not_nil assigns(:results) | ||
128 | - assert_template partial: '_community_display' | ||
129 | - end | ||
130 | 145 | ||
131 | should 'filter community by default environment' do | 146 | should 'filter community by default environment' do |
132 | get :index, { "selected_type" => :community} | 147 | get :index, { "selected_type" => :community} |
@@ -140,4 +155,22 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -140,4 +155,22 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
140 | assert_select ".search-item", 5 | 155 | assert_select ".search-item", 5 |
141 | end | 156 | end |
142 | 157 | ||
158 | + should 'not show private text_article' do | ||
159 | + get :index, { :selected_type => "text_article" } | ||
160 | + assert_response :success | ||
161 | + assert_select ".search-item", 6 | ||
162 | + end | ||
163 | + | ||
164 | + should 'not show private uploaded_file' do | ||
165 | + get :index, { :selected_type => "uploaded_file" } | ||
166 | + assert_response :success | ||
167 | + assert_select ".search-item", 0 | ||
168 | + end | ||
169 | + | ||
170 | + should 'not show private event' do | ||
171 | + get :index, { :selected_type => "event" } | ||
172 | + assert_response :success | ||
173 | + assert_select ".search-item", 0 | ||
174 | + end | ||
175 | + | ||
143 | end | 176 | end |