Commit 90e5428e8f27524a4432d5c70101559454bb6ccf

Authored by Macartur Sousa
1 parent 309125dd
Exists in elasticsearch_api

Adding initial test

Signed-off-by: Arthur Jahn <stutrzbecher@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
plugins/elasticsearch/Gemfile
1 1 source 'https://rubygems.org'
2 2  
3 3 gem 'elasticsearch-model'
4   -gem 'elasticsearch-rails'
  4 +gem 'elasticsearch-rails'
5 5 gem 'elasticsearch-extensions'
... ...
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
... ... @@ -2,10 +2,11 @@ module ElasticsearchIndexedModel
2 2  
3 3 def self.included base
4 4 base.send :include, Elasticsearch::Model
  5 + base.extend ClassMethods
5 6 base.class_eval do
6 7 settings index: { number_of_shards: 1 } do
7 8 mappings dynamic: 'false' do
8   - base::SEARCHABLE_FIELDS.each do |field, value|
  9 + base.indexable_fields.each do |field, value|
9 10 indexes field
10 11 print '.'
11 12 end
... ... @@ -20,8 +21,7 @@ module ElasticsearchIndexedModel
20 21 }
21 22 end
22 23 end
23   - base.extend ClassMethods
24   - base.send :import
  24 + base.send :import
25 25 end
26 26  
27 27 module ClassMethods
... ...
plugins/elasticsearch/lib/ext/article.rb
... ... @@ -1,13 +0,0 @@
1   -require_dependency 'article'
2   -require_relative '../elasticsearch_indexed_model'
3   -
4   -class Article
5   - include ElasticsearchIndexedModel
6   -
7   - def self.control_fields
8   - [
9   - :advertise,
10   - :published,
11   - ]
12   - end
13   -end
plugins/elasticsearch/lib/ext/community.rb
... ... @@ -2,9 +2,8 @@ require_dependency &#39;community&#39;
2 2 require_relative '../elasticsearch_indexed_model'
3 3  
4 4 class Community
5   - include ElasticsearchIndexedModel
6   -
7 5 def self.control_fields
8 6 []
9 7 end
  8 + include ElasticsearchIndexedModel
10 9 end
... ...
plugins/elasticsearch/lib/ext/event.rb
... ... @@ -2,12 +2,11 @@ require_dependency &#39;event&#39;
2 2 require_relative '../elasticsearch_indexed_model'
3 3  
4 4 class Event
5   - include ElasticsearchIndexedModel
6   -
7 5 def self.control_fields
8 6 [
9 7 :advertise,
10 8 :published,
11 9 ]
12 10 end
  11 + include ElasticsearchIndexedModel
13 12 end
... ...
plugins/elasticsearch/lib/ext/person.rb
... ... @@ -2,12 +2,11 @@ require_dependency &#39;person&#39;
2 2 require_relative '../elasticsearch_indexed_model'
3 3  
4 4 class Person
5   - include ElasticsearchIndexedModel
6   -
7 5 def self.control_fields
8 6 [
9 7 :visible,
10 8 :public_profile,
11 9 ]
12 10 end
  11 + include ElasticsearchIndexedModel
13 12 end
... ...
plugins/elasticsearch/lib/ext/text_article.rb
... ... @@ -2,12 +2,11 @@ require_dependency &#39;text_article&#39;
2 2 require_relative '../elasticsearch_indexed_model'
3 3  
4 4 class TextArticle
5   - include ElasticsearchIndexedModel
6   -
7 5 def self.control_fields
8 6 [
9 7 :advertise,
10 8 :published,
11 9 ]
12 10 end
  11 + include ElasticsearchIndexedModel
13 12 end
... ...
plugins/elasticsearch/lib/ext/uploaded_file.rb
... ... @@ -2,12 +2,11 @@ require_dependency &#39;uploaded_file&#39;
2 2 require_relative '../elasticsearch_indexed_model'
3 3  
4 4 class UploadedFile
5   - include ElasticsearchIndexedModel
6   -
7 5 def self.control_fields
8 6 [
9 7 :advertise,
10 8 :published,
11 9 ]
12 10 end
  11 + include ElasticsearchIndexedModel
13 12 end
... ...
plugins/elasticsearch/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require 'test_helper'
  2 +
  3 +
  4 +require 'elasticsearch/extensions/test/cluster'
  5 +require 'elasticsearch/extensions/test/cluster/tasks'
  6 +
  7 +
  8 +def start_cluster
  9 + if not Elasticsearch::Extensions::Test::Cluster.running?(on: 9250)
  10 + Elasticsearch::Extensions::Test::Cluster.start
  11 + end
  12 +end
  13 +
  14 +def stop_cluster
  15 + if Elasticsearch::Extensions::Test::Cluster.running?(on: 9250)
  16 + Elasticsearch::Extensions::Test::Cluster.stop
  17 + end
  18 +end
  19 +
  20 +
... ...
plugins/elasticsearch/test/unit/elasticsearch_test.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require "#{File.dirname(__FILE__)}/../test_helper"
  2 +
  3 +class ElasticsearchTest < ActiveSupport::TestCase
  4 + def setup
  5 + start_cluster
  6 + @environment = Environment.default
  7 + @environment.enable_plugin(ElasticsearchPlugin)
  8 + @profile = create_user('testing').person
  9 + end
  10 +
  11 + def teardown
  12 + stop_cluster
  13 + end
  14 +
  15 +
  16 + should ' be return yellow for health status' do
  17 + cluster = Elasticsearch::Model.client.cluster
  18 + assert_equal 'yellow', cluster.health["status"]
  19 + end
  20 +end
... ...
plugins/elasticsearch/test/unit/index_models_test.rb
... ... @@ -1,21 +0,0 @@
1   -require 'test_helper'
2   -
3   -class IndexModelsTest < ActiveSupport::TestCase
4   -
5   - should "check index models on elasticsearch" do
6   - fields = []
7   - mappings = []
8   -
9   - ActiveRecord::Base.descendants.each do |model|
10   - if model.const_defined?("SEARCHABLE_FIELDS")
11   - mappings << model.mappings.instance_values['mapping'].keys.sort
12   - fields << model::SEARCHABLE_FIELDS.keys.sort
13   - end
14   - end
15   -
16   - mappings.count.times do |i|
17   - assert_equal mappings[i], fields[i]
18   - end
19   - end
20   -
21   -end