tire 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tire/search.rb CHANGED
@@ -22,7 +22,7 @@ module Tire
22
22
  end
23
23
 
24
24
  def sort(&block)
25
- @sort = Sort.new(&block)
25
+ @sort = Sort.new(&block).to_ary
26
26
  self
27
27
  end
28
28
 
@@ -91,7 +91,7 @@ module Tire
91
91
  request.update( { :size => @size } ) if @size
92
92
  request.update( { :from => @from } ) if @from
93
93
  request.update( { :fields => @fields } ) if @fields
94
- MultiJson.encode(request)
94
+ request.to_json
95
95
  end
96
96
 
97
97
  def logged(error=nil)
@@ -20,6 +20,10 @@ module Tire
20
20
  self
21
21
  end
22
22
 
23
+ def to_ary
24
+ @value
25
+ end
26
+
23
27
  def to_json
24
28
  @value.to_json
25
29
  end
data/lib/tire/tasks.rb CHANGED
@@ -52,8 +52,9 @@ namespace :tire do
52
52
  end
53
53
 
54
54
  unless index.exists?
55
- puts "[IMPORT] Creating index '#{index.name}' with mapping:",
56
- MultiJson.encode(klass.mapping_to_hash, :pretty => true)
55
+ mapping = defined?(Yajl) ? Yajl::Encoder.encode(klass.mapping_to_hash, :pretty => true) :
56
+ MultiJson.encode(klass.mapping_to_hash)
57
+ puts "[IMPORT] Creating index '#{index.name}' with mapping:", mapping
57
58
  index.create :mappings => klass.mapping_to_hash
58
59
  end
59
60
 
data/lib/tire/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tire
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -66,12 +66,16 @@ module Tire
66
66
 
67
67
  should "log request in correct format" do
68
68
  log = (<<-"log;").gsub(/^ +/, '')
69
- # 2011-03-19 11:00:00:#{RUBY_VERSION < "1.9" ? "L" : "000"} [_search] (["articles", "users"])
69
+ # 2011-03-19 11:00:00:000 [_search] (["articles", "users"])
70
70
  #
71
71
  curl -X GET http://...
72
72
 
73
73
  log;
74
- @logger.expects(:write).with(log)
74
+ @logger.expects(:write).with do |payload|
75
+ payload =~ Regexp.new( Regexp.escape('2011-03-19 11:00:00') )
76
+ payload =~ Regexp.new( Regexp.escape('_search') )
77
+ payload =~ Regexp.new( Regexp.escape('(["articles", "users"])') )
78
+ end
75
79
  @logger.log_request('_search', ["articles", "users"], 'curl -X GET http://...')
76
80
  end
77
81
 
@@ -98,13 +102,20 @@ module Tire
98
102
  }
99
103
  json;
100
104
  log = (<<-"log;").gsub(/^\s*/, '')
101
- # 2011-03-19 11:00:00:#{RUBY_VERSION < "1.9" ? "L" : "000"} [200 OK] (4 msec)
105
+ # 2011-03-19 11:00:00:000 [200 OK] (4 msec)
102
106
  #
103
107
  log;
104
108
  # log += json.split.map { |line| "# #{line}" }.join("\n")
105
109
  json.each_line { |line| log += "# #{line}" }
106
110
  log += "\n\n"
107
- @logger.expects(:write).with(log)
111
+ @logger.expects(:write).with do |payload|
112
+ payload =~ Regexp.new( Regexp.escape('2011-03-19 11:00:00') )
113
+ payload =~ Regexp.new( Regexp.escape('[200 OK]') )
114
+ payload =~ Regexp.new( Regexp.escape('(4 msec)') )
115
+ payload =~ Regexp.new( Regexp.escape('took') )
116
+ payload =~ Regexp.new( Regexp.escape('hits') )
117
+ payload =~ Regexp.new( Regexp.escape('_score') )
118
+ end
108
119
  @logger.log_response('200 OK', 4, json)
