aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/netex_import.rb2
-rw-r--r--config/environments/development.rb7
-rw-r--r--spec/controllers/api/v1/lines_controller_spec.rb2
-rw-r--r--spec/factories/imports.rb5
-rw-r--r--spec/requests/api/v1/netex_import_spec.rb31
5 files changed, 23 insertions, 24 deletions
diff --git a/app/models/netex_import.rb b/app/models/netex_import.rb
index 40eaca523..4a1c6f1e5 100644
--- a/app/models/netex_import.rb
+++ b/app/models/netex_import.rb
@@ -8,7 +8,7 @@ class NetexImport < Import
begin
Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}"))
rescue Exception => e
- logger.error "IEV server error : e.message"
+ logger.error "IEV server error : #{e.message}"
logger.error e.backtrace.inspect
end
end
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 35f697d04..624382000 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -71,10 +71,9 @@ Rails.application.configure do
cas_server: "http://stif-portail-dev.af83.priv/sessions"
}
end
- config.stif_portail_api =
- {
- key: "Ohphie1Voo6the5hohpi",
- url: "http://stif-portail-dev.af83.priv"
+ config.stif_portail_api = {
+ key: "Ohphie1Voo6the5hohpi",
+ url: "http://stif-portail-dev.af83.priv"
}
# Ext. apps links
diff --git a/spec/controllers/api/v1/lines_controller_spec.rb b/spec/controllers/api/v1/lines_controller_spec.rb
index 30c2f1a50..d57eed766 100644
--- a/spec/controllers/api/v1/lines_controller_spec.rb
+++ b/spec/controllers/api/v1/lines_controller_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Api::V1::LinesController, :type => :controller do
let!(:line) { referential.lines.first || create(:line) }
- it_behaves_like "api key protected controller", :wip do
+ it_behaves_like "api key protected controller" do
let(:data){line}
end
describe "GET #index" do
diff --git a/spec/factories/imports.rb b/spec/factories/imports.rb
index eea1894a5..e19fe92bb 100644
--- a/spec/factories/imports.rb
+++ b/spec/factories/imports.rb
@@ -10,9 +10,8 @@ FactoryGirl.define do
started_at nil
ended_at nil
- factory :netex_import do
- type 'NetexImport'
- file {Rails.root.join('spec', 'fixtures', 'terminated_job.json')}
+ factory :netex_import, class: NetexImport do
+ file {File.open(Rails.root.join('spec', 'fixtures', 'terminated_job.json'))}
end
end
end
diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb
index b7a5c94ee..de281aa66 100644
--- a/spec/requests/api/v1/netex_import_spec.rb
+++ b/spec/requests/api/v1/netex_import_spec.rb
@@ -8,63 +8,64 @@ RSpec.describe "NetexImport", type: :request do
let( :file ){ fixture_file_upload( file_path ) }
let( :post_request ) do
- -> do
+ -> (attributes) do
post "/api/v1/netex_imports.json",
attributes,
authorization
end
end
- let( :attributes ){ {
+ let( :legal_attributes ){ {
netex_import: {
name: 'hello world',
file: file,
referential_id: referential.id}
} }
+ let( :illegal_attributes ){ {
+ netex_import: {
+ referential_id: referential.id}
+ } }
+
context 'with correct credentials and correct request' do
let( :authorization ){ authorization_token_header( get_api_key.token ) }
it 'succeeds' do
- post_request.()
+ post_request.(legal_attributes)
expect( response ).to be_success
- expect( JSON.parse(response.body) ).to eq({'id' => NetexImport.last.id, 'type' => 'NetexImport'})
+ expect( json_response_body ).to eq({'id' => NetexImport.last.id, 'type' => 'NetexImport'})
end
it 'creates a NetexImport object in the DB' do
- expect(&post_request).to change{NetexImport.count}.by(1)
+ expect{ post_request.(legal_attributes) }.to change{NetexImport.count}.by(1)
end
end
context 'with incorrect credentials and correct request' do
let( :authorization ){ authorization_token_header( "#{referential.id}-incorrect_token") }
- it 'succeeds not' do
- post_request.()
+ it 'does not succeed' do
+ post_request.(legal_attributes)
expect( response.status ).to eq(401)
end
it 'does not create an Import object' do
- expect(&post_request).not_to change{Import.count}
+ expect{ post_request.(legal_attributes) }.not_to change{Import.count}
end
end
context 'with correct credentials and incorrect request' do
let( :authorization ){ authorization_token_header( get_api_key.token ) }
- let( :attributes ){ {
- netex_import: {
- referential_id: referential.id}
- } }
- it 'succeeds not' do
- post_request.()
+ it 'does not succeed' do
+ post_request.(illegal_attributes)
expect( response.status ).to eq(406)
expect( json_response_body['errors']['file'] ).not_to be_empty
end
it 'does not create an Import object' do
- expect(&post_request).not_to change{Import.count}
+ expect{ post_request.(illegal_attributes) }.not_to change{Import.count}
end
end
end