tire 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.travis.yml +3 -0
  2. data/README.markdown +49 -29
  3. data/examples/rails-application-template.rb +15 -15
  4. data/examples/tire-dsl.rb +24 -24
  5. data/lib/tire.rb +2 -1
  6. data/lib/tire/alias.rb +3 -3
  7. data/lib/tire/dsl.rb +17 -19
  8. data/lib/tire/index.rb +67 -10
  9. data/lib/tire/model/callbacks.rb +1 -1
  10. data/lib/tire/model/indexing.rb +2 -2
  11. data/lib/tire/model/naming.rb +1 -1
  12. data/lib/tire/model/percolate.rb +3 -3
  13. data/lib/tire/model/persistence.rb +1 -1
  14. data/lib/tire/model/persistence/attributes.rb +2 -2
  15. data/lib/tire/model/persistence/storage.rb +2 -2
  16. data/lib/tire/model/search.rb +8 -8
  17. data/lib/tire/multi_search.rb +4 -4
  18. data/lib/tire/rubyext/ruby_1_8.rb +1 -1
  19. data/lib/tire/search.rb +1 -1
  20. data/lib/tire/search/scan.rb +1 -1
  21. data/lib/tire/tasks.rb +1 -1
  22. data/lib/tire/version.rb +7 -11
  23. data/test/integration/active_record_searchable_test.rb +42 -0
  24. data/test/integration/dis_max_queries_test.rb +1 -1
  25. data/test/integration/dsl_search_test.rb +9 -0
  26. data/test/integration/index_mapping_test.rb +82 -7
  27. data/test/integration/persistent_model_test.rb +17 -0
  28. data/test/integration/sort_test.rb +16 -0
  29. data/test/models/active_record_models.rb +9 -0
  30. data/test/models/persistent_article.rb +1 -1
  31. data/test/models/persistent_article_in_index.rb +1 -1
  32. data/test/models/persistent_article_in_namespace.rb +1 -1
  33. data/test/models/persistent_article_with_percolation.rb +5 -0
  34. data/test/models/persistent_articles_with_custom_index_name.rb +1 -1
  35. data/test/test_helper.rb +1 -1
  36. data/test/unit/index_alias_test.rb +1 -1
  37. data/test/unit/index_test.rb +79 -1
  38. data/test/unit/model_persistence_test.rb +11 -1
  39. data/test/unit/model_search_test.rb +2 -2
  40. data/test/unit/tire_test.rb +11 -7
  41. data/tire.gemspec +4 -3
  42. metadata +61 -51
@@ -307,10 +307,20 @@ module Tire
307
307
  assert_equal '4chan', article.comments.first.nick
308
308
  end
309
309
 
310
- should "automatically format strings in UTC format as Time" do
310
+ should "automatically format strings in ISO8601 with the default UTC designator" do
311
311
  article = PersistentArticle.new :published_on => '2011-11-01T23:00:00Z'
312
312
  assert_instance_of Time, article.published_on
313
313
  assert_equal 2011, article.published_on.year
314
+ assert_equal 23, article.published_on.hour
315
+ assert_equal 00, article.published_on.min
316
+ end
317
+
318
+ should "automatically format strings in ISO8601 with a time zone offset" do
319
+ article = PersistentArticle.new :published_on => '2011-11-01T00:00:00+01:00'
320
+ assert_instance_of Time, article.published_on
321
+ assert_equal 2011, article.published_on.year
322
+ assert_equal 23, article.published_on.hour
323
+ assert_equal 00, article.published_on.min
314
324
  end
315
325
 
316
326
  should "cast anonymous Hashes as Hashr instances" do
@@ -748,7 +748,7 @@ module Tire
748
748
  percolate!
749
749
  end
750
750
 
751
- assert_equal true, ::ActiveModelArticleWithCallbacks.percolator
751
+ assert_equal true, ::ActiveModelArticleWithPercolation.percolator
752
752
  end
753
753
 
754
754
  should "set the percolator pattern" do
@@ -756,7 +756,7 @@ module Tire
756
756
  percolate! 'tags:alert'
757
757
  end
758
758
 
759
- assert_equal 'tags:alert', ::ActiveModelArticleWithCallbacks.percolator
759
+ assert_equal 'tags:alert', ::ActiveModelArticleWithPercolation.percolator
760
760
  end
