jchris-couchrest 0.9.12 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.md} +10 -8
- data/Rakefile +60 -39
- data/THANKS.md +18 -0
- data/examples/word_count/markov +1 -1
- data/examples/word_count/views/word_count/count-reduce.js +2 -2
- data/examples/word_count/word_count.rb +2 -2
- data/examples/word_count/word_count_query.rb +2 -2
- data/lib/couchrest/commands/push.rb +8 -4
- data/lib/couchrest/core/database.rb +95 -14
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +63 -0
- data/lib/couchrest/core/model.rb +203 -120
- data/lib/couchrest/core/server.rb +1 -1
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/pager.rb +10 -10
- data/lib/couchrest/monkeypatches.rb +1 -1
- data/lib/couchrest.rb +20 -2
- data/spec/couchrest/core/couchrest_spec.rb +33 -23
- data/spec/couchrest/core/database_spec.rb +163 -8
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +130 -0
- data/spec/couchrest/core/model_spec.rb +319 -35
- data/spec/couchrest/helpers/pager_spec.rb +2 -2
- data/spec/fixtures/attachments/README +3 -0
- data/spec/spec_helper.rb +17 -3
- data/utils/remap.rb +2 -2
- data/utils/subset.rb +2 -2
- metadata +24 -33
- data/THANKS +0 -15
- data/bin/couchapp +0 -55
- data/bin/couchview +0 -48
- data/lib/couchrest/helper/file_manager.rb +0 -285
- data/lib/couchrest/helper/templates/example-map.js +0 -8
- data/lib/couchrest/helper/templates/example-reduce.js +0 -10
- data/lib/couchrest/helper/templates/index.html +0 -26
- data/spec/couchapp_spec.rb +0 -82
- data/spec/couchrest/helpers/file_manager_spec.rb +0 -170
@@ -1,170 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
|
3
|
-
describe CouchRest::FileManager do
|
4
|
-
before(:all) do
|
5
|
-
@cr = CouchRest.new(COUCHHOST)
|
6
|
-
@db = @cr.database(TESTDB)
|
7
|
-
@db.delete! rescue nil
|
8
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
9
|
-
end
|
10
|
-
it "should initialize" do
|
11
|
-
@fm = CouchRest::FileManager.new(TESTDB)
|
12
|
-
@fm.should_not be_nil
|
13
|
-
end
|
14
|
-
it "should require a db name" do
|
15
|
-
lambda{CouchRest::FileManager.new}.should raise_error
|
16
|
-
end
|
17
|
-
it "should accept a db name" do
|
18
|
-
@fm = CouchRest::FileManager.new(TESTDB, 'http://localhost')
|
19
|
-
@fm.db.name.should == TESTDB
|
20
|
-
end
|
21
|
-
it "should default to localhost couchdb" do
|
22
|
-
@fm = CouchRest::FileManager.new(TESTDB)
|
23
|
-
@fm.db.host.should == 'http://localhost:5984'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe CouchRest::FileManager, "generating an app" do
|
28
|
-
before(:all) do
|
29
|
-
@appdir = FIXTURE_PATH + '/couchapp'
|
30
|
-
`rm -rf #{@appdir}`
|
31
|
-
`mkdir -p #{@appdir}`
|
32
|
-
CouchRest::FileManager.generate_app(@appdir)
|
33
|
-
end
|
34
|
-
it "should create an attachments directory" do
|
35
|
-
Dir["#{@appdir}/*"].select{|x|x =~ /attachments/}.length.should == 1
|
36
|
-
end
|
37
|
-
it "should create a views directory" do
|
38
|
-
Dir["#{@appdir}/*"].select{|x|x =~ /views/}.length.should == 1
|
39
|
-
end
|
40
|
-
it "should create index.html" do
|
41
|
-
html = File.open("#{@appdir}/attachments/index.html").read
|
42
|
-
html.should match(/DOCTYPE/)
|
43
|
-
end
|
44
|
-
it "should create an example view" do
|
45
|
-
map = File.open("#{@appdir}/views/example-map.js").read
|
46
|
-
map.should match(/function\(doc\)/)
|
47
|
-
reduce = File.open("#{@appdir}/views/example-reduce.js").read
|
48
|
-
reduce.should match(/rereduce/)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe CouchRest::FileManager, "pushing an app" do
|
53
|
-
before(:all) do
|
54
|
-
@cr = CouchRest.new(COUCHHOST)
|
55
|
-
@db = @cr.database(TESTDB)
|
56
|
-
@db.delete! rescue nil
|
57
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
58
|
-
|
59
|
-
@appdir = FIXTURE_PATH + '/couchapp'
|
60
|
-
`rm -rf #{@appdir}`
|
61
|
-
`mkdir -p #{@appdir}`
|
62
|
-
CouchRest::FileManager.generate_app(@appdir)
|
63
|
-
|
64
|
-
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
65
|
-
r = @fm.push_app(@appdir, "couchapp")
|
66
|
-
end
|
67
|
-
it "should create a design document" do
|
68
|
-
lambda{@db.get("_design/couchapp")}.should_not raise_error
|
69
|
-
end
|
70
|
-
it "should create the views" do
|
71
|
-
doc = @db.get("_design/couchapp")
|
72
|
-
doc['views']['example']['map'].should match(/function/)
|
73
|
-
end
|
74
|
-
it "should create the index" do
|
75
|
-
doc = @db.get("_design/couchapp")
|
76
|
-
doc['_attachments']['index.html']["content_type"].should == 'text/html'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
describe CouchRest::FileManager, "pushing views" do
|
82
|
-
before(:all) do
|
83
|
-
@cr = CouchRest.new(COUCHHOST)
|
84
|
-
@db = @cr.database(TESTDB)
|
85
|
-
@db.delete! rescue nil
|
86
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
87
|
-
|
88
|
-
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
89
|
-
@view_dir = FIXTURE_PATH + '/views'
|
90
|
-
ds = @fm.push_views(@view_dir)
|
91
|
-
@design = @db.get("_design/test_view")
|
92
|
-
end
|
93
|
-
it "should create a design document for each folder" do
|
94
|
-
@design["views"].should_not be_nil
|
95
|
-
end
|
96
|
-
it "should push a map and reduce view" do
|
97
|
-
@design["views"]["test-map"].should_not be_nil
|
98
|
-
@design["views"]["test-reduce"].should_not be_nil
|
99
|
-
end
|
100
|
-
it "should push a map only view" do
|
101
|
-
@design["views"]["only-map"].should_not be_nil
|
102
|
-
@design["views"]["only-reduce"].should be_nil
|
103
|
-
end
|
104
|
-
it "should include library files" do
|
105
|
-
@design["views"]["only-map"]["map"].should include("globalLib")
|
106
|
-
@design["views"]["only-map"]["map"].should include("justThisView")
|
107
|
-
end
|
108
|
-
it "should not create extra design docs" do
|
109
|
-
docs = @db.documents(:startkey => '_design', :endkey => '_design/ZZZZZZ')
|
110
|
-
docs['total_rows'].should == 1
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe CouchRest::FileManager, "pushing a directory with id" do
|
115
|
-
before(:all) do
|
116
|
-
@cr = CouchRest.new(COUCHHOST)
|
117
|
-
@db = @cr.database(TESTDB)
|
118
|
-
@db.delete! rescue nil
|
119
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
120
|
-
|
121
|
-
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
122
|
-
@push_dir = FIXTURE_PATH + '/attachments'
|
123
|
-
ds = @fm.push_directory(@push_dir, 'attached')
|
124
|
-
end
|
125
|
-
it "should create a document for the folder" do
|
126
|
-
@db.get("attached")
|
127
|
-
end
|
128
|
-
it "should make attachments" do
|
129
|
-
doc = @db.get("attached")
|
130
|
-
doc["_attachments"]["test.html"].should_not be_nil
|
131
|
-
end
|
132
|
-
it "should set the content type" do
|
133
|
-
doc = @db.get("attached")
|
134
|
-
doc["_attachments"]["test.html"]["content_type"].should == "text/html"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe CouchRest::FileManager, "pushing a directory without id" do
|
139
|
-
before(:all) do
|
140
|
-
@cr = CouchRest.new(COUCHHOST)
|
141
|
-
@db = @cr.database(TESTDB)
|
142
|
-
@db.delete! rescue nil
|
143
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
144
|
-
|
145
|
-
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
146
|
-
@push_dir = FIXTURE_PATH + '/attachments'
|
147
|
-
ds = @fm.push_directory(@push_dir)
|
148
|
-
end
|
149
|
-
it "should use the dirname" do
|
150
|
-
doc = @db.get("attachments")
|
151
|
-
doc["_attachments"]["test.html"].should_not be_nil
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe CouchRest::FileManager, "pushing a directory/ without id" do
|
156
|
-
before(:all) do
|
157
|
-
@cr = CouchRest.new(COUCHHOST)
|
158
|
-
@db = @cr.database(TESTDB)
|
159
|
-
@db.delete! rescue nil
|
160
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
161
|
-
|
162
|
-
@fm = CouchRest::FileManager.new(TESTDB, COUCHHOST)
|
163
|
-
@push_dir = FIXTURE_PATH + '/attachments/'
|
164
|
-
ds = @fm.push_directory(@push_dir)
|
165
|
-
end
|
166
|
-
it "should use the dirname" do
|
167
|
-
doc = @db.get("attachments")
|
168
|
-
doc["_attachments"]["test.html"].should_not be_nil
|
169
|
-
end
|
170
|
-
end
|