<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -47,13 +47,17 @@ class InsideOutTest &lt; Book::TestCase
     assert_select '.stderr', /crontab file updated/
   end
 
-  section 3.1, 'rails' do
+  section 3.1, 'convert to rails' do
     assert_select '.stdout', /==  CreateProducts: migrated/
     assert_select '.stdout', '3 tests, 0 assertions, 0 failures, 3 errors'
     assert_select '.stdout', '3 tests, 12 assertions, 0 failures, 0 errors'
     assert_select '.stdout', '7 tests, 10 assertions, 0 failures, 0 errors'
     assert_select 'td', '24.95'
     assert_select 'input[value=/images/auto.jpg]'
+  end
+
+  section 3.2, 'deploy rails' do
+    assert_select '.stderr', :text =&gt; /failed:/, :count =&gt; 0
     assert_select 'tr:only-child'
   end
 end</diff>
      <filename>checkinout.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,13 +31,14 @@ set :branch, 'master'
 set :scm_verbose, true
 set :use_sudo, false
 
-# task which causes Passenger to initiate a restart
+# additional tasks
 namespace :deploy do
-  desc &quot;Restarting Passenger&quot;
+  desc 'Restarting Passenger'
   task :restart, :roles =&gt; :app do
     run &quot;mkdir -p #{current_path}/tmp&quot; 
     run &quot;touch #{current_path}/tmp/restart.txt&quot; 
   end
 end
 
+# insert tasks into the deployment sequence
 after &quot;deploy:symlink&quot;, &quot;deploy:restart&quot;</diff>
      <filename>data/capistrano/deploy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,9 @@ class Product &lt; ActiveRecord::Base
 
   def self.import(source)
     if source =~ /^http:/
-      input = Net::HTTP.get(URI.parse(uri))
+      input = Net::HTTP.get(URI.parse(source))
     else
-      input = File.open(source)
+      input = File.open(source) {|file| file.read}
     end
 
     REXML::Document.new(input).each_element('//product') do |xproduct|</diff>
      <filename>data/rails/product.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,7 +21,7 @@ class ProductTest &lt; ActiveSupport::TestCase
     assert_equal 28.5, product.price
   end
 
-  def test_unit
+  test &quot;Pragmatic Unit Testing&quot; do
     product = Product.find_by_base_id(4)
     assert_equal 'Pragmatic Unit Testing (C#)', product.title
     assert_match /&lt;p&gt;\s+Pragmatic programmers use feedback/, product.description</diff>
      <filename>data/rails/product_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -135,7 +135,7 @@ section 2.1, 'Rack' do
     data[/()/,1] = read('rack/test_product_server.rb')
   end
 
-  desc 'Establish connection, use Builder, and send response.'
+  desc 'Code: Establish connection, use Builder, and send response.'
   edit 'product_server.rb' do |data|
     data[/()/,1] = read('rack/product_server.rb')
   end
@@ -285,15 +285,15 @@ section 2.3, 'Whenever' do
   cmd 'whenever'
 
   edit 'config/deploy.rb' do |data|
-    data &lt;&lt; &quot;\n&quot; + &lt;&lt;-'EOF'.unindent(6)
-      namespace :deploy do
-        desc &quot;Update the crontab file&quot;
-          task :update_crontab, :roles =&gt; :db do
-          run &quot;cd #{release_path} &amp;&amp; whenever --update-crontab #{application}&quot;
-        end
+    data[/namespace :deploy.*?^()end/m,1] = &quot;\n&quot; + &lt;&lt;-'EOF'.unindent(4)
+      desc 'Update the crontab file'
+        task :update_crontab, :roles =&gt; :db do
+        run &quot;cd #{current_path} &amp;&amp; whenever --update-crontab #{application}&quot;
       end
+    EOF
 
-      after &quot;deploy:symlink&quot;, &quot;deploy:update_crontab&quot;
+    data[/^after &quot;deploy:symlink&quot;, &quot;deploy:restart&quot;\n()/,1] = &lt;&lt;-EOF.unindent(6)
+      after &quot;deploy:restart&quot;, &quot;deploy:update_crontab&quot;
     EOF
   end
 
@@ -307,7 +307,7 @@ section 2.3, 'Whenever' do
   cmd 'cap deploy'
 end
 
-section 3.1, 'Rails' do
+section 3.1, 'Convert to Rails' do
   overview &lt;&lt;-EOF
     Taking a step back, we have done something real.  It doesn't do much,
     but it didn't really take much code either.  But the problems are starting
@@ -375,40 +375,71 @@ section 3.1, 'Rails' do
   get '/products/1'
   get '/products/1/edit'
   get '/products/new'
+end
 
-  desc 'Update whenever to use runner'
+section 3.2, 'Deploy Rails' do
+  overview &lt;&lt;-EOF
+    Capistrano is understands Rails, but there are a few things you need
+    to be aware of.
+  EOF
+  desc 'Update whenever to use runner.'
   edit 'config/schedule.rb' do |data|
