slipcover 0.2.66 → 0.2.67
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.
- checksums.yaml +4 -4
- data/lib/slipcover/query.rb +16 -8
- data/lib/slipcover/version.rb +1 -1
- data/spec/query_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 417ec7939c7ef5d78b6c8ef1d0a1847e3045705e
|
4
|
+
data.tar.gz: 09f2b87cb89c7f9726a857beaf1632c9b3e4e4f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd92b0951ef316fe3328fa91f23a3da98f711ef8c748dd0947ef6b719d2b30883ea9715a8d05e501f8cbb5db279c47286d77b9ba4ea0b4c55deef5b4da60535
|
7
|
+
data.tar.gz: 76247d31077baa3f46c0a6fae8e2c30681811e8ea2f1b2f9eddf5b7937591b8a71d753e994fd9c6b9122b6c627ecb326df7a386bb92b543cefdc125fd8022f13
|
data/lib/slipcover/query.rb
CHANGED
@@ -12,10 +12,7 @@ module Slipcover
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def all(opts={})
|
15
|
-
|
16
|
-
url_with_qs = add_qs_to_url(url, repackage(opts_params))
|
17
|
-
|
18
|
-
http_adapter.post(url_with_qs, body_params)[:rows].map do |row|
|
15
|
+
do_http_request(opts)[:rows].map do |row|
|
19
16
|
doc_data = opts[:include_docs] ? row["doc"] : row
|
20
17
|
Document.new(database.name, doc_data.symbolize_keys)
|
21
18
|
end
|
@@ -27,16 +24,27 @@ module Slipcover
|
|
27
24
|
|
28
25
|
private
|
29
26
|
|
27
|
+
# This is here because Cloudant doesn't support POST without supplying
|
28
|
+
# `keys`.
|
29
|
+
def do_http_request(opts)
|
30
|
+
if opts.include?(:keys)
|
31
|
+
opts_params, body_params = url_params_and_body(opts)
|
32
|
+
url_with_qs = add_qs_to_url(url, repackage(opts_params))
|
33
|
+
http_adapter.post(url_with_qs, body_params)
|
34
|
+
else
|
35
|
+
url_with_qs = add_qs_to_url(url, repackage(opts))
|
36
|
+
http_adapter.get(url_with_qs)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
30
40
|
def url_params_and_body(opts)
|
31
41
|
keys_for_body = [:keys]
|
32
42
|
[opts.except(*keys_for_body), opts.slice(*keys_for_body)]
|
33
43
|
end
|
34
44
|
|
35
45
|
def repackage(opts)
|
36
|
-
opts
|
37
|
-
|
38
|
-
opts.each do |key, value|
|
39
|
-
opts[key] = jsonify_param(value) if jsonify_key?(key)
|
46
|
+
opts.each_with_object({}) do |(key, value), result|
|
47
|
+
result[key] = jsonify_key?(key) ? jsonify_param(value) : value
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
data/lib/slipcover/version.rb
CHANGED
data/spec/query_spec.rb
CHANGED
@@ -71,6 +71,20 @@ describe Slipcover::Query do
|
|
71
71
|
results.first[:name].should == "blah&"
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
# These tests are here because Cloudant doesn't support POST without
|
76
|
+
# supplying `keys`.
|
77
|
+
it "performs a GET request when keys is not supplied" do
|
78
|
+
Slipcover::HttpAdapter.any_instance.should_receive(:get).
|
79
|
+
and_call_original
|
80
|
+
query.all
|
81
|
+
end
|
82
|
+
|
83
|
+
it "performs a POST request when keys is supplied" do
|
84
|
+
Slipcover::HttpAdapter.any_instance.should_receive(:post).
|
85
|
+
and_call_original
|
86
|
+
query.all(keys: ["Fito"])
|
87
|
+
end
|
74
88
|
end
|
75
89
|
end
|
76
90
|
end
|