Skip to content

Commit

Permalink
fix importing csv with BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell committed Jan 18, 2015
1 parent 3785366 commit bf3f5dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_admin_import/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def file_path
def encode_file
data = File.read(file_path).encode(force_encoding, invalid: :replace, undef: :replace)
File.open(file_path, 'w') do |f|
f.write(data)
f.write(data.sub("\xEF\xBB\xBF")) #without bom
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/files/authors_bom.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,Last name,Birthday
John,Doe,1986-05-01
Jane,Roe,1988-11-16
9 changes: 9 additions & 0 deletions spec/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ def upload_file!(name, ext='csv')
end
end

context "BOM" do
it "should import file with many records" do
upload_file!(:authors_bom)
expect(page).to have_content "Successfully imported 2 authors"
expect(Author.count).to eq(2)
end

end

context "with headers" do

it "should import file with many records" do
Expand Down

0 comments on commit bf3f5dd

Please sign in to comment.