From 7f818c2cf10c9732c77acb05b60028f34a6a75ef Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Tue, 16 Sep 2008 11:44:02 -0400 Subject: [PATCH] added attachment uploading --- lib/couchrest/helper/file_manager.rb | 7 +++++-- spec/couchapp_spec.rb | 13 ++++++++++++- spec/file_manager_spec.rb | 8 ++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/couchrest/helper/file_manager.rb b/lib/couchrest/helper/file_manager.rb index 3d5bd67..4e36bef 100644 --- a/lib/couchrest/helper/file_manager.rb +++ b/lib/couchrest/helper/file_manager.rb @@ -47,10 +47,12 @@ 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) - end + end to_be_removed.each do |p| say "deleting #{p}" @@ -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 diff --git a/spec/couchapp_spec.rb b/spec/couchapp_spec.rb index c8ae0b0..e81b2b9 100644 --- a/spec/couchapp_spec.rb +++ b/spec/couchapp_spec.rb @@ -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 diff --git a/spec/file_manager_spec.rb b/spec/file_manager_spec.rb index 0953520..9feb7e1 100644 --- a/spec/file_manager_spec.rb +++ b/spec/file_manager_spec.rb @@ -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