rummageable 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,15 @@
1
1
  module Rummageable
2
2
  class Fake
3
- def index(documents)
3
+ def index(documents, index_name)
4
4
  end
5
5
 
6
- def delete(link)
6
+ def delete(link, index_name)
7
7
  end
8
8
 
9
- def commit
9
+ def amend(link, amendments, index_name)
10
+ end
11
+
12
+ def commit(index_name)
10
13
  end
11
14
 
12
15
  def validate_structure(hash, parents=[])
@@ -1,28 +1,28 @@
1
1
  module Rummageable
2
2
  class Implementation
3
- def index(documents)
3
+ def index(documents, index_name)
4
4
  documents = [documents].flatten
5
5
  documents.each do |document|
6
6
  validate_structure document
7
7
  end
8
- url = Rummageable.rummager_host + Rummageable.path_prefix + "/documents"
8
+ url = Rummageable.rummager_host + index_name + "/documents"
9
9
  0.step(documents.length - 1, CHUNK_SIZE).each do |i|
10
10
  body = JSON.dump(documents[i, CHUNK_SIZE])
11
11
  RestClient.post url, body, content_type: :json, accept: :json
12
12
  end
13
13
  end
14
14
 
15
- def amend(link, amendments)
15
+ def amend(link, amendments, index_name)
16
16
  validate_structure amendments
17
- RestClient.post url_for(link), amendments
17
+ RestClient.post url_for(link, index_name), amendments
18
18
  end
19
19
 
20
- def delete(link)
21
- RestClient.delete url_for(link), content_type: :json, accept: :json
20
+ def delete(link, index_name)
21
+ RestClient.delete url_for(link, index_name), content_type: :json, accept: :json
22
22
  end
23
23
 
24
- def commit
25
- url = Rummageable.rummager_host + Rummageable.path_prefix + "/commit"
24
+ def commit(index_name)
25
+ url = Rummageable.rummager_host + index_name + "/commit"
26
26
  RestClient.post url, {}
27
27
  end
28
28
 
@@ -43,9 +43,9 @@ module Rummageable
43
43
  end
44
44
 
45
45
  private
46
- def url_for(link)
46
+ def url_for(link, index_name)
47
47
  [
48
- Rummageable.rummager_host, Rummageable.path_prefix,
48
+ Rummageable.rummager_host, index_name,
49
49
  "/documents/", CGI.escape(link)
50
50
  ].join("")
51
51
  end
@@ -1,3 +1,3 @@
1
1
  module Rummageable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/rummageable.rb CHANGED
@@ -20,9 +20,9 @@ module Rummageable
20
20
  @rummager_host || Plek.current.find(rummager_service_name)
21
21
  end
22
22
 
23
- attr_writer :path_prefix
24
- def path_prefix
25
- @path_prefix || ""
23
+ attr_writer :default_index
24
+ def default_index
25
+ @default_index || ""
26
26
  end
27
27
 
28
28
  attr_writer :implementation
@@ -33,20 +33,20 @@ module Rummageable
33
33
  # documents must be either a hash (for one document) or an array of hashes
34
34
  # (for multiple documents)
35
35
  #
36
- def index(documents)
37
- implementation.index(documents)
36
+ def index(documents, index_name = default_index)
37
+ implementation.index(documents, index_name)
38
38
  end
39
39
 
40
- def delete(link)
41
- implementation.delete(link)
40
+ def delete(link, index_name = default_index)
41
+ implementation.delete(link, index_name)
42
42
  end
43
43
 
44
- def amend(link, amendments)
45
- implementation.amend(link, amendments)
44
+ def amend(link, amendments, index_name = default_index)
45
+ implementation.amend(link, amendments, index_name)
46
46
  end
47
47
 
48
- def commit
49
- implementation.commit
48
+ def commit(index_name = default_index)
49
+ implementation.commit(index_name)
50
50
  end
51
51
 
