elastomer-client 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.overcommit.yml +5 -0
  3. data/.rubocop.yml +83 -0
  4. data/CHANGELOG.md +8 -0
  5. data/Gemfile +2 -2
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/elastomer-client.gemspec +4 -2
  9. data/lib/elastomer/client.rb +42 -37
  10. data/lib/elastomer/client/bulk.rb +2 -2
  11. data/lib/elastomer/client/cluster.rb +19 -19
  12. data/lib/elastomer/client/delete_by_query.rb +7 -7
  13. data/lib/elastomer/client/docs.rb +81 -24
  14. data/lib/elastomer/client/errors.rb +2 -2
  15. data/lib/elastomer/client/index.rb +65 -29
  16. data/lib/elastomer/client/multi_percolate.rb +127 -0
  17. data/lib/elastomer/client/multi_search.rb +2 -2
  18. data/lib/elastomer/client/nodes.rb +4 -4
  19. data/lib/elastomer/client/percolator.rb +77 -0
  20. data/lib/elastomer/client/repository.rb +7 -7
  21. data/lib/elastomer/client/scroller.rb +14 -14
  22. data/lib/elastomer/client/snapshot.rb +9 -9
  23. data/lib/elastomer/client/template.rb +3 -3
  24. data/lib/elastomer/client/warmer.rb +5 -16
  25. data/lib/elastomer/core_ext/time.rb +1 -1
  26. data/lib/elastomer/middleware/encode_json.rb +5 -5
  27. data/lib/elastomer/middleware/opaque_id.rb +3 -3
  28. data/lib/elastomer/middleware/parse_json.rb +5 -5
  29. data/lib/elastomer/notifications.rb +4 -4
  30. data/lib/elastomer/version.rb +1 -1
  31. data/script/bootstrap +2 -0
  32. data/script/console +5 -5
  33. data/test/assertions.rb +26 -24
  34. data/test/client/bulk_test.rb +111 -111
  35. data/test/client/cluster_test.rb +58 -58
  36. data/test/client/delete_by_query_test.rb +53 -53
  37. data/test/client/docs_test.rb +279 -203
  38. data/test/client/errors_test.rb +1 -1
  39. data/test/client/index_test.rb +143 -109
  40. data/test/client/multi_percolate_test.rb +130 -0
  41. data/test/client/multi_search_test.rb +30 -28
  42. data/test/client/nodes_test.rb +30 -29
  43. data/test/client/percolator_test.rb +52 -0
  44. data/test/client/repository_test.rb +23 -23
  45. data/test/client/scroller_test.rb +40 -40
  46. data/test/client/snapshot_test.rb +15 -15
  47. data/test/client/stubbed_client_test.rb +15 -15
  48. data/test/client/template_test.rb +10 -10
  49. data/test/client/warmer_test.rb +18 -18
  50. data/test/client_test.rb +53 -53
  51. data/test/core_ext/time_test.rb +12 -12
  52. data/test/middleware/encode_json_test.rb +20 -20
  53. data/test/middleware/opaque_id_test.rb +10 -10
  54. data/test/middleware/parse_json_test.rb +14 -14
  55. data/test/notifications_test.rb +32 -32
  56. data/test/test_helper.rb +24 -24
  57. metadata +38 -2
@@ -1,29 +1,29 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  describe Elastomer::Client::Scroller do
4
4
 
5
5
  before do
6
- @name = 'elastomer-scroller-test'
6
+ @name = "elastomer-scroller-test"
7
7
  @index = $client.index(@name)
8
8
 
9
9
  unless @index.exists?
10
10
  @index.create \
