added attachment uploading

This commit is contained in:
Chris Anderson 2008-09-16 11:44:02 -04:00
parent baa2c1dd37
commit 7f818c2cf1
3 changed files with 25 additions and 3 deletions

View file

@ -47,6 +47,8 @@ module CouchRest
return
end
doc["signatures"] ||= {}
doc["_attachments"] ||= {}
# remove deleted docs
to_be_removed = doc["signatures"].keys.select do |d|
!pushfiles.collect{|p| p.keys.first}.include?(d)
@ -69,7 +71,6 @@ module CouchRest
doc["_attachments"][path].delete("length")
doc["_attachments"][path]["data"] = @attachments[path]["data"]
doc["_attachments"][path].merge!({"data" => @attachments[path]["data"]} )
end
end
@ -190,12 +191,14 @@ module CouchRest
viewdir = File.join(appdir,"views")
attachdir = File.join(appdir,"attachments")
views, lang = read_design_views(viewdir)
# attachments = read_attachments(attachdir)
docid = "_design/#{appname}"
design = @db.get(docid) rescue {}
design['_id'] = docid
design['views'] = views
design['language'] = lang
@db.save(design)
push_directory(attachdir, docid)
# puts views.inspect
end

View file

@ -39,6 +39,16 @@ describe "couchapp" do
`#{@run} push my-app #{TESTDB}`
lambda{@db.get("_design/my-app")}.should_not raise_error
end
it "should create the views" do
`#{@run} push my-app #{TESTDB}`
doc = @db.get("_design/my-app")
doc['views']['example']['map'].should match(/function/)
end
it "should create the index" do
`#{@run} push my-app #{TESTDB}`
doc = @db.get("_design/my-app")
doc['_attachments']['index.html']["content_type"].should == 'text/html'
end
end
describe "push my-app my-design #{TESTDB}" do
@ -50,7 +60,8 @@ describe "couchapp" do
`#{@run} generate my-app`
end
it "should create the design document" do
`#{@run} push my-app my-design #{TESTDB}`
lambda{@db.get("_design/my-design")}.should_not raise_error
end
end
end

View file

@ -67,6 +67,14 @@ describe CouchRest::FileManager, "pushing an app" do
it "should create a design document" do
lambda{@db.get("_design/couchapp")}.should_not raise_error
end
it "should create the views" do
doc = @db.get("_design/couchapp")
doc['views']['example']['map'].should match(/function/)
end
it "should create the index" do
doc = @db.get("_design/couchapp")
doc['_attachments']['index.html']["content_type"].should == 'text/html'
end
end