-    data[/(command.*)/,1] = &quot;runner 'Product.import(\&quot;http://#{HOST}/testdata.xml\&quot;)'&quot;
+    data[/^(root =.*\s+)/,1] = ''
+    data[/(command.*load_products.*)/,1] = 
+      &quot;runner \&quot;Product.import('http://#{HOST}/testdata.xml')\&quot;&quot;
   end
 
-  desc 'Tell Rails about the gem path'
+  desc 'Peek at the results.'
+  cmd 'whenever'
+
+  desc 'Add GEM_HOME to environment.rb, migration tasks, and do cleanup.'
   edit 'config/deploy.rb' do |data|
-    data &lt;&lt; &quot;\n&quot; + &lt;&lt;-'EOF'.unindent(6)
-      load 'ext/rails-database-migrations.rb'
+    data[/set :deploy_to.*\n()/,1] = &lt;&lt;-'EOF'.unindent(6)
+      set :gemhome, &quot;/home/#{user}/.gems&quot;
+    EOF
+
+    data[/namespace :deploy.*?^()end/m,1] = &quot;\n&quot; + &lt;&lt;-'EOF'.unindent(4)
+      desc 'set db path outside of application directory'
+      task :set_db_path do
+        run &quot;sed -i 's|db/production|#{deploy_to}/depot|' &quot; +
+            &quot;#{release_path}/config/database.yml&quot;
+      end
 
-      set :gemhome, &quot;/home/sa3ruby/.gemlocal&quot;
-      task :after_deploy do
-        run &quot;cp #{current_release}/config/environment.rb &quot; +
-            &quot;#{current_release}/config/environment.rb-&quot;
-        run &quot;echo ENV[\\'GEM_HOME\\']=\\'#{gemhome}\\' &gt; &quot; +
-            &quot;#{current_release}/config/environment.rb&quot;
-        run &quot;echo ENV[\\'GEM_PATH\\']=\\'#{gemhome}\\' &gt;&gt; &quot; +
-            &quot;#{current_release}/config/environment.rb&quot;
-        run &quot;cat #{current_release}/config/environment.rb- &gt;&gt; &quot; +
-            &quot;#{current_release}/config/environment.rb&quot;
-        run &quot;rm #{current_release}/config/environment.rb-&quot;
-        deploy::cleanup
+      desc 'set GEM_HOME in the environment'
+      task :set_gem_home do
+        run &quot;sed -i '1iENV[%(GEM_HOME)]=%(#{gemhome})\\n' &quot; +
+            &quot;#{release_path}/config/environment.rb&quot;
       end
     EOF
+
+    data[/^(after &quot;deploy:symlink&quot;, &quot;deploy:restart&quot;\n)/,1] = &lt;&lt;-EOF.unindent(6)
+      after &quot;deploy:update_code&quot;, &quot;deploy:set_db_path&quot;
+      after &quot;deploy:update_code&quot;, &quot;deploy:set_gem_home&quot;
+      after &quot;deploy:symlink&quot;, &quot;deploy:restart&quot;
+      after &quot;deploy:restart&quot;, &quot;deploy:cleanup&quot;
+    EOF
+
+    data &lt;&lt; &quot;\n&quot; + &lt;&lt;-EOF.unindent(6)
+      # Rails migration tasks
+      load 'ext/rails-database-migrations.rb'
+    EOF
   end
   
+  desc 'Tell git what file NOT to retain'
+  edit '.gitignore' do |data|
+    data &lt;&lt; &lt;&lt;-EOF.unindent(6)
+      db/*.sqlite3
+      log/*.log
+      tmp/**/*
+    EOF
+  end
+ 
   desc 'Commit.  Push.  Deploy.'
   cmd 'git st'
   cmd 'git add .'
   cmd 'git commit -m &quot;convert to Rails!&quot;'
   cmd 'git push'
   cmd 'cap deploy:migrations'
-  cmd 'cap deploy'
 
   desc &quot;See this live.&quot;
   get &quot;http://#{HOST}/products&quot;</diff>
      <filename>insideout.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bb095bdf239ffe791f369c3fb9f78480e6f2a844</id>
    </parent>
  </parents>
  <author>
    <name>Sam Ruby</name>
    <email>rubys@intertwingly.net</email>
  </author>
  <url>http://github.com/rubys/awdwr/commit/7fc0a0b9e17dec50fad2572adc2dca97d83e0729</url>
  <id>7fc0a0b9e17dec50fad2572adc2dca97d83e0729</id>
  <committed-date>2009-07-11T09:38:00-07:00</committed-date>
  <authored-date>2009-07-11T09:38:00-07:00</authored-date>
  <message>Split Rails chapter into two, and other cleanup</message>
  <tree>304583f9e50b42c02501ee7f62ea7011636359b5</tree>
  <committer>
    <name>Sam Ruby</name>
    <email>rubys@intertwingly.net</email>
  </committer>
</commit>
