require "rails_helper"

# Test against de implemented csv builder in
#   spec/dummy/app/csv_builders/csv_builder.rb
# that implements the module
describe CsvBuilder do

  describe ".find_for_route" do
    it "returns the actual builder class" do
      described_class.find_for_route("workflow_instance/scenario1s#selection").should eq WorkflowInstance::SelectionCsvBuilder
      described_class.find_for_route("workflow_instance/scenario2s#selection").should eq WorkflowInstance::Scenario2::SelectionCsvBuilder
    end

    it "returns nil when no builder can be found" do
      described_class.find_for_route("bogus/route#show").should eq nil
    end
  end

  describe ".find_for_route_lookup_order" do
    it "returns the preferred lookup order highest priority first" do
      described_class.find_for_route_lookup_order("workflow_instance/scenario1s#selection").should eq [
        'WorkflowInstance::Scenario1::SelectionCsvBuilder',
        'WorkflowInstance::SelectionCsvBuilder'
      ]
    end
  end

  describe "#data" do
    it "uses #to_csv for base class builders" do
      described_class.new(double(to_csv: 'custom;csv')).data.should eq "custom;csv"
    end

  end
end
