Skip to content

Commit

Permalink
win1251 real specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell committed Jan 19, 2015
1 parent 50d055c commit 190c8ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/active_admin_import/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ def define_methods_for(attr_name)
end

def encode(data)
data = data.force_encoding("UTF-8")
unless data.valid_encoding?
data = data.encode(force_encoding,
invalid: :replace, undef: :replace, replace: "")
end
data = data.force_encoding(force_encoding) if force_encoding?
data = data.encode('UTF-8',
invalid: :replace, undef: :replace)
begin
data.sub("\xEF\xBB\xBF", "") # bom
rescue ArgumentError => _
rescue StandardError => _
data
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/authors_win1251_win_endline.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Name,Last name,Birthday
Алексей,Панкратов,1986-05-01
�������,���������,1986-05-01
Jane,Roe,1988-11-16
3 changes: 3 additions & 0 deletions spec/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def upload_file!(name, ext='csv')
end

context "Win1251" do
let(:options) {
{template_object: ActiveAdminImport::Model.new(force_encoding: "Windows-1251")}
}

before do
upload_file!(:authors_win1251_win_endline)
Expand Down

0 comments on commit 190c8ce

Please sign in to comment.