Permalink
Browse files

we can now upload a csv which populates the database

  • Loading branch information...
1 parent 453e3af commit 8a9a99570181ceb67742323095b2ebf18bfd9fde @lfendy committed Nov 18, 2011
Showing with 20 additions and 20 deletions.
  1. +2 −1 app/controllers/import_csv_controller.rb
  2. +4 −0 spec/fixtures/consultants.csv
  3. +14 −19 spec/integration/upload_file_spec.rb
@@ -2,7 +2,8 @@
class ImportCsvController < ApplicationController
def upload
- consultants = CSVParser.parse params[:dump][:file]
+
+ consultants = CSVParser.parse((params[:dump][:file]).read)
consultants.each do |c|
Consultant.create(c)
end
@@ -0,0 +1,4 @@
+David Oh,Dev,Consultant,doh@thoughtworks.com,ruby
+Weiwei Ding,Dev,Consultant,wding@thoughtworks.com,ruby
+Liauw Fendy,Dev,Consultant,lfendy@thoughtworks.com,ruby
+Pei Shi Yong,Dev,Consultant,pyong@thoughtworks.com,ruby
@@ -1,27 +1,22 @@
require 'spec_helper'
describe "upload_file" do
- before :each do
- str = <<TAG
-David Oh,Dev,Consultant,doh@thoughtworks.com,ruby
-Weiwei Ding,Dev,Consultant,wding@thoughtworks.com,ruby
-Liauw Fendy,Dev,Consultant,lfendy@thoughtworks.com,ruby
-Pei Shi Yong,Dev,Consultant,pyong@thoughtworks.com,ruby
-TAG
- post 'import_csv', {:dump => {:file => str}}
- end
- it "should create the correct number entries in the database" do
- Consultant.count.should== 4
- end
+ describe "uploads file and populate the database" do
+ let(:test_file) do
+ fixture_file_upload('/consultants.csv', 'text/plain')
+ end
- it "should create consultants with the correct attributes" do
- c = Consultant.find_by_name("David Oh")
- c.should be
- c.role.should == "Dev"
- c.email.should == "doh@thoughtworks.com"
- c.skill.should == "ruby"
- c.grade.should == "Consultant"
+ it "should create entries in database" do
+ post 'import_csv', {:dump => {:file => test_file}}
+ Consultant.count.should_not == 0
+ c = Consultant.find_by_name("David Oh")
+ c.should be
+ c.role.should == "Dev"
+ c.email.should == "doh@thoughtworks.com"
+ c.skill.should == "ruby"
+ c.grade.should == "Consultant"
+ end
end
end

0 comments on commit 8a9a995

Please sign in to comment.