diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/stif/permission_translator.rb | 2 | ||||
| -rw-r--r-- | lib/tasks/ci.rake | 37 | ||||
| -rw-r--r-- | lib/tom_tom.rb | 28 | ||||
| -rw-r--r-- | lib/tom_tom/matrix.rb | 1 | 
4 files changed, 47 insertions, 21 deletions
| diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 09a7c610c..aefe50fe1 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -48,7 +48,7 @@ module Stif      def translation_table        {          "boiv:read-offer" => %w{sessions.create}, -        "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create}, +        "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create workbenches.update},        }      end diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index cb9ed77e7..0723e4ccb 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -8,12 +8,21 @@ namespace :ci do        end    end +  def parallel_tests? +    ENV["PARALLEL_TESTS"] == "true" +  end +    desc "Prepare CI build"    task :setup do      cp "config/database.yml", "config/database.yml.orig"      cp "config/database/ci.yml", "config/database.yml"      puts "Use #{database_name} database" -    sh "RAILS_ENV=test rake db:drop db:create db:migrate" + +    if parallel_tests? +      sh "RAILS_ENV=test rake parallel:drop parallel:create parallel:migrate" +    else +      sh "RAILS_ENV=test rake db:drop db:create db:migrate" +    end    end    def git_branch @@ -43,11 +52,7 @@ namespace :ci do    end    task :assets do -    sh "RAILS_ENV=test bundle exec rake assets:precompile" -  end - -  task :i18n_js_export do -    sh "RAILS_ENV=test bundle exec rake i18n:js:export" +    sh "RAILS_ENV=test bundle exec rake assets:precompile i18n:js:export"    end    task :jest do @@ -71,12 +76,28 @@ namespace :ci do      sh "RAILS_ENV=test bundle exec rake assets:clobber"    end -  task :build => ["ci:setup", "ci:assets", "ci:i18n_js_export", "spec", "ci:jest", "cucumber", "ci:check_security"] +  task :spec do +    if parallel_tests? +      # parallel tasks invokes this task .. +      # but development db isn't available during ci tasks +      Rake::Task["db:abort_if_pending_migrations"].clear + +      Rake::Task["parallel:spec"].invoke +    else +      Rake::Task["spec"].invoke +    end +  end + +  task :build => ["ci:setup", "ci:assets", "ci:spec", "ci:jest", "cucumber", "ci:check_security"]    namespace :docker do      task :clean do        puts "Drop #{database_name} database" -      sh "RAILS_ENV=test rake db:drop" +      if parallel_tests? +        sh "RAILS_ENV=test rake parallel:drop" +      else +        sh "RAILS_ENV=test rake db:drop" +      end        # Restore projet config/database.yml        # cp "config/database.yml.orig", "config/database.yml" if File.exists?("config/database.yml.orig") diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index fcebcc7ac..91f1a3800 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -1,26 +1,30 @@  module TomTom    BASE_URL = 'https://api.tomtom.com' -  @api_key = Rails.application.secrets.tomtom_api_key -  @connection = Faraday.new( -    url: BASE_URL, -    params: { -      key: @api_key -    } -  ) do |faraday| -    faraday.use FaradayMiddleware::FollowRedirects, limit: 1 -    faraday.adapter Faraday.default_adapter +  @@api_key = Rails.application.secrets.tomtom_api_key +  cattr_accessor :api_key + +  def self.connection +    @connection ||= Faraday.new( +      url: BASE_URL, +      params: { +        key: api_key +      } +    ) do |faraday| +      faraday.use FaradayMiddleware::FollowRedirects, limit: 1 +      faraday.adapter Faraday.default_adapter +    end    end    def self.enabled? -    @api_key.present? +    api_key.present? && /[a-zA-Z0-9]{32}/ === api_key    end    def self.batch(way_costs) -    TomTom::Batch.new(@connection).batch(way_costs) +    TomTom::Batch.new(connection).batch(way_costs)    end    def self.matrix(way_costs) -    TomTom::Matrix.new(@connection).matrix(way_costs) +    TomTom::Matrix.new(connection).matrix(way_costs)    end  end diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index 96518f7cf..e779abbf7 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -19,6 +19,7 @@ module TomTom          req.headers['Content-Type'] = 'application/json'          req.params[:routeType] = 'shortest' +        req.params[:traffic] = 'false'          req.params[:travelMode] = 'bus'          req.body = build_request_body(points) | 
