juozasg-couchrest 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +176 -0
- data/README.rdoc +67 -0
- data/Rakefile +86 -0
- data/THANKS +15 -0
- data/bin/couchapp +58 -0
- data/bin/couchdir +20 -0
- data/bin/couchview +48 -0
- data/examples/model/example.rb +138 -0
- data/examples/word_count/markov +38 -0
- data/examples/word_count/views/books/chunked-map.js +3 -0
- data/examples/word_count/views/books/united-map.js +1 -0
- data/examples/word_count/views/markov/chain-map.js +6 -0
- data/examples/word_count/views/markov/chain-reduce.js +7 -0
- data/examples/word_count/views/word_count/count-map.js +6 -0
- data/examples/word_count/views/word_count/count-reduce.js +3 -0
- data/examples/word_count/word_count.rb +67 -0
- data/examples/word_count/word_count_query.rb +39 -0
- data/lib/couchrest/commands/generate.rb +71 -0
- data/lib/couchrest/commands/push.rb +103 -0
- data/lib/couchrest/core/database.rb +173 -0
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +60 -0
- data/lib/couchrest/core/model.rb +557 -0
- data/lib/couchrest/core/server.rb +51 -0
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/file_manager.rb +317 -0
- data/lib/couchrest/helper/pager.rb +103 -0
- data/lib/couchrest/helper/streamer.rb +44 -0
- data/lib/couchrest/helper/templates/bar.txt +11 -0
- data/lib/couchrest/helper/templates/example-map.js +8 -0
- data/lib/couchrest/helper/templates/example-reduce.js +10 -0
- data/lib/couchrest/helper/templates/index.html +26 -0
- data/lib/couchrest/monkeypatches.rb +24 -0
- data/lib/couchrest.rb +125 -0
- data/spec/couchapp_spec.rb +87 -0
- data/spec/couchrest/core/couchrest_spec.rb +191 -0
- data/spec/couchrest/core/database_spec.rb +478 -0
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +96 -0
- data/spec/couchrest/core/model_spec.rb +660 -0
- data/spec/couchrest/helpers/file_manager_spec.rb +203 -0
- data/spec/couchrest/helpers/pager_spec.rb +122 -0
- data/spec/couchrest/helpers/streamer_spec.rb +23 -0
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +11 -0
- data/spec/fixtures/views/lib.js +3 -0
- data/spec/fixtures/views/test_view/lib.js +3 -0
- data/spec/fixtures/views/test_view/only-map.js +4 -0
- data/spec/fixtures/views/test_view/test-map.js +3 -0
- data/spec/fixtures/views/test_view/test-reduce.js +3 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +14 -0
- data/utils/remap.rb +27 -0
- data/utils/subset.rb +30 -0
- metadata +154 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "couchapp" do
|
4
|
+
before(:all) do
|
5
|
+
@fixdir = FIXTURE_PATH + '/couchapp-test'
|
6
|
+
@couchapp = File.expand_path(File.dirname(__FILE__)) + '/../bin/couchapp'
|
7
|
+
`rm -rf #{@fixdir}`
|
8
|
+
`mkdir -p #{@fixdir}`
|
9
|
+
@run = "cd #{@fixdir} && #{@couchapp}"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "--help" do
|
13
|
+
it "should output the opts" do
|
14
|
+
`#{@run} --help`.should match(/Usage/)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "generate my-app" do
|
19
|
+
it "should create an app directory" do
|
20
|
+
`#{@run} generate my-app`.should match(/generating/i)
|
21
|
+
Dir["#{@fixdir}/*"].select{|x|x =~ /my-app/}.length.should == 1
|
22
|
+
end
|
23
|
+
it "should create a views directory" do
|
24
|
+
`#{@run} generate my-app`.should match(/generating/i)
|
25
|
+
Dir["#{@fixdir}/my-app/*"].select{|x|x =~ /views/}.length.should == 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "push my-app #{TESTDB}" do
|
30
|
+
before(:all) do
|
31
|
+
@cr = CouchRest.new(COUCHHOST)
|
32
|
+
@db = @cr.database(TESTDB)
|
33
|
+
@db.delete! rescue nil
|
34
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
35
|
+
`#{@run} generate my-app`
|
36
|
+
end
|
37
|
+
it "should create the design document with the app name" do
|
38
|
+
`#{@run} push my-app #{TESTDB}`
|
39
|
+
lambda{@db.get("_design/my-app")}.should_not raise_error
|
40
|
+
end
|
41
|
+
it "should create the views" do
|
42
|
+
`#{@run} push my-app #{TESTDB}`
|
43
|
+
doc = @db.get("_design/my-app")
|
44
|
+
doc['views']['example']['map'].should match(/function/)
|
45
|
+
end
|
46
|
+
it "should create view for all the views" do
|
47
|
+
`echo 'moremap' > #{@fixdir}/my-app/views/more-map.js`
|
48
|
+
`#{@run} push my-app #{TESTDB}`
|
49
|
+
doc = @db.get("_design/my-app")
|
50
|
+
doc['views']['more']['map'].should match(/moremap/)
|
51
|
+
end
|
52
|
+
it "should create the index" do
|
53
|
+
`#{@run} push my-app #{TESTDB}`
|
54
|
+
doc = @db.get("_design/my-app")
|
55
|
+
doc['_attachments']['index.html']["content_type"].should == 'text/html'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "push . #{TESTDB}" do
|
60
|
+
before(:all) do
|
61
|
+
@cr = CouchRest.new(COUCHHOST)
|
62
|
+
@db = @cr.database(TESTDB)
|
63
|
+
@db.delete! rescue nil
|
64
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
65
|
+
`#{@run} generate my-app`
|
66
|
+
end
|
67
|
+
it "should create the design document" do
|
68
|
+
`cd #{@fixdir}/my-app && #{@couchapp} push . #{TESTDB}`
|
69
|
+
lambda{@db.get("_design/my-app")}.should_not raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "push my-app my-design #{TESTDB}" do
|
74
|
+
before(:all) do
|
75
|
+
@cr = CouchRest.new(COUCHHOST)
|
76
|
+
@db = @cr.database(TESTDB)
|
77
|
+
@db.delete! rescue nil
|
78
|
+
@db = @cr.create_db(TESTDB) rescue nil
|
79
|
+
`#{@run} generate my-app`
|
80
|
+
end
|
81
|
+
it "should create the design document" do
|
82
|
+
`#{@run} push my-app my-design #{TESTDB}`
|
83
|
+
lambda{@db.get("_design/my-design")}.should_not raise_error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe CouchRest do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@cr = CouchRest.new(COUCHHOST)
|
7
|
+
begin
|
8
|
+
@db = @cr.database(TESTDB)
|
9
|
+
@db.delete! rescue nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
begin
|
15
|
+
@db.delete! rescue nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "getting info" do
|
20
|
+
it "should list databases" do
|
21
|
+
@cr.databases.should be_an_instance_of(Array)
|
22
|
+
end
|
23
|
+
it "should get info" do
|
24
|
+
@cr.info["couchdb"].should == "Welcome"
|
25
|
+
@cr.info.class.should == Hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should restart" do
|
30
|
+
@cr.restart!
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should provide one-time access to uuids" do
|
34
|
+
@cr.next_uuid.should_not be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "initializing a database" do
|
38
|
+
it "should return a db" do
|
39
|
+
db = @cr.database(TESTDB)
|
40
|
+
db.should be_an_instance_of(CouchRest::Database)
|
41
|
+
db.host.should == @cr.uri
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "parsing urls" do
|
46
|
+
it "should parse just a dbname" do
|
47
|
+
db = CouchRest.parse "my-db"
|
48
|
+
db[:database].should == "my-db"
|
49
|
+
db[:host].should == "localhost:5984"
|
50
|
+
end
|
51
|
+
it "should parse a host and db" do
|
52
|
+
db = CouchRest.parse "localhost/my-db"
|
53
|
+
db[:database].should == "my-db"
|
54
|
+
db[:host].should == "localhost"
|
55
|
+
end
|
56
|
+
it "should parse a host and db with http" do
|
57
|
+
db = CouchRest.parse "http://localhost/my-db"
|
58
|
+
db[:database].should == "my-db"
|
59
|
+
db[:host].should == "localhost"
|
60
|
+
end
|
61
|
+
it "should parse a host with a port and db" do
|
62
|
+
db = CouchRest.parse "localhost:5555/my-db"
|
63
|
+
db[:database].should == "my-db"
|
64
|
+
db[:host].should == "localhost:5555"
|
65
|
+
end
|
66
|
+
it "should parse a host with a port and db with http" do
|
67
|
+
db = CouchRest.parse "http://localhost:5555/my-db"
|
68
|
+
db[:database].should == "my-db"
|
69
|
+
db[:host].should == "localhost:5555"
|
70
|
+
end
|
71
|
+
it "should parse just a host" do
|
72
|
+
db = CouchRest.parse "http://localhost:5555/"
|
73
|
+
db[:database].should be_nil
|
74
|
+
db[:host].should == "localhost:5555"
|
75
|
+
end
|
76
|
+
it "should parse just a host no slash" do
|
77
|
+
db = CouchRest.parse "http://localhost:5555"
|
78
|
+
db[:host].should == "localhost:5555"
|
79
|
+
db[:database].should be_nil
|
80
|
+
end
|
81
|
+
it "should get docid" do
|
82
|
+
db = CouchRest.parse "localhost:5555/my-db/my-doc"
|
83
|
+
db[:database].should == "my-db"
|
84
|
+
db[:host].should == "localhost:5555"
|
85
|
+
db[:doc].should == "my-doc"
|
86
|
+
end
|
87
|
+
it "should get docid with http" do
|
88
|
+
db = CouchRest.parse "http://localhost:5555/my-db/my-doc"
|
89
|
+
db[:database].should == "my-db"
|
90
|
+
db[:host].should == "localhost:5555"
|
91
|
+
db[:doc].should == "my-doc"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should parse a host and db" do
|
95
|
+
db = CouchRest.parse "127.0.0.1/my-db"
|
96
|
+
db[:database].should == "my-db"
|
97
|
+
db[:host].should == "127.0.0.1"
|
98
|
+
end
|
99
|
+
it "should parse a host and db with http" do
|
100
|
+
db = CouchRest.parse "http://127.0.0.1/my-db"
|
101
|
+
db[:database].should == "my-db"
|
102
|
+
db[:host].should == "127.0.0.1"
|
103
|
+
end
|
104
|
+
it "should parse a host with a port and db" do
|
105
|
+
db = CouchRest.parse "127.0.0.1:5555/my-db"
|
106
|
+
db[:database].should == "my-db"
|
107
|
+
db[:host].should == "127.0.0.1:5555"
|
108
|
+
end
|
109
|
+
it "should parse a host with a port and db with http" do
|
110
|
+
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
|
111
|
+
db[:database].should == "my-db"
|
112
|
+
db[:host].should == "127.0.0.1:5555"
|
113
|
+
end
|
114
|
+
it "should parse just a host" do
|
115
|
+
db = CouchRest.parse "http://127.0.0.1:5555/"
|
116
|
+
db[:database].should be_nil
|
117
|
+
db[:host].should == "127.0.0.1:5555"
|
118
|
+
end
|
119
|
+
it "should parse just a host no slash" do
|
120
|
+
db = CouchRest.parse "http://127.0.0.1:5555"
|
121
|
+
db[:host].should == "127.0.0.1:5555"
|
122
|
+
db[:database].should be_nil
|
123
|
+
end
|
124
|
+
it "should get docid" do
|
125
|
+
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
|
126
|
+
db[:database].should == "my-db"
|
127
|
+
db[:host].should == "127.0.0.1:5555"
|
128
|
+
db[:doc].should == "my-doc"
|
129
|
+
end
|
130
|
+
it "should get docid with http" do
|
131
|
+
db = CouchRest.parse "http://127.0.0.1:5555/my-db/my-doc"
|
132
|
+
db[:database].should == "my-db"
|
133
|
+
db[:host].should == "127.0.0.1:5555"
|
134
|
+
db[:doc].should == "my-doc"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "easy initializing a database adapter" do
|
139
|
+
it "should be possible without an explicit CouchRest instantiation" do
|
140
|
+
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
141
|
+
db.should be_an_instance_of(CouchRest::Database)
|
142
|
+
db.host.should == "localhost:5984"
|
143
|
+
end
|
144
|
+
# TODO add https support (need test environment...)
|
145
|
+
# it "should work with https" # do
|
146
|
+
# db = CouchRest.database "https://localhost:5984/couchrest-test"
|
147
|
+
# db.host.should == "https://localhost:5984"
|
148
|
+
# end
|
149
|
+
it "should not create the database automatically" do
|
150
|
+
db = CouchRest.database "http://localhost:5984/couchrest-test"
|
151
|
+
lambda{db.info}.should raise_error(RestClient::ResourceNotFound)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "ensuring the db exists" do
|
156
|
+
it "should be super easy" do
|
157
|
+
db = CouchRest.database! "http://localhost:5984/couchrest-test-2"
|
158
|
+
db.name.should == 'couchrest-test-2'
|
159
|
+
db.info["db_name"].should == 'couchrest-test-2'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "successfully creating a database" do
|
164
|
+
it "should start without a database" do
|
165
|
+
@cr.databases.should_not include(TESTDB)
|
166
|
+
end
|
167
|
+
it "should return the created database" do
|
168
|
+
db = @cr.create_db(TESTDB)
|
169
|
+
db.should be_an_instance_of(CouchRest::Database)
|
170
|
+
end
|
171
|
+
it "should create the database" do
|
172
|
+
db = @cr.create_db(TESTDB)
|
173
|
+
@cr.databases.should include(TESTDB)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "failing to create a database because the name is taken" do
|
178
|
+
before(:each) do
|
179
|
+
db = @cr.create_db(TESTDB)
|
180
|
+
end
|
181
|
+
it "should start with the test database" do
|
182
|
+
@cr.databases.should include(TESTDB)
|
183
|
+
end
|
184
|
+
it "should PUT the database and raise an error" do
|
185
|
+
lambda{
|
186
|
+
@cr.create_db(TESTDB)
|
187
|
+
}.should raise_error(RestClient::Request::RequestFailed)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|