rummageable 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rummageable/fake.rb +3 -0
- data/lib/rummageable/implementation.rb +19 -2
- data/lib/rummageable/version.rb +2 -2
- data/lib/rummageable.rb +9 -0
- data/test/rummageable_test.rb +43 -5
- metadata +18 -7
data/lib/rummageable/fake.rb
CHANGED
@@ -12,9 +12,18 @@ module Rummageable
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def amend(link, amendments)
|
16
|
+
validate_structure amendments
|
17
|
+
RestClient.post url_for(link), amendments
|
18
|
+
end
|
19
|
+
|
15
20
|
def delete(link)
|
16
|
-
|
17
|
-
|
21
|
+
RestClient.delete url_for(link), content_type: :json, accept: :json
|
22
|
+
end
|
23
|
+
|
24
|
+
def commit
|
25
|
+
url = Rummageable.rummager_host + Rummageable.path_prefix + "/commit"
|
26
|
+
RestClient.post url, {}
|
18
27
|
end
|
19
28
|
|
20
29
|
def validate_structure(hash, parents=[])
|
@@ -32,5 +41,13 @@ module Rummageable
|
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def url_for(link)
|
47
|
+
[
|
48
|
+
Rummageable.rummager_host, Rummageable.path_prefix,
|
49
|
+
"/documents/", CGI.escape(link)
|
50
|
+
].join("")
|
51
|
+
end
|
35
52
|
end
|
36
53
|
end
|
data/lib/rummageable/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Rummageable
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.3.0"
|
3
|
+
end
|
data/lib/rummageable.rb
CHANGED
@@ -41,6 +41,14 @@ module Rummageable
|
|
41
41
|
implementation.delete(link)
|
42
42
|
end
|
43
43
|
|
44
|
+
def amend(link, amendments)
|
45
|
+
implementation.amend(link, amendments)
|
46
|
+
end
|
47
|
+
|
48
|
+
def commit
|
49
|
+
implementation.commit
|
50
|
+
end
|
51
|
+
|
44
52
|
VALID_KEYS = [
|
45
53
|
%w[title],
|
46
54
|
%w[description],
|
@@ -49,6 +57,7 @@ module Rummageable
|
|
49
57
|
%w[subsection],
|
50
58
|
%w[link],
|
51
59
|
%w[indexable_content],
|
60
|
+
%w[boost_phrases],
|
52
61
|
%w[additional_links title],
|
53
62
|
%w[additional_links link],
|
54
63
|
%w[additional_links link_order],
|
data/test/rummageable_test.rb
CHANGED
@@ -15,6 +15,7 @@ class RummageableTest < MiniTest::Unit::TestCase
|
|
15
15
|
"subsection" => "NAME OF SUBSECTION",
|
16
16
|
"link" => "/link",
|
17
17
|
"indexable_content" => "TEXT",
|
18
|
+
"boost_phrases" => "BOOST",
|
18
19
|
"additional_links" => [
|
19
20
|
{"title" => "LINK1", "link" => "/link1"},
|
20
21
|
{"title" => "LINK2", "link" => "/link2"},
|
@@ -93,21 +94,51 @@ class RummageableTest < MiniTest::Unit::TestCase
|
|
93
94
|
def test_should_delete_a_document_by_its_link
|
94
95
|
link = "http://example.com/foo"
|
95
96
|
|
96
|
-
stub_request(:delete, "#{API}/documents/http
|
97
|
+
stub_request(:delete, "#{API}/documents/http:%2F%2Fexample.com%2Ffoo").
|
97
98
|
to_return(status: 200, body: '{"status":"OK"}')
|
98
99
|
|
99
100
|
Rummageable.delete(link)
|
100
101
|
end
|
101
102
|
|
103
|
+
def test_should_post_amendments
|
104
|
+
stub_request(:post, "#{API}/documents/%2Ffoobang").
|
105
|
+
with(body: {"title" => "Cheese", "indexable_content" => "Blah"}).
|
106
|
+
to_return(status: 200, body: '{"status":"OK"}')
|
107
|
+
|
108
|
+
Rummageable.amend("/foobang", {"title" => "Cheese", "indexable_content" => "Blah"})
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_should_reject_unknown_amendments
|
112
|
+
stub_request(:post, "#{API}/documents/%2Ffoobang").
|
113
|
+
to_return(status: 200, body: '{"status":"OK"}')
|
114
|
+
|
115
|
+
assert_raises Rummageable::InvalidDocument do
|
116
|
+
Rummageable.amend("/foobang", {"title" => "Cheese", "face" => "Blah"})
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_not_requested :any, "#{API}/documents/%2Ffoobang"
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_should_fail_amendments_with_symbols
|
123
|
+
stub_request(:post, "#{API}/documents/%2Ffoobang").
|
124
|
+
to_return(status: 200, body: '{"status":"OK"}')
|
125
|
+
|
126
|
+
assert_raises Rummageable::InvalidDocument do
|
127
|
+
Rummageable.amend("/foobang", {title: "Cheese"})
|
128
|
+
end
|
129
|
+
|
130
|
+
assert_not_requested :any, "#{API}/documents/%2Ffoobang"
|
131
|
+
end
|
132
|
+
|
102
133
|
def test_should_delete_to_rummageable_host_determined_by_rummager_service_name
|
103
134
|
link = "http://example.com/foo"
|
104
|
-
stub_request(:delete, "#{API}/documents/http
|
105
|
-
stub_request(:delete, "http://whitehall-search.test.alphagov.co.uk/documents/http
|
135
|
+
stub_request(:delete, "#{API}/documents/http:%2F%2Fexample.com%2Ffoo")
|
136
|
+
stub_request(:delete, "http://whitehall-search.test.alphagov.co.uk/documents/http:%2F%2Fexample.com%2Ffoo")
|
106
137
|
with_rummager_service_name("whitehall-search") do
|
107
138
|
Rummageable.delete(link)
|
108
139
|
end
|
109
|
-
assert_not_requested(:delete, "#{API}/#{API}/documents/http
|
110
|
-
assert_requested(:delete, "http://whitehall-search.test.alphagov.co.uk/documents/http
|
140
|
+
assert_not_requested(:delete, "#{API}/#{API}/documents/http:%2F%2Fexample.com%2Ffoo")
|
141
|
+
assert_requested(:delete, "http://whitehall-search.test.alphagov.co.uk/documents/http:%2F%2Fexample.com%2Ffoo")
|
111
142
|
end
|
112
143
|
|
113
144
|
def test_should_defer_to_plek_for_the_location_of_the_rummager_host
|
@@ -121,6 +152,13 @@ class RummageableTest < MiniTest::Unit::TestCase
|
|
121
152
|
Rummageable.rummager_host = nil
|
122
153
|
end
|
123
154
|
|
155
|
+
def test_should_commit_to_rummmageable_host
|
156
|
+
stub_request(:post, "#{API}/commit").
|
157
|
+
to_return(status: 200, body: '{"result":"OK"}')
|
158
|
+
|
159
|
+
Rummageable.commit
|
160
|
+
end
|
161
|
+
|
124
162
|
private
|
125
163
|
|
126
164
|
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.
|
5
|
+
version: 0.3.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-
|
13
|
+
date: 2012-06-27 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -67,6 +67,17 @@ dependencies:
|
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
69
|
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: gem_publisher
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
70
81
|
description: Mediator for apps that want their content to be in the search index
|
71
82
|
email:
|
72
83
|
executables: []
|
@@ -76,10 +87,10 @@ extensions: []
|
|
76
87
|
extra_rdoc_files: []
|
77
88
|
|
78
89
|
files:
|
79
|
-
- lib/rummageable
|
90
|
+
- lib/rummageable.rb
|
80
91
|
- lib/rummageable/implementation.rb
|
81
92
|
- lib/rummageable/version.rb
|
82
|
-
- lib/rummageable.rb
|
93
|
+
- lib/rummageable/fake.rb
|
83
94
|
- test/rummageable_test.rb
|
84
95
|
homepage: https://github.com/alphagov/rummageable
|
85
96
|
licenses: []
|
@@ -94,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
105
|
requirements:
|
95
106
|
- - ">="
|
96
107
|
- !ruby/object:Gem::Version
|
97
|
-
hash:
|
108
|
+
hash: 3837460675569533093
|
98
109
|
segments:
|
99
110
|
- 0
|
100
111
|
version: "0"
|
@@ -103,14 +114,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
114
|
requirements:
|
104
115
|
- - ">="
|
105
116
|
- !ruby/object:Gem::Version
|
106
|
-
hash:
|
117
|
+
hash: 3837460675569533093
|
107
118
|
segments:
|
108
119
|
- 0
|
109
120
|
version: "0"
|
110
121
|
requirements: []
|
111
122
|
|
112
123
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
124
|
+
rubygems_version: 1.8.12
|
114
125
|
signing_key:
|
115
126
|
specification_version: 3
|
116
127
|
summary: Mediator for apps that want their content to be in the search index
|