aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/import.rb2
-rw-r--r--app/workers/workbench_import_worker.rb19
-rw-r--r--config/environments/development.rb3
-rw-r--r--config/initializers/apartment.rb57
-rw-r--r--spec/controllers/imports_controller_spec.rb1
-rw-r--r--spec/factories/api_keys.rb6
-rw-r--r--spec/models/workbench_import_spec.rb12
-rw-r--r--spec/workers/stop_area_referential_sync_worker_spec.rb1
-rw-r--r--spec/workers/workbench_import_worker_spec.rb25
9 files changed, 95 insertions, 31 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index 535c676b1..3d276c4ae 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -6,7 +6,7 @@ class Import < ActiveRecord::Base
belongs_to :parent, class_name: to_s
extend Enumerize
- enumerize :status, in: %i(new pending successful failed running aborted canceled)
+ enumerize :status, in: %i(new downloading analyzing pending successful failed running aborted canceled)
validates :file, presence: true
diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb
new file mode 100644
index 000000000..3c3d19a66
--- /dev/null
+++ b/app/workers/workbench_import_worker.rb
@@ -0,0 +1,19 @@
+class WorkbenchImportWorker
+ include Sidekiq::Worker
+ attr_reader :import, :downloaded
+
+ def perform(import_id)
+ @import = Import.find(import_id)
+ @downloaded = nil
+ download
+ end
+
+ def download
+
+
+ require 'pry'
+ binding.pry
+ 42
+
+ end
+end
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 5b2bd7402..648a9a82c 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -82,7 +82,8 @@ Rails.application.configure do
config.portal_url = "http://stif-boiv-staging.af83.priv"
# IEV url
- config.iev_url = "http://localhost:8080"
+ config.iev_url = ENV.fetch('IEV_URL', 'http://localhost:8080')
+ config.front_end_url = ENV.fetch('FRONT_END_URL', 'http://localhost:3000')
# file to data for demo
config.demo_data = "tmp/demo.zip"
diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb
index 29ce6564f..e1e86449c 100644
--- a/config/initializers/apartment.rb
+++ b/config/initializers/apartment.rb
@@ -18,34 +18,35 @@ Apartment.configure do |config|
# config.excluded_models = %w{Tenant}
#
config.excluded_models = [
- "Referential",
- "ReferentialMetadata",
- "Organisation",
- "User",
- "Api::V1::ApiKey",
- "RuleParameterSet",
- "StopAreaReferential",
- "StopAreaReferentialMembership",
- "StopAreaReferentialSync",
- "StopAreaReferentialSyncMessage",
- "Chouette::StopArea",
- "LineReferential",
- "LineReferentialMembership",
- "LineReferentialSync",
- "LineReferentialSyncMessage",
- "Chouette::Line",
- "Chouette::GroupOfLine",
- "Chouette::Company",
- "Chouette::Network",
- "ReferentialCloning",
- "Workbench",
- "CleanUp",
- "CleanUpResult",
- "Calendar",
- "Import",
- "NetexImport",
- "ImportMessage",
- "ImportResource"
+ 'Referential',
+ 'ReferentialMetadata',
+ 'Organisation',
+ 'User',
+ 'Api::V1::ApiKey',
+ 'RuleParameterSet',
+ 'StopAreaReferential',
+ 'StopAreaReferentialMembership',
+ 'StopAreaReferentialSync',
+ 'StopAreaReferentialSyncMessage',
+ 'Chouette::StopArea',
+ 'LineReferential',
+ 'LineReferentialMembership',
+ 'LineReferentialSync',
+ 'LineReferentialSyncMessage',
+ 'Chouette::Line',
+ 'Chouette::GroupOfLine',
+ 'Chouette::Company',
+ 'Chouette::Network',
+ 'ReferentialCloning',
+ 'Workbench',
+ 'CleanUp',
+ 'CleanUpResult',
+ 'Calendar',
+ 'Import',
+ 'NetexImport',
+ 'WorkbenchImport',
+ 'ImportMessage',
+ 'ImportResource'
]
# use postgres schemas?
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
index 7b575ab61..f07190496 100644
--- a/spec/controllers/imports_controller_spec.rb
+++ b/spec/controllers/imports_controller_spec.rb
@@ -15,6 +15,7 @@ RSpec.describe ImportsController, :type => :controller do
it 'should be successful' do
get :download, workbench_id: workbench.id, id: import.id, token: import.token_download
expect(response).to be_success
+ expect( response.body ).to eq(import.file.read)
end
end
end
diff --git a/spec/factories/api_keys.rb b/spec/factories/api_keys.rb
new file mode 100644
index 000000000..bd31edecc
--- /dev/null
+++ b/spec/factories/api_keys.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :api_key, class: Api::V1::ApiKey do
+ token { "#{referential.id}-#{SecureRandom.hex}" }
+ referential
+ end
+end
diff --git a/spec/models/workbench_import_spec.rb b/spec/models/workbench_import_spec.rb
new file mode 100644
index 000000000..629973dca
--- /dev/null
+++ b/spec/models/workbench_import_spec.rb
@@ -0,0 +1,12 @@
+RSpec.describe WorkbenchImport do
+ let( :workbench_import ){ build_stubbed :workbench_import }
+
+ it 'is valid' do
+ expect( workbench_import ).to be_valid
+ end
+
+ it 'or not...' do
+ expect( build_stubbed :workbench_import, status: 'what?' ).not_to be_valid
+ end
+
+end
diff --git a/spec/workers/stop_area_referential_sync_worker_spec.rb b/spec/workers/stop_area_referential_sync_worker_spec.rb
index 48b64e55e..50c7cf45f 100644
--- a/spec/workers/stop_area_referential_sync_worker_spec.rb
+++ b/spec/workers/stop_area_referential_sync_worker_spec.rb
@@ -1,4 +1,3 @@
-require 'rails_helper'
RSpec.describe StopAreaReferentialSyncWorker, type: :worker do
let!(:stop_area_referential_sync) { create :stop_area_referential_sync }
diff --git a/spec/workers/workbench_import_worker_spec.rb b/spec/workers/workbench_import_worker_spec.rb
new file mode 100644
index 000000000..bfe631fc4
--- /dev/null
+++ b/spec/workers/workbench_import_worker_spec.rb
@@ -0,0 +1,25 @@
+RSpec.describe WorkbenchImportWorker, type: [:worker, :request] do
+
+ let( :worker ) { described_class.new }
+ let( :import ){ build_stubbed :import }
+ let( :workbench ){ import.workbench }
+ let( :referential ){ import.referential }
+ let( :api_key ){ build_stubbed :api_key, referential: referential }
+
+ let( :path ){ download_workbench_import_path(workbench, import) }
+ let( :result ){ import.file.read }
+
+ before do
+ # That should be `build_stubbed's` job, no?
+ allow(Import).to receive(:find).with(import.id).and_return(import)
+ end
+ it 'downloads a zip file' do
+ # /workbenches/:workbench_id/imports/:id/download
+ stub_request(:get, path)
+ .with(headers: authorization_token_header(api_key))
+ .to_return(body: result)
+ # WTH was I trying to test ;) Ah yeah HTTP into download
+ worker.perform import.id
+ expect( worker.downloaded ).to eq( result )
+ end
+end