From c3406cebf6614a4aaeb921c60409c6603d550d9f Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 13 Jul 2016 15:12:11 -0300 Subject: [PATCH] Refactored structure and tests --- plugins/elasticsearch/helpers/nested_helper/environment.rb | 25 ------------------------- plugins/elasticsearch/helpers/nested_helper/profile.rb | 29 ----------------------------- plugins/elasticsearch/helpers/searchable_model/elasticsearch_indexed_model.rb | 100 ---------------------------------------------------------------------------------------------------- plugins/elasticsearch/helpers/searchable_model/filter.rb | 43 ------------------------------------------- plugins/elasticsearch/helpers/searchable_model_helper.rb | 9 --------- plugins/elasticsearch/lib/ext/community.rb | 2 +- plugins/elasticsearch/lib/ext/event.rb | 4 ++-- plugins/elasticsearch/lib/ext/person.rb | 2 +- plugins/elasticsearch/lib/ext/text_article.rb | 4 ++-- plugins/elasticsearch/lib/ext/uploaded_file.rb | 4 ++-- plugins/elasticsearch/lib/nested_helper/environment.rb | 25 +++++++++++++++++++++++++ plugins/elasticsearch/lib/nested_helper/profile.rb | 29 +++++++++++++++++++++++++++++ plugins/elasticsearch/lib/searchable_model/elasticsearch_indexed_model.rb | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/lib/searchable_model/filter.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/lib/searchable_model_helper.rb | 9 +++++++++ plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/test/api/elasticsearch_plugin_entities_test.rb | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb | 52 ---------------------------------------------------- plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb | 124 ---------------------------------------------------------------------------------------------------------------------------- plugins/elasticsearch/test/unit/community_test.rb | 24 ++++++++++++++++++++++++ plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb | 115 ------------------------------------------------------------------------------------------------------------------- plugins/elasticsearch/test/unit/elasticsearch_helper_test.rb | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/elasticsearch/test/unit/event_test.rb | 24 ++++++++++++++++++++++++ plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb | 75 --------------------------------------------------------------------------- plugins/elasticsearch/test/unit/models/community_test.rb | 24 ------------------------ plugins/elasticsearch/test/unit/models/event_test.rb | 24 ------------------------ plugins/elasticsearch/test/unit/models/person_test.rb | 23 ----------------------- plugins/elasticsearch/test/unit/models/text_article_test.rb | 24 ------------------------ plugins/elasticsearch/test/unit/models/uploaded_file_test.rb | 24 ------------------------ plugins/elasticsearch/test/unit/person_test.rb | 23 +++++++++++++++++++++++ plugins/elasticsearch/test/unit/text_article_test.rb | 24 ++++++++++++++++++++++++ plugins/elasticsearch/test/unit/uploaded_file_test.rb | 24 ++++++++++++++++++++++++ 33 files changed, 697 insertions(+), 699 deletions(-) delete mode 100644 plugins/elasticsearch/helpers/nested_helper/environment.rb delete mode 100644 plugins/elasticsearch/helpers/nested_helper/profile.rb delete mode 100644 plugins/elasticsearch/helpers/searchable_model/elasticsearch_indexed_model.rb delete mode 100644 plugins/elasticsearch/helpers/searchable_model/filter.rb delete mode 100644 plugins/elasticsearch/helpers/searchable_model_helper.rb create mode 100644 plugins/elasticsearch/lib/nested_helper/environment.rb create mode 100644 plugins/elasticsearch/lib/nested_helper/profile.rb create mode 100644 plugins/elasticsearch/lib/searchable_model/elasticsearch_indexed_model.rb create mode 100644 plugins/elasticsearch/lib/searchable_model/filter.rb create mode 100644 plugins/elasticsearch/lib/searchable_model_helper.rb create mode 100644 plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb create mode 100644 plugins/elasticsearch/test/api/elasticsearch_plugin_entities_test.rb create mode 100644 plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb delete mode 100644 plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb delete mode 100644 plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb create mode 100644 plugins/elasticsearch/test/unit/community_test.rb delete mode 100644 plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb create mode 100644 plugins/elasticsearch/test/unit/elasticsearch_helper_test.rb create mode 100644 plugins/elasticsearch/test/unit/event_test.rb delete mode 100644 plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb delete mode 100644 plugins/elasticsearch/test/unit/models/community_test.rb delete mode 100644 plugins/elasticsearch/test/unit/models/event_test.rb delete mode 100644 plugins/elasticsearch/test/unit/models/person_test.rb delete mode 100644 plugins/elasticsearch/test/unit/models/text_article_test.rb delete mode 100644 plugins/elasticsearch/test/unit/models/uploaded_file_test.rb create mode 100644 plugins/elasticsearch/test/unit/person_test.rb create mode 100644 plugins/elasticsearch/test/unit/text_article_test.rb create mode 100644 plugins/elasticsearch/test/unit/uploaded_file_test.rb diff --git a/plugins/elasticsearch/helpers/nested_helper/environment.rb b/plugins/elasticsearch/helpers/nested_helper/environment.rb deleted file mode 100644 index f923e25..0000000 --- a/plugins/elasticsearch/helpers/nested_helper/environment.rb +++ /dev/null @@ -1,25 +0,0 @@ -module NestedEnvironment - - def self.environment_hash - { - :id => { type: :integer }, - :is_default => {type: :boolean } - } - end - - def self.environment_filter environment=1 - { - query: { - nested: { - path: "environment", - query: { - bool: { - must: { term: { "environment.id" => environment } }, - } - } - } - } - } - end - -end diff --git a/plugins/elasticsearch/helpers/nested_helper/profile.rb b/plugins/elasticsearch/helpers/nested_helper/profile.rb deleted file mode 100644 index d3bd6f0..0000000 --- a/plugins/elasticsearch/helpers/nested_helper/profile.rb +++ /dev/null @@ -1,29 +0,0 @@ -module NestedProfile - - def self.hash - { - :id => { type: :integer }, - :visible => { type: :boolean }, - :public_profile => { type: :boolean } - } - end - - def self.filter - { - query: { - nested: { - path: "profile", - query: { - bool: { - must:[ - { term: { "profile.visible" => true } }, - { term: { "profile.public_profile" => true } } - ], - } - } - } - } - } - end - -end diff --git a/plugins/elasticsearch/helpers/searchable_model/elasticsearch_indexed_model.rb b/plugins/elasticsearch/helpers/searchable_model/elasticsearch_indexed_model.rb deleted file mode 100644 index 1866c29..0000000 --- a/plugins/elasticsearch/helpers/searchable_model/elasticsearch_indexed_model.rb +++ /dev/null @@ -1,100 +0,0 @@ -require_relative '../nested_helper/environment' - -module ElasticsearchIndexedModel - - def self.included base - base.send :include, Elasticsearch::Model - base.send :include, Elasticsearch::Model::Callbacks - - base.send :index_name, "#{Rails.env}_#{base.index_name}" - - base.extend ClassMethods - base.send :include, InstanceMethods - - base.class_eval do - settings index: { number_of_shards: 1 } do - mappings dynamic: 'false' do - base.indexed_fields.each do |field, value| - type = value[:type].presence - - if type == :nested - indexes(field, type: type) do - value[:hash].each do |hash_field, hash_value| - indexes(hash_field, base.indexes_as_hash(hash_field,hash_value[:type].presence)) - end - end - else - indexes(field, base.indexes_as_hash(field,type)) - end - print '.' - end - end - - base.__elasticsearch__.client.indices.delete \ - index: base.index_name rescue nil - base.__elasticsearch__.client.indices.create \ - index: base.index_name, - body: { - settings: base.settings.to_hash, - mappings: base.mappings.to_hash - } - end - end - base.send :import - end - - module ClassMethods - - def indexes_as_hash(name, type) - hash = {} - if type.nil? - hash[:fields] = raw_field(name, type) - else - hash[:type] = type if not type.nil? - end - hash - end - - def raw_field name, type - { - raw: { - type: "string", - index: "not_analyzed" - } - } - end - - def indexed_fields - fields = { - :id => {type: :integer }, - :environment => {type: :nested, hash: NestedEnvironment::environment_hash }, - :category_ids => {type: :integer }, - :created_at => {type: :date } - } - fields.update(self::SEARCHABLE_FIELDS) - fields.update(self.control_fields) - fields - end - - end - - module InstanceMethods - def as_indexed_json options={} - attrs = {} - - self.class.indexed_fields.each do |field, value| - type = value[:type].presence - if type == :nested - attrs[field] = {} - value[:hash].each do |hash_field, hash_value| - attrs[field][hash_field] = self.send(field).send(hash_field) - end - else - attrs[field] = self.send(field) - end - end - attrs.as_json - end - end - -end diff --git a/plugins/elasticsearch/helpers/searchable_model/filter.rb b/plugins/elasticsearch/helpers/searchable_model/filter.rb deleted file mode 100644 index 8d1117c..0000000 --- a/plugins/elasticsearch/helpers/searchable_model/filter.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative '../nested_helper/environment' - -module Filter - - def self.included base - base.extend ClassMethods - base.send :include, InstanceMethods - end - - module ClassMethods - - def filter options={} - environment = options[:environment].presence - - result_filter = {} - result_filter[:indices] = {:index => self.index_name, :no_match_filter => "none" } - result_filter[:indices][:filter] = { :bool => self.filter_bool(environment) } - - result_filter - end - - def filter_bool environment - result_filter = {} - - result_filter[:must] = [ NestedEnvironment::environment_filter(environment) ] - - self.nested_filter.each {|filter| result_filter[:must].append(filter)} if self.respond_to? :nested_filter - self.must.each {|filter| result_filter[:must].append(filter) } if self.respond_to? :must - - result_filter[:should] = self.should if self.respond_to? :should - result_filter[:must_not] = self.must_not if self.respond_to? :must_not - - result_filter - end - - - end - - module InstanceMethods - - end - -end diff --git a/plugins/elasticsearch/helpers/searchable_model_helper.rb b/plugins/elasticsearch/helpers/searchable_model_helper.rb deleted file mode 100644 index 5e81d85..0000000 --- a/plugins/elasticsearch/helpers/searchable_model_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative './searchable_model/elasticsearch_indexed_model' -require_relative './searchable_model/filter' - -module SearchableModelHelper - def self.included base - base.send :include, ElasticsearchIndexedModel - base.send :include, Filter - end -end diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb index 7deebb3..4dcf128 100644 --- a/plugins/elasticsearch/lib/ext/community.rb +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -1,5 +1,5 @@ require_dependency 'community' -require_relative '../../helpers/searchable_model_helper' +require_relative '../searchable_model_helper' class Community diff --git a/plugins/elasticsearch/lib/ext/event.rb b/plugins/elasticsearch/lib/ext/event.rb index c503da7..24ed4e4 100644 --- a/plugins/elasticsearch/lib/ext/event.rb +++ b/plugins/elasticsearch/lib/ext/event.rb @@ -1,7 +1,7 @@ require_dependency 'event' -require_relative '../../helpers/searchable_model_helper' -require_relative '../../helpers/nested_helper/profile' +require_relative '../searchable_model_helper' +require_relative '../nested_helper/profile' class Event #TODO: o filtro é feito de forma diferente do artigo diff --git a/plugins/elasticsearch/lib/ext/person.rb b/plugins/elasticsearch/lib/ext/person.rb index 4299b19..453d9b3 100644 --- a/plugins/elasticsearch/lib/ext/person.rb +++ b/plugins/elasticsearch/lib/ext/person.rb @@ -1,6 +1,6 @@ require_dependency 'person' -require_relative '../../helpers/searchable_model_helper' +require_relative '../searchable_model_helper' class Person diff --git a/plugins/elasticsearch/lib/ext/text_article.rb b/plugins/elasticsearch/lib/ext/text_article.rb index c28ff24..5c65e18 100644 --- a/plugins/elasticsearch/lib/ext/text_article.rb +++ b/plugins/elasticsearch/lib/ext/text_article.rb @@ -3,8 +3,8 @@ require_dependency 'raw_html_article' require_dependency 'tiny_mce_article' require_dependency 'text_article' -require_relative '../../helpers/searchable_model_helper' -require_relative '../../helpers/nested_helper/profile' +require_relative '../searchable_model_helper' +require_relative '../nested_helper/profile' class TextArticle diff --git a/plugins/elasticsearch/lib/ext/uploaded_file.rb b/plugins/elasticsearch/lib/ext/uploaded_file.rb index a31aeca..a3827d3 100644 --- a/plugins/elasticsearch/lib/ext/uploaded_file.rb +++ b/plugins/elasticsearch/lib/ext/uploaded_file.rb @@ -1,7 +1,7 @@ require_dependency 'uploaded_file' -require_relative '../../helpers/searchable_model_helper' -require_relative '../../helpers/nested_helper/profile' +require_relative '../searchable_model_helper' +require_relative '../nested_helper/profile' class UploadedFile def self.control_fields diff --git a/plugins/elasticsearch/lib/nested_helper/environment.rb b/plugins/elasticsearch/lib/nested_helper/environment.rb new file mode 100644 index 0000000..761b125 --- /dev/null +++ b/plugins/elasticsearch/lib/nested_helper/environment.rb @@ -0,0 +1,25 @@ +module NestedEnvironment + + def self.hash + { + :id => { type: :integer }, + :is_default => {type: :boolean } + } + end + + def self.filter environment=1 + { + query: { + nested: { + path: "environment", + query: { + bool: { + must: { term: { "environment.id" => environment } }, + } + } + } + } + } + end + +end diff --git a/plugins/elasticsearch/lib/nested_helper/profile.rb b/plugins/elasticsearch/lib/nested_helper/profile.rb new file mode 100644 index 0000000..d3bd6f0 --- /dev/null +++ b/plugins/elasticsearch/lib/nested_helper/profile.rb @@ -0,0 +1,29 @@ +module NestedProfile + + def self.hash + { + :id => { type: :integer }, + :visible => { type: :boolean }, + :public_profile => { type: :boolean } + } + end + + def self.filter + { + query: { + nested: { + path: "profile", + query: { + bool: { + must:[ + { term: { "profile.visible" => true } }, + { term: { "profile.public_profile" => true } } + ], + } + } + } + } + } + end + +end diff --git a/plugins/elasticsearch/lib/searchable_model/elasticsearch_indexed_model.rb b/plugins/elasticsearch/lib/searchable_model/elasticsearch_indexed_model.rb new file mode 100644 index 0000000..63b375d --- /dev/null +++ b/plugins/elasticsearch/lib/searchable_model/elasticsearch_indexed_model.rb @@ -0,0 +1,99 @@ +require_relative '../nested_helper/environment' + +module ElasticsearchIndexedModel + + def self.included base + base.send :include, Elasticsearch::Model + base.send :include, Elasticsearch::Model::Callbacks + + base.send :index_name, "#{Rails.env}_#{base.index_name}" + + base.extend ClassMethods + base.send :include, InstanceMethods + + base.class_eval do + settings index: { number_of_shards: 1 } do + mappings dynamic: 'false' do + base.indexed_fields.each do |field, value| + type = value[:type].presence + + if type == :nested + indexes(field, type: type) do + value[:hash].each do |hash_field, hash_value| + indexes(hash_field, base.indexes_as_hash(hash_field,hash_value[:type].presence)) + end + end + else + indexes(field, base.indexes_as_hash(field,type)) + end + print '.' + end + end + + base.__elasticsearch__.client.indices.delete \ + index: base.index_name rescue nil + base.__elasticsearch__.client.indices.create \ + index: base.index_name, + body: { + settings: base.settings.to_hash, + mappings: base.mappings.to_hash + } + end + end + base.send :import + end + + module ClassMethods + + def indexes_as_hash(name, type) + hash = {} + if type.nil? + hash[:fields] = raw_field(name, type) + else + hash[:type] = type if not type.nil? + end + hash + end + + def raw_field name, type + { + raw: { + type: "string", + index: "not_analyzed" + } + } + end + + def indexed_fields + fields = { + :environment => {type: :nested, hash: NestedEnvironment::hash }, + :category_ids => {type: :integer }, + :created_at => {type: :date } + } + fields.update(self::SEARCHABLE_FIELDS) + fields.update(self.control_fields) + fields + end + + end + + module InstanceMethods + def as_indexed_json options={} + attrs = {} + + self.class.indexed_fields.each do |field, value| + type = value[:type].presence + if type == :nested + attrs[field] = {} + value[:hash].each do |hash_field, hash_value| + attrs[field][hash_field] = self.send(field).send(hash_field) + end + else + attrs[field] = self.send(field) + end + end + attrs.as_json + end + end + +end diff --git a/plugins/elasticsearch/lib/searchable_model/filter.rb b/plugins/elasticsearch/lib/searchable_model/filter.rb new file mode 100644 index 0000000..88ff870 --- /dev/null +++ b/plugins/elasticsearch/lib/searchable_model/filter.rb @@ -0,0 +1,42 @@ +require_relative '../nested_helper/environment' + +module Filter + + def self.included base + base.extend ClassMethods + base.send :include, InstanceMethods + end + + module ClassMethods + + def filter options={} + environment = options[:environment].presence + + result_filter = {} + result_filter[:indices] = {:index => self.index_name, :no_match_filter => "none" } + result_filter[:indices][:filter] = { :bool => self.filter_bool(environment) } + + result_filter + end + + def filter_bool environment + result_filter = {} + + result_filter[:must] = [ NestedEnvironment::filter(environment) ] + + self.nested_filter.each {|filter| result_filter[:must].append(filter)} if self.respond_to? :nested_filter + self.must.each {|filter| result_filter[:must].append(filter) } if self.respond_to? :must + + result_filter[:should] = self.should if self.respond_to? :should + result_filter[:must_not] = self.must_not if self.respond_to? :must_not + + result_filter + end + + end + + module InstanceMethods + + end + +end diff --git a/plugins/elasticsearch/lib/searchable_model_helper.rb b/plugins/elasticsearch/lib/searchable_model_helper.rb new file mode 100644 index 0000000..5e81d85 --- /dev/null +++ b/plugins/elasticsearch/lib/searchable_model_helper.rb @@ -0,0 +1,9 @@ +require_relative './searchable_model/elasticsearch_indexed_model' +require_relative './searchable_model/filter' + +module SearchableModelHelper + def self.included base + base.send :include, ElasticsearchIndexedModel + base.send :include, Filter + end +end diff --git a/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb b/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb new file mode 100644 index 0000000..a7d1e05 --- /dev/null +++ b/plugins/elasticsearch/test/api/elasticsearch_plugin_api_test.rb @@ -0,0 +1,52 @@ +require "#{File.dirname(__FILE__)}/../test_helper" +require_relative '../../helpers/elasticsearch_helper' + +class ElasticsearchPluginApiTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + include ElasticsearchHelper + + def indexed_models + [Community, Person] + end + + def create_instances + 7.times.each {|index| create_user "person #{index}"} + 4.times.each {|index| fast_create Community, name: "community #{index}" } + end + + should 'show all types avaliable in /search/types endpoint' do + get "/api/v1/search/types" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal searchable_types.stringify_keys.keys, json["types"] + end + + should 'respond with endpoint /search with more than 10 results' do + get "/api/v1/search" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 10, json["results"].count + end + + should 'respond with query in downcase' do + get "/api/v1/search?query=person" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 7, json["results"].count + end + + should 'respond with query in uppercase' do + get "/api/v1/search?query=PERSON" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 7, json["results"].count + end + + should 'respond with selected_type' do + get "/api/v1/search?selected_type=community" + json = JSON.parse(last_response.body) + assert_equal 200, last_response.status + assert_equal 4, json["results"].count + end +end diff --git a/plugins/elasticsearch/test/api/elasticsearch_plugin_entities_test.rb b/plugins/elasticsearch/test/api/elasticsearch_plugin_entities_test.rb new file mode 100644 index 0000000..1059ab8 --- /dev/null +++ b/plugins/elasticsearch/test/api/elasticsearch_plugin_entities_test.rb @@ -0,0 +1,124 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class ElasticsearchPluginEntitiesTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Person,TextArticle,UploadedFile,Community,Event] + end + + def create_instances + user = create_user "sample person", environment_id: 1 + + fast_create Community, name: "sample community", created_at: 10.days.ago,updated_at: 5.days.ago, environment_id: 1 + + fast_create UploadedFile, name: "sample uploadedfile", created_at: 3.days.ago, updated_at: 1.days.ago, author_id: user.person.id, abstract: "sample abstract", profile_id: user.person.id + fast_create Event, name: "sample event", created_at: 20.days.ago, updated_at: 5.days.ago, author_id: user.person.id, abstract: "sample abstract", profile_id: user.person.id + fast_create RawHTMLArticle, name: "sample raw html article", created_at: 15.days.ago ,updated_at: 5.days.ago, author_id: user.person.id, profile_id: user.person.id + fast_create TinyMceArticle, name: "sample tiny mce article", created_at: 5.days.ago, updated_at: 5.days.ago, author_id: user.person.id, profile_id: user.person.id + end + + should 'show attributes from person' do + params = {:selected_type => "person" } + get "/api/v1/search?#{params.to_query}" + json= JSON.parse(last_response.body) + + expected_person = Person.find_by name: "sample person" + + assert_equal 200, last_response.status + assert_equal expected_person.id, json['results'][0]['id'] + assert_equal expected_person.name, json['results'][0]['name'] + assert_equal expected_person.type, json['results'][0]['type'] + assert_equal "", json['results'][0]['description'] + assert_equal expected_person.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] + assert_equal expected_person.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] + end + + + should 'show attributes from community' do + params = {:selected_type => "community" } + get "/api/v1/search?#{params.to_query}" + json= JSON.parse(last_response.body) + + expected_community = Community.find_by name: "sample community" + + assert_equal 200, last_response.status + + assert_equal expected_community.id, json['results'][0]['id'] + assert_equal expected_community.name, json['results'][0]['name'] + assert_equal expected_community.type, json['results'][0]['type'] + assert_equal "", json['results'][0]['description'] + assert_equal expected_community.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] + assert_equal expected_community.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] + end + + should 'show attributes from text_article' do + params = {:selected_type => "text_article" } + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + + expected_text_articles = TextArticle.all + + expected_text_articles.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal "TextArticle", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + + assert_equal expected_author, json['results'][index]['author'] + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + + should 'show attributes from uploaded_file' do + params = {:selected_type => "uploaded_file"} + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + + expected_uploaded_files = UploadedFile.all + expected_uploaded_files.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal object.abstract, json['results'][index]['abstract'] + assert_equal "UploadedFile", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + assert_equal expected_author, json['results'][index]['author'] + + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + + should 'show attributes from event' do + params = {:selected_type => "event"} + get "/api/v1/search?#{params.to_query}" + + json= JSON.parse(last_response.body) + + assert_equal 200, last_response.status + expected_events = Event.all + expected_events.each_with_index {|object,index| + assert_equal object.id, json['results'][index]['id'] + assert_equal object.name, json['results'][index]['name'] + assert_equal object.abstract, json['results'][index]['abstract'] + assert_equal "Event", json['results'][index]['type'] + + expected_author = (object.author.nil?) ? "" : object.author.name + assert_equal expected_author, json['results'][index]['author'] + + assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] + assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] + } + end + +end diff --git a/plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb b/plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb new file mode 100644 index 0000000..6357568 --- /dev/null +++ b/plugins/elasticsearch/test/functional/elasticsearch_plugin_controller_test.rb @@ -0,0 +1,115 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class ElasticsearchPluginControllerTest < ActionController::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Community, Person] + end + + def create_instances + create_people + create_communities + end + + def create_people + 5.times do | index | + create_user "person #{index}" + end + end + + def create_communities + 6.times do | index | + fast_create Community, name: "community #{index}", created_at: Date.new + end + 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(:sort_types) + assert_not_nil assigns(:selected_sort) + end + + should 'return 10 results if selected_type is nil and query is nil' do + get :index + assert_response :success + assert_select ".search-item" , 10 + end + + should 'render pagination if results has more than 10' do + get :index + assert_response :success + assert_select ".pagination", 1 + end + + should 'return results filtered by selected_type' do + get :index, { 'selected_type' => :community} + assert_response :success + assert_select ".search-item", 6 + assert_template partial: '_community_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_template partial: '_person_display' + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) + end + + should 'return results filtered by query with downcase' do + get :index, {'query' => "person 1"} + assert_response :success + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) + end + + should 'return new person indexed' do + get :index, { "selected_type" => :community} + assert_response :success + assert_select ".search-item", 6 + + fast_create Community, name: "community #{7}", created_at: Date.new + Community.import + sleep 2 + + get :index, { "selected_type" => :community} + assert_response :success + assert_select ".search-item", 7 + end + + should 'not return person deleted' do + get :index, { "selected_type" => :community} + assert_response :success + assert_select ".search-item", 6 + + Community.first.delete + Community.import + + get :index, { "selected_type" => :community} + assert_response :success + assert_select ".search-item", 5 + end + + should 'redirect to elasticsearch plugin when request are send to core' do + @controller = SearchController.new + get 'index' + params = {:action => 'index', :controller => 'search'} + assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params + end + + should 'pass params to elastic search controller' do + get 'index', { query: 'community' } + assert_not_nil assigns(:results) + assert_template partial: '_community_display' + end +end diff --git a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb deleted file mode 100644 index 7ed74f0..0000000 --- a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_api_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" -require_relative '../../../helpers/elasticsearch_helper' - -class ElasticsearchPluginApiTest < ActiveSupport::TestCase - - include ElasticsearchTestHelper - include ElasticsearchHelper - - def indexed_models - [Community, Person] - end - - def create_instances - 7.times.each {|index| create_user "person #{index}"} - 4.times.each {|index| fast_create Community, name: "community #{index}" } - end - - should 'show all types avaliable in /search/types endpoint' do - get "/api/v1/search/types" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal searchable_types.stringify_keys.keys, json["types"] - end - - should 'respond with endpoint /search with more than 10 results' do - get "/api/v1/search" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal 10, json["results"].count - end - - should 'respond with query in downcase' do - get "/api/v1/search?query=person" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal 7, json["results"].count - end - - should 'respond with query in uppercase' do - get "/api/v1/search?query=PERSON" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal 7, json["results"].count - end - - should 'respond with selected_type' do - get "/api/v1/search?selected_type=community" - json = JSON.parse(last_response.body) - assert_equal 200, last_response.status - assert_equal 4, json["results"].count - end -end diff --git a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb b/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb deleted file mode 100644 index 986e862..0000000 --- a/plugins/elasticsearch/test/unit/api/elasticsearch_plugin_entities_test.rb +++ /dev/null @@ -1,124 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class ElasticsearchPluginEntitiesTest < ActiveSupport::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [Person,TextArticle,UploadedFile,Community,Event] - end - - def create_instances - user = create_user "sample person", environment_id: 1 - - fast_create Community, name: "sample community", created_at: 10.days.ago,updated_at: 5.days.ago, environment_id: 1 - - fast_create UploadedFile, name: "sample uploadedfile", created_at: 3.days.ago, updated_at: 1.days.ago, author_id: user.person.id, abstract: "sample abstract", profile_id: user.person.id - fast_create Event, name: "sample event", created_at: 20.days.ago, updated_at: 5.days.ago, author_id: user.person.id, abstract: "sample abstract", profile_id: user.person.id - fast_create RawHTMLArticle, name: "sample raw html article", created_at: 15.days.ago ,updated_at: 5.days.ago, author_id: user.person.id, profile_id: user.person.id - fast_create TinyMceArticle, name: "sample tiny mce article", created_at: 5.days.ago, updated_at: 5.days.ago, author_id: user.person.id, profile_id: user.person.id - end - - should 'show attributes from person' do - params = {:selected_type => "person" } - get "/api/v1/search?#{params.to_query}" - json= JSON.parse(last_response.body) - - expected_person = Person.find_by name: "sample person" - - assert_equal 200, last_response.status - assert_equal expected_person.id, json['results'][0]['id'] - assert_equal expected_person.name, json['results'][0]['name'] - assert_equal expected_person.type, json['results'][0]['type'] - assert_equal "", json['results'][0]['description'] - assert_equal expected_person.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] - assert_equal expected_person.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] - end - - - should 'show attributes from community' do - params = {:selected_type => "community" } - get "/api/v1/search?#{params.to_query}" - json= JSON.parse(last_response.body) - - expected_community = Community.find_by name: "sample community" - - assert_equal 200, last_response.status - - assert_equal expected_community.id, json['results'][0]['id'] - assert_equal expected_community.name, json['results'][0]['name'] - assert_equal expected_community.type, json['results'][0]['type'] - assert_equal "", json['results'][0]['description'] - assert_equal expected_community.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['created_at'] - assert_equal expected_community.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][0]['updated_at'] - end - - should 'show attributes from text_article' do - params = {:selected_type => "text_article" } - get "/api/v1/search?#{params.to_query}" - - json= JSON.parse(last_response.body) - - assert_equal 200, last_response.status - - expected_text_articles = TextArticle.all - - expected_text_articles.each_with_index {|object,index| - assert_equal object.id, json['results'][index]['id'] - assert_equal object.name, json['results'][index]['name'] - assert_equal "TextArticle", json['results'][index]['type'] - - expected_author = (object.author.nil?) ? "" : object.author.name - - assert_equal expected_author, json['results'][index]['author'] - assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] - assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] - } - end - - should 'show attributes from uploaded_file' do - params = {:selected_type => "uploaded_file"} - get "/api/v1/search?#{params.to_query}" - - json= JSON.parse(last_response.body) - - assert_equal 200, last_response.status - - expected_uploaded_files = UploadedFile.all - expected_uploaded_files.each_with_index {|object,index| - assert_equal object.id, json['results'][index]['id'] - assert_equal object.name, json['results'][index]['name'] - assert_equal object.abstract, json['results'][index]['abstract'] - assert_equal "UploadedFile", json['results'][index]['type'] - - expected_author = (object.author.nil?) ? "" : object.author.name - assert_equal expected_author, json['results'][index]['author'] - - assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] - assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] - } - end - - should 'show attributes from event' do - params = {:selected_type => "event"} - get "/api/v1/search?#{params.to_query}" - - json= JSON.parse(last_response.body) - - assert_equal 200, last_response.status - expected_events = Event.all - expected_events.each_with_index {|object,index| - assert_equal object.id, json['results'][index]['id'] - assert_equal object.name, json['results'][index]['name'] - assert_equal object.abstract, json['results'][index]['abstract'] - assert_equal "Event", json['results'][index]['type'] - - expected_author = (object.author.nil?) ? "" : object.author.name - assert_equal expected_author, json['results'][index]['author'] - - assert_equal object.created_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['created_at'] - assert_equal object.updated_at.strftime("%Y/%m/%d %H:%M:%S"), json['results'][index]['updated_at'] - } - end - -end diff --git a/plugins/elasticsearch/test/unit/community_test.rb b/plugins/elasticsearch/test/unit/community_test.rb new file mode 100644 index 0000000..4a68f75 --- /dev/null +++ b/plugins/elasticsearch/test/unit/community_test.rb @@ -0,0 +1,24 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class CommunityTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Community] + end + + should 'index searchable fields for Community model' do + Community::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Community), key + end + end + + should 'index control fields for Community model' do + Community::control_fields.each do |key, value| + assert_includes indexed_fields(Community), key + assert_equal indexed_fields(Community)[key][:type], value[:type] || 'string' + end + 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 deleted file mode 100644 index c98adc9..0000000 --- a/plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb +++ /dev/null @@ -1,115 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class ElasticsearchPluginControllerTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [Community, Person] - end - - def create_instances - create_people - create_communities - end - - def create_people - 5.times do | index | - create_user "person #{index}" - end - end - - def create_communities - 6.times do | index | - fast_create Community, name: "community #{index}", created_at: Date.new - end - 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(:sort_types) - assert_not_nil assigns(:selected_sort) - end - - should 'return 10 results if selected_type is nil and query is nil' do - get :index - assert_response :success - assert_select ".search-item" , 10 - end - - should 'render pagination if results has more than 10' do - get :index - assert_response :success - assert_select ".pagination", 1 - end - - should 'return results filtered by selected_type' do - get :index, { 'selected_type' => :community} - assert_response :success - assert_select ".search-item", 6 - assert_template partial: '_community_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_template partial: '_person_display' - assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) - end - - should 'return results filtered by query with downcase' do - get :index, {'query' => "person 1"} - assert_response :success - assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) - end - - should 'return new person indexed' do - get :index, { "selected_type" => :community} - assert_response :success - assert_select ".search-item", 6 - - fast_create Community, name: "community #{7}", created_at: Date.new - Community.import - sleep 2 - - get :index, { "selected_type" => :community} - assert_response :success - assert_select ".search-item", 7 - end - - should 'not return person deleted' do - get :index, { "selected_type" => :community} - assert_response :success - assert_select ".search-item", 6 - - Community.first.delete - Community.import - - get :index, { "selected_type" => :community} - assert_response :success - assert_select ".search-item", 5 - end - - should 'redirect to elasticsearch plugin when request are send to core' do - @controller = SearchController.new - get 'index' - params = {:action => 'index', :controller => 'search'} - assert_redirected_to controller: 'elasticsearch_plugin', action: 'search', params: params - end - - should 'pass params to elastic search controller' do - get 'index', { query: 'community' } - assert_not_nil assigns(:results) - assert_template partial: '_community_display' - end -end diff --git a/plugins/elasticsearch/test/unit/elasticsearch_helper_test.rb b/plugins/elasticsearch/test/unit/elasticsearch_helper_test.rb new file mode 100644 index 0000000..87822d8 --- /dev/null +++ b/plugins/elasticsearch/test/unit/elasticsearch_helper_test.rb @@ -0,0 +1,75 @@ +require "#{File.dirname(__FILE__)}/../test_helper" +require_relative '../../helpers/elasticsearch_helper.rb' + +class ElasticsearchHelperTest < ActiveSupport::TestCase + + include ElasticsearchTestHelper + include ElasticsearchHelper + + attr_accessor :params + + def indexed_models + [Person,TextArticle,UploadedFile,Community,Event] + end + + def create_instances + create_user "Jose Abreu" + create_user "Joana Abreu" + create_user "Joao Abreu" + create_user "Ana Abreu" + end + + should 'return default_per_page when nil is passed' do + assert_not_nil default_per_page nil + assert_equal 10, default_per_page(nil) + end + + should 'return default_per_page when per_page is passed' do + assert_equal 15, default_per_page(15) + end + + should 'have indexed_models in searchable_models' do + assert_equivalent indexed_models, searchable_models + end + + should 'return fields from models using weight' do + class StubClass + SEARCHABLE_FIELDS = {:name => {:weight => 10}, + :login => {:weight => 20}, + :description => {:weight => 2}} + end + + expected = ["name^10", "login^20", "description^2"] + assert_equivalent expected, fields_from_models([StubClass]) + end + + should 'search from model Person sorted by Alphabetic' do + self.params= {:selected_type => 'person', + :filter => 'lexical', + :query => "Abreu", + :per_page => 4} + + result = process_results + assert_equal ["Ana Abreu","Joana Abreu","Joao Abreu","Jose Abreu"], result.map(&:name) + end + + should 'search from model Person sorted by More Recent' do + self.params= {:selected_type => 'person', + :filter => 'more_recent', + :query => 'ABREU', + :per_page => 4} + + result = process_results + assert_equal ["Ana Abreu","Joao Abreu","Joana Abreu","Jose Abreu"], result.map(&:name) + end + + should 'search from model Person sorted by Relevance' do + self.params= {:selected_type => 'person', + :query => 'JOA BREU', + :per_page => 4} + + result = process_results + assert_equal ["Joana Abreu", "Joao Abreu"], result.map(&:name) + end + +end diff --git a/plugins/elasticsearch/test/unit/event_test.rb b/plugins/elasticsearch/test/unit/event_test.rb new file mode 100644 index 0000000..ecdc277 --- /dev/null +++ b/plugins/elasticsearch/test/unit/event_test.rb @@ -0,0 +1,24 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class EventTest < ActionController::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Event] + end + + should 'index searchable fields for Event model' do + Event::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Event), key + end + end + + should 'index control fields for Event model' do + Event::control_fields.each do |key, value| + assert_includes indexed_fields(Event), key + assert_equal indexed_fields(Event)[key][:type], value[:type] || 'string' + end + end + +end diff --git a/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb b/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb deleted file mode 100644 index e3a6216..0000000 --- a/plugins/elasticsearch/test/unit/helpers/elasticsearch_helper_test.rb +++ /dev/null @@ -1,75 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" -require_relative '../../../helpers/elasticsearch_helper.rb' - -class ElasticsearchHelperTest < ActiveSupport::TestCase - - include ElasticsearchTestHelper - include ElasticsearchHelper - - attr_accessor :params - - def indexed_models - [Person,TextArticle,UploadedFile,Community,Event] - end - - def create_instances - create_user "Jose Abreu" - create_user "Joana Abreu" - create_user "Joao Abreu" - create_user "Ana Abreu" - end - - should 'return default_per_page when nil is passed' do - assert_not_nil default_per_page nil - assert_equal 10, default_per_page(nil) - end - - should 'return default_per_page when per_page is passed' do - assert_equal 15, default_per_page(15) - end - - should 'have indexed_models in searchable_models' do - assert_equivalent indexed_models, searchable_models - end - - should 'return fields from models using weight' do - class StubClass - SEARCHABLE_FIELDS = {:name => {:weight => 10}, - :login => {:weight => 20}, - :description => {:weight => 2}} - end - - expected = ["name^10", "login^20", "description^2"] - assert_equivalent expected, fields_from_models([StubClass]) - end - - should 'search from model Person sorted by Alphabetic' do - self.params= {:selected_type => 'person', - :filter => 'lexical', - :query => "Abreu", - :per_page => 4} - - result = process_results - assert_equal ["Ana Abreu","Joana Abreu","Joao Abreu","Jose Abreu"], result.map(&:name) - end - - should 'search from model Person sorted by More Recent' do - self.params= {:selected_type => 'person', - :filter => 'more_recent', - :query => 'ABREU', - :per_page => 4} - - result = process_results - assert_equal ["Ana Abreu","Joao Abreu","Joana Abreu","Jose Abreu"], result.map(&:name) - end - - should 'search from model Person sorted by Relevance' do - self.params= {:selected_type => 'person', - :query => 'JOA BREU', - :per_page => 4} - - result = process_results - assert_equal ["Joana Abreu", "Joao Abreu"], result.map(&:name) - end - -end diff --git a/plugins/elasticsearch/test/unit/models/community_test.rb b/plugins/elasticsearch/test/unit/models/community_test.rb deleted file mode 100644 index 1066c2a..0000000 --- a/plugins/elasticsearch/test/unit/models/community_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class CommunityTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [Community] - end - - should 'index searchable fields for Community model' do - Community::SEARCHABLE_FIELDS.each do |key, value| - assert_includes indexed_fields(Community), key - end - end - - should 'index control fields for Community model' do - Community::control_fields.each do |key, value| - assert_includes indexed_fields(Community), key - assert_equal indexed_fields(Community)[key][:type], value[:type] || 'string' - end - end - -end diff --git a/plugins/elasticsearch/test/unit/models/event_test.rb b/plugins/elasticsearch/test/unit/models/event_test.rb deleted file mode 100644 index 07c56fa..0000000 --- a/plugins/elasticsearch/test/unit/models/event_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class EventTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [Event] - end - - should 'index searchable fields for Event model' do - Event::SEARCHABLE_FIELDS.each do |key, value| - assert_includes indexed_fields(Event), key - end - end - - should 'index control fields for Event model' do - Event::control_fields.each do |key, value| - assert_includes indexed_fields(Event), key - assert_equal indexed_fields(Event)[key][:type], value[:type] || 'string' - end - end - -end diff --git a/plugins/elasticsearch/test/unit/models/person_test.rb b/plugins/elasticsearch/test/unit/models/person_test.rb deleted file mode 100644 index 1e5baad..0000000 --- a/plugins/elasticsearch/test/unit/models/person_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class PersonTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [Person] - end - - should 'index searchable fields for Person model' do - Person::SEARCHABLE_FIELDS.each do |key, value| - assert_includes indexed_fields(Person), key - end - end - - should 'index control fields for Person model' do - Person::control_fields.each do |key, value| - assert_includes indexed_fields(Person), key - assert_equal indexed_fields(Person)[key][:type], value[:type] || 'string' - end - end -end diff --git a/plugins/elasticsearch/test/unit/models/text_article_test.rb b/plugins/elasticsearch/test/unit/models/text_article_test.rb deleted file mode 100644 index 873c5a4..0000000 --- a/plugins/elasticsearch/test/unit/models/text_article_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class TextArticleTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [TextArticle] - end - - should 'index searchable fields for TextArticle model' do - TextArticle::SEARCHABLE_FIELDS.each do |key, value| - assert_includes indexed_fields(TextArticle), key - end - end - - should 'index control fields for TextArticle model' do - TextArticle::control_fields.each do |key, value| - assert_includes indexed_fields(TextArticle), key - assert_equal indexed_fields(TextArticle)[key][:type], value[:type] || 'string' - end - end - -end diff --git a/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb b/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb deleted file mode 100644 index 7615f7a..0000000 --- a/plugins/elasticsearch/test/unit/models/uploaded_file_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "#{File.dirname(__FILE__)}/../../test_helper" - -class UploadedFileTest < ActionController::TestCase - - include ElasticsearchTestHelper - - def indexed_models - [UploadedFile] - end - - should 'index searchable fields for UploadedFile model' do - UploadedFile::SEARCHABLE_FIELDS.each do |key, value| - assert_includes indexed_fields(UploadedFile), key - end - end - - should 'index control fields for UploadedFile model' do - UploadedFile::control_fields.each do |key, value| - assert_includes indexed_fields(UploadedFile), key - assert_equal indexed_fields(UploadedFile)[key][:type], value[:type].presence || 'string' - end - end - -end diff --git a/plugins/elasticsearch/test/unit/person_test.rb b/plugins/elasticsearch/test/unit/person_test.rb new file mode 100644 index 0000000..c56d47a --- /dev/null +++ b/plugins/elasticsearch/test/unit/person_test.rb @@ -0,0 +1,23 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class PersonTest < ActionController::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [Person] + end + + should 'index searchable fields for Person model' do + Person::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(Person), key + end + end + + should 'index control fields for Person model' do + Person::control_fields.each do |key, value| + assert_includes indexed_fields(Person), key + assert_equal indexed_fields(Person)[key][:type], value[:type] || 'string' + end + end +end diff --git a/plugins/elasticsearch/test/unit/text_article_test.rb b/plugins/elasticsearch/test/unit/text_article_test.rb new file mode 100644 index 0000000..2354fac --- /dev/null +++ b/plugins/elasticsearch/test/unit/text_article_test.rb @@ -0,0 +1,24 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class TextArticleTest < ActionController::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [TextArticle] + end + + should 'index searchable fields for TextArticle model' do + TextArticle::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(TextArticle), key + end + end + + should 'index control fields for TextArticle model' do + TextArticle::control_fields.each do |key, value| + assert_includes indexed_fields(TextArticle), key + assert_equal indexed_fields(TextArticle)[key][:type], value[:type] || 'string' + end + end + +end diff --git a/plugins/elasticsearch/test/unit/uploaded_file_test.rb b/plugins/elasticsearch/test/unit/uploaded_file_test.rb new file mode 100644 index 0000000..7a3ae19 --- /dev/null +++ b/plugins/elasticsearch/test/unit/uploaded_file_test.rb @@ -0,0 +1,24 @@ +require "#{File.dirname(__FILE__)}/../test_helper" + +class UploadedFileTest < ActionController::TestCase + + include ElasticsearchTestHelper + + def indexed_models + [UploadedFile] + end + + should 'index searchable fields for UploadedFile model' do + UploadedFile::SEARCHABLE_FIELDS.each do |key, value| + assert_includes indexed_fields(UploadedFile), key + end + end + + should 'index control fields for UploadedFile model' do + UploadedFile::control_fields.each do |key, value| + assert_includes indexed_fields(UploadedFile), key + assert_equal indexed_fields(UploadedFile)[key][:type], value[:type].presence || 'string' + end + end + +end -- libgit2 0.21.2