diff --git a/plugins/elasticsearch/test/test_helper.rb b/plugins/elasticsearch/test/test_helper.rb index 1d8d247..34797fb 100644 --- a/plugins/elasticsearch/test/test_helper.rb +++ b/plugins/elasticsearch/test/test_helper.rb @@ -1 +1,29 @@ require 'test_helper' + +class ElasticsearchTestHelper < ActionController::TestCase + + def setup + setup_environment + import_instancies + end + + def teardown + indexed_models.each {|model| + model.__elasticsearch__.client.indices.delete index: model.index_name + } + end + + def import_instancies + indexed_models.each {|model| + model.__elasticsearch__.create_index! + model.import + } + sleep 2 + end + + def setup_environment + @environment = Environment.default + @environment.enable_plugin(ElasticsearchPlugin) + end + +end diff --git a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb index dad4091..30ab344 100644 --- a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb +++ b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb @@ -1,34 +1,18 @@ require "#{File.dirname(__FILE__)}/../../test_helper" -class ElasticsearchPluginControllerTest < ActionController::TestCase +class ElasticsearchPluginControllerTest < ElasticsearchTestHelper - def setup - @environment = Environment.default - @environment.enable_plugin(ElasticsearchPlugin) + def indexed_models + [Community, Person] + end - community = fast_create(Community) - community.name = "I like organic" - community.created_at = Time.now - community.save + def setup create_instances - import_instancies + super end def teardown - Person.__elasticsearch__.client.indices.delete index: Person.index_name - Community.__elasticsearch__.client.indices.delete index: Community.index_name - end - - def import_instancies - #TODO: fix this, when update or create a new person - # the Elasticsearch::Model can update the - # indexes models - Person.__elasticsearch__.create_index! - Community.__elasticsearch__.create_index! - - Person.import - Community.import - sleep 2 + super end def create_instances @@ -73,18 +57,21 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase get :index, { 'selected_type' => :person} assert_response :success assert_select ".search-item", 5 + assert_template partial: '_person_display' end should 'return results filtered by query' do get :index, { 'query' => "person_"} assert_response :success assert_select ".search-item", 5 + assert_template partial: '_person_display' end should 'return results filtered by query with uppercase' do get :index, {'query' => "PERSON_1"} assert_response :success assert_select ".search-item", 1 + assert_template partial: '_person_display' end should 'return results filtered by query with downcase' do @@ -122,18 +109,14 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase end should 'redirect to elasticsearch plugin when request are send to core' do - oldcontroller = @controller @controller = SearchController.new get 'index' - params = {} - params[:action] = 'index' - params[:controller] = 'search' + params = {:action => 'index', :controller => 'search'} assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params - @controller = oldcontroller end should 'pass params to elastic search controller' do - get 'index', { query: 'like' } + get 'index', { query: 'community_' } assert_not_nil assigns(:results) assert_template partial: '_community_display' end -- libgit2 0.21.2