aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-07-19 18:41:01 +0200
committerRobert2017-07-19 18:41:01 +0200
commitb1904db1a8145620f600736a9933c043a4dfcf9f (patch)
tree7bd7923721d1614080bb62b705b1d045b6fee42f /spec
parentd2abe2d195a8a8a3bf4539816049be60ca06e187 (diff)
downloadchouette-core-b1904db1a8145620f600736a9933c043a4dfcf9f.tar.bz2
Refs: #3506@1h; Code Review
Diffstat (limited to 'spec')
-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
3 files changed, 19 insertions, 19 deletions
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