Skip to content

Commit

Permalink
fix import csv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lfendy committed Nov 18, 2011
1 parent 8a9a995 commit 82bff0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion app/controllers/import_csv_controller.rb
Expand Up @@ -2,7 +2,6 @@

class ImportCsvController < ApplicationController
def upload

consultants = CSVParser.parse((params[:dump][:file]).read)
consultants.each do |c|
Consultant.create(c)
Expand Down
13 changes: 10 additions & 3 deletions spec/controllers/import_csv_controller_spec.rb
Expand Up @@ -3,24 +3,31 @@

describe ImportCsvController do
describe "upload csv" do
before :each do
file = ""
file.stub(:read).and_return("haha")
controller.stub!(:params).and_return({
:dump => {:file => file}
})
end

it 'should parse the csv file' do
CSVParser.should_receive(:parse).with("haha").and_return([])
post 'upload', {:dump => {:file => "haha" }}
post 'upload'
end

it "should create the same number of consultants that was parsed" do
hashes = [{}, {}]
CSVParser.stub(:parse).and_return(hashes)
Consultant.should_receive(:create).twice
post 'upload', {:dump => {:file => "haha" }}
post 'upload'
end

it "should create consultants with the parsed attributes" do
hashes = [{:key=>nil}]
CSVParser.stub(:parse).and_return(hashes)
Consultant.should_receive(:create).with(hashes.first)
post 'upload', {:dump => {:file => "haha" }}
post 'upload'
end
end

Expand Down

0 comments on commit 82bff0a

Please sign in to comment.