Skip to content

Commit 611ed9b

Browse files
authored
Merge pull request #126 from activeadmin-plugins/constantize_vars
constantize unchaged variables
2 parents fd2737f + 380cf9c commit 611ed9b

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ group :test do
2323
gem 'pry'
2424
gem 'database_cleaner'
2525
gem 'capybara'
26-
gem 'selenium-webdriver'
2726
gem 'poltergeist'
27+
gem 'selenium-webdriver', '< 3.0', platforms: :ruby_19
2828
gem 'json', '< 2.0', platforms: :ruby_19 # Json 2.0 requires Ruby >= 2.0
2929
gem 'mime-types', '< 3.0.0', platforms: [:ruby_19, :ruby_20]
3030
gem 'tins', '< 1.3.4', platforms: :ruby_19

lib/active_admin_import/model.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
# frozen_string_literal: true
33

44
require 'rchardet'
5+
require 'zip'
56

67
module ActiveAdminImport
78
class Model
89
include ActiveModel::Model
910
include ActiveModel::Validations
1011
include ActiveModel::Validations::Callbacks
1112

13+
module CONST
14+
ZIP_TYPE = 'application/zip'.freeze
15+
TMP_FILE = 'active-admin-import-unzipped'.freeze
16+
CSV_TYPES = %w(
17+
text/csv
18+
text/x-csv
19+
text/x-comma-separated-values
20+
text/comma-separated-values
21+
application/csv
22+
application/vnd.ms-excel
23+
application/vnd.msexcel
24+
).freeze
25+
end
26+
1227
validates :file, presence: {
1328
message: ->(*_) { I18n.t('active_admin_import.no_file_error') }
1429
}, unless: ->(me) { me.new_record? }
@@ -66,7 +81,7 @@ def persisted?
6681
end
6782

6883
def archive?
69-
file_type == 'application/zip'
84+
file_type == CONST::ZIP_TYPE
7085
end
7186

7287
alias to_hash attributes
@@ -90,24 +105,15 @@ def encode_file
90105

91106
def unzip_file
92107
Zip::File.open(file_path) do |zip_file|
93-
self.file = Tempfile.new('active-admin-import-unzipped')
108+
self.file = Tempfile.new(CONST::TMP_FILE)
94109
data = zip_file.entries.select(&:file?).first.get_input_stream.read
95110
file << data
96111
file.close
97112
end
98113
end
99114

100115
def csv_allowed_types
101-
[
102-
'text/csv',
103-
'text/x-csv',
104-
'text/x-comma-separated-values',
105-
'text/comma-separated-values',
106-
'application/csv',
107-
'application/vnd.ms-excel',
108-
'application/vnd.msexcel'
109-
110-
]
116+
CONST::CSV_TYPES
111117
end
112118

113119
def correct_content_type

0 commit comments

Comments
 (0)