<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,5 +4,4 @@ class ActivecouchModelGenerator &lt; Rails::Generator::NamedBase
       m.template 'model.rb', File.join('app', 'models', &quot;#{class_name.underscore}.rb&quot;)
     end
   end
-  
 end
\ No newline at end of file</diff>
      <filename>generators/activecouch_model/activecouch_model_generator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,8 @@ module ActiveCouch
   class Exporter
     class &lt;&lt; self # Class methods
       def export(site, view, opts = {})
+        existing_view = {}
+        
         if view.name.nil? || (view.database.nil? &amp;&amp; opts[:database].nil?)
           raise ActiveCouch::ViewError, &quot;Both the name and the database need to be defined in your view&quot;
         end
@@ -12,9 +14,12 @@ module ActiveCouch
         # as an option to the export method
         database_name = view.database || opts[:database]
         conn = Connection.new(site)
-        # view for a view with name 'by_name' and database 'activecouch_test' should be PUT to
+        # The view function for a view with name 'by_name' and database 'activecouch_test' should be PUT to
         # http://#{host}:#{port}/activecouch_test/_design/by_name.
-        response = conn.put(&quot;/#{database_name}/_design/#{view.name}&quot;, view.to_json)
+        if(view_json = exists?(site, &quot;/#{database_name}/_design/#{view.name}&quot;))
+          existing_view = JSON.parse(view_json)
+        end
+        response = conn.put(&quot;/#{database_name}/_design/#{view.name}&quot;, view.to_json(existing_view))
         case response.code
         when '201'
           true # 201 = success
@@ -23,10 +28,33 @@ module ActiveCouch
         end
       end
 
+      def delete(site, view, opts = {})
+        rev = nil
+        
+        if view.name.nil? || (view.database.nil? &amp;&amp; opts[:database].nil?)
+          raise ActiveCouch::ViewError, &quot;Both the name and the database need to be defined in your view&quot;
+        end
+        # If the database is not defined in the view, it can be supported
+        # as an option to the export method
+        database_name = view.database || opts[:database]
+        conn = Connection.new(site)
+        if(view_json = exists?(site, &quot;/#{database_name}/_design/#{view.name}&quot;))
+          rev = JSON.parse(view_json)['_rev']
+        end
+        # The view function for a view with name 'by_name' and database 'activecouch_test' should be PUT to
+        # http://#{host}:#{port}/activecouch_test/_design/by_name.
+        response = conn.delete(&quot;/#{database_name}/_design/#{view.name}?rev=#{rev}&quot;)
+        if response.code =~ /20[0,2]/
+          true # 201 = success
+        else
+          raise ActiveCouch::ViewError, &quot;Error deleting view - got HTTP response #{response.code}&quot;
+        end
+      end
+
       def exists?(site, name)
         conn = Connection.new(site)
         response = conn.get(&quot;/#{name}&quot;)
-        true
+        response
       rescue ActiveCouch::ResourceNotFound
         false
       end</diff>
      <filename>lib/active_couch/views/exporter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,9 +37,10 @@ module ActiveCouch
         @attrs = attrs unless attrs.nil? || !attrs.is_a?(Array)
       end
       
-      def to_json
-        results_hash = { &quot;_id&quot; =&gt; &quot;_design/#{@name}&quot;, &quot;language&quot; =&gt; view_language }
-        results_hash[&quot;views&quot;] =  view_function
+      def to_json(existing_view = {})
+        results_hash = {  &quot;_id&quot; =&gt; &quot;_design/#{@name}&quot;, &quot;language&quot; =&gt; view_language }
+        results_hash.merge!(existing_view)
+        results_hash['views'] = view_function
         # Returns the JSON format for the function
         results_hash.to_json
       end</diff>
      <filename>lib/active_couch/views/view.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,7 @@ describe ActiveCouch::Exporter, &quot;#export (that actually connects to a CouchDB se
     ActiveCouch::Exporter.delete_database('http://localhost:5984/', 'ac_test_3')
   end
 
-  it &quot;should be able to create a permanent view when sent the migrate method&quot; do
+  it &quot;should be able to create a permanent view when sent the export method&quot; do
     ActiveCouch::Exporter.export('http://localhost:5984', ByFace).should == true
     # This is the view document. To actually query this particular view, the URL to be used
     # is http://#{host}:#{port}/ac_test_1/_view/by_face/by_face 
@@ -28,7 +28,7 @@ describe ActiveCouch::Exporter, &quot;#export (that actually connects to a CouchDB se
   end
 end
 
-describe ActiveCouch::Exporter, &quot;#migrate with site and migration&quot; do
+describe ActiveCouch::Exporter, &quot;#export with site and migration&quot; do
   before(:all) do
     class ByFace &lt; ActiveCouch::View
       define :for_db =&gt; 'test_db' do</diff>
      <filename>spec/exporter/export_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,8 +3,7 @@ if defined? RAILS_ENV
 end
 
 namespace :activecouch do
-  desc &quot;Set of tools for making Ruby On Rails play nice with CouchDB&quot;
-  
+  desc &quot;Creates a database in CouchDB&quot;
   task :create_db do
     unless (database = ENV['db']).nil?
       site = YAML::load(File.open(File.join(Rails.root, 'config', 'activecouch.yml')))[Rails.env]['site']
@@ -20,6 +19,7 @@ namespace :activecouch do
     end
   end
 
+  desc &quot;Deletes a database from CouchDB&quot;
   task :delete_db do
     unless (database = ENV['db']).nil?
       site = YAML::load(File.open(File.join(Rails.root, 'config', 'activecouch.yml')))[Rails.env]['site']
@@ -34,7 +34,8 @@ namespace :activecouch do
       puts &quot;You need to specify a database. Usage: rake activecouch:delete_db db=&lt;database_name&gt;&quot;
     end
   end
-  
+
+  desc &quot;Saves a view in CouchDB&quot;
   task :save_view do
     unless (view_name = ENV['view']).nil?
       site = YAML::load(File.open(File.join(Rails.root, 'config', 'activecouch.yml')))[Rails.env]['site']
@@ -55,11 +56,11 @@ namespace :activecouch do
     unless (view_name = ENV['view']).nil?
       site = YAML::load(File.open(File.join(Rails.root, 'config', 'activecouch.yml')))[Rails.env]['site']
       unless(view = Object.const_get(view_name)).nil?
-        saved = ActiveCouch::Exporter.export(site, view)
-        if saved
-          puts &quot;View exported successfully&quot;
+        deleted = ActiveCouch::Exporter.delete(site, view)
+        if deleted
+          puts &quot;View deleted successfully&quot;
         else
-          puts &quot;There was an error in the export. Please check your CouchDB logs&quot;
+          puts &quot;There was an error in the deletion of the view. Please check your CouchDB logs&quot;
         end
       else
         puts &quot;Have you defined your view? Use ./script/generate activecouch_view ViewName from the root of your Rails app&quot;</diff>
      <filename>tasks/activecouch.rake</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4fd3a77bcc917dd479861721506d7dd68a1d6e3e</id>
    </parent>
  </parents>
  <author>
    <name>Arun Thampi</name>
    <email>arun@Macintosh.(none)</email>
  </author>
  <url>http://github.com/arunthampi/activecouch/commit/24c26442decf5f57d36114f05396b9889ed1aba6</url>
  <id>24c26442decf5f57d36114f05396b9889ed1aba6</id>
  <committed-date>2008-10-21T20:58:19-07:00</committed-date>
  <authored-date>2008-10-21T20:58:19-07:00</authored-date>
  <message>Make the exporter view over-write existing views. Deleting views also work. Specs in the works</message>
  <tree>02d969f6eff422717c0acf0bc1c2e3e60faf2296</tree>
  <committer>
    <name>Arun Thampi</name>
    <email>arun@Macintosh.(none)</email>
  </committer>
</commit>
