Commit 44f3264c2e3021d2abaebadaf1d92769ef5e60f7

Authored by Luke Baker
1 parent 65f54225

use FasterCSV gem only for ruby 1.8

Gemfile
... ... @@ -19,7 +19,7 @@ gem "has_scope", "0.4.2"
19 19 gem "responders", "0.4.8"
20 20 gem "thoughtbot-clearance", "0.8.2",
21 21 :require => "clearance"
22   -gem "fastercsv", "1.5.1"
  22 +gem "fastercsv", "1.5.1", :platforms => :ruby_18
23 23 gem "delayed_job", "2.0.6"
24 24 gem "redis", "~> 3.0.1"
25 25  
... ...
app/models/question.rb
... ... @@ -580,7 +580,7 @@ class Question < ActiveRecord::Base
580 580 raise "Unsupported export type: #{type}"
581 581 end
582 582  
583   - csv_data = FasterCSV.generate do |csv|
  583 + csv_data = CSVBridge.generate do |csv|
584 584 csv << headers
585 585 case type
586 586 when 'votes'
... ...
lib/csv_bridge.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require 'csv'
  2 +require 'fastercsv'
  3 +
  4 +if CSV.const_defined?(:Reader)
  5 + class CSVBridge < FasterCSV
  6 + end
  7 +else
  8 + class CSVBridge < CSV
  9 + end
  10 +end
... ...
lib/tasks/import_bt_test_data.rb
... ... @@ -11,7 +11,7 @@ inserts = []
11 11  
12 12 timestring = Time.now.to_s(:db) #isn't rails awesome?
13 13 totalchoices=0
14   -FasterCSV.foreach(BASEDIR + "choices_7000.txt", {:headers => :first_row, :return_headers => false}) do |choice|
  14 +CSVBridge.foreach(BASEDIR + "choices_7000.txt", {:headers => :first_row, :return_headers => false}) do |choice|
15 15 # for each choice, create an insert with unique id
16 16 id = choice[0].to_i + choice_offset
17 17 wins = choice[1].to_i
... ... @@ -26,7 +26,7 @@ ActiveRecord::Base.connection.execute(sql)
26 26 inserts = []
27 27 prompt_offset = Prompt.last.id
28 28 totalprompts = 0
29   -FasterCSV.foreach(BASEDIR + "prompts_7000.txt", {:headers => :first_row, :return_headers => false}) do |prompt|
  29 +CSVBridge.foreach(BASEDIR + "prompts_7000.txt", {:headers => :first_row, :return_headers => false}) do |prompt|
30 30 id = prompt[0].to_i + prompt_offset
31 31 left_choice_id = prompt[1].to_i + choice_offset
32 32 right_choice_id = prompt[2].to_i + choice_offset
... ... @@ -43,7 +43,7 @@ ActiveRecord::Base.connection.execute(sql)
43 43 inserts = []
44 44 vote_offset = Vote.last.id
45 45 totalvotes=0
46   -FasterCSV.foreach(BASEDIR + "votes_7000.txt", {:headers => :first_row, :return_headers => false}) do |vote|
  46 +CSVBridge.foreach(BASEDIR + "votes_7000.txt", {:headers => :first_row, :return_headers => false}) do |vote|
47 47 id = vote[0].to_i + vote_offset
48 48 prompt_id = vote[1].to_i + prompt_offset
49 49 choice_id = vote[2].to_i + choice_offset
... ...
spec/models/question_spec.rb
... ... @@ -539,7 +539,7 @@ describe Question do
539 539  
540 540 # Not specifying exact file syntax, it's likely to change frequently
541 541 #
542   - rows = FasterCSV.parse(csv)
  542 + rows = CSVBridge.parse(csv)
543 543 rows.first.should include("Vote ID")
544 544 rows.first.should_not include("Idea ID")
545 545  
... ... @@ -567,7 +567,7 @@ describe Question do
567 567 it "should export non vote data to a string" do
568 568 csv = @aoi_question.export('non_votes')
569 569  
570   - rows = FasterCSV.parse(csv)
  570 + rows = CSVBridge.parse(csv)
571 571 rows.first.should include("Record ID")
572 572 rows.first.should include("Record Type")
573 573 rows.first.should_not include("Idea ID")
... ... @@ -580,7 +580,7 @@ describe Question do
580 580  
581 581 # Not specifying exact file syntax, it's likely to change frequently
582 582 #
583   - rows = FasterCSV.parse(csv)
  583 + rows = CSVBridge.parse(csv)
584 584 rows.first.should include("Idea ID")
585 585 rows.first.should_not include("Skip ID")
586 586 end
... ... @@ -648,7 +648,7 @@ describe Question do
648 648  
649 649 # Not specifying exact file syntax, it's likely to change frequently
650 650 #
651   - rows = FasterCSV.parse(csv)
  651 + rows = CSVBridge.parse(csv)
652 652 rows.first.should include("Idea ID")
653 653 rows.first.should_not include("Skip ID")
654 654  
... ... @@ -664,7 +664,7 @@ describe Question do
664 664  
665 665 # Not specifying exact file syntax, it's likely to change frequently
666 666 #
667   - rows = FasterCSV.parse(csv)
  667 + rows = CSVBridge.parse(csv)
668 668 rows.first.should include("Vote ID")
669 669 rows.first.should_not include("Idea ID")
670 670  
... ...