OSDN Git Service

CSV処理がテストに通るよう修正
authorYOSHIDA Hiroki <hyoshida@appirits.com>
Tue, 14 May 2013 12:50:02 +0000 (21:50 +0900)
committerYOSHIDA Hiroki <hyoshida@appirits.com>
Wed, 15 May 2013 02:55:52 +0000 (11:55 +0900)
app/controllers/admin/orders_controller.rb
app/controllers/admin/products_controller.rb
app/controllers/admin/return_items_controller.rb
app/controllers/admin/stock_csv_controller.rb
app/controllers/admin/totals_controller.rb
app/models/order.rb
app/models/product.rb
config/initializers/add_csv_download/add_csv_download.rb
lib/csv_util.rb

index 571e614..6ded5b2 100644 (file)
@@ -89,7 +89,7 @@ class Admin::OrdersController < Admin::BaseController
   def csv_download
     get_search_form
     csv_data, filename = Order.csv(@search_list)
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
 
   private
index c3ab496..9e80d2d 100644 (file)
@@ -111,7 +111,7 @@ class Admin::ProductsController < Admin::BaseController
     @search_list = []
     get_search_form
     csv_data, filename = Product.csv(@search_list)
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
 
   def csv_upload
@@ -144,7 +144,7 @@ class Admin::ProductsController < Admin::BaseController
     @search_list = []
     get_search_form
     csv_data, filename = Product.actual_count_list_csv(@search_list)
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
 
   protected
index a3b4f52..70d76ab 100644 (file)
@@ -130,7 +130,7 @@ class Admin::ReturnItemsController < Admin::BaseController
     title = %w(商品ID 商品コード 商品名 規格名称 商品型番 返品数 返品日時)
     
     csv_data = CSVUtil.make_csv_string(rows, title)   
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
     
 
index c746eb6..e4ada70 100644 (file)
@@ -46,7 +46,7 @@ class Admin::StockCsvController < Admin::BaseController
     filename = '%s.csv' % name
     title = %w(商品コード 商品名 仕入先名 実在庫数 不良在庫数)
     csv_data = CSVUtil.make_csv_string(rows, title)  
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
   
   private
index f0005bd..e6ae9ce 100644 (file)
@@ -55,7 +55,7 @@ class Admin::TotalsController < Admin::BaseController
   def csv
     totalizer = Object.const_get("#{params[:page]}_totalizer".classify)
     csv_data, filename = totalizer.csv(params)
-    send_data(csv_data, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
+    send_data(csv_data.tosjis, :type => "application/octet-stream; name=#{filename}; charset=shift_jis; header=present",:disposition => 'attachment', :filename => filename)
   end
 end
 
index 297b5d7..854df26 100644 (file)
@@ -131,7 +131,7 @@ class Order < ActiveRecord::Base
       end
     end
     filename = "order_#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
-    [str.tosjis, filename]
+    [str, filename]
   end
 
   private
index 86b2b9f..4ec29d2 100644 (file)
@@ -308,7 +308,7 @@ class Product < ActiveRecord::Base
       end
     end
     filename = "product_#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
-    [str.tosjis, filename]
+    [str, filename]
   end
 
   def self.actual_count_list_csv(search_list)
@@ -329,7 +329,7 @@ class Product < ActiveRecord::Base
       end
     end
     filename = "actual_count_list_#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
-    [str.tosjis, filename]
+    [str, filename]
   end
 
   def master_shop?
index 3171653..99b183a 100644 (file)
@@ -26,7 +26,7 @@ module AddCSVDownload
         end
       end
       filename = "#{csv_output_setting_name}#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"      
-      [str.tosjis, filename]
+      [str, filename]
     end
 
     private
index cd6c7e8..05fd143 100644 (file)
@@ -34,17 +34,11 @@ class CSVUtil
       return pairs
     end
     
-    def make_csv_string(rows, title)
-      # date = DateTime.now
-      # CSV に吐く
-      str = CSV.generate("") do |writer|
-        writer << title
-        rows.each do |row|
-          writer << row
-        end
+    def make_csv_string(rows, header)
+      CSV.generate do |writer|
+        writer << header
+        rows.each {|row| writer << row }
       end
-      return str.tosjis
     end
-
   end
 end