52
52
  VALID_KEYS = [
@@ -55,6 +55,7 @@ module Rummageable
55
55
  %w[format],
56
56
  %w[section],
57
57
  %w[subsection],
58
+ %w[subsubsection],
58
59
  %w[link],
59
60
  %w[indexable_content],
60
61
  %w[boost_phrases],
@@ -13,6 +13,7 @@ class RummageableTest < MiniTest::Unit::TestCase
13
13
  "format" => "NAME OF FORMAT",
14
14
  "section" => "NAME OF SECTION",
15
15
  "subsection" => "NAME OF SUBSECTION",
16
+ "subsubsection" => "NAME OF SUBSUBSECTION",
16
17
  "link" => "/link",
17
18
  "indexable_content" => "TEXT",
18
19
  "boost_phrases" => "BOOST",
@@ -80,6 +81,30 @@ class RummageableTest < MiniTest::Unit::TestCase
80
81
  end
81
82
  end
82
83
 
84
+ def test_allows_indexing_to_an_alternative_index
85
+ document = {
86
+ "title" => "TITLE",
87
+ "description" => "DESCRIPTION",
88
+ "format" => "NAME OF FORMAT",
89
+ "section" => "NAME OF SECTION",
90
+ "subsection" => "NAME OF SUBSECTION",
91
+ "link" => "/link",
92
+ "indexable_content" => "TEXT",
93
+ "boost_phrases" => "BOOST",
94
+ "additional_links" => [
95
+ {"title" => "LINK1", "link" => "/link1"},
96
+ {"title" => "LINK2", "link" => "/link2"},
97
+ ]
98
+ }
99
+ json = JSON.dump([document])
100
+
101
+ stub_request(:post, "#{API}/alternative/documents").
102
+ with(body: json).
103
+ to_return(status: 200, body: '{"status":"OK"}')
104
+
105
+ Rummageable.index(document, "/alternative")
106
+ end
107
+
83
108
  def test_should_post_to_rummageable_host_determined_by_rummager_service_name
84
109
  document = {"title" => "TITLE"}
85
110
  stub_request(:post, "#{API}/documents")
@@ -100,6 +125,15 @@ class RummageableTest < MiniTest::Unit::TestCase
100
125
  Rummageable.delete(link)
101
126
  end
102
127
 
128
+ def test_should_allow_deletion_from_an_alternative_index
129
+ link = "http://example.com/foo"
130
+
131
+ stub_request(:delete, "#{API}/alternative/documents/http:%2F%2Fexample.com%2Ffoo").
132
+ to_return(status: 200, body: '{"status":"OK"}')
133
+
134
+ Rummageable.delete(link, '/alternative')
135
+ end
136
+
103
137
  def test_should_post_amendments
104
138
  stub_request(:post, "#{API}/documents/%2Ffoobang").
105
139
  with(body: {"title" => "Cheese", "indexable_content" => "Blah"}).
@@ -159,6 +193,13 @@ class RummageableTest < MiniTest::Unit::TestCase
159
193
  Rummageable.commit
160
194
  end
161
195
 
196
+ def test_should_allow_committing_an_alternative_index
197
+ stub_request(:post, "#{API}/alternative/commit").
198
+ to_return(status: 200, body: '{"result":"OK"}')
199
+
200
+ Rummageable.commit '/alternative'
201
+ end
202
+
162
203
  private
163
204
 
164
205
  def with_rummager_service_name(service_name)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rummageable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - GovUK Beta Team
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-20 00:00:00 Z
13
+ date: 2012-10-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -87,10 +87,10 @@ extensions: []
87
87
  extra_rdoc_files: []
88
88
 
89
89
  files:
90
- - lib/rummageable.rb
91
90
  - lib/rummageable/implementation.rb
92
- - lib/rummageable/version.rb
93
91
  - lib/rummageable/fake.rb
92
+ - lib/rummageable/version.rb
93
+ - lib/rummageable.rb
94
94
  - test/rummageable_test.rb
95
95
  homepage: https://github.com/alphagov/rummageable
96
96
  licenses: []
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- hash: 354247613567923491
108
+ hash: 636288066068398025
109
109
  segments:
110
110
  - 0
111
111
  version: "0"
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- hash: 354247613567923491
117
+ hash: 636288066068398025
118
118
  segments:
119
119
  - 0
120
120
  version: "0"