rufus-jig 0.1.23 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/CHANGELOG.txt +8 -0
- data/README.rdoc +41 -11
- data/Rakefile +37 -12
- data/TODO.txt +6 -3
- data/lib/rufus/jig/adapters/em.rb +21 -24
- data/lib/rufus/jig/adapters/net.rb +3 -4
- data/lib/rufus/jig/adapters/net_persistent.rb +26 -7
- data/lib/rufus/jig/adapters/patron.rb +25 -10
- data/lib/rufus/jig/couch.rb +199 -36
- data/lib/rufus/jig/http.rb +183 -90
- data/lib/rufus/jig/path.rb +4 -4
- data/lib/rufus/jig/version.rb +1 -1
- data/rufus-jig.gemspec +55 -34
- data/spec/couch/attachements_spec.rb +113 -0
- data/spec/couch/basic_auth_spec.rb +75 -0
- data/spec/couch/conditional_spec.rb +178 -0
- data/spec/couch/continuous.rb +97 -0
- data/spec/couch/couch_spec.rb +64 -0
- data/spec/couch/db_spec.rb +366 -0
- data/{test → spec/couch}/tweet.png +0 -0
- data/spec/couch/views_spec.rb +326 -0
- data/spec/couch_url.txt +2 -0
- data/spec/jig/basic_auth_spec.rb +51 -0
- data/spec/jig/conditional_spec.rb +76 -0
- data/spec/jig/delete_spec.rb +32 -0
- data/spec/jig/get_spec.rb +116 -0
- data/spec/jig/misc_spec.rb +120 -0
- data/spec/jig/new_spec.rb +95 -0
- data/spec/jig/parse_uri_spec.rb +139 -0
- data/spec/jig/post_spec.rb +79 -0
- data/spec/jig/prefix_spec.rb +51 -0
- data/spec/jig/put_spec.rb +68 -0
- data/spec/jig/timeout_spec.rb +94 -0
- data/{test → spec}/server.rb +14 -4
- data/spec/spec_helper.rb +61 -0
- data/spec/support/couch_helper.rb +14 -0
- data/spec/support/server_helper.rb +32 -0
- metadata +98 -43
- data/lib/rufus/jig/adapters/net_response.rb +0 -42
- data/test/base.rb +0 -53
- data/test/bm/bm0.rb +0 -49
- data/test/bm/bm1.rb +0 -43
- data/test/conc/put_vs_delete.rb +0 -28
- data/test/couch_base.rb +0 -52
- data/test/couch_url.txt +0 -1
- data/test/ct_0_couch.rb +0 -64
- data/test/ct_1_couchdb.rb +0 -204
- data/test/ct_2_couchdb_options.rb +0 -50
- data/test/ct_3_couchdb_views.rb +0 -106
- data/test/ct_4_attachments.rb +0 -126
- data/test/ct_5_couchdb_continuous.rb +0 -92
- data/test/cut_0_auth_couch.rb +0 -62
- data/test/test.rb +0 -28
- data/test/to.sh +0 -25
- data/test/tt_0_get_timeout.rb +0 -92
- data/test/ut_0_http_get.rb +0 -191
- data/test/ut_1_http_post.rb +0 -81
- data/test/ut_2_http_delete.rb +0 -42
- data/test/ut_3_http_put.rb +0 -105
- data/test/ut_4_http_prefix.rb +0 -50
- data/test/ut_5_http_misc.rb +0 -65
- data/test/ut_6_args.rb +0 -98
- data/test/ut_7_parse_uri.rb +0 -79
- data/test/ut_8_auth.rb +0 -37
data/lib/rufus/jig/path.rb
CHANGED
@@ -41,7 +41,7 @@ module Rufus::Jig
|
|
41
41
|
# p Rufus::Jig::Path.add_params('/toto', :q => 'nada', 'x' => 2)
|
42
42
|
# # => "/toto?q=nada&x=2"
|
43
43
|
#
|
44
|
-
def self.add_params
|
44
|
+
def self.add_params(path, h)
|
45
45
|
|
46
46
|
params = h.collect { |k, v| "#{k}=#{v}" }.join('&')
|
47
47
|
|
@@ -55,7 +55,7 @@ module Rufus::Jig
|
|
55
55
|
# p Rufus::Jig::Path.join('division', 'customer', :restricted => true)
|
56
56
|
# # => '/division/customer?restricted=true'
|
57
57
|
#
|
58
|
-
def self.join
|
58
|
+
def self.join(*elts)
|
59
59
|
|
60
60
|
elts, params = if elts.last.is_a?(Hash)
|
61
61
|
[ elts[0..-2], elts.last ]
|
@@ -79,14 +79,14 @@ module Rufus::Jig
|
|
79
79
|
|
80
80
|
# Makes sure there is a forward slash in the given string.
|
81
81
|
#
|
82
|
-
def self.to_path
|
82
|
+
def self.to_path(s)
|
83
83
|
|
84
84
|
s.match(/^\//) ? s : "/#{s}"
|
85
85
|
end
|
86
86
|
|
87
87
|
# Removes any forward slashes at the beginning of the given string.
|
88
88
|
#
|
89
|
-
def self.to_name
|
89
|
+
def self.to_name(s)
|
90
90
|
|
91
91
|
if m = s.match(/^\/+(.+)$/)
|
92
92
|
m[1]
|
data/lib/rufus/jig/version.rb
CHANGED
data/rufus-jig.gemspec
CHANGED
@@ -5,17 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rufus-jig}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux", "Kenneth Kalmer"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-08}
|
13
13
|
s.description = %q{
|
14
14
|
Json Interwebs Get.
|
15
15
|
|
16
16
|
An HTTP client, greedy with JSON content, GETting conditionally.
|
17
17
|
|
18
|
-
Uses
|
18
|
+
Uses Yajl-ruby whenever possible.
|
19
19
|
}
|
20
20
|
s.email = %q{jmettraux@gmail.com}
|
21
21
|
s.extra_rdoc_files = [
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
]
|
25
25
|
s.files = [
|
26
26
|
".gitignore",
|
27
|
+
".rspec",
|
27
28
|
"CHANGELOG.txt",
|
28
29
|
"CREDITS.txt",
|
29
30
|
"LICENSE.txt",
|
@@ -35,59 +36,77 @@ Gem::Specification.new do |s|
|
|
35
36
|
"lib/rufus/jig/adapters/em.rb",
|
36
37
|
"lib/rufus/jig/adapters/net.rb",
|
37
38
|
"lib/rufus/jig/adapters/net_persistent.rb",
|
38
|
-
"lib/rufus/jig/adapters/net_response.rb",
|
39
39
|
"lib/rufus/jig/adapters/patron.rb",
|
40
40
|
"lib/rufus/jig/couch.rb",
|
41
41
|
"lib/rufus/jig/http.rb",
|
42
42
|
"lib/rufus/jig/path.rb",
|
43
43
|
"lib/rufus/jig/version.rb",
|
44
44
|
"rufus-jig.gemspec",
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
69
|
-
"test/ut_6_args.rb",
|
70
|
-
"test/ut_7_parse_uri.rb",
|
71
|
-
"test/ut_8_auth.rb"
|
45
|
+
"spec/couch/attachements_spec.rb",
|
46
|
+
"spec/couch/basic_auth_spec.rb",
|
47
|
+
"spec/couch/conditional_spec.rb",
|
48
|
+
"spec/couch/continuous.rb",
|
49
|
+
"spec/couch/couch_spec.rb",
|
50
|
+
"spec/couch/db_spec.rb",
|
51
|
+
"spec/couch/tweet.png",
|
52
|
+
"spec/couch/views_spec.rb",
|
53
|
+
"spec/couch_url.txt",
|
54
|
+
"spec/jig/basic_auth_spec.rb",
|
55
|
+
"spec/jig/conditional_spec.rb",
|
56
|
+
"spec/jig/delete_spec.rb",
|
57
|
+
"spec/jig/get_spec.rb",
|
58
|
+
"spec/jig/misc_spec.rb",
|
59
|
+
"spec/jig/new_spec.rb",
|
60
|
+
"spec/jig/parse_uri_spec.rb",
|
61
|
+
"spec/jig/post_spec.rb",
|
62
|
+
"spec/jig/prefix_spec.rb",
|
63
|
+
"spec/jig/put_spec.rb",
|
64
|
+
"spec/jig/timeout_spec.rb",
|
65
|
+
"spec/server.rb",
|
66
|
+
"spec/spec_helper.rb",
|
67
|
+
"spec/support/couch_helper.rb",
|
68
|
+
"spec/support/server_helper.rb"
|
72
69
|
]
|
73
70
|
s.homepage = %q{http://github.com/jmettraux/rufus-jig/}
|
74
71
|
s.rdoc_options = ["--charset=UTF-8"]
|
75
72
|
s.require_paths = ["lib"]
|
76
73
|
s.rubyforge_project = %q{rufus}
|
77
|
-
s.rubygems_version = %q{1.3.
|
74
|
+
s.rubygems_version = %q{1.3.7}
|
78
75
|
s.summary = %q{An HTTP client, greedy with JSON content, GETting conditionally.}
|
79
76
|
s.test_files = [
|
80
|
-
"
|
77
|
+
"spec/couch/attachements_spec.rb",
|
78
|
+
"spec/couch/basic_auth_spec.rb",
|
79
|
+
"spec/couch/conditional_spec.rb",
|
80
|
+
"spec/couch/continuous.rb",
|
81
|
+
"spec/couch/couch_spec.rb",
|
82
|
+
"spec/couch/db_spec.rb",
|
83
|
+
"spec/couch/views_spec.rb",
|
84
|
+
"spec/jig/basic_auth_spec.rb",
|
85
|
+
"spec/jig/conditional_spec.rb",
|
86
|
+
"spec/jig/delete_spec.rb",
|
87
|
+
"spec/jig/get_spec.rb",
|
88
|
+
"spec/jig/misc_spec.rb",
|
89
|
+
"spec/jig/new_spec.rb",
|
90
|
+
"spec/jig/parse_uri_spec.rb",
|
91
|
+
"spec/jig/post_spec.rb",
|
92
|
+
"spec/jig/prefix_spec.rb",
|
93
|
+
"spec/jig/put_spec.rb",
|
94
|
+
"spec/jig/timeout_spec.rb",
|
95
|
+
"spec/server.rb",
|
96
|
+
"spec/spec_helper.rb",
|
97
|
+
"spec/support/couch_helper.rb",
|
98
|
+
"spec/support/server_helper.rb"
|
81
99
|
]
|
82
100
|
|
83
101
|
if s.respond_to? :specification_version then
|
84
102
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
85
103
|
s.specification_version = 3
|
86
104
|
|
87
|
-
if Gem::Version.new(Gem::
|
105
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
88
106
|
s.add_runtime_dependency(%q<rufus-lru>, [">= 0"])
|
89
107
|
s.add_runtime_dependency(%q<rufus-json>, [">= 0.2.5"])
|
90
108
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
109
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
|
91
110
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
92
111
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
93
112
|
s.add_development_dependency(%q<patron>, [">= 0"])
|
@@ -97,6 +116,7 @@ Gem::Specification.new do |s|
|
|
97
116
|
s.add_dependency(%q<rufus-lru>, [">= 0"])
|
98
117
|
s.add_dependency(%q<rufus-json>, [">= 0.2.5"])
|
99
118
|
s.add_dependency(%q<rake>, [">= 0"])
|
119
|
+
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
|
100
120
|
s.add_dependency(%q<yard>, [">= 0"])
|
101
121
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
102
122
|
s.add_dependency(%q<patron>, [">= 0"])
|
@@ -107,6 +127,7 @@ Gem::Specification.new do |s|
|
|
107
127
|
s.add_dependency(%q<rufus-lru>, [">= 0"])
|
108
128
|
s.add_dependency(%q<rufus-json>, [">= 0.2.5"])
|
109
129
|
s.add_dependency(%q<rake>, [">= 0"])
|
130
|
+
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
|
110
131
|
s.add_dependency(%q<yard>, [">= 0"])
|
111
132
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
112
133
|
s.add_dependency(%q<patron>, [">= 0"])
|
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# specifying rufus-jig
|
4
|
+
#
|
5
|
+
# Tue Nov 30 09:12:59 JST 2010
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
9
|
+
|
10
|
+
|
11
|
+
describe Rufus::Jig::Couch do
|
12
|
+
|
13
|
+
context 'with attachments' do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
|
17
|
+
h = Rufus::Jig::Http.new(couch_url)
|
18
|
+
begin
|
19
|
+
h.delete('/rufus_jig_test')
|
20
|
+
rescue Exception => e
|
21
|
+
#p e
|
22
|
+
end
|
23
|
+
|
24
|
+
h.put('/rufus_jig_test', '')
|
25
|
+
h.close
|
26
|
+
|
27
|
+
@c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
|
28
|
+
|
29
|
+
@c.put('_id' => 'thedoc', 'function' => 'recipient for attachements')
|
30
|
+
@d = @c.get('thedoc')
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
|
35
|
+
@c.close
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#attach' do
|
39
|
+
|
40
|
+
it 'attaches' do
|
41
|
+
|
42
|
+
@c.attach(
|
43
|
+
'thedoc', @d['_rev'], 'message', 'this is a message',
|
44
|
+
:content_type => 'text/plain')
|
45
|
+
|
46
|
+
@c.get('thedoc/message').should == 'this is a message'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'attaches with the right content-type' do
|
50
|
+
|
51
|
+
@c.attach(
|
52
|
+
'thedoc', @d['_rev'], 'message', 'this is a message',
|
53
|
+
:content_type => 'text/plain')
|
54
|
+
|
55
|
+
r = @c.get('thedoc/message', :raw => true)
|
56
|
+
r.status.should == 200
|
57
|
+
r.headers['Content-Type'].should == 'text/plain'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the couch response' do
|
61
|
+
|
62
|
+
r = @c.attach(
|
63
|
+
'thedoc', @d['_rev'], 'message', 'this is a message',
|
64
|
+
:content_type => 'text/plain')
|
65
|
+
|
66
|
+
r.keys.sort.should == %w[ id ok rev ]
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'raises if it failed' do
|
70
|
+
|
71
|
+
lambda {
|
72
|
+
@c.attach(
|
73
|
+
'thedoc', '999-123e', 'message', 'this is a message',
|
74
|
+
:content_type => 'text/plain')
|
75
|
+
}.should raise_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#detach' do
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
|
83
|
+
r = @c.attach(
|
84
|
+
'thedoc', @d['_rev'],
|
85
|
+
'image', File.read(File.join(File.dirname(__FILE__), 'tweet.png')),
|
86
|
+
:content_type => 'image/png')
|
87
|
+
@d['_rev'] = r['rev']
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'detaches' do
|
91
|
+
|
92
|
+
@c.detach('thedoc', @d['_rev'], 'image')
|
93
|
+
|
94
|
+
@c.get('thedoc/image').should == nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the couch response' do
|
98
|
+
|
99
|
+
r = @c.detach('thedoc', @d['_rev'], 'image')
|
100
|
+
|
101
|
+
r.keys.sort.should == %w[ id ok rev ]
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'raises if it failed' do
|
105
|
+
|
106
|
+
lambda {
|
107
|
+
@c.detach('thedoc', '999-12340e', 'image')
|
108
|
+
}.should raise_error
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# specifying rufus-jig
|
4
|
+
#
|
5
|
+
# Wed Dec 1 15:16:31 JST 2010
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
9
|
+
|
10
|
+
|
11
|
+
describe Rufus::Jig::Couch do
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
|
15
|
+
@c.close
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'HTTP basic authorization' do
|
19
|
+
|
20
|
+
context 'without authorization' do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
|
24
|
+
@c = Rufus::Jig::Couch.new('127.0.0.1', 4567, 'tcouch')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gets denied' do
|
28
|
+
|
29
|
+
lambda {
|
30
|
+
@c.get('.')
|
31
|
+
}.should raise_error(Rufus::Jig::HttpError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'cannot do #on_change' do
|
35
|
+
|
36
|
+
lambda {
|
37
|
+
@c.on_change do |id, deleted, doc|
|
38
|
+
end
|
39
|
+
}.should raise_error(Rufus::Jig::HttpError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with authorization' do
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
|
47
|
+
@c = Rufus::Jig::Couch.new(
|
48
|
+
'127.0.0.1', 4567, 'tcouch', :basic_auth => %w[ admin nimda ])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'gets through' do
|
52
|
+
|
53
|
+
@c.get('.').should == { 'id' => 'nada' }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can do #on_change' do
|
57
|
+
|
58
|
+
res = nil
|
59
|
+
|
60
|
+
t = Thread.new {
|
61
|
+
@c.on_change do |id, deleted, doc|
|
62
|
+
res = [ id, deleted, doc ]
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
sleep 0.200
|
67
|
+
|
68
|
+
t.kill
|
69
|
+
|
70
|
+
res.should == [ 'x', false, { 'hello' => 'world' } ]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,178 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# specifying rufus-jig
|
4
|
+
#
|
5
|
+
# Mon Dec 6 20:16:11 JST 2010
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
9
|
+
|
10
|
+
|
11
|
+
describe Rufus::Jig::Couch do
|
12
|
+
|
13
|
+
context 'with conditional GET (and POST)' do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
|
17
|
+
h = Rufus::Jig::Http.new(couch_url)
|
18
|
+
|
19
|
+
begin
|
20
|
+
h.delete('/rufus_jig_test')
|
21
|
+
rescue Exception => e
|
22
|
+
#p e
|
23
|
+
end
|
24
|
+
|
25
|
+
h.put('/rufus_jig_test', '')
|
26
|
+
|
27
|
+
h.put('/rufus_jig_test/d0', '{"_id":"d0","type":"door"}')
|
28
|
+
h.put('/rufus_jig_test/d1', '{"_id":"d1","type":"window"}')
|
29
|
+
h.put('/rufus_jig_test/d2', '{"_id":"d2","type":"window"}')
|
30
|
+
h.put('/rufus_jig_test/d3', '{"_id":"d3","type":"wall"}')
|
31
|
+
h.put('/rufus_jig_test/d4', '{"_id":"d4","type":"roof"}')
|
32
|
+
|
33
|
+
h.put(
|
34
|
+
'/rufus_jig_test/_design/my_test',
|
35
|
+
{
|
36
|
+
'_id' => '_design/my_test',
|
37
|
+
'views' => {
|
38
|
+
'my_view' => {
|
39
|
+
'map' => "function(doc) { emit(doc['type'], null); }"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
:content_type => :json)
|
44
|
+
|
45
|
+
h.close
|
46
|
+
|
47
|
+
@c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
|
48
|
+
end
|
49
|
+
|
50
|
+
after(:each) do
|
51
|
+
|
52
|
+
@c.close
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#get' do
|
56
|
+
|
57
|
+
it 'caches _all_docs' do
|
58
|
+
|
59
|
+
@c.get('_all_docs')
|
60
|
+
s0 = @c.http.last_response.status
|
61
|
+
@c.get('_all_docs')
|
62
|
+
s1 = @c.http.last_response.status
|
63
|
+
|
64
|
+
s0.should == 200
|
65
|
+
s1.should == 304
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#post with :keys' do
|
70
|
+
|
71
|
+
it "doesn't cache by default" do
|
72
|
+
|
73
|
+
@c.post('_all_docs', { 'keys' => %w[ d0 d2 ] })
|
74
|
+
s0 = @c.http.last_response.status
|
75
|
+
@c.post('_all_docs', { 'keys' => %w[ d0 d2 ] })
|
76
|
+
s1 = @c.http.last_response.status
|
77
|
+
|
78
|
+
s0.should == 200
|
79
|
+
s1.should == 200
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'caches _all_docs when :cache => true' do
|
83
|
+
|
84
|
+
@c.post('_all_docs', { 'keys' => %w[ d1 d2 ] }, :cache => true)
|
85
|
+
s0 = @c.http.last_response.status
|
86
|
+
@c.post('_all_docs', { 'keys' => %w[ d1 d2 ] }, :cache => true)
|
87
|
+
s1 = @c.http.last_response.status
|
88
|
+
|
89
|
+
s0.should == 200
|
90
|
+
s1.should == 304
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'caches _all_docs too much when :cache => true' do
|
94
|
+
|
95
|
+
@c.post('_all_docs', { 'keys' => %w[ d1 d2 ] }, :cache => true)
|
96
|
+
s0 = @c.http.last_response.status
|
97
|
+
@c.post('_all_docs', { 'keys' => %w[ d0 d2 ] }, :cache => true)
|
98
|
+
s1 = @c.http.last_response.status
|
99
|
+
|
100
|
+
s0.should == 200
|
101
|
+
s1.should == 304
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'caches _all_docs when :cache => :with_body' do
|
105
|
+
|
106
|
+
@c.post('_all_docs', { 'keys' => %w[ d2 d3 ] }, :cache => :with_body)
|
107
|
+
s0 = @c.http.last_response.status
|
108
|
+
@c.post('_all_docs', { 'keys' => %w[ d2 d3 ] }, :cache => :with_body)
|
109
|
+
s1 = @c.http.last_response.status
|
110
|
+
|
111
|
+
s0.should == 200
|
112
|
+
s1.should == 304
|
113
|
+
end
|
114
|
+
|
115
|
+
it "doesn't cache _all_docs too much when :cache => :with_body" do
|
116
|
+
|
117
|
+
@c.post('_all_docs', { 'keys' => %w[ d2 d3 ] }, :cache => :with_body)
|
118
|
+
s0 = @c.http.last_response.status
|
119
|
+
@c.post('_all_docs', { 'keys' => %w[ d0 d3 ] }, :cache => :with_body)
|
120
|
+
s1 = @c.http.last_response.status
|
121
|
+
|
122
|
+
s0.should == 200
|
123
|
+
s1.should == 200
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#query' do
|
128
|
+
|
129
|
+
it 'caches as expected with :keys' do
|
130
|
+
|
131
|
+
@c.query('my_test:my_view', :keys => %w[ door window ])
|
132
|
+
s0 = @c.http.last_response.status
|
133
|
+
@c.query('my_test:my_view', :keys => %w[ door window ])
|
134
|
+
s1 = @c.http.last_response.status
|
135
|
+
|
136
|
+
s0.should == 200
|
137
|
+
s1.should == 304
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'does not cache when the :keys are different' do
|
141
|
+
|
142
|
+
@c.query('my_test:my_view', :keys => %w[ door window ])
|
143
|
+
s0 = @c.http.last_response.status
|
144
|
+
@c.query('my_test:my_view', :keys => %w[ door wall ])
|
145
|
+
s1 = @c.http.last_response.status
|
146
|
+
|
147
|
+
s0.should == 200
|
148
|
+
s1.should == 200
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#all' do
|
153
|
+
|
154
|
+
it 'caches as expected with :keys' do
|
155
|
+
|
156
|
+
@c.all(:keys => %w[ d0 d3 ])
|
157
|
+
s0 = @c.http.last_response.status
|
158
|
+
@c.all(:keys => %w[ d0 d3 ])
|
159
|
+
s1 = @c.http.last_response.status
|
160
|
+
|
161
|
+
s0.should == 200
|
162
|
+
s1.should == 304
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'does not cache when the :keys are different' do
|
166
|
+
|
167
|
+
@c.all(:keys => %w[ d0 d3 ])
|
168
|
+
s0 = @c.http.last_response.status
|
169
|
+
@c.all(:keys => %w[ d1 d3 ])
|
170
|
+
s1 = @c.http.last_response.status
|
171
|
+
|
172
|
+
s0.should == 200
|
173
|
+
s1.should == 200
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|