<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -109,6 +109,7 @@ class Import &lt; ActiveRecord::Base
     self.destroy
     begin File.unlink(@csv_filename); rescue; end # In case we created an extra csv file
     Mailers::ImportMailer.deliver_complete(importer, successful, unsuccessful)
+    [successful, unsuccessful]
   end
   
   def find_state_by_abbreviation_or_name(state_string)</diff>
      <filename>app/models/import.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + &quot;/../config/environment&quot;)
 require 'test_help'
 
 class ActiveSupport::TestCase
+  include ActionController::TestProcess
   # Transactional fixtures accelerate your tests by wrapping each test method
   # in a transaction that's rolled back on completion.  This ensures that the
   # test database remains unchanged so your fixtures don't have to be reloaded
@@ -39,4 +40,131 @@ class ActiveSupport::TestCase
     @request.session[:user] = User.find(:first, :conditions =&gt; {:username =&gt; username}).id
     @request.session[:ministry_id] = 1
   end
-end
\ No newline at end of file
+  
+  protected
+    def upload_file(options = {})
+      use_temp_file options[:filename] do |file|
+        att = attachment_model.create :uploaded_data =&gt; fixture_file_upload(file, options[:content_type] || 'image/png')
+        att.reload unless att.new_record?
+        return att
+      end
+    end
+        
+    def use_temp_file(fixture_filename)
+      temp_path = File.join('/tmp', File.basename(fixture_filename))
+      FileUtils.mkdir_p File.join(fixture_path, 'tmp')
+      FileUtils.cp File.join(fixture_path, fixture_filename), File.join(fixture_path, temp_path)
+      yield temp_path
+    ensure
+      FileUtils.rm_rf File.join(fixture_path, 'tmp')
+    end
+end
+# 
+# 
+# class ActiveSupport::TestCase #:nodoc:
+#   include ActionController::TestProcess
+#   def create_fixtures(*table_names)
+#     if block_given?
+#       Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names) { yield }
+#     else
+#       Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names)
+#     end
+#   end
+# 
+#   def setup
+#     Attachment.saves = 0
+#     DbFile.transaction { [Attachment, FileAttachment, OrphanAttachment, MinimalAttachment, DbFile].each { |klass| klass.delete_all } }
+#     attachment_model self.class.attachment_model
+#   end
+#   
+#   def teardown
+#     FileUtils.rm_rf File.join(File.dirname(__FILE__), 'files')
+#   end
+# 
+#   self.use_transactional_fixtures = true
+#   self.use_instantiated_fixtures  = false
+# 
+#   def self.attachment_model(klass = nil)
+#     @attachment_model = klass if klass 
+#     @attachment_model
+#   end
+# 
+#   def self.test_against_class(test_method, klass, subclass = false)
+#     define_method(&quot;#{test_method}_on_#{:sub if subclass}class&quot;) do
+#       klass = Class.new(klass) if subclass
+#       attachment_model klass
+#       send test_method, klass
+#     end
+#   end
+# 
+#   def self.test_against_subclass(test_method, klass)
+#     test_against_class test_method, klass, true
+#   end
+# 
+#   protected
+#     def upload_file(options = {})
+#       use_temp_file options[:filename] do |file|
+#         att = attachment_model.create :uploaded_data =&gt; fixture_file_upload(file, options[:content_type] || 'image/png')
+#         att.reload unless att.new_record?
+#         return att
+#       end
+#     end
+# 
+#     def upload_merb_file(options = {})
+#       use_temp_file options[:filename] do |file|
+#         att = attachment_model.create :uploaded_data =&gt; {&quot;size&quot; =&gt; file.size, &quot;content_type&quot; =&gt; options[:content_type] || 'image/png', &quot;filename&quot; =&gt; file, 'tempfile' =&gt; fixture_file_upload(file, options[:content_type] || 'image/png')}
+#         att.reload unless att.new_record?
+#         return att
+#       end
+#     end
+#     
+#     def use_temp_file(fixture_filename)
+#       temp_path = File.join('/tmp', File.basename(fixture_filename))
+#       FileUtils.mkdir_p File.join(fixture_path, 'tmp')
+#       FileUtils.cp File.join(fixture_path, fixture_filename), File.join(fixture_path, temp_path)
+#       yield temp_path
+#     ensure
+#       FileUtils.rm_rf File.join(fixture_path, 'tmp')
+#     end
+# 
+#     def assert_created(num = 1)
+#       assert_difference attachment_model.base_class, :count, num do
+#         if attachment_model.included_modules.include? DbFile
+#           assert_difference DbFile, :count, num do
+#             yield
+#           end
+#         else
+#           yield
+#         end
+#       end
+#     end
+#     
+#     def assert_not_created
+#       assert_created(0) { yield }
+#     end
+#     
+#     def should_reject_by_size_with(klass)
+#       attachment_model klass
+#       assert_not_created do
+#         attachment = upload_file :filename =&gt; '/files/rails.png'
+#         assert attachment.new_record?
+#         assert attachment.errors.on(:size)
+#         assert_nil attachment.db_file if attachment.respond_to?(:db_file)
+#       end
+#     end
+#     
+#     def assert_difference(object, method = nil, difference = 1)
+#       initial_value = object.send(method)
+#       yield
+#       assert_equal initial_value + difference, object.send(method)
+#     end
+#     
+#     def assert_no_difference(object, method, &amp;block)
+#       assert_difference object, method, 0, &amp;block
+#     end
+#     
+#     def attachment_model(klass = nil)
+#       @attachment_model = klass if klass 
+#       @attachment_model
+#     end
+# end</diff>
      <filename>test/test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,31 @@ require File.dirname(__FILE__) + '/../test_helper'
 
 class ImportTest &lt; ActiveSupport::TestCase
   # Replace this with your real tests.
