akdubya-cushion 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +94 -174
- data/lib/cushion.rb +54 -10
- data/lib/cushion/database.rb +294 -203
- data/lib/cushion/design.rb +4 -5
- data/lib/cushion/document.rb +119 -69
- data/lib/cushion/server.rb +9 -13
- data/spec/cushion_spec.rb +0 -2
- data/spec/database_spec.rb +215 -132
- data/spec/document_spec.rb +172 -0
- data/spec/server_spec.rb +52 -66
- metadata +3 -2
@@ -0,0 +1,172 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helpers'
|
2
|
+
|
3
|
+
describe "A Cushion Document" do
|
4
|
+
before do
|
5
|
+
@db = Cushion.db!('http://127.0.0.1:5984/cushion_test')
|
6
|
+
@doc = Cushion::Document.new
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
@db.drop rescue nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a default database setting" do
|
14
|
+
Cushion::Document.set_database(@db)
|
15
|
+
Cushion::Document.database.should == @db
|
16
|
+
@doc.database.should == @db
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should initialize with attributes and headers" do
|
20
|
+
@db.store("_id" => "adoc")
|
21
|
+
adoc = Cushion::Document.new(@db.fetch("adoc"))
|
22
|
+
adoc.id.should.not.be.nil
|
23
|
+
adoc.headers.should.not.be.empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should retrieve response headers with #headers (if available)" do
|
27
|
+
@db.store("_id" => "adoc")
|
28
|
+
adoc = Cushion::Document.new(@db.fetch("adoc"))
|
29
|
+
adoc.headers[:server].should.not.be.nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should read from an attribute like a Hash" do
|
33
|
+
@doc["_id"].should == nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should write to an attribute like a Hash" do
|
37
|
+
@doc["foo"] = "bar"
|
38
|
+
@doc["foo"].should == "bar"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have indifferent access" do
|
42
|
+
@doc[:foo] = "bar"
|
43
|
+
@doc[:foo].should == "bar"
|
44
|
+
@doc["foo"].should == "bar"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should merge attributes like a Hash" do
|
48
|
+
@doc[:foo] = "bar"
|
49
|
+
@doc.merge!("foo" => "baz", "bit" => "byte")
|
50
|
+
@doc[:foo].should == "baz"
|
51
|
+
@doc[:bit].should == "byte"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should delete attributes like a Hash" do
|
55
|
+
@doc[:baz] = "bat"
|
56
|
+
@doc.delete(:baz).should == "bat"
|
57
|
+
@doc[:baz].should.be.nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should check for attribute existence like a Hash" do
|
61
|
+
@doc.key?("check").should.be.false
|
62
|
+
@doc["check"] = "hello"
|
63
|
+
@doc.key?("check").should.be.true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have getter and checker methods for id" do
|
67
|
+
@doc.id?.should.be.false
|
68
|
+
@doc[:_id] = "abc"
|
69
|
+
@doc.id.should == "abc"
|
70
|
+
@doc.id?.should.be.true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have getter and checker methods for rev" do
|
74
|
+
@doc.rev?.should.be.false
|
75
|
+
@doc[:_rev] = "123"
|
76
|
+
@doc.rev.should == "123"
|
77
|
+
@doc.rev?.should.be.true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should save to the database with #save" do
|
81
|
+
@doc[:_id] = "mydoc"
|
82
|
+
@doc.save.should.be.true
|
83
|
+
@doc.rev?.should.be.true
|
84
|
+
@db.key?("mydoc").should.be.true
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should save with inline attachments" do
|
88
|
+
@doc.attachments["foo.txt"] = { "content_type" => "text/plain",
|
89
|
+
"data" => "Hello World" }
|
90
|
+
@doc.save.should.be.true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should respond correctly to #new_document?" do
|
94
|
+
@doc.new_document?.should.be.true
|
95
|
+
@doc.save
|
96
|
+
@doc.new_document?.should.be.false
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should store an attachment with #attach" do
|
100
|
+
@doc.save.should.be.true
|
101
|
+
@doc.attach("foo.txt", "hello", "text/plain").should.be.true
|
102
|
+
@doc.attachments["foo.txt"].should.not.be.nil
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "with attachments" do
|
106
|
+
before do
|
107
|
+
@doc[:_id] = "mydoc"
|
108
|
+
@doc.save
|
109
|
+
@doc.attach("foo.txt", "hello", "text/plain")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should destroy an attachment with #detach" do
|
113
|
+
@doc.detach("foo.txt").should.be.true
|
114
|
+
@db.key?("mydoc", "foo.txt").should.be.false
|
115
|
+
@doc.attachments["foo.txt"].should.be.nil
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should retrieve attachment data with #fetch" do
|
119
|
+
@doc.fetch("foo.txt").should == "hello"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should rename an attachment with #rename" do
|
123
|
+
@doc.rename("foo.txt", "bar.txt").should.be.true
|
124
|
+
@doc.attachments["foo.txt"].should.be.nil
|
125
|
+
@doc.attachments["bar.txt"]["content_type"].should == "text/plain"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should reload from the database with #reload" do
|
130
|
+
@doc.save
|
131
|
+
@doc["foo"] = "bar"
|
132
|
+
@doc.reload.should.be.same_as @doc
|
133
|
+
@doc["foo"].should.be.nil
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should copy itself to a new document with #copy_to" do
|
137
|
+
@doc["foo"] = "bar"
|
138
|
+
@doc.save
|
139
|
+
@doc.copy_to("newdoc").should.be.true
|
140
|
+
@db.fetch("newdoc")["foo"].should == "bar"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should copy itself to an existing doc with #copy_to" do
|
144
|
+
res = @db.store("_id" => "otherdoc")
|
145
|
+
@doc["foo"] = "bar"
|
146
|
+
@doc.save
|
147
|
+
@doc.copy_to("otherdoc", :rev => res['rev']).should.be.true
|
148
|
+
@db.fetch("otherdoc")["foo"].should == "bar"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should move itself to a new document with #move_to" do
|
152
|
+
@doc.merge!("_id" => "123", "foo" => "bar")
|
153
|
+
@doc.save
|
154
|
+
@doc.move_to("newdoc").should.be.true
|
155
|
+
@db.fetch("newdoc")["foo"].should == "bar"
|
156
|
+
@db.key?("123").should.be.false
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should move itself to an existing doc with #move_to" do
|
160
|
+
@doc.merge!("_id" => "123", "foo" => "bar")
|
161
|
+
res = @db.store("_id" => "otherdoc")
|
162
|
+
@doc.save
|
163
|
+
@doc.move_to("otherdoc", :rev => res['rev']).should.be.true
|
164
|
+
@db.fetch("otherdoc")["foo"].should == "bar"
|
165
|
+
@db.key?("123").should.be.false
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should serialize its attributes with #to_json" do
|
169
|
+
@doc.merge!("_id" => "123", "foo" => "bar")
|
170
|
+
@doc.to_json.should == "{\"_id\":\"123\",\"foo\":\"bar\"}"
|
171
|
+
end
|
172
|
+
end
|
data/spec/server_spec.rb
CHANGED
@@ -1,81 +1,71 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helpers'
|
2
2
|
|
3
|
-
describe "Cushion
|
4
|
-
|
3
|
+
describe "A Cushion server" do
|
5
4
|
before do
|
6
5
|
@server = Cushion::Server.new
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@server.info["couchdb"].should == "Welcome"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should retrieve active tasks" do
|
16
|
-
@server.active_tasks.should == []
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should retrieve the server config" do
|
20
|
-
@server.config["couchdb"].should.not.be.nil
|
21
|
-
end
|
8
|
+
it "should retrieve the welcome message with #info" do
|
9
|
+
@server.info["couchdb"].should == "Welcome"
|
10
|
+
end
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
it "should retrieve active tasks with #active_tasks" do
|
13
|
+
@server.active_tasks.should == []
|
14
|
+
end
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
it "should retrieve the server config with #config" do
|
17
|
+
@server.config["couchdb"].should.not.be.nil
|
18
|
+
end
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
it "should set config options with #set_config" do
|
21
|
+
@server.set_config("newsection", "newoption", "newvalue").should == "\"newvalue\"\n"
|
22
|
+
end
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
24
|
+
it "should restart the server with #restart" do
|
25
|
+
@server.restart["ok"].should.be.true
|
26
|
+
end
|
39
27
|
|
28
|
+
it "should retrieve server stats with #stats" do
|
29
|
+
@server.stats["httpd_status_codes"].should.not.be.nil
|
40
30
|
end
|
41
31
|
|
42
|
-
|
32
|
+
it "should retrieve and cache UUIDs from the server with #next_uuid" do
|
33
|
+
@server.next_uuid.length.should == 32
|
34
|
+
@server.instance_variable_get(:@uuids).length.should == 999
|
35
|
+
end
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
it "should retrieve a list of all databases on the server" do
|
50
|
-
@server.create(:server_list_test)
|
51
|
-
@server.all_dbs.should.include "server_list_test"
|
52
|
-
@server.drop(:server_list_test)
|
53
|
-
end
|
37
|
+
it "should create and drop databases" do
|
38
|
+
@server.create(:server_test)["ok"].should.be.true
|
39
|
+
@server.drop(:server_test)["ok"].should.be.true
|
40
|
+
end
|
54
41
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
42
|
+
it "should retrieve a list of all databases on the server with #all_dbs" do
|
43
|
+
@server.create(:server_list_test)
|
44
|
+
@server.all_dbs.should.include "server_list_test"
|
45
|
+
@server.drop(:server_list_test)
|
46
|
+
end
|
60
47
|
|
61
|
-
|
62
|
-
|
63
|
-
|
48
|
+
it "should recreate a database with #recreate" do
|
49
|
+
@server.recreate(:server_recreate_test).should.be.kind_of Cushion::Database
|
50
|
+
@server.all_dbs.should.include "server_recreate_test"
|
51
|
+
@server.drop(:server_recreate_test)
|
52
|
+
end
|
64
53
|
|
65
|
-
|
66
|
-
|
67
|
-
|
54
|
+
it "should instantiate a Cushion::Database with #[:dbname]" do
|
55
|
+
@server[:server_test].should.be.kind_of Cushion::Database
|
56
|
+
end
|
68
57
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@server.drop(:server_autocreate_test)
|
73
|
-
end
|
58
|
+
it "should instantiate a Cushion::Database with #('dbname')" do
|
59
|
+
@server.db(:server_test).should.be.kind_of Cushion::Database
|
60
|
+
end
|
74
61
|
|
62
|
+
it "should create a database if it does not already exist with #db!('dbname')" do
|
63
|
+
@server.db!(:server_autocreate_test).should.be.kind_of Cushion::Database
|
64
|
+
@server.all_dbs.should.include "server_autocreate_test"
|
65
|
+
@server.drop(:server_autocreate_test)
|
75
66
|
end
|
76
67
|
|
77
68
|
describe "Replication" do
|
78
|
-
|
79
69
|
before do
|
80
70
|
@server.create(:server_replication_test1)
|
81
71
|
@server.create(:server_replication_test2)
|
@@ -85,23 +75,21 @@ describe "Cushion::Server" do
|
|
85
75
|
@server.drop(:server_replication_test1)
|
86
76
|
@server.drop(:server_replication_test2)
|
87
77
|
end
|
88
|
-
|
78
|
+
|
89
79
|
it "should replicate databases" do
|
90
|
-
@server[:server_replication_test1].
|
80
|
+
@server[:server_replication_test1].store("_id" => "abc")
|
91
81
|
@server.replicate(:server_replication_test1, :server_replication_test2)["session_id"].should.not.be.nil
|
92
|
-
lambda { @server[:server_replication_test2].
|
82
|
+
lambda { @server[:server_replication_test2].fetch("abc") }.should.not.raise
|
93
83
|
end
|
94
|
-
|
95
84
|
end
|
96
85
|
|
97
86
|
describe "Content Negotiation" do
|
98
|
-
|
99
|
-
it "should transmit a parsed json request body" do
|
87
|
+
it "should transmit a parsed json request body when type is app/json" do
|
100
88
|
@server.send(:construct_payload, {:foo => "bar"},
|
101
89
|
:content_type => "application/json").should == "{\"foo\":\"bar\"}"
|
102
90
|
end
|
103
91
|
|
104
|
-
it "should transmit a plain request body" do
|
92
|
+
it "should transmit a plain request body when type is text/plain" do
|
105
93
|
@server.send(:construct_payload, "Hello Baybay",
|
106
94
|
:content_type => "text/plain").should == "Hello Baybay"
|
107
95
|
end
|
@@ -110,10 +98,8 @@ describe "Cushion::Server" do
|
|
110
98
|
@server.get('').should.be.kind_of Hash
|
111
99
|
end
|
112
100
|
|
113
|
-
it "should return a plain string" do
|
101
|
+
it "should return a plain string when accept is text/plain" do
|
114
102
|
@server.get('', :accept => "text/plain").should.be.kind_of String
|
115
103
|
end
|
116
|
-
|
117
104
|
end
|
118
|
-
|
119
105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akdubya-cushion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksander Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/cushion/core_ext.rb
|
43
43
|
- lib/cushion.rb
|
44
44
|
- spec/server_spec.rb
|
45
|
+
- spec/document_spec.rb
|
45
46
|
- spec/database_spec.rb
|
46
47
|
- spec/helpers.rb
|
47
48
|
- spec/cushion_spec.rb
|