File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed
Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def import_options
8080 protected
8181
8282 def prepare_headers ( headers )
83- @headers = Hash [ headers . zip ( headers . map { |el | el . underscore . gsub ( /\s +/ , '_' ) } ) ]
83+ @headers = Hash [ headers . zip ( headers . map { |el | el . underscore . gsub ( /\s +/ , '_' ) } ) ] . with_indifferent_access
8484 @headers . merge! ( options [ :headers_rewrites ] )
8585 @headers
8686 end
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ module ActiveAdminImport
1616 :template_object ,
1717 :resource_class ,
1818 :resource_label ,
19- :plural_resource_label
19+ :plural_resource_label ,
20+ :headers_rewrites
2021 ] . freeze
2122
2223
Original file line number Diff line number Diff line change 1+ Name,Second name,Birthday
2+ John,Doe,1986-05-01
Original file line number Diff line number Diff line change @@ -145,6 +145,20 @@ def upload_file!(name, ext='csv')
145145 end
146146 end
147147
148+ context "with different header attribute names" do
149+
150+ let ( :options ) {
151+ {
152+ headers_rewrites : { :'Second name' => :last_name }
153+ }
154+ }
155+
156+ it "should import file" do
157+ upload_file! ( :author_broken_header )
158+ expect ( page ) . to have_content "Successfully imported 1 author"
159+ expect ( Author . count ) . to eq ( 1 )
160+ end
161+ end
148162
149163 context "with semicolons separator" do
150164 let ( :options ) {
You can’t perform that action at this time.
0 commit comments