elasticsearch_autocomplete 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec053155e8286256103931b33b97f4bae9108f0f
4
- data.tar.gz: 3f2f2be1ab323398e21dbe1feb543313b5903cc7
3
+ metadata.gz: a87e3e5a235180354eabcb8fb4ed51c88e79152a
4
+ data.tar.gz: 597ba4146d2e445899a3aafd2e3a91137e64e350
5
5
  SHA512:
6
- metadata.gz: b5a457a872f4bd0540fa8f26ffc87faa72744a8dbc67a28d020b7f7f05403d2640f40e61578fcd9da38e29a31caf259b7a4d33ccba41e8b032b6d50ce45e08bc
7
- data.tar.gz: 4bbf9a2a52d161b122323f5c0b08c7b98989406babde58749f1cfaff72b1297d1d38fe5734e7a1576727dc1a967cb4f3200b3c88ae45c30ae7f674763b695852
6
+ metadata.gz: 675ae4a73d7bed41485d2db1dcf189ef7f531b5d64cb9efa1c8ed7f01b7de2bf21b9a3880440ea2c5a0c2a6cfbc78198e291a8579767e78d6cd2115a2930ca89
7
+ data.tar.gz: f120c92b1e5b9c091bf9b3ac3bac6bc9ae0cfc2c9416032f1ecbaae15e122691a0bdcda30c8fdd4410ebfaf8cee5591f410cec21ae2ff04a039950a76ccc5cd8
data/README.md CHANGED
@@ -63,7 +63,7 @@ class Product < ActiveRecord::Base
63
63
  end
64
64
  ```
65
65
 
66
- If you wand to define settings and mapping for elasticsearch index yourselves:
66
+ If you want to define settings and mapping for elasticsearch index yourselves:
67
67
 
68
68
  ```ruby
69
69
  class Product < ActiveRecord::Base
@@ -22,4 +22,5 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency 'rake'
23
23
  gem.add_development_dependency 'rspec'
24
24
  gem.add_development_dependency 'oj'
25
+ gem.add_development_dependency 'activerecord', '>= 3.2'
25
26
  end
@@ -19,9 +19,11 @@ module ElasticsearchAutocomplete
19
19
  :full => {:base => 'ac', :full => 'ac_full'}
20
20
  }
21
21
 
22
- def self.val_to_array(val, zero=false)
22
+ def self.val_to_terms(val, zero=false)
23
23
  return [] unless val
24
24
  return val if val.is_a?(Array)
25
+ return [true] if val == 'true'
26
+ return [false] if val == 'false'
25
27
  a = val.to_s.split(',').map(&:to_i)
26
28
  zero ? a : a.reject(&:zero?)
27
29
  end
@@ -58,10 +58,10 @@ module ElasticsearchAutocomplete
58
58
  by(options[:order], options[:sort_mode] || 'asc') if options[:order].present?
59
59
  end
60
60
 
61
- filter(:and, :filters => options[:with].map { |k, v| {:terms => {k => ElasticsearchAutocomplete.val_to_array(v)}} }) if options[:with].present?
61
+ filter(:and, :filters => options[:with].map { |k, v| {:terms => {k => ElasticsearchAutocomplete.val_to_terms(v)}} }) if options[:with].present?
62
62
  if options[:without].present?
63
63
  options[:without].each do |k, v|
64
- filter(:not, {:terms => {k => ElasticsearchAutocomplete.val_to_array(v, true)}})
64
+ filter(:not, {:terms => {k => ElasticsearchAutocomplete.val_to_terms(v, true)}})
65
65
  end
66
66
  end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module ElasticsearchAutocomplete
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -66,6 +66,40 @@ describe ElasticsearchAutocomplete do
66
66
  results.map{|x| x.is_a?(ActiveModelUser).should == true }
67
67
  end
68
68
  end
69
+
70
+ describe '#val_to_terms' do
71
+ it 'empty array if argument is blank' do
72
+ ElasticsearchAutocomplete.val_to_terms(nil).should == []
73
+ end
74
+
75
+ it 'array if argument is array' do
76
+ ElasticsearchAutocomplete.val_to_terms([1, 2]).should == [1, 2]
77
+ end
78
+
79
+ it 'comma separated values' do
80
+ ElasticsearchAutocomplete.val_to_terms('1,2').should == [1, 2]
81
+ end
82
+
83
+ context 'skip zero' do
84
+ it 'skip zero by default' do
85
+ ElasticsearchAutocomplete.val_to_terms('0,1,2').should == [1, 2]
86
+ end
87
+
88
+ it 'include zero' do
89
+ ElasticsearchAutocomplete.val_to_terms('0,1,2', true).should == [0, 1, 2]
90
+ end
91
+ end
92
+
93
+ context 'boolean' do
94
+ it 'true value' do
95
+ ElasticsearchAutocomplete.val_to_terms('true').should == [true]
96
+ end
97
+
98
+ it 'false value' do
99
+ ElasticsearchAutocomplete.val_to_terms('false').should == [false]
100
+ end
101
+ end
102
+ end
69
103
  end
70
104
 
71
105
  shared_examples 'basic autocomplete' do |model|
data/spec/spec_helper.rb CHANGED
@@ -38,14 +38,11 @@ class ActiveModelBase
38
38
  end
39
39
 
40
40
  def save
41
- _run_save_callbacks do
42
- end
41
+ run_callbacks(:save) {}
43
42
  end
44
43
 
45
44
  def destroy
46
- _run_destroy_callbacks do
47
- @destroyed = true
48
- end
45
+ run_callbacks(:destroy) { @destroyed = true }
49
46
  end
50
47
 
51
48
  def destroyed?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Leschenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tire
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
69
83
  description: Simple autocomplete for your models using awesome elasticsearch and tire
70
84
  gem
71
85
  email: