<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,9 @@
 #!/usr/bin/env ruby
 
 require 'rubygems'
+require 'yaml'
+require 'pp'
+
 module ContributeHelper; end
 
 class Contribute
@@ -10,6 +13,7 @@ class Contribute
     [
       Dependencies::Sphinx,
       Dependencies::Mysql,
+      Dependencies::AR,
       Dependencies::Ginger
     ]
   end
@@ -18,9 +22,9 @@ class Contribute
     show_welcome_screen
     
     (
-      check_for_dependencies         &amp;&amp;
-      create_database_yaml           &amp;&amp;
-      check_mysql_gem_is_working     &amp;&amp;
+      check_for_dependencies   &amp;&amp;
+      create_database_yaml     &amp;&amp;
+      check_mysql_is_working   &amp;&amp;
       create_test_database
     ) || exit(1)
     
@@ -33,62 +37,175 @@ WELCOME_SCREEN = &lt;&lt;-EO_WELCOME
 
 Thanks for contributing to Thinking Sphinx.
 
-In this script we'll help you get started contributing to Thinking Sphinx
+In this script we'll help you get setup to hack:
+
+ &lt;b&gt;1.&lt;/b&gt; We'll check that you have the right software installed and running.
+ &lt;b&gt;2.&lt;/b&gt; We'll set up the test database for specs to run against.
 
 EO_WELCOME
 
+DONE_SCREEN = &lt;&lt;-EO_DONE
+&lt;banner&gt;Setup done!&lt;/banner&gt;
+
+All done! Now you can start hacking by running
+
+  &lt;b&gt;rake spec&lt;/b&gt;
+
+EO_DONE
+
+REVIEW_YAML = &lt;&lt;-EO_REVIEW_YAML
+
+Please review the database details in the yaml file details before continuing.
+
+This file is used by the specs to connect to the database.
+
+Current details:
+EO_REVIEW_YAML
+
+
+
+MYSQL_FAILED = &lt;&lt;-EO_MYSQL_FAILED
+
+Looks like we couldn't successfully talk to the mysql database.
+
+Don't worry though...
+
+EO_MYSQL_FAILED
+
+CREATE_DATABASE_FAILED = &lt;&lt;-EO_CREATE_DATABASE_FAILED
+
+Looks like we couldn't create a test database to work against.
+
+Don't worry though...
+
+EO_CREATE_DATABASE_FAILED
+
   def show_welcome_screen
     colour_puts WELCOME_SCREEN
+    wait!
   end
 
   def show_done_screen
-    puts &quot;done!&quot;
+    colour_puts DONE_SCREEN
   end
-  
-  def check_for_dependencies
-    colour_puts &quot;&lt;banner&gt;Checking for required software&lt;/banner&gt;&quot;
+
+  # create database.yml
+  def create_database_yaml
+    colour_puts &quot;&lt;banner&gt;creating database yaml&lt;/banner&gt;&quot;
     puts
     
-    all_found = true
     
-    dependencies.each do |klass|
-      dep = klass.new
-      print &quot; * #{dep.name}... &quot;
-      dep.check!
-      
-      if dep.found?
-        if dep.location
-          colour_puts &quot;&lt;green&gt;found at #{dep.location}&lt;/green&gt;&quot;
-        else
-          colour_puts &quot;&lt;green&gt;found&lt;/green&gt;&quot;
-        end
-      else
-        all_found &amp;= false
-        colour_puts &quot;&lt;red&gt;not found&lt;/red&gt;&quot;
-      end
+    config = {
+          'username' =&gt; 'root',
+          'password' =&gt; nil,
+          'host'     =&gt; 'localhost'
+        }
+    
+    
+    colour_print &quot; * &lt;b&gt;#{db_yml}&lt;/b&gt;... &quot;
+    unless File.exist?(db_yml)
+      open(db_yml,'w') {|f| f &lt;&lt; config.to_yaml}
+      colour_puts &quot;&lt;green&gt;created&lt;/green&gt;&quot;
+    else
+      config = YAML.load_file(db_yml)
+      colour_puts &quot;&lt;green&gt;already exists&lt;/green&gt;&quot;
+    end
+    
+    colour_puts REVIEW_YAML
+    
+    config.each do |(k,v)|
+      colour_puts &quot; * &lt;b&gt;#{k}&lt;/b&gt;: #{v}&quot;
     end
     
     puts
     
-    all_found
+    wait!
+    true
   end
-
+  
   def check_mysql_is_working
-    colour_puts &quot;&lt;banner&gt;check mysql gem is working&lt;/banner&gt;&quot;
-    false
-  end
-
-  # create database.yml
-  def create_database_yaml
-    colour_puts &quot;&lt;banner&gt;creating database yaml&lt;/banner&gt;&quot;
+    require 'activerecord'
+    colour_puts &quot;&lt;banner&gt;check mysql is working&lt;/banner&gt;&quot;
+    puts
+    
+    connect_to_db
+    
+    print &quot; * connecting to mysql... &quot;
+    
+    begin
+      ActiveRecord::Base.connection.select_value('select sysdate() from dual')
+      
+      colour_puts &quot;&lt;green&gt;successful&lt;/green&gt;&quot;
+      puts
+      
+      return true
+    rescue Mysql::Error
+      colour_puts &quot;&lt;red&gt;failed&lt;/red&gt;&quot;
+      
+      puts MYSQL_FAILED
+    end
+    
     false
   end
 
   # create test db
   def create_test_database
     colour_puts &quot;&lt;banner&gt;create test database&lt;/banner&gt;&quot;
+    puts
+    
+    connect_to_db
+    
+    colour_print &quot; * &lt;b&gt;creating thinking_sphinx database&lt;/b&gt;... &quot;
+    begin
+      ActiveRecord::Base.connection.create_database('thinking_sphinx')
+      colour_puts &quot;&lt;green&gt;successful&lt;/green&gt;&quot;
+    rescue ActiveRecord::StatementInvalid
+      if $!.message[/database exists/]
+        colour_puts &quot;&lt;green&gt;successful&lt;/green&gt; (database already existed)&quot;
+        puts
+        return true
+      else
+        colour_puts &quot;&lt;red&gt;failed&lt;/red&gt;&quot;
+      end
+    end
+    
+    colour_puts CREATE_DATABASE_FAILED
+    
     false
   end
+  
+  # project
+  def ts_root
+    File.expand_path(File.dirname(__FILE__))
+  end
+  
+  def specs
+    ts_root / 'spec'
+  end
+  
+  def db_yml
+    specs / 'fixtures' / 'database.yml'
+  end
+  
+  def connect_to_db
+    config = YAML.load_file(db_yml)
+    config.update(:adapter =&gt; 'mysql', :database =&gt; 'test')
+    config.symbolize_keys!
+
+    ActiveRecord::Base.establish_connection(config)
+  end
+end
+
+
+
+
+
+
+
+class String
+  def /(other)
+    &quot;#{self}/#{other}&quot;
+  end
 end
 
 module ContributeHelper
@@ -126,6 +243,35 @@ module ContributeHelper
   end
   
   
+  def check_for_dependencies
+    colour_puts &quot;&lt;banner&gt;Checking for required software&lt;/banner&gt;&quot;
+    puts
+    
+    all_found = true
+    
+    dependencies.each do |klass|
+      dep = klass.new
+      print &quot; * #{dep.name}... &quot;
+      dep.check!
+      
+      if dep.found?
+        if dep.location
+          colour_puts &quot;&lt;green&gt;found at #{dep.location}&lt;/green&gt;&quot;
+        else
+          colour_puts &quot;&lt;green&gt;found&lt;/green&gt;&quot;
+        end
+      else
+        all_found &amp;= false
+        colour_puts &quot;&lt;red&gt;not found&lt;/red&gt;&quot;
+      end
+    end
+    
+    puts
+    
+    all_found
+  end
+  
+  
   
   DEFAULT_TERMINAL_COLORS = &quot;\e[0m\e[37m\e[40m&quot;
   def subs_colour(data)
@@ -141,6 +287,18 @@ module ContributeHelper
   def colour_puts(text)
     puts subs_colour(text)
   end
+
+  def colour_print(text)
+    print subs_colour(text)
+  end
+
+  
+  def wait!
+    colour_puts &quot;&lt;b&gt;Hit Enter to continue, or Ctrl-C to quit.&lt;/b&gt;&quot;
+    STDIN.readline
+  rescue Interrupt
+    exit!
+  end
 end
 
 module Dependencies
@@ -148,6 +306,10 @@ module Dependencies
     name 'mysql'
   end
   
+  class AR &lt; ContributeHelper::Gem
+    name 'activerecord'
+  end
+  
   class Ginger &lt; ContributeHelper::Gem
     name 'ginger'
   end</diff>
      <filename>contribute.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d723846cce37aa6c69e08e0d1a17ccaaafc6e5d9</id>
    </parent>
  </parents>
  <author>
    <name>lachie</name>
    <email>lachiec@gmail.com</email>
  </author>
  <url>http://github.com/isaacfeliu/thinking-sphinx/commit/63739b5d2ff0c52b9f77e0e3339464a84a6f9f67</url>
  <id>63739b5d2ff0c52b9f77e0e3339464a84a6f9f67</id>
  <committed-date>2009-01-08T14:43:55-08:00</committed-date>
  <authored-date>2009-01-08T14:43:55-08:00</authored-date>
  <message>finished basic contribute script</message>
  <tree>6c341779b9588134301070cc4a3f9a3d4a4a0a3a</tree>
  <committer>
    <name>lachie</name>
    <email>lachiec@gmail.com</email>
  </committer>
</commit>