761
761
 
762
762
  should "mark the class for percolation on index update" do
@@ -29,19 +29,23 @@ module Tire
29
29
  Tire.search 'dummy', payload
30
30
  end
31
31
 
32
- should "allow searching with a JSON string" do
33
- payload = '{"query":{"query_string":{"query":"foo"}}}'
34
- Search::Search.expects(:new).with('dummy', :payload => payload).returns( stub(:perform => true) )
35
-
36
- Tire.search 'dummy', payload
37
- end
38
-
39
32
  should "raise an error when passed incorrect payload" do
40
33
  assert_raise(ArgumentError) do
41
34
  Tire.search 'dummy', 1
42
35
  end
43
36
  end
44
37
 
38
+ should "extract URL parameters from options" do
39
+ payload = { :query => { :match => { :foo => 'bar' } } }
40
+
41
+ Search::Search.expects(:new).with do |index,options|
42
+ assert_equal 'bar', options[:payload][:query][:match][:foo]
43
+ assert_equal 'count', options[:search_type]
44
+ end.returns( stub(:perform => true) )
45
+
46
+ Tire.search 'dummy', :query => { :match => { :foo => 'bar' } }, :search_type => 'count'
47
+ end
48
+
45
49
  should "raise SearchRequestFailed when receiving bad response from backend" do
46
50
  assert_raise(Search::SearchRequestFailed) do
47
51
  Tire::Configuration.client.expects(:get).returns( mock_response('INDEX DOES NOT EXIST', 404) )
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "tire"
7
7
  s.version = Tire::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.summary = "Ruby client for ElasticSearch"
9
+ s.summary = "Ruby client for Elasticsearch"
10
10
  s.homepage = "http://github.com/karmi/tire"
11
11
  s.authors = [ 'Karel Minarik' ]
12
12
  s.email = 'karmi@karmi.cz'
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.add_dependency "multi_json", "~> 1.3"
32
32
  s.add_dependency "activemodel", ">= 3.0"
33
33
  s.add_dependency "hashr", "~> 0.0.19"
34
+ s.add_dependency "activesupport"
34
35
 
35
36
  # = Development dependencies
36
37
  #
@@ -53,9 +54,9 @@ Gem::Specification.new do |s|
53
54
  end
54
55
 
55
56
  s.description = <<-DESC
56
- Tire is a Ruby client for the ElasticSearch search engine/database.
57
+ Tire is a Ruby client for the Elasticsearch search engine/database.
57
58
 
58
- It provides Ruby-like API for fluent communication with the ElasticSearch server
59
+ It provides Ruby-like API for fluent communication with the Elasticsearch server
59
60
  and blends with ActiveModel class for convenient usage in Rails applications.
60
61
 
61
62
  It allows to delete and create indices, define mapping for them, supports
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-05 00:00:00.000000000 Z
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70237728923180 !ruby/object:Gem::Requirement
16
+ requirement: &70310347391340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70237728923180
24
+ version_requirements: *70310347391340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70237728922400 !ruby/object:Gem::Requirement
27
+ requirement: &70310347390800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.6'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70237728922400
35
+ version_requirements: *70310347390800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &70237728921620 !ruby/object:Gem::Requirement
38
+ requirement: &70310347390300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70237728921620
46
+ version_requirements: *70310347390300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemodel
49
- requirement: &70237728920960 !ruby/object:Gem::Requirement
49
+ requirement: &70310347389840 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70237728920960
57
+ version_requirements: *70310347389840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hashr
60
- requirement: &70237728920260 !ruby/object:Gem::Requirement
60
+ requirement: &70310347405760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,21 @@ dependencies:
65
65
  version: 0.0.19
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70237728920260
68
+ version_requirements: *70310347405760
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: &70310347405380 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70310347405380
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: bundler
71
- requirement: &70237728919580 !ruby/object:Gem::Requirement
82
+ requirement: &70310347404840 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '1.0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70237728919580
90
+ version_requirements: *70310347404840
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: shoulda
82
- requirement: &70237728919000 !ruby/object:Gem::Requirement
93
+ requirement: &70310347404420 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70237728919000
101
+ version_requirements: *70310347404420
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: mocha
93
- requirement: &70237728944780 !ruby/object:Gem::Requirement
104
+ requirement: &70310347403880 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ~>
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0.13'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70237728944780
112
+ version_requirements: *70310347403880
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: minitest
104
- requirement: &70237728944020 !ruby/object:Gem::Requirement
115
+ requirement: &70310347403380 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ~>
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '2.12'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70237728944020
123
+ version_requirements: *70310347403380
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: activerecord
115
- requirement: &70237728943340 !ruby/object:Gem::Requirement
126
+ requirement: &70310347402920 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: '3.0'
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70237728943340
134
+ version_requirements: *70310347402920
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: mongoid
126
- requirement: &70237728942600 !ruby/object:Gem::Requirement
137
+ requirement: &70310347402460 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ~>
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '2.2'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *70237728942600
145
+ version_requirements: *70310347402460
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: redis-persistence
137
- requirement: &70237728942140 !ruby/object:Gem::Requirement
148
+ requirement: &70310347402080 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,10 +153,10 @@ dependencies:
142
153
  version: '0'
