Commit 121887c0b1fa722e116da0d5055e09eff8023e3c
1 parent
2c266d11
Exists in
elasticsearch_api
Fixed elasticsearch tests
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
4 changed files
with
36 additions
and
29 deletions
Show diff stats
plugins/elasticsearch/Rakefile
@@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
2 | 2 | ||
3 | require 'open-uri' | 3 | require 'open-uri' |
4 | 4 | ||
5 | +def elasticsearch_development | ||
6 | + return ENV["ELASTICSEARCH_DEVELOPMENT"].nil? | ||
7 | +end | ||
8 | + | ||
5 | desc "download elasticsearch" | 9 | desc "download elasticsearch" |
6 | task :download do | 10 | task :download do |
7 | unless File.exists? '/tmp/elasticsearch.deb' | 11 | unless File.exists? '/tmp/elasticsearch.deb' |
@@ -22,13 +26,19 @@ task :start do | @@ -22,13 +26,19 @@ task :start do | ||
22 | if not system 'sudo systemctl start elasticsearch > /dev/null' | 26 | if not system 'sudo systemctl start elasticsearch > /dev/null' |
23 | Rake::Task['install'].invoke | 27 | Rake::Task['install'].invoke |
24 | end | 28 | end |
25 | - sh 'sudo systemctl start elasticsearch' | ||
26 | - sh 'sudo systemctl enable elasticsearch' | ||
27 | - sleep 100 # this sleep gives time to the service to be ready. | 29 | + puts "Enable Elasticsearch service" |
30 | + if elasticsearch_development | ||
31 | + sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' | ||
32 | + sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' | ||
33 | + sleep 2 | ||
34 | + end | ||
28 | end | 35 | end |
29 | 36 | ||
30 | desc "stop elasticsearch" | 37 | desc "stop elasticsearch" |
31 | task :stop do | 38 | task :stop do |
32 | - sh 'sudo systemctl stop elasticsearch' | ||
33 | - sh 'sudo systemctl disable elasticsearch' | 39 | + puts "Disable elasticsearch service" |
40 | + if elasticsearch_development | ||
41 | + sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1' | ||
42 | + sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1' | ||
43 | + end | ||
34 | end | 44 | end |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
@@ -2,6 +2,7 @@ module ElasticsearchIndexedModel | @@ -2,6 +2,7 @@ module ElasticsearchIndexedModel | ||
2 | 2 | ||
3 | def self.included base | 3 | def self.included base |
4 | base.send :include, Elasticsearch::Model | 4 | base.send :include, Elasticsearch::Model |
5 | + base.send :index_name, "#{Rails.env}_#{base.index_name}" | ||
5 | base.extend ClassMethods | 6 | base.extend ClassMethods |
6 | base.class_eval do | 7 | base.class_eval do |
7 | settings index: { number_of_shards: 1 } do | 8 | settings index: { number_of_shards: 1 } do |
@@ -12,6 +13,7 @@ module ElasticsearchIndexedModel | @@ -12,6 +13,7 @@ module ElasticsearchIndexedModel | ||
12 | print '.' | 13 | print '.' |
13 | end | 14 | end |
14 | end | 15 | end |
16 | + | ||
15 | base.__elasticsearch__.client.indices.delete \ | 17 | base.__elasticsearch__.client.indices.delete \ |
16 | index: base.index_name rescue nil | 18 | index: base.index_name rescue nil |
17 | base.__elasticsearch__.client.indices.create \ | 19 | base.__elasticsearch__.client.indices.create \ |
plugins/elasticsearch/test/test_helper.rb
@@ -13,18 +13,14 @@ module ElasticsearchTestHelper | @@ -13,18 +13,14 @@ module ElasticsearchTestHelper | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def teardown | 15 | def teardown |
16 | - indexed_models.each {|model| | ||
17 | - model.__elasticsearch__.client.indices.delete index: model.index_name | ||
18 | - } | ||
19 | end | 16 | end |
20 | 17 | ||
21 | def import_instancies | 18 | def import_instancies |
22 | indexed_models.each {|model| | 19 | indexed_models.each {|model| |
23 | - model.__elasticsearch__.create_index! | ||
24 | - sleep 2 | 20 | + model.__elasticsearch__.create_index! force: true |
25 | model.import | 21 | model.import |
26 | - sleep 1 | ||
27 | } | 22 | } |
23 | + sleep 1 | ||
28 | end | 24 | end |
29 | 25 | ||
30 | def setup_environment | 26 | def setup_environment |
plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb
@@ -20,7 +20,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -20,7 +20,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
20 | end | 20 | end |
21 | 21 | ||
22 | def create_communities | 22 | def create_communities |
23 | - 10.times do | index | | 23 | + 6.times do | index | |
24 | fast_create Community, name: "community_#{index}", created_at: Date.new | 24 | fast_create Community, name: "community_#{index}", created_at: Date.new |
25 | end | 25 | end |
26 | end | 26 | end |
@@ -47,10 +47,10 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -47,10 +47,10 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
47 | end | 47 | end |
48 | 48 | ||
49 | should 'return results filtered by selected_type' do | 49 | should 'return results filtered by selected_type' do |
50 | - get :index, { 'selected_type' => :person} | 50 | + get :index, { 'selected_type' => :community} |
51 | assert_response :success | 51 | assert_response :success |
52 | - assert_select ".search-item", 5 | ||
53 | - assert_template partial: '_person_display' | 52 | + assert_select ".search-item", 6 |
53 | + assert_template partial: '_community_display' | ||
54 | end | 54 | end |
55 | 55 | ||
56 | should 'return results filtered by query' do | 56 | should 'return results filtered by query' do |
@@ -74,31 +74,30 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -74,31 +74,30 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
74 | end | 74 | end |
75 | 75 | ||
76 | should 'return new person indexed' do | 76 | should 'return new person indexed' do |
77 | - get :index, { "selected_type" => :person} | 77 | + get :index, { "selected_type" => :community} |
78 | assert_response :success | 78 | assert_response :success |
79 | - assert_select ".search-item", 5 | 79 | + assert_select ".search-item", 6 |
80 | 80 | ||
81 | - object = create_user "New Person" | ||
82 | - Person.import | ||
83 | - sleep 1 | 81 | + fast_create Community, name: "community_#{7}", created_at: Date.new |
82 | + Community.import | ||
83 | + sleep 2 | ||
84 | 84 | ||
85 | - get :index, { "selected_type" => :person} | 85 | + get :index, { "selected_type" => :community} |
86 | assert_response :success | 86 | assert_response :success |
87 | - assert_select ".search-item", 6 | 87 | + assert_select ".search-item", 7 |
88 | end | 88 | end |
89 | 89 | ||
90 | should 'not return person deleted' do | 90 | should 'not return person deleted' do |
91 | - get :index, { "selected_type" => :person} | 91 | + get :index, { "selected_type" => :community} |
92 | assert_response :success | 92 | assert_response :success |
93 | - assert_select ".search-item", 5 | 93 | + assert_select ".search-item", 6 |
94 | 94 | ||
95 | - Person.first.delete | ||
96 | - Person.import | ||
97 | - sleep 1 | 95 | + Community.first.delete |
96 | + Community.import | ||
98 | 97 | ||
99 | - get :index, { "selected_type" => :person} | 98 | + get :index, { "selected_type" => :community} |
100 | assert_response :success | 99 | assert_response :success |
101 | - assert_select ".search-item", 4 | 100 | + assert_select ".search-item", 5 |
102 | end | 101 | end |
103 | 102 | ||
104 | should 'redirect to elasticsearch plugin when request are send to core' do | 103 | should 'redirect to elasticsearch plugin when request are send to core' do |