From 7008ae6787d0a7714730d23ef79c9668af28f48a Mon Sep 17 00:00:00 2001 From: ArthurJahn Date: Thu, 9 Jun 2016 18:14:11 +0000 Subject: [PATCH] tests for models indexed fields - related to #331 --- plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb | 1 + plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb | 28 ++++++++++++++++++++++++++++ plugins/elasticsearch/test/unit/models/community_test.rb | 22 ++++++++++++++++++++++ plugins/elasticsearch/test/unit/models/event_test.rb | 21 +++++++++++++++++++++ plugins/elasticsearch/test/unit/models/person_test.rb | 24 ++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 0 deletions(-) create mode 100644 plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb create mode 100644 plugins/elasticsearch/test/unit/models/community_test.rb create mode 100644 plugins/elasticsearch/test/unit/models/event_test.rb create mode 100644 plugins/elasticsearch/test/unit/models/person_test.rb diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index c46c1ce..3bb6fb0 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -49,6 +49,7 @@ class ElasticsearchPluginController < ApplicationController def get_query text, klass=nil query = {} unless text.blank? + text = text.downcase query = { query: { match_all: { diff --git a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb new file mode 100644 index 0000000..e7b6246 --- /dev/null +++ b/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb @@ -0,0 +1,28 @@ +require "#{File.dirname(__FILE__)}/../../test_helper" + +class ElasticsearchPluginControllerTest < ActionController::TestCase + def setup + start_cluster + end + + def teardown + stop_cluster + end + + should 'work and uses control filter variables' do + get :index + assert_response :success + assert_not_nil assigns(:searchable_types) + assert_not_nil assigns(:selected_type) + assert_not_nil assigns(:search_filter_types) + assert_not_nil assigns(:selected_filter_field) + end + + should 'return all results if selected_type is nil' do + get :index, {'selected_type' => :person, :q => 'John'} + assert_response :success + assert_tag tag: "div", attributes: { class: "results" }, + children: { count: 2 } + end + +end diff --git a/plugins/elasticsearch/test/unit/models/community_test.rb b/plugins/elasticsearch/test/unit/models/community_test.rb new file mode 100644 index 0000000..b068a67 --- /dev/null +++ b/plugins/elasticsearch/test/unit/models/community_test.rb @@ -0,0 +1,22 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class CommunityTest < ActiveSupport::TestCase + def setup + start_cluster + @environment = Environment.default + @environment.enable_plugin(ElasticsearchPlugin) + @profile = create_user('testing').person + end + + def teardown + stop_cluster + end + + should 'index custom fields for Event model' do + community_cluster = Community.__elasticsearch__.client.cluster + + assert_not_nil Community.mappings.to_hash[:community][:properties][:name] + assert_not_nil Community.mappings.to_hash[:community][:properties][:identifier] + assert_not_nil Community.mappings.to_hash[:community][:properties][:nickname] + end +end diff --git a/plugins/elasticsearch/test/unit/models/event_test.rb b/plugins/elasticsearch/test/unit/models/event_test.rb new file mode 100644 index 0000000..3bc1498 --- /dev/null +++ b/plugins/elasticsearch/test/unit/models/event_test.rb @@ -0,0 +1,21 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class EventTest < ActiveSupport::TestCase + def setup + start_cluster + @environment = Environment.default + @environment.enable_plugin(ElasticsearchPlugin) + @profile = create_user('testing').person + end + + def teardown + stop_cluster + end + + should 'index custom fields for Event model' do + event_cluster = Event.__elasticsearch__.client.cluster + + assert_not_nil Event.mappings.to_hash[:event][:properties][:advertise] + assert_not_nil Event.mappings.to_hash[:event][:properties][:published] + end +end diff --git a/plugins/elasticsearch/test/unit/models/person_test.rb b/plugins/elasticsearch/test/unit/models/person_test.rb new file mode 100644 index 0000000..09e616d --- /dev/null +++ b/plugins/elasticsearch/test/unit/models/person_test.rb @@ -0,0 +1,24 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class PersonTest < ActiveSupport::TestCase + def setup + start_cluster + @environment = Environment.default + @environment.enable_plugin(ElasticsearchPlugin) + @profile = create_user('testing').person + end + + def teardown + stop_cluster + end + + should 'index custom fields for Event model' do + person_cluster = Person.__elasticsearch__.client.cluster + + assert_not_nil Person.mappings.to_hash[:person][:properties][:name] + assert_not_nil Person.mappings.to_hash[:person][:properties][:identifier] + assert_not_nil Person.mappings.to_hash[:person][:properties][:nickname] + assert_not_nil Person.mappings.to_hash[:person][:properties][:visible] + end + +end -- libgit2 0.21.2