Skip to content

Commit

Permalink
allow change headers in callabcks, specs added
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell committed Mar 18, 2015
1 parent cb44dc2 commit 771d851
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 77 deletions.
5 changes: 3 additions & 2 deletions lib/active_admin_import/importer.rb
Expand Up @@ -2,7 +2,8 @@
module ActiveAdminImport
class Importer

attr_reader :resource, :options, :result, :headers, :csv_lines, :model
attr_reader :resource, :options, :result, :model
attr_accessor :csv_lines, :headers

OPTIONS = [
:validate,
Expand Down Expand Up @@ -85,7 +86,7 @@ def process_file
end

def prepare_headers
headers = self.headers.present? ? self.headers : yield
headers = self.headers.present? ? self.headers.map(&:to_s) : yield
@headers = Hash[headers.zip(headers.map { |el| el.underscore.gsub(/\s+/, '_') })].with_indifferent_access
@headers.merge!(options[:headers_rewrites].symbolize_keys.slice(*@headers.symbolize_keys.keys))
@headers
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/files/posts_for_author.csv
@@ -0,0 +1,3 @@
"Title","Body"
"title1","some body"
"title2","some body"
2 changes: 2 additions & 0 deletions spec/fixtures/files/posts_for_author_no_headers.csv
@@ -0,0 +1,2 @@
"title1","some body"
"title2","some body"

0 comments on commit 771d851

Please sign in to comment.