143
154
  type: :development
144
155
  prerelease: false
145
- version_requirements: *70237728942140
156
+ version_requirements: *70310347402080
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: faraday
148
- requirement: &70237728941680 !ruby/object:Gem::Requirement
159
+ requirement: &70310347401620 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - ! '>='
@@ -153,10 +164,10 @@ dependencies:
153
164
  version: '0'
154
165
  type: :development
155
166
  prerelease: false
156
- version_requirements: *70237728941680
167
+ version_requirements: *70310347401620
157
168
  - !ruby/object:Gem::Dependency
158
169
  name: yajl-ruby
159
- requirement: &70237728941160 !ruby/object:Gem::Requirement
170
+ requirement: &70310347401120 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
173
  - - ~>
@@ -164,10 +175,10 @@ dependencies:
164
175
  version: '1.0'
165
176
  type: :development
166
177
  prerelease: false
167
- version_requirements: *70237728941160
178
+ version_requirements: *70310347401120
168
179
  - !ruby/object:Gem::Dependency
169
180
  name: sqlite3
170
- requirement: &70237728940740 !ruby/object:Gem::Requirement
181
+ requirement: &70310347400700 !ruby/object:Gem::Requirement
171
182
  none: false
172
183
  requirements:
173
184
  - - ! '>='
@@ -175,10 +186,10 @@ dependencies:
175
186
  version: '0'
176
187
  type: :development
177
188
  prerelease: false
178
- version_requirements: *70237728940740
189
+ version_requirements: *70310347400700
179
190
  - !ruby/object:Gem::Dependency
180
191
  name: bson_ext
181
- requirement: &70237728940240 !ruby/object:Gem::Requirement
192
+ requirement: &70310347400240 !ruby/object:Gem::Requirement
182
193
  none: false
183
194
  requirements:
184
195
  - - ! '>='
@@ -186,10 +197,10 @@ dependencies:
186
197
  version: '0'
187
198
  type: :development
188
199
  prerelease: false
189
- version_requirements: *70237728940240
200
+ version_requirements: *70310347400240
190
201
  - !ruby/object:Gem::Dependency
191
202
  name: curb
192
- requirement: &70237728939820 !ruby/object:Gem::Requirement
203
+ requirement: &70310347399820 !ruby/object:Gem::Requirement
193
204
  none: false
194
205
  requirements:
195
206
  - - ! '>='
@@ -197,10 +208,10 @@ dependencies:
197
208
  version: '0'
198
209
  type: :development
199
210
  prerelease: false
200
- version_requirements: *70237728939820
211
+ version_requirements: *70310347399820
201
212
  - !ruby/object:Gem::Dependency
202
213
  name: oj
203
- requirement: &70237728939400 !ruby/object:Gem::Requirement
214
+ requirement: &70310347399340 !ruby/object:Gem::Requirement
204
215
  none: false
205
216
  requirements:
206
217
  - - ! '>='
@@ -208,10 +219,10 @@ dependencies:
208
219
  version: '0'
209
220
  type: :development
210
221
  prerelease: false
211
- version_requirements: *70237728939400
222
+ version_requirements: *70310347399340
212
223
  - !ruby/object:Gem::Dependency