-  test &quot;the truth&quot; do
-    assert true
+  test &quot;run import with no good rows&quot; do
+    import =  create_import('files/sample_import_bad.csv')
+    successful, unsuccessful = import.run!(Campus.first.id, Ministry.first, people(:josh))
+    assert_equal(0, successful.length)
+    assert_equal(1, unsuccessful.length)
   end
+  
+  test &quot;create from xls file&quot; do
+    import =  create_import('files/sample_import.xls')
+    successful, unsuccessful = import.run!(Campus.first.id, Ministry.first, people(:josh))
+    assert_equal(1, successful.length)
+    assert_equal(0, unsuccessful.length)
+  end
+   
+   test &quot;create with one good row, one bad&quot; do
+    import =  create_import('files/sample_import_one_of_each.csv')
+    successful, unsuccessful = import.run!(Campus.first.id, Ministry.first, people(:josh))
+    assert_equal(1, successful.length)
+    assert_equal(1, unsuccessful.length)
+   end
+  
+  private
+    def create_import(filename)
+      use_temp_file(filename) do |file|
+        Import.create!(:uploaded_data =&gt; fixture_file_upload(file, 'text/csv'), :parent_id =&gt; Campus.first.id, :person_id =&gt; 50000)
+      end
+    end
 end</diff>
      <filename>test/unit/import_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>14bd0686118d6a3d9babbda303d220e7fe2e8e05</id>
    </parent>
  </parents>
  <author>
    <name>Josh Starcher</name>
    <email>josh@josh-starchers-mac-pro.local</email>
  </author>
  <url>http://github.com/twinge/ministry-tracker/commit/664c0227178ad6d15771173fe2f40a93338359ee</url>
  <id>664c0227178ad6d15771173fe2f40a93338359ee</id>
  <committed-date>2009-10-21T06:49:55-07:00</committed-date>
  <authored-date>2009-10-21T06:49:55-07:00</authored-date>
  <message>added unit tests for import</message>
  <tree>e225ccd89ef4c683baa2bb25c9b9e8f06173f355</tree>
  <committer>
    <name>Josh Starcher</name>
    <email>josh@josh-starchers-mac-pro.local</email>
  </committer>
</commit>