11
- :settings => { 'index.number_of_shards' => 1, 'index.number_of_replicas' => 0 },
11
+ :settings => { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
12
12
  :mappings => {
13
13
  :tweet => {
14
14
  :_source => { :enabled => true }, :_all => { :enabled => false },
15
15
  :properties => {
16
- :message => { :type => 'string', :analyzer => 'standard' },
17
- :author => { :type => 'string', :index => 'not_analyzed' },
18
- :sorter => { :type => 'integer' }
16
+ :message => { :type => "string", :analyzer => "standard" },
17
+ :author => { :type => "string", :index => "not_analyzed" },
18
+ :sorter => { :type => "integer" }
19
19
  }
20
20
  },
21
21
  :book => {
22
22
  :_source => { :enabled => true }, :_all => { :enabled => false },
23
23
  :properties => {
24
- :title => { :type => 'string', :analyzer => 'standard' },
25
- :author => { :type => 'string', :index => 'not_analyzed' },
26
- :sorter => { :type => 'integer' }
24
+ :title => { :type => "string", :analyzer => "standard" },
25
+ :author => { :type => "string", :index => "not_analyzed" },
26
+ :sorter => { :type => "integer" }
27
27
  }
28
28
  }
29
29
  }
@@ -37,76 +37,76 @@ describe Elastomer::Client::Scroller do
37
37
  @index.delete if @index.exists?
38
38
  end
39
39
 
40
- it 'scans over all documents in an index' do
40
+ it "scans over all documents in an index" do
41
41
  scan = @index.scan '{"query":{"match_all":{}}}', :size => 10
42
42
 
43
- counts = {'tweet' => 0, 'book' => 0}
44
- scan.each_document { |h| counts[h['_type']] += 1 }
43
+ counts = {"tweet" => 0, "book" => 0}
44
+ scan.each_document { |h| counts[h["_type"]] += 1 }
45
45
 
46
- assert_equal 50, counts['tweet']
47
- assert_equal 25, counts['book']
46
+ assert_equal 50, counts["tweet"]
47
+ assert_equal 25, counts["book"]
48
48
  end
49
49
 
50
- it 'restricts the scan to a single document type' do
51
- scan = @index.scan '{"query":{"match_all":{}}}', :type => 'book'
50
+ it "restricts the scan to a single document type" do
51
+ scan = @index.scan '{"query":{"match_all":{}}}', :type => "book"
52
52
 
53
- counts = {'tweet' => 0, 'book' => 0}
54
- scan.each_document { |h| counts[h['_type']] += 1 }
53
+ counts = {"tweet" => 0, "book" => 0}
54
+ scan.each_document { |h| counts[h["_type"]] += 1 }
55
55
 
56
- assert_equal 0, counts['tweet']
57
- assert_equal 25, counts['book']
56
+ assert_equal 0, counts["tweet"]
57
+ assert_equal 25, counts["book"]
58
58
  end
59
59
 
60
- it 'limits results by query' do
60
+ it "limits results by query" do
61
61
  scan = @index.scan :query => { :bool => { :should => [
62
- {:match => {:author => 'pea53'}},
63
- {:match => {:title => '17'}}
62
+ {:match => {:author => "pea53"}},
63
+ {:match => {:title => "17"}}
64
64
  ]}}
65
65
 
66
- counts = {'tweet' => 0, 'book' => 0}
67
- scan.each_document { |h| counts[h['_type']] += 1 }
66
+ counts = {"tweet" => 0, "book" => 0}
67
+ scan.each_document { |h| counts[h["_type"]] += 1 }
68
68
 
69
- assert_equal 50, counts['tweet']
70
- assert_equal 1, counts['book']
69
+ assert_equal 50, counts["tweet"]
70
+ assert_equal 1, counts["book"]
71
71
  end
72
72
 
73
- it 'scrolls and sorts over all documents' do
73
+ it "scrolls and sorts over all documents" do
74
74
  scroll = @index.scroll({
75
75
  :query => {:match_all => {}},
76
76
  :sort => {:sorter => {:order => :asc}}
77
- }, :type => 'tweet')
77
+ }, :type => "tweet")
78
78
 
79
79
  tweets = []
80
- scroll.each_document { |h| tweets << h['_id'].to_i }
80
+ scroll.each_document { |h| tweets << h["_id"].to_i }
81
81
 
82
82
  expected = (0...50).to_a.reverse
83
83
  assert_equal expected, tweets
84
84
  end
85
85
 
