Skip to content

Commit

Permalink
Option to force old headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecadeline committed Apr 26, 2021
1 parent f0736e1 commit 80a69b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v01/entities/vrp_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ module VrpConfiguration
optional(:geometry_polyline, type: Boolean, documentation: { hidden: true }, desc: '[DEPRECATED] Use geometry instead, with :polylines or :encoded_polylines')
optional(:intermediate_solutions, type: Boolean, desc: 'Return intermediate solutions if available')
optional(:csv, type: Boolean, desc: 'The output is a CSV file if you do not specify api format')
optional(:use_deprecated_csv_headers, type: Boolean, desc: 'Forces API to ignore provided language to return old CSV headers')
optional(:allow_empty_result, type: Boolean, desc: 'Allow no solution from the solver used')
end

Expand Down
8 changes: 8 additions & 0 deletions models/vrp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def self.filter(hash)
self.remove_unnecessary_relations(hash)
self.generate_schedule_indices_from_date(hash)
self.generate_linked_service_ids_for_relations(hash)
self.use_deprecated_csv_headers(hash)
end

def self.remove_unnecessary_units(hash)
Expand Down Expand Up @@ -589,6 +590,13 @@ def self.generate_linked_service_ids_for_relations(hash)
}
end

def self.use_deprecated_csv_headers(hash)
return unless hash[:configuration] && hash[:configuration][:restitution]&.key?(:use_deprecated_csv_headers)

I18n.locale = :legacy if hash[:configuration][:restitution][:use_deprecated_csv_headers]
hash[:configuration][:restitution].delete(:use_deprecated_csv_headers)
end

def configuration=(configuration)
self.config = configuration
self.preprocessing = configuration[:preprocessing] if configuration[:preprocessing]
Expand Down
10 changes: 10 additions & 0 deletions test/api/v01/output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ def test_provided_language
submit_csv api_key: 'demo', vrp: vrp, http_accept_language: provided
end
}

vrp[:configuration][:restitution][:use_deprecated_csv_headers] = true # test with false too
OutputHelper::Result.stub(
:build_csv,
lambda { |_solutions|
assert_equal :legacy, I18n.locale # default valuen when http_accept_language is unknown
}
) do
submit_csv api_key: 'demo', vrp: vrp, http_accept_language: 'fr'
end
end

def test_returned_types
Expand Down

0 comments on commit 80a69b1

Please sign in to comment.