213
224
  name: turn
214
- requirement: &70237728938900 !ruby/object:Gem::Requirement
225
+ requirement: &70310347398820 !ruby/object:Gem::Requirement
215
226
  none: false
216
227
  requirements:
217
228
  - - ~>
@@ -219,9 +230,9 @@ dependencies:
219
230
  version: '0.9'
220
231
  type: :development
221
232
  prerelease: false
222
- version_requirements: *70237728938900
223
- description: ! " Tire is a Ruby client for the ElasticSearch search engine/database.\n\n
224
- \ It provides Ruby-like API for fluent communication with the ElasticSearch server\n
233
+ version_requirements: *70310347398820
234
+ description: ! " Tire is a Ruby client for the Elasticsearch search engine/database.\n\n
235
+ \ It provides Ruby-like API for fluent communication with the Elasticsearch server\n
225
236
  \ and blends with ActiveModel class for convenient usage in Rails applications.\n\n
226
237
  \ It allows to delete and create indices, define mapping for them, supports\n the
227
238
  bulk API, and presents an easy-to-use DSL for constructing your queries.\n\n It
@@ -338,6 +349,7 @@ files:
338
349
  - test/models/persistent_article_in_namespace.rb
339
350
  - test/models/persistent_article_with_casting.rb
340
351
  - test/models/persistent_article_with_defaults.rb
352
+ - test/models/persistent_article_with_percolation.rb
341
353
  - test/models/persistent_articles_with_custom_index_name.rb
342
354
  - test/models/supermodel_article.rb
343
355
  - test/models/validated_model.rb
@@ -373,14 +385,11 @@ homepage: http://github.com/karmi/tire
373
385
  licenses: []
374
386
  post_install_message: ! "================================================================================\n\n
375
387
  \ Please check the documentation at <http://karmi.github.com/tire/>.\n\n--------------------------------------------------------------------------------\n\n
376
- \ IMPORTANT CHANGES LATELY:\n\n * Added the support for the Count API\n * Escape
377
- single quotes in `to_curl` serialization\n * Added JRuby compatibility\n * Added
378
- proper `as_json` support for `Results::Collection` and `Results::Item` classes\n
379
- \ * Added extracting the `routing` information in the `Index#store` method\n *
380
- Refactored the `update_index` method for search and persistence integration\n *
381
- Cast collection properties in Model::Persistence as empty Array by default\n *
382
- Allow passing `:index` option to `MyModel.import`\n * Update to Mocha ~> 0.13\n
383
- \ * Update to MultiJson ~> 1.3\n\n See the full changelog at <http://github.com/karmi/tire/commits/v0.5.4>.\n\n--------------------------------------------------------------------------------\n"
388
+ \ IMPORTANT CHANGES LATELY:\n\n * Improved documentation\n * Improved isolation
389
+ of Tire methods in model integrations\n * Improved handling of times/dates in `Model::Persistence`\n
390
+ \ * Added support for \"Put Mapping\" and \"Delete mapping\" APIs\n * Added escaping
391
+ document IDs in URLs\n * Allowed passing URL options when passing search definition
392
+ as a Hash\n\n See the full changelog at <http://github.com/karmi/tire/commits/v0.5.5>.\n\n--------------------------------------------------------------------------------\n"
384
393
  rdoc_options:
385
394
  - --charset=UTF-8
386
395
  require_paths:
@@ -402,7 +411,7 @@ rubyforge_project: tire
402
411
  rubygems_version: 1.8.11
403
412
  signing_key:
404
413
  specification_version: 3
405
- summary: Ruby client for ElasticSearch
414
+ summary: Ruby client for Elasticsearch
406
415
  test_files:
407
416
  - test/fixtures/articles/1.json
408
417
  - test/fixtures/articles/2.json
@@ -457,6 +466,7 @@ test_files:
457
466
  - test/models/persistent_article_in_namespace.rb
458
467
  - test/models/persistent_article_with_casting.rb
459
468
  - test/models/persistent_article_with_defaults.rb
469
+ - test/models/persistent_article_with_percolation.rb
460
470
  - test/models/persistent_articles_with_custom_index_name.rb
461
471
  - test/models/supermodel_article.rb
462
472
  - test/models/validated_model.rb