86
- it 'propagates URL query strings' do
87
- scan = @index.scan(nil, { :q => 'author:pea53 || title:17' })
86
+ it "propagates URL query strings" do
87
+ scan = @index.scan(nil, { :q => "author:pea53 || title:17" })
88
88
 
89
- counts = {'tweet' => 0, 'book' => 0}
90
- scan.each_document { |h| counts[h['_type']] += 1 }
89
+ counts = {"tweet" => 0, "book" => 0}
90
+ scan.each_document { |h| counts[h["_type"]] += 1 }
91
91
 
92
- assert_equal 50, counts['tweet']
93
- assert_equal 1, counts['book']
92
+ assert_equal 50, counts["tweet"]
93
+ assert_equal 1, counts["book"]
94
94
  end
95
95
 
96
96
  def populate!
97
97
  h = @index.bulk do |b|
98
98
  50.times { |num|
99
- b.index %Q({"author":"pea53","message":"this is tweet number #{num}","sorter":#{50-num}}), :_id => num, :_type => 'tweet'
99
+ b.index %Q({"author":"pea53","message":"this is tweet number #{num}","sorter":#{50-num}}), :_id => num, :_type => "tweet"
100
100
  }
101
101
  end
102
- h['items'].each {|item| assert_bulk_index(item) }
102
+ h["items"].each {|item| assert_bulk_index(item) }
103
103
 
104
104
  h = @index.bulk do |b|
105
105
  25.times { |num|
106
- b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), :_id => num, :_type => 'book'
106
+ b.index %Q({"author":"Pratchett","title":"DiscWorld Book #{num}","sorter":#{25-num}}), :_id => num, :_type => "book"
107
107
  }
108
108
  end
109
- h['items'].each {|item| assert_bulk_index(item) }
109
+ h["items"].each {|item| assert_bulk_index(item) }
110
110
 
111
111
  @index.refresh
112
112
  end
@@ -1,5 +1,5 @@
1
1
 
2
- require File.expand_path('../../test_helper', __FILE__)
2
+ require File.expand_path("../../test_helper", __FILE__)
3
3
 
4
4
  describe Elastomer::Client::Snapshot do
5
5
  if es_version_1_x?
@@ -8,16 +8,16 @@ describe Elastomer::Client::Snapshot do
8
8
  skip "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
9
9
  end
10
10
 
11
- @index_name = 'elastomer-snapshot-test-index'
11
+ @index_name = "elastomer-snapshot-test-index"
12
12
  @index = $client.index(@index_name)
13
- @name = 'elastomer-test'
13
+ @name = "elastomer-test"
14
14
  end
15
15
 
16
16
  after do
17
17
  @index.delete if @index && @index.exists?
18
18
  end
19
19
 
20
- it 'determines if a snapshot exists' do
20
+ it "determines if a snapshot exists" do
21
21
  with_tmp_repo do |repo|
22
22
  snapshot = repo.snapshot(@name)
23
23
  assert_equal false, snapshot.exists?
@@ -27,14 +27,14 @@ describe Elastomer::Client::Snapshot do
27
27
  end
28
28
  end
29
29
 
30
- it 'creates snapshots' do
30
+ it "creates snapshots" do
31
31
  with_tmp_repo do |repo|
32
32
  response = repo.snapshot(@name).create({}, :wait_for_completion => true)
33
33
  assert_equal @name, response["snapshot"]["snapshot"]
34
34
  end
35
35
  end
36
36
 
37
- it 'creates snapshots with options' do
37
+ it "creates snapshots with options" do
38
38
  @index.create(:number_of_shards => 1, :number_of_replicas => 0)
39
39
  with_tmp_repo do |repo|
40
40
  response = repo.snapshot(@name).create({:indices => [@index_name]}, :wait_for_completion => true)
@@ -43,7 +43,7 @@ describe Elastomer::Client::Snapshot do
43
43
  end
44
44
  end
45
45
 
46
- it 'gets snapshot info for one and all' do
46
+ it "gets snapshot info for one and all" do
47
47
  with_tmp_snapshot do |snapshot, repo|
48
48
  response = snapshot.get
49
49
  assert_equal snapshot.name, response["snapshots"][0]["snapshot"]
@@ -52,7 +52,7 @@ describe Elastomer::Client::Snapshot do
52
52
  end
53
53
  end
54
54
 
55
- it 'gets snapshot status for one and all' do
55
+ it "gets snapshot status for one and all" do
56
56
  @index.create(:number_of_shards => 1, :number_of_replicas => 0)
57
57
  with_tmp_repo do |repo|
58
58
  repo.snapshot(@name).create({:indices => [@index_name]}, :wait_for_completion => true)
@@ -61,7 +61,7 @@ describe Elastomer::Client::Snapshot do
61
61
  end
62
62
  end
63
63
 
64
- it 'gets status of snapshots in progress' do
64
+ it "gets status of snapshots in progress" do
65
65
  # we can't reliably get status of an in-progress snapshot in tests, so
66
66
  # check for an empty result instead
67
67
  with_tmp_repo do |repo|
@@ -72,19 +72,19 @@ describe Elastomer::Client::Snapshot do
72
72
  end
73
73
  end
74
74
 
75
- it 'disallows nil repo name with non-nil snapshot name' do
76
- assert_raises(ArgumentError) { $client.repository.snapshot('snapshot') }
77
- assert_raises(ArgumentError) { $client.snapshot(nil, 'snapshot') }
75
+ it "disallows nil repo name with non-nil snapshot name" do
76
+ assert_raises(ArgumentError) { $client.repository.snapshot("snapshot") }
77
+ assert_raises(ArgumentError) { $client.snapshot(nil, "snapshot") }
78
78
  end
79
79
 
80
- it 'deletes snapshots' do
80
+ it "deletes snapshots" do
81
81
  with_tmp_snapshot do |snapshot|
82
82
  response = snapshot.delete
83
83
  assert_equal true, response["acknowledged"]
84
84
  end
85
85
  end
86
86
 
87
- it 'restores snapshots' do
87
+ it "restores snapshots" do
88
88
  @index.create(:number_of_shards => 1, :number_of_replicas => 0)
89
89
  wait_for_index(@index_name)
90
90
  with_tmp_repo do |repo|
@@ -106,7 +106,7 @@ describe Elastomer::Client::Snapshot do
106
106
  @restored_index.delete if @restored_index && @restored_index.exists?
107
107
  end
108
108
 
109
- it 'restores snapshots with options' do
109
+ it "restores snapshots with options" do
110
110
  @index.create(:number_of_shards => 1, :number_of_replicas => 0)
111
111
  wait_for_index(@index_name)
112
112
  with_tmp_repo do |repo|
@@ -1,40 +1,40 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
- describe 'stubbed client tests' do
3
+ describe "stubbed client tests" do
4
4
  before do
5
5
  @stubs = Faraday::Adapter.lookup_middleware(:test)::Stubs.new
6
6
  @client = Elastomer::Client.new :adapter => [:test, @stubs]
7
7
  end
8
8
 
9
9
  describe Elastomer::Client::Cluster do
10
- it 'reroutes shards' do
11
- @stubs.post '/_cluster/reroute?dry_run=true' do |env|
10
+ it "reroutes shards" do
11
+ @stubs.post "/_cluster/reroute?dry_run=true" do |env|
12
12
  assert_match %r/^\{"commands":\[\{"move":\{[^\{\}]+\}\}\]\}$/, env[:body]
13
- [200, {'Content-Type' => 'application/json'}, '{"acknowledged" : true}']
13
+ [200, {"Content-Type" => "application/json"}, '{"acknowledged" : true}']
14
14
  end
15
15
 
16
- commands = { :move => { :index => 'test', :shard => 0, :from_node => 'node1', :to_node => 'node2' }}
16
+ commands = { :move => { :index => "test", :shard => 0, :from_node => "node1", :to_node => "node2" }}
17
17
  h = @client.cluster.reroute commands, :dry_run => true
18
18
  assert_acknowledged h
19
19
  end
20
20
 
21
- it 'performs a shutdown of the cluster' do
22
- @stubs.post('/_shutdown') { [200, {'Content-Type' => 'application/json'}, '{"cluster_name":"elasticsearch"}'] }
21
+ it "performs a shutdown of the cluster" do
22
+ @stubs.post("/_shutdown") { [200, {"Content-Type" => "application/json"}, '{"cluster_name":"elasticsearch"}'] }
23
23
  h = @client.cluster.shutdown
24
- assert_equal "elasticsearch", h['cluster_name']
24
+ assert_equal "elasticsearch", h["cluster_name"]
25
25
  end
26
26
  end
27
27
 
28
28
  describe Elastomer::Client::Nodes do
29
- it 'performs a shutdown of the node(s)' do
30
- @stubs.post('/_cluster/nodes/_all/_shutdown') { [200, {'Content-Type' => 'application/json'}, '{"nodes":{"1":{"name":"Node1"}}}'] }
31
- @stubs.post('/_cluster/nodes/node2/_shutdown') { [200, {'Content-Type' => 'application/json'}, '{"nodes":{"2":{"name":"Node2"}}}'] }
29
+ it "performs a shutdown of the node(s)" do
30
+ @stubs.post("/_cluster/nodes/_all/_shutdown") { [200, {"Content-Type" => "application/json"}, '{"nodes":{"1":{"name":"Node1"}}}'] }
31
+ @stubs.post("/_cluster/nodes/node2/_shutdown") { [200, {"Content-Type" => "application/json"}, '{"nodes":{"2":{"name":"Node2"}}}'] }
32
32
 
33
33
  h = @client.nodes("_all").shutdown
34
- assert_equal "Node1", h['nodes']['1']['name']
34
+ assert_equal "Node1", h["nodes"]["1"]["name"]
35
35
 
36
- h = @client.nodes('node2').shutdown
37
- assert_equal 'Node2', h['nodes']['2']['name']
36
+ h = @client.nodes("node2").shutdown
37
+ assert_equal "Node2", h["nodes"]["2"]["name"]
38
38
  end
39
39
  end
40
40
  end
@@ -1,9 +1,9 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  describe Elastomer::Client::Cluster do
4
4
 
5
5
  before do
6
- @name = 'elastomer-template-test'
6
+ @name = "elastomer-template-test"
7
7
  @template = $client.template @name
8
8
  end
9
9
 
@@ -11,29 +11,29 @@ describe Elastomer::Client::Cluster do
11
11
  @template.delete if @template.exists?
12
12
  end
13
13
 
14
- it 'lists templates in the cluster' do
15
- @template.create({:template => 'test-elastomer*'})
14
+ it "lists templates in the cluster" do
15
+ @template.create({:template => "test-elastomer*"})
16
16
  templates = $client.cluster.templates
17
17
  assert !templates.empty?, "expected to see a template"
18
18
  end
19
19
 
20
- it 'creates a template' do
21
- assert !@template.exists?, 'the template should not exist'
20
+ it "creates a template" do
21
+ assert !@template.exists?, "the template should not exist"
22
22
 
23
23
  @template.create({
24
- :template => 'test-elastomer*',
24
+ :template => "test-elastomer*",
25
25
  :settings => { :number_of_shards => 3 },
26
26
  :mappings => {
27
27
  :doco => { :_source => { :enabled => false }}
28
28
  }
29
29
  })
30
30
 
31
- assert @template.exists?, ' we now have a cluster-test template'
31
+ assert @template.exists?, " we now have a cluster-test template"
32
32
 
33
33
  template = @template.get
34
34
  assert_equal [@name], template.keys
35
- assert_equal 'test-elastomer*', template[@name]['template']
36
- assert_equal '3', template[@name]['settings']['index.number_of_shards']
35
+ assert_equal "test-elastomer*", template[@name]["template"]
36
+ assert_equal "3", template[@name]["settings"]["index.number_of_shards"]
37
37
  end
38
38
 
39
39
  end
@@ -1,19 +1,19 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  describe Elastomer::Client::Warmer do
4
4
  before do
5
- @name = 'elastomer-warmer-test'
5
+ @name = "elastomer-warmer-test"
6
6
  @index = $client.index(@name)
7
7
 
8
8
  unless @index.exists?
9
9
  @index.create(
10
- :settings => { 'index.number_of_shards' => 1, 'index.number_of_replicas' => 0 },
10
+ :settings => { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
11
11
  :mappings => {
12
12
  :tweet => {
13
13
  :_source => { :enabled => true }, :_all => { :enabled => false },
14
14
  :properties => {
15
- :message => { :type => 'string', :analyzer => 'standard' },
16
- :author => { :type => 'string', :index => 'not_analyzed' }
15
+ :message => { :type => "string", :analyzer => "standard" },
16
+ :author => { :type => "string", :index => "not_analyzed" }
17
17
  }
18
18
  }
19
19
  }
@@ -26,31 +26,31 @@ describe Elastomer::Client::Warmer do
26
26
  @index.delete if @index.exists?
27
27
  end
28
28
 
29
- it 'creates warmers' do
30
- h = @index.warmer('test1').create(:query => { :match_all => {}})
29
+ it "creates warmers" do
30
+ h = @index.warmer("test1").create(:query => { :match_all => {}})
31
31
  assert_acknowledged h
32
32
  end
33
33
 
34
- it 'deletes warmers' do
35
- @index.warmer('test1').create(:query => { :match_all => {}})
34
+ it "deletes warmers" do
35
+ @index.warmer("test1").create(:query => { :match_all => {}})
36
36
 
37
- h = @index.warmer('test1').delete
37
+ h = @index.warmer("test1").delete
38
38
  assert_acknowledged h
39
39
  end
40
40
 
41
- it 'gets warmers' do
41
+ it "gets warmers" do
42
42
  body = { "query" => {"match_all" => {}}}
43
- @index.warmer('test1').create(body)
43
+ @index.warmer("test1").create(body)
44
44
 
45
- h = @index.warmer('test1').get
45
+ h = @index.warmer("test1").get
46
46
  assert_equal body, h[@name]["warmers"]["test1"]["source"]
47
47
  end
48
48
 
49
- it 'knows when warmers exist' do
50
- assert_equal false, @index.warmer('test1').exists?
51
- assert_equal false, @index.warmer('test1').exist?
49
+ it "knows when warmers exist" do
50
+ assert_equal false, @index.warmer("test1").exists?
51
+ assert_equal false, @index.warmer("test1").exist?
52
52
 
53
- h = @index.warmer('test1').create(:query => { :match_all => {}})
54
- assert_equal true, @index.warmer('test1').exists?
53
+ h = @index.warmer("test1").create(:query => { :match_all => {}})
54
+ assert_equal true, @index.warmer("test1").exists?
55
55
  end
56
56
  end
data/test/client_test.rb CHANGED
@@ -1,8 +1,8 @@
1
- require File.expand_path('../test_helper', __FILE__)
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  describe Elastomer::Client do
4
4
 
5
- it 'uses the adapter specified at creation' do
5
+ it "uses the adapter specified at creation" do
6
6
  c = Elastomer::Client.new(:adapter => :test)
7
7
  assert_includes c.connection.builder.handlers, Faraday::Adapter::Test
8
8
  end
@@ -13,50 +13,50 @@ describe Elastomer::Client do
13
13
  assert_includes c.connection.builder.handlers, adapter
14
14
  end
15
15
 
16
- it 'uses the same connection for all requests' do
16
+ it "uses the same connection for all requests" do
17
17
  c = $client.connection
18
18
  assert_same c, $client.connection
19
19
  end
20
20
 
21
- it 'raises an error for unknown HTTP request methods' do
22
- assert_raises(ArgumentError) { $client.request :foo, '/', {} }
21
+ it "raises an error for unknown HTTP request methods" do
22
+ assert_raises(ArgumentError) { $client.request :foo, "/", {} }
23
23
  end
24
24
 
25
- it 'raises an error on 4XX responses with an `error` field' do
25
+ it "raises an error on 4XX responses with an `error` field" do
26
26
  begin
27
- $client.get '/non-existent-index/_search?q=*:*'
28
- assert false, 'exception was not raised when it should have been'
27
+ $client.get "/non-existent-index/_search?q=*:*"
28
+ assert false, "exception was not raised when it should have been"
29
29
  rescue Elastomer::Client::Error => err
30
30
  assert_equal 404, err.status
31
- assert_equal 'IndexMissingException[[non-existent-index] missing]', err.message
31
+ assert_equal "IndexMissingException[[non-existent-index] missing]", err.message
32
32
  end
33
33
  end
34
34
 
35
- it 'handles path expansions' do
36
- uri = $client.expand_path '/{foo}/{bar}', :foo => '_cluster', :bar => 'health'
37
- assert_equal '/_cluster/health', uri
35
+ it "handles path expansions" do
36
+ uri = $client.expand_path "/{foo}/{bar}", :foo => "_cluster", :bar => "health"
37
+ assert_equal "/_cluster/health", uri
38
38
 
39
- uri = $client.expand_path '{/foo}{/baz}{/bar}', :foo => '_cluster', :bar => 'state'
40
- assert_equal '/_cluster/state', uri
39
+ uri = $client.expand_path "{/foo}{/baz}{/bar}", :foo => "_cluster", :bar => "state"
40
+ assert_equal "/_cluster/state", uri
41
41
  end
42
42
 
43
- it 'handles query parameters' do
44
- uri = $client.expand_path '/_cluster/health', :level => 'shards'
45
- assert_equal '/_cluster/health?level=shards', uri
43
+ it "handles query parameters" do
44
+ uri = $client.expand_path "/_cluster/health", :level => "shards"
45
+ assert_equal "/_cluster/health?level=shards", uri
46
46
  end
47
47
 
48
- it 'validates path expansions' do
48
+ it "validates path expansions" do
49
49
  assert_raises(ArgumentError) {
50
- $client.expand_path '/{foo}/{bar}', :foo => '_cluster', :bar => nil
50
+ $client.expand_path "/{foo}/{bar}", :foo => "_cluster", :bar => nil
51
51
  }
52
52
 
53
53
  assert_raises(ArgumentError) {
54
- $client.expand_path '/{foo}/{bar}', :foo => '_cluster', :bar => ''
54
+ $client.expand_path "/{foo}/{bar}", :foo => "_cluster", :bar => ""
55
55
  }
56
56
  end
57
57
 
58
- describe 'when extracting and converting :body params' do
59
- it 'deletes the :body from the params (or it gets the hose)' do
58
+ describe "when extracting and converting :body params" do
59
+ it "deletes the :body from the params (or it gets the hose)" do
60
60
  params = { :body => nil, :q => "what what?" }
61
61
  body = $client.extract_body params
62
62
 
@@ -64,27 +64,27 @@ describe Elastomer::Client do
64
64
  assert_equal({:q => "what what?"}, params)
65
65
  end
66
66
 
67
- it 'leaves String values unchanged' do
67
+ it "leaves String values unchanged" do
68
68
  body = $client.extract_body :body => '{"query":{"match_all":{}}}'
69
69
  assert_equal '{"query":{"match_all":{}}}', body
70
70
 
71
- body = $client.extract_body :body => 'not a JSON string, but who cares!'
72
- assert_equal 'not a JSON string, but who cares!', body
71
+ body = $client.extract_body :body => "not a JSON string, but who cares!"
72
+ assert_equal "not a JSON string, but who cares!", body
73
73
  end
74
74
 
75
- it 'joins Array values' do
75
+ it "joins Array values" do
76
76
  body = $client.extract_body :body => %w[foo bar baz]
77
77
  assert_equal "foo\nbar\nbaz\n", body
78
78
 
79
79
  body = $client.extract_body :body => [
80
- 'the first entry',
81
- 'the second entry',
80
+ "the first entry",
81
+ "the second entry",
82
82
  nil
83
83
  ]
84
84
  assert_equal "the first entry\nthe second entry\n", body
85
85
  end
86
86
 
87
- it 'converts values to JSON' do
87
+ it "converts values to JSON" do
88
88
  body = $client.extract_body :body => true
89
89
  assert_equal "true", body
90
90
 
@@ -93,61 +93,61 @@ describe Elastomer::Client do
93
93
  end
94
94
  end
95
95
 
96
- describe 'when validating parameters' do
97
- it 'rejects nil values' do
96
+ describe "when validating parameters" do
97
+ it "rejects nil values" do
98
98
  assert_raises(ArgumentError) { $client.assert_param_presence nil }
99
99
  end
100
100
 
101
- it 'rejects empty strings' do
101
+ it "rejects empty strings" do
102
102
  assert_raises(ArgumentError) { $client.assert_param_presence "" }
103
103
  assert_raises(ArgumentError) { $client.assert_param_presence " " }
104
104
  assert_raises(ArgumentError) { $client.assert_param_presence " \t \r \n " }
105
105
  end
106
106
 
107
- it 'rejects empty strings and nil values found in arrays' do
108
- assert_raises(ArgumentError) { $client.assert_param_presence ['foo', nil, 'bar'] }
109
- assert_raises(ArgumentError) { $client.assert_param_presence ['baz', " \t \r \n "] }
107
+ it "rejects empty strings and nil values found in arrays" do
108
+ assert_raises(ArgumentError) { $client.assert_param_presence ["foo", nil, "bar"] }
109
+ assert_raises(ArgumentError) { $client.assert_param_presence ["baz", " \t \r \n "] }
110
110
  end
111
111
 
112
- it 'strips whitespace from strings' do
113
- assert_equal 'foo', $client.assert_param_presence(" foo \t")
112
+ it "strips whitespace from strings" do
113
+ assert_equal "foo", $client.assert_param_presence(" foo \t")
114
114
  end
115
115
 
116
- it 'joins array values into a string' do
117
- assert_equal 'foo,bar', $client.assert_param_presence(%w[foo bar])
116
+ it "joins array values into a string" do
117
+ assert_equal "foo,bar", $client.assert_param_presence(%w[foo bar])
118
118
  end
119
119
 
120
- it 'flattens arrays' do
121
- assert_equal 'foo,bar,baz,buz', $client.assert_param_presence([" foo \t", %w[bar baz buz]])
120
+ it "flattens arrays" do
121
+ assert_equal "foo,bar,baz,buz", $client.assert_param_presence([" foo \t", %w[bar baz buz]])
122
122
  end
123
123
 
124
- it 'allows strings' do
125
- assert_equal 'foo', $client.assert_param_presence("foo")
124
+ it "allows strings" do
125
+ assert_equal "foo", $client.assert_param_presence("foo")
126
126
  end
127
127
 
128
- it 'converts numbers and symbols to strings' do
129
- assert_equal 'foo', $client.assert_param_presence(:foo)
130
- assert_equal '9', $client.assert_param_presence(9)
128
+ it "converts numbers and symbols to strings" do
129
+ assert_equal "foo", $client.assert_param_presence(:foo)
130
+ assert_equal "9", $client.assert_param_presence(9)
131
131
  end
132
132
  end
133
133
 
134
- describe 'top level actions' do
135
- it 'pings the cluster' do
134
+ describe "top level actions" do
135
+ it "pings the cluster" do
136
136
  assert_equal true, $client.ping
137
137
  assert_equal true, $client.available?
138
138
  end
139
139
 
140
- it 'gets cluster info' do
140
+ it "gets cluster info" do
141
141
  h = $client.info
142
- assert h.key?('name'), 'expected cluster name to be returned'
143
- assert h.key?('status'), 'expected cluster info status to be returned'
142
+ assert h.key?("name"), "expected cluster name to be returned"
143
+ assert h.key?("status"), "expected cluster info status to be returned"
144
144
  end
145
145
 
146
- it 'gets cluster version' do
146
+ it "gets cluster version" do
147
147
  assert_match /[\d\.]+/, $client.version
148
148
  end
149
149
 
150
- it 'gets semantic version' do
150
+ it "gets semantic version" do
151
151
  version_string = $client.version
152
152
  assert_equal Semantic::Version.new(version_string), $client.semantic_version
153
153
  end