Commit b101aa2a53bc9370f6aa827a8849c0316240192e
1 parent
220a5f3e
Exists in
fix_sign_up_form
Elasticsearch: 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 | 2 | |
| 3 | 3 | require 'open-uri' |
| 4 | 4 | |
| 5 | +def elasticsearch_development | |
| 6 | + return ENV["ELASTICSEARCH_DEVELOPMENT"].nil? | |
| 7 | +end | |
| 8 | + | |
| 5 | 9 | desc "download elasticsearch" |
| 6 | 10 | task :download do |
| 7 | 11 | unless File.exists? '/tmp/elasticsearch.deb' |
| ... | ... | @@ -22,13 +26,19 @@ task :start do |
| 22 | 26 | if not system 'sudo systemctl start elasticsearch > /dev/null' |
| 23 | 27 | Rake::Task['install'].invoke |
| 24 | 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 | 35 | end |
| 29 | 36 | |
| 30 | 37 | desc "stop elasticsearch" |
| 31 | 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 | 44 | end | ... | ... |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
| ... | ... | @@ -2,6 +2,7 @@ module ElasticsearchIndexedModel |
| 2 | 2 | |
| 3 | 3 | def self.included base |
| 4 | 4 | base.send :include, Elasticsearch::Model |
| 5 | + base.send :index_name, "#{Rails.env}_#{base.index_name}" | |
| 5 | 6 | base.extend ClassMethods |
| 6 | 7 | base.class_eval do |
| 7 | 8 | settings index: { number_of_shards: 1 } do |
| ... | ... | @@ -12,6 +13,7 @@ module ElasticsearchIndexedModel |
| 12 | 13 | print '.' |
| 13 | 14 | end |
| 14 | 15 | end |
| 16 | + | |
| 15 | 17 | base.__elasticsearch__.client.indices.delete \ |
| 16 | 18 | index: base.index_name rescue nil |
| 17 | 19 | base.__elasticsearch__.client.indices.create \ | ... | ... |
plugins/elasticsearch/test/test_helper.rb
| ... | ... | @@ -13,18 +13,14 @@ module ElasticsearchTestHelper |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def teardown |
| 16 | - indexed_models.each {|model| | |
| 17 | - model.__elasticsearch__.client.indices.delete index: model.index_name | |
| 18 | - } | |
| 19 | 16 | end |
| 20 | 17 | |
| 21 | 18 | def import_instancies |
| 22 | 19 | indexed_models.each {|model| |
| 23 | - model.__elasticsearch__.create_index! | |
| 24 | - sleep 2 | |
| 20 | + model.__elasticsearch__.create_index! force: true | |
| 25 | 21 | model.import |
| 26 | - sleep 1 | |
| 27 | 22 | } |
| 23 | + sleep 1 | |
| 28 | 24 | end |
| 29 | 25 | |
| 30 | 26 | def setup_environment | ... | ... |
plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb
| ... | ... | @@ -20,7 +20,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | def create_communities |
| 23 | - 10.times do | index | | |
| 23 | + 6.times do | index | | |
| 24 | 24 | fast_create Community, name: "community_#{index}", created_at: Date.new |
| 25 | 25 | end |
| 26 | 26 | end |
| ... | ... | @@ -47,10 +47,10 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase |
| 47 | 47 | end |
| 48 | 48 | |
| 49 | 49 | should 'return results filtered by selected_type' do |
| 50 | - get :index, { 'selected_type' => :person} | |
| 50 | + get :index, { 'selected_type' => :community} | |
| 51 | 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 | 54 | end |
| 55 | 55 | |
| 56 | 56 | should 'return results filtered by query' do |
| ... | ... | @@ -74,31 +74,30 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | 76 | should 'return new person indexed' do |
| 77 | - get :index, { "selected_type" => :person} | |
| 77 | + get :index, { "selected_type" => :community} | |
| 78 | 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 | 86 | assert_response :success |
| 87 | - assert_select ".search-item", 6 | |
| 87 | + assert_select ".search-item", 7 | |
| 88 | 88 | end |
| 89 | 89 | |
| 90 | 90 | should 'not return person deleted' do |
| 91 | - get :index, { "selected_type" => :person} | |
| 91 | + get :index, { "selected_type" => :community} | |
| 92 | 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 | 99 | assert_response :success |
| 101 | - assert_select ".search-item", 4 | |
| 100 | + assert_select ".search-item", 5 | |
| 102 | 101 | end |
| 103 | 102 | |
| 104 | 103 | should 'redirect to elasticsearch plugin when request are send to core' do | ... | ... |