Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #18 from vijendra/master

Please make a pull.
  • Loading branch information...
commit fe55376f3fab4d0edec5d95abc3a3199cdd85305 2 parents beaf3a7 + c518bcf
@schorsch schorsch authored
Showing with 17 additions and 8 deletions.
  1. +5 −7 app/models/attachment.rb
  2. +12 −1 spec/models/attachment_spec.rb
View
12 app/models/attachment.rb
@@ -53,15 +53,13 @@ def rows(size = 0)
# When parsing data, we expect our file to be saved as valid utf-8
def parsed_data
@parsed_data ||= begin
- CSV.read(full_filename, col_sep: col_sep, quote_char: quote_char, row_sep: "rn", encoding: "ISO-8859-1:UTF-8")
- rescue CSV::MalformedCSVError
+ CSV.read(full_filename, col_sep: col_sep, quote_char: quote_char)
+ rescue CSV::MalformedCSVError => er
rows = []
- #one more attempt. #TODO check if this is required.
+ #one more attempt. If BOM is present in the file.
begin
- f = File.open(full_filename, "r:ISO-8859-1")
- CSV.parse(f.read.encode("UTF-8") , col_sep: col_sep, quote_char: quote_char) do |row|
- rows << row
- end
+ f = File.open(full_filename, "rb:bom|utf-8")
+ rows = CSV.parse(f.read.force_encoding("ISO-8859-1"))
ensure
return rows
end
View
13 spec/models/attachment_spec.rb
@@ -27,4 +27,15 @@
it "reveals specified number of rows" do
@attachment.rows(1).size.should == 1
end
-end
+
+ describe "different csv formats" do
+ {'google_native_test_.csv' => 3, 'google_outlook_test.csv' => 3, 'test1.csv' => 2}.each do |csv_file, count|
+ it "should able to read #{csv_file}" do
+ attachment = Factory(:attachment, :uploaded_data => file_upload(csv_file))
+ attachment.rows.first.size.should be > 1
+ attachment.rows.size.should == count
+ end
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.