I just started my ImportsController and was this was really the way to
go:
////////import.rb/////////////////
class Import < ActiveRecord::Base
has_attached_file :csv
validates_attachment_presence :csv
after_save :process_csv
private
def process_csv
FasterCSV.foreach( csv.path) do |row|
#TODO
end
end
end
/////////import_spec.rb/////////////////
require 'spec_helper'
describe Import do
it "should should succeed creating a valid Import from the factory" do
import = Factory.build(:import)
import.csv.stub!(:url).and_return("#{RAILS_ROOT}/spec/csv/3_products.csv")
import.save
end
describe "handling CSV files" do
describe "to import products" do
before(:each) do
@import = Factory.build(:import)
@import.csv.stub!(:url).and_return("#{RAILS_ROOT}/spec/csv/3_products.csv")
end
def do_save
@import.save
end
it "should process the csv file after save" do
@import.should_receive(:process_csv)
do_save
end
it "should load the csv file" do
FasterCSV.should_receive(:foreach)
do_save
end
end
end
end
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users