require 'rails_helper'

describe WorkflowInstance::IndexCsvBuilder do
  it "handles windows carriage returns" do
    wi = create :workflow_instance_scenario1
    wi.owner_initialization.update(my_explanation: "My explanation\r\n having multiple\rlines\n with extra")
    expected_csv = <<-CSV.strip_heredoc
      SC1,Core initialisatie,HazBeenChecked,Dattum,My identifier,Window from,Window to,Number of visits,My fraction,My explanation,Contr. initialisatie
      ,pending,0,,,,,,,My explanation  having multiple lines  with extra,pending
    CSV

    result = described_class.new([wi], controller: double(record_class: WorkflowInstance::Scenario1)).data
    result.should eq expected_csv

    # works with single resource as well
    result = described_class.new(wi, controller: double(record_class: WorkflowInstance::Scenario1)).data
    result.should eq expected_csv
  end
end
