Commit 324b48bd9462125eb84e1a6ff8ec1c787fa4ccd7
1 parent
123b7823
Exists in
elasticsearch_api
Adding tests and refactored control_fields indexed
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
11 changed files
with
59 additions
and
39 deletions
Show diff stats
plugins/elasticsearch/Rakefile
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
... | ... | @@ -7,7 +7,8 @@ module ElasticsearchIndexedModel |
7 | 7 | settings index: { number_of_shards: 1 } do |
8 | 8 | mappings dynamic: 'false' do |
9 | 9 | base.indexable_fields.each do |field, value| |
10 | - indexes field | |
10 | + value = {} if value.nil? | |
11 | + indexes field, type: value[:type].presence | |
11 | 12 | print '.' |
12 | 13 | end |
13 | 14 | end |
... | ... | @@ -26,7 +27,7 @@ module ElasticsearchIndexedModel |
26 | 27 | |
27 | 28 | module ClassMethods |
28 | 29 | def indexable_fields |
29 | - self::SEARCHABLE_FIELDS.keys + self.control_fields | |
30 | + self::SEARCHABLE_FIELDS.update self.control_fields | |
30 | 31 | end |
31 | 32 | end |
32 | 33 | ... | ... |
plugins/elasticsearch/lib/ext/community.rb
plugins/elasticsearch/lib/ext/event.rb
plugins/elasticsearch/lib/ext/person.rb
... | ... | @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class Person |
5 | 5 | def self.control_fields |
6 | - [ | |
7 | - :visible, | |
8 | - :public_profile, | |
9 | - ] | |
6 | + { | |
7 | + :visible => {type: 'boolean'}, | |
8 | + :public_profile => {type: 'boolean'}, | |
9 | + } | |
10 | 10 | end |
11 | 11 | include ElasticsearchIndexedModel |
12 | 12 | end | ... | ... |
plugins/elasticsearch/lib/ext/text_article.rb
... | ... | @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class TextArticle |
5 | 5 | def self.control_fields |
6 | - [ | |
7 | - :advertise, | |
8 | - :published, | |
9 | - ] | |
6 | + { | |
7 | + :advertise => nil, | |
8 | + :published => nil, | |
9 | + } | |
10 | 10 | end |
11 | 11 | include ElasticsearchIndexedModel |
12 | 12 | end | ... | ... |
plugins/elasticsearch/lib/ext/uploaded_file.rb
... | ... | @@ -3,10 +3,10 @@ require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class UploadedFile |
5 | 5 | def self.control_fields |
6 | - [ | |
7 | - :advertise, | |
8 | - :published, | |
9 | - ] | |
6 | + { | |
7 | + :advertise => nil, | |
8 | + :published => nil, | |
9 | + } | |
10 | 10 | end |
11 | 11 | include ElasticsearchIndexedModel |
12 | 12 | end | ... | ... |
plugins/elasticsearch/test/test_helper.rb
plugins/elasticsearch/test/unit/models/community_test.rb
... | ... | @@ -3,19 +3,24 @@ require "#{File.dirname(__FILE__)}/../../test_helper" |
3 | 3 | class CommunityTest < ElasticsearchTestHelper |
4 | 4 | |
5 | 5 | def indexed_models |
6 | - [Community, Person] | |
6 | + [Community] | |
7 | 7 | end |
8 | 8 | |
9 | 9 | def setup |
10 | - @profile = create_user('testing').person | |
11 | 10 | super |
12 | 11 | end |
13 | 12 | |
14 | - should 'index custom fields for Event model' do | |
15 | - community_cluster = Community.__elasticsearch__.client.cluster | |
13 | + should 'index searchable fields for Community model' do | |
14 | + Community::SEARCHABLE_FIELDS.each do |key, value| | |
15 | + assert_includes indexed_fields(Community), key | |
16 | + end | |
17 | + end | |
16 | 18 | |
17 | - assert_not_nil Community.mappings.to_hash[:community][:properties][:name] | |
18 | - assert_not_nil Community.mappings.to_hash[:community][:properties][:identifier] | |
19 | - assert_not_nil Community.mappings.to_hash[:community][:properties][:nickname] | |
19 | + should 'index control fields for Community model' do | |
20 | + Community::control_fields.each do |key, value| | |
21 | + assert_includes indexed_fields(Community), key | |
22 | + assert_includes indexed_fields(Community)[key][:type], value[:type] || 'string' | |
23 | + end | |
20 | 24 | end |
25 | + | |
21 | 26 | end | ... | ... |
plugins/elasticsearch/test/unit/models/event_test.rb
... | ... | @@ -7,14 +7,20 @@ class EventTest < ElasticsearchTestHelper |
7 | 7 | end |
8 | 8 | |
9 | 9 | def setup |
10 | - @profile = create_user('testing').person | |
11 | 10 | super |
12 | 11 | end |
13 | 12 | |
14 | - should 'index custom fields for Event model' do | |
15 | - event_cluster = Event.__elasticsearch__.client.cluster | |
13 | + should 'index searchable fields for Event model' do | |
14 | + Event::SEARCHABLE_FIELDS.each do |key, value| | |
15 | + assert_includes indexed_fields(Event), key | |
16 | + end | |
17 | + end | |
16 | 18 | |
17 | - assert_not_nil Event.mappings.to_hash[:event][:properties][:advertise] | |
18 | - assert_not_nil Event.mappings.to_hash[:event][:properties][:published] | |
19 | + should 'index control fields for Event model' do | |
20 | + Event::control_fields.each do |key, value| | |
21 | + assert_includes indexed_fields(Event), key | |
22 | + assert_includes indexed_fields(Event)[key][:type], value[:type] || 'string' | |
23 | + end | |
19 | 24 | end |
25 | + | |
20 | 26 | end | ... | ... |
plugins/elasticsearch/test/unit/models/person_test.rb
... | ... | @@ -3,21 +3,24 @@ require "#{File.dirname(__FILE__)}/../../test_helper" |
3 | 3 | class PersonTest < ElasticsearchTestHelper |
4 | 4 | |
5 | 5 | def indexed_models |
6 | - [Event] | |
6 | + [Person] | |
7 | 7 | end |
8 | 8 | |
9 | 9 | def setup |
10 | - @profile = create_user('testing').person | |
11 | 10 | super |
12 | 11 | end |
13 | 12 | |
14 | - should 'index custom fields for Event model' do | |
15 | - person_cluster = Person.__elasticsearch__.client.cluster | |
13 | + should 'index searchable fields for Person model' do | |
14 | + Person::SEARCHABLE_FIELDS.each do |key, value| | |
15 | + assert_includes indexed_fields(Person), key | |
16 | + end | |
17 | + end | |
16 | 18 | |
17 | - assert_not_nil Person.mappings.to_hash[:person][:properties][:name] | |
18 | - assert_not_nil Person.mappings.to_hash[:person][:properties][:identifier] | |
19 | - assert_not_nil Person.mappings.to_hash[:person][:properties][:nickname] | |
20 | - assert_not_nil Person.mappings.to_hash[:person][:properties][:visible] | |
19 | + should 'index control fields for Person model' do | |
20 | + Person::control_fields.each do |key, value| | |
21 | + assert_includes indexed_fields(Person), key | |
22 | + assert_includes indexed_fields(Person)[key][:type], value[:type] || 'string' | |
23 | + end | |
21 | 24 | end |
22 | 25 | |
23 | 26 | end | ... | ... |