Commit 44f3264c2e3021d2abaebadaf1d92769ef5e60f7
1 parent
65f54225
Exists in
master
and in
1 other branch
use FasterCSV gem only for ruby 1.8
Showing
5 changed files
with
20 additions
and
10 deletions
Show diff stats
Gemfile
| @@ -19,7 +19,7 @@ gem "has_scope", "0.4.2" | @@ -19,7 +19,7 @@ gem "has_scope", "0.4.2" | ||
| 19 | gem "responders", "0.4.8" | 19 | gem "responders", "0.4.8" |
| 20 | gem "thoughtbot-clearance", "0.8.2", | 20 | gem "thoughtbot-clearance", "0.8.2", |
| 21 | :require => "clearance" | 21 | :require => "clearance" |
| 22 | -gem "fastercsv", "1.5.1" | 22 | +gem "fastercsv", "1.5.1", :platforms => :ruby_18 |
| 23 | gem "delayed_job", "2.0.6" | 23 | gem "delayed_job", "2.0.6" |
| 24 | gem "redis", "~> 3.0.1" | 24 | gem "redis", "~> 3.0.1" |
| 25 | 25 |
app/models/question.rb
| @@ -580,7 +580,7 @@ class Question < ActiveRecord::Base | @@ -580,7 +580,7 @@ class Question < ActiveRecord::Base | ||
| 580 | raise "Unsupported export type: #{type}" | 580 | raise "Unsupported export type: #{type}" |
| 581 | end | 581 | end |
| 582 | 582 | ||
| 583 | - csv_data = FasterCSV.generate do |csv| | 583 | + csv_data = CSVBridge.generate do |csv| |
| 584 | csv << headers | 584 | csv << headers |
| 585 | case type | 585 | case type |
| 586 | when 'votes' | 586 | when 'votes' |
lib/tasks/import_bt_test_data.rb
| @@ -11,7 +11,7 @@ inserts = [] | @@ -11,7 +11,7 @@ inserts = [] | ||
| 11 | 11 | ||
| 12 | timestring = Time.now.to_s(:db) #isn't rails awesome? | 12 | timestring = Time.now.to_s(:db) #isn't rails awesome? |
| 13 | totalchoices=0 | 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 | # for each choice, create an insert with unique id | 15 | # for each choice, create an insert with unique id |
| 16 | id = choice[0].to_i + choice_offset | 16 | id = choice[0].to_i + choice_offset |
| 17 | wins = choice[1].to_i | 17 | wins = choice[1].to_i |
| @@ -26,7 +26,7 @@ ActiveRecord::Base.connection.execute(sql) | @@ -26,7 +26,7 @@ ActiveRecord::Base.connection.execute(sql) | ||
| 26 | inserts = [] | 26 | inserts = [] |
| 27 | prompt_offset = Prompt.last.id | 27 | prompt_offset = Prompt.last.id |
| 28 | totalprompts = 0 | 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 | id = prompt[0].to_i + prompt_offset | 30 | id = prompt[0].to_i + prompt_offset |
| 31 | left_choice_id = prompt[1].to_i + choice_offset | 31 | left_choice_id = prompt[1].to_i + choice_offset |
| 32 | right_choice_id = prompt[2].to_i + choice_offset | 32 | right_choice_id = prompt[2].to_i + choice_offset |
| @@ -43,7 +43,7 @@ ActiveRecord::Base.connection.execute(sql) | @@ -43,7 +43,7 @@ ActiveRecord::Base.connection.execute(sql) | ||
| 43 | inserts = [] | 43 | inserts = [] |
| 44 | vote_offset = Vote.last.id | 44 | vote_offset = Vote.last.id |
| 45 | totalvotes=0 | 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 | id = vote[0].to_i + vote_offset | 47 | id = vote[0].to_i + vote_offset |
| 48 | prompt_id = vote[1].to_i + prompt_offset | 48 | prompt_id = vote[1].to_i + prompt_offset |
| 49 | choice_id = vote[2].to_i + choice_offset | 49 | choice_id = vote[2].to_i + choice_offset |
spec/models/question_spec.rb
| @@ -539,7 +539,7 @@ describe Question do | @@ -539,7 +539,7 @@ describe Question do | ||
| 539 | 539 | ||
| 540 | # Not specifying exact file syntax, it's likely to change frequently | 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 | rows.first.should include("Vote ID") | 543 | rows.first.should include("Vote ID") |
| 544 | rows.first.should_not include("Idea ID") | 544 | rows.first.should_not include("Idea ID") |
| 545 | 545 | ||
| @@ -567,7 +567,7 @@ describe Question do | @@ -567,7 +567,7 @@ describe Question do | ||
| 567 | it "should export non vote data to a string" do | 567 | it "should export non vote data to a string" do |
| 568 | csv = @aoi_question.export('non_votes') | 568 | csv = @aoi_question.export('non_votes') |
| 569 | 569 | ||
| 570 | - rows = FasterCSV.parse(csv) | 570 | + rows = CSVBridge.parse(csv) |
| 571 | rows.first.should include("Record ID") | 571 | rows.first.should include("Record ID") |
| 572 | rows.first.should include("Record Type") | 572 | rows.first.should include("Record Type") |
| 573 | rows.first.should_not include("Idea ID") | 573 | rows.first.should_not include("Idea ID") |
| @@ -580,7 +580,7 @@ describe Question do | @@ -580,7 +580,7 @@ describe Question do | ||
| 580 | 580 | ||
| 581 | # Not specifying exact file syntax, it's likely to change frequently | 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 | rows.first.should include("Idea ID") | 584 | rows.first.should include("Idea ID") |
| 585 | rows.first.should_not include("Skip ID") | 585 | rows.first.should_not include("Skip ID") |
| 586 | end | 586 | end |
| @@ -648,7 +648,7 @@ describe Question do | @@ -648,7 +648,7 @@ describe Question do | ||
| 648 | 648 | ||
| 649 | # Not specifying exact file syntax, it's likely to change frequently | 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 | rows.first.should include("Idea ID") | 652 | rows.first.should include("Idea ID") |
| 653 | rows.first.should_not include("Skip ID") | 653 | rows.first.should_not include("Skip ID") |
| 654 | 654 | ||
| @@ -664,7 +664,7 @@ describe Question do | @@ -664,7 +664,7 @@ describe Question do | ||
| 664 | 664 | ||
| 665 | # Not specifying exact file syntax, it's likely to change frequently | 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 | rows.first.should include("Vote ID") | 668 | rows.first.should include("Vote ID") |
| 669 | rows.first.should_not include("Idea ID") | 669 | rows.first.should_not include("Idea ID") |
| 670 | 670 |