109
120
  end
110
121
 
@@ -41,6 +41,14 @@ module Tire
41
41
 
42
42
  end
43
43
 
44
+ context "Array" do
45
+
46
+ should "encode itself to JSON" do
47
+ assert_equal '["one","two"]', ['one','two'].to_json
48
+ end
49
+
50
+ end
51
+
44
52
  end
45
53
 
46
54
  end
@@ -24,12 +24,18 @@ module Tire::Search
24
24
  Filter.new('geo_distance', { :distance => '12km', :location => [40, -70] }).to_json )
25
25
  end
26
26
 
27
- should "encode 'or' filter declarations as JSON" do
27
+ should "encode 'or' filter with multiple other filters" do
28
28
  # See http://www.elasticsearch.org/guide/reference/query-dsl/or-filter.html
29
29
  assert_equal( { :or => [ {:terms => {:tags => ['foo']}}, {:terms => {:tags => ['bar']}} ] }.to_json,
30
30
  Filter.new('or', {:terms => {:tags => ['foo']}}, {:terms => {:tags => ['bar']}}).to_json )
31
31
  end
32
32
 
33
+ should "encode 'bool' filter with multiple filters" do
34
+ # http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter.html
35
+ assert_equal( { :bool => [ {:must => {:terms => {:tags => ['foo']}}}, {:should => {:terms => {:tags => ['bar']}}} ] }.to_json,
36
+ Filter.new('bool', {:must => {:terms => {:tags => ['foo']}}}, { :should => {:terms => {:tags => ['bar']}}}).to_json )
37
+ end
38
+
33
39
  end
34
40
 
35
41
  end
data/tire.gemspec CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.required_rubygems_version = ">= 1.3.6"
26
26
 
27
- s.add_dependency "rake", "~> 0.8.0"
27
+ s.add_dependency "rake", ">= 0.8.0"
28
28
  s.add_dependency "bundler", "~> 1.0.0"
29
29
  s.add_dependency "rest-client", "~> 1.6.0"
30
30
  s.add_dependency "multi_json", "~> 1.0"
31
- s.add_dependency "activemodel", "~> 3.0.7"
31
+ s.add_dependency "activemodel", "~> 3.0"
32
32
 
33
33
  s.add_development_dependency "yajl-ruby", "~> 0.8.0"
34
34
  s.add_development_dependency "turn"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tire
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karel Minarik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-04 00:00:00 +02:00
18
+ date: 2011-06-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 63
30
30
  segments:
@@ -89,12 +89,11 @@ dependencies:
89
89
  requirements:
90
90
  - - ~>
91
91
  - !ruby/object:Gem::Version
92
- hash: 9
92
+ hash: 7
93
93
  segments:
94
94
  - 3
95
95
  - 0
96
- - 7
97
- version: 3.0.7
96
+ version: "3.0"
98
97
  type: :runtime
99
98
  version_requirements: *id005
100
99
  - !ruby/object:Gem::Dependency
@@ -312,7 +311,7 @@ files:
312
311
  - test/unit/model_search_test.rb
313
312
  - test/unit/results_collection_test.rb
314
313
  - test/unit/results_item_test.rb
315
- - test/unit/rubyext_hash_test.rb
314
+ - test/unit/rubyext_test.rb
316
315
  - test/unit/search_facet_test.rb
317
316
  - test/unit/search_filter_test.rb
318
317
  - test/unit/search_highlight_test.rb
@@ -396,7 +395,7 @@ test_files:
396
395
  - test/unit/model_search_test.rb
397
396
  - test/unit/results_collection_test.rb
398
397
  - test/unit/results_item_test.rb
399
- - test/unit/rubyext_hash_test.rb
398
+ - test/unit/rubyext_test.rb
400
399
  - test/unit/search_facet_test.rb
401
400
  - test/unit/search_filter_test.rb
402
401
  - test/unit/search_highlight_test.rb