@@ -96,7 +96,6 @@ def upload_file!(name, ext='csv')
9696 [ :empty , :only_headers ] . each do |file |
9797 context "when #{ file } file" do
9898 it "should render warning" do
99-
10099 upload_file! ( file )
101100 expect ( page ) . to have_content I18n . t ( 'active_admin_import.file_empty_error' )
102101 expect ( Author . count ) . to eq ( 0 )
@@ -113,6 +112,10 @@ def upload_file!(name, ext='csv')
113112 end
114113
115114 context "Win1251" do
115+ let ( :options ) do
116+ attributes = { force_encoding : "Windows-1251" }
117+ { template_object : ActiveAdminImport ::Model . new ( attributes ) }
118+ end
116119
117120 before do
118121 upload_file! ( :authors_win1251_win_endline )
@@ -153,20 +156,24 @@ def upload_file!(name, ext='csv')
153156 expect ( page ) . to have_content "Successfully imported 1 author"
154157 expect ( Author . count ) . to eq ( 1 )
155158 end
159+
156160 end
157161
158162
159163 context "without headers" do
160164 context "with known csv headers" do
161- let ( :options ) {
162- { template_object : ActiveAdminImport ::Model . new ( csv_headers : [ 'Name' , 'Last name' , 'Birthday' ] ) }
163- }
165+
166+ let ( :options ) do
167+ attributes = { csv_headers : [ 'Name' , 'Last name' , 'Birthday' ] }
168+ { template_object : ActiveAdminImport ::Model . new ( attributes ) }
169+ end
164170
165171 it "should import file" do
166172 upload_file! ( :authors_no_headers )
167173 expect ( page ) . to have_content "Successfully imported 2 authors"
168174 expect ( Author . count ) . to eq ( 2 )
169175 end
176+
170177 end
171178
172179 context "with unknown csv headers" do
@@ -224,10 +231,10 @@ def upload_file!(name, ext='csv')
224231 end
225232
226233 context "when not allowed" do
227- let ( :options ) { {
228- template_object : ActiveAdminImport :: Model . new ( allow_archive : false )
229- } }
230-
234+ let ( :options ) do
235+ attributes = { allow_archive : false }
236+ { template_object : ActiveAdminImport :: Model . new ( attributes ) }
237+ end
231238 it "should render error" do
232239 with_zipped_csv ( :authors ) do
233240 upload_file! ( :authors , :zip )
@@ -240,11 +247,9 @@ def upload_file!(name, ext='csv')
240247
241248 context "with different header attribute names" do
242249
243- let ( :options ) {
244- {
245- headers_rewrites : { :'Second name' => :last_name }
246- }
247- }
250+ let ( :options ) do
251+ { headers_rewrites : { :'Second name' => :last_name } }
252+ end
248253
249254 it "should import file" do
250255 upload_file! ( :author_broken_header )
@@ -254,9 +259,12 @@ def upload_file!(name, ext='csv')
254259 end
255260
256261 context "with semicolons separator" do
257- let ( :options ) {
258- { template_object : ActiveAdminImport ::Model . new ( csv_options : { col_sep : ";" } ) }
259- }
262+
263+ let ( :options ) do
264+ attributes = { csv_options : { col_sep : ";" } }
265+ { template_object : ActiveAdminImport ::Model . new ( attributes ) }
266+ end
267+
260268 it "should import file" do
261269 upload_file! ( :authors_with_semicolons )
262270 expect ( page ) . to have_content "Successfully imported 2 authors"
@@ -268,12 +276,14 @@ def upload_file!(name, ext='csv')
268276
269277
270278 context "with callback procs options" do
271- let ( :options ) { {
272- before_import : proc { |_ |} ,
273- after_import : proc { |_ |} ,
274- before_batch_import : proc { |_ |} ,
275- after_batch_import : proc { |_ |}
276- } }
279+ let ( :options ) do
280+ {
281+ before_import : proc { |_ | } ,
282+ after_import : proc { |_ | } ,
283+ before_batch_import : proc { |_ | } ,
284+ after_batch_import : proc { |_ | }
285+ }
286+ end
277287
278288
279289 it "should call each callback" do
0 commit comments