aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/tom_tom_spec.rb12
-rw-r--r--spec/models/user_spec.rb4
-rw-r--r--spec/requests/api/v1/netex_import_spec.rb238
-rw-r--r--spec/services/route_way_cost_calculator_spec.rb4
-rw-r--r--spec/views/line_referentials/show.html.slim_spec.rb28
-rw-r--r--spec/views/stop_area_referentials/show.html.slim_spec.rb27
6 files changed, 165 insertions, 148 deletions
diff --git a/spec/lib/tom_tom_spec.rb b/spec/lib/tom_tom_spec.rb
index 71584e242..4571609c3 100644
--- a/spec/lib/tom_tom_spec.rb
+++ b/spec/lib/tom_tom_spec.rb
@@ -1,15 +1,19 @@
RSpec.describe TomTom do
describe ".enabled?" do
it "returns true when API key is set" do
- TomTom.instance_variable_set(:@api_key, 'fake key')
-
+ dummy_key = ['a'..'z','A'..'Z',0..9].map(&:to_a).flatten.sample(32).join
+ allow(TomTom).to receive(:api_key).and_return dummy_key
expect(TomTom.enabled?).to be true
end
it "returns false without an API key" do
- TomTom.instance_variable_set(:@api_key, '')
+ allow(TomTom).to receive(:api_key).and_return ''
+ expect(TomTom.enabled?).to be_falsy
+ end
- expect(TomTom.enabled?).to be false
+ it "returns false when API key is malformed" do
+ allow(TomTom).to receive(:api_key).and_return 'it will not work'
+ expect(TomTom.enabled?).to be_falsy
end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 51ccfccd3..17fa38d4a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -90,8 +90,8 @@ RSpec.describe User, :type => :model do
expect(user.name).to eq('Alban Peignier')
expect(user.email).to eq('alban.peignier@af83.com')
- expect(user.updated_at.utc).to be_within(1.second).of Time.now
- expect(user.synced_at.utc).to be_within(1.second).of Time.now
+ expect(user.updated_at.utc).to be_within(3.second).of Time.now
+ expect(user.synced_at.utc).to be_within(3.second).of Time.now
end
it 'should update organisation assignement' do
diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb
index a108b476f..6518e063c 100644
--- a/spec/requests/api/v1/netex_import_spec.rb
+++ b/spec/requests/api/v1/netex_import_spec.rb
@@ -1,119 +1,119 @@
-RSpec.describe "Import::Netex", type: :request do
-
- describe 'POST netex_imports' do
-
- let( :referential ){ create :workbench_referential }
- let( :workbench ){ referential.workbench }
- let( :workbench_import ){ create :workbench_import }
-
- let( :file_path ){ fixtures_path 'single_reference_import.zip' }
- let( :file ){ fixture_file_upload( file_path ) }
-
- let( :post_request ) do
- -> (attributes) do
- post api_v1_netex_imports_path(format: :json),
- attributes,
- authorization
- end
- end
-
- let( :legal_attributes ) do
- {
- name: 'offre1',
- file: file,
- workbench_id: workbench.id,
- parent_id: workbench_import.id,
- parent_type: workbench_import.class.name
- }
- end
-
-
- context 'with correct credentials and correct request' do
- let( :authorization ){ authorization_token_header( get_api_key.token ) }
- #TODO Check why referential_id is nil
- it 'succeeds' do
- # skip "Problem with referential_id" do
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
-
- post_request.(netex_import: legal_attributes)
- expect( response ).to be_success
- expect( json_response_body ).to eq(
- 'id' => Import::Netex.last.id,
- 'referential_id' => Referential.last.id,
- 'workbench_id' => workbench.id
- )
- # end
- end
-
-
- it 'creates a NetexImport object in the DB' do
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
-
- expect{ post_request.(netex_import: legal_attributes) }.to change{Import::Netex.count}.by(1)
- end
-
- it 'creates a correct Referential', pending: 'see #5073' do
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
-
- legal_attributes # force object creation for correct to change behavior
- expect{post_request.(netex_import: legal_attributes)}.to change{Referential.count}.by(1)
- Referential.last.tap do | ref |
- expect( ref.workbench_id ).to eq(workbench.id)
- expect( ref.organisation_id ).to eq(workbench.organisation_id)
- end
- end
- end
-
-
- context 'with incorrect credentials and correct request', pending: "see #4311 & #5072" do
- let( :authorization ){ authorization_token_header( "#{referential.id}-incorrect_token") }
-
- it 'does not create any DB object and does not succeed' do
- legal_attributes # force object creation for correct to change behavior
- expect{ post_request.(netex_import: legal_attributes) }.not_to change{Referential.count}
- expect( response.status ).to eq(401)
- end
-
- end
-
- context 'with correct credentials and incorrect request' do
- let( :authorization ){ authorization_token_header( get_api_key.token ) }
-
- shared_examples_for 'illegal attributes' do |bad_attribute, illegal_value=nil|
- context "missing #{bad_attribute}" do
- let!( :illegal_attributes ){ legal_attributes.merge( bad_attribute => illegal_value ) }
- it 'does not succeed' do
- # TODO: Handle better when `ReferentialMetadataKludge` is reworked
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108')
- create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109')
-
- post_request.(netex_import: illegal_attributes)
- expect( response.status ).to eq(406)
- expect( json_response_body['errors'][bad_attribute.to_s] ).not_to be_empty
- end
-
- it 'does not create an Import object' do
- expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Import::Base.count}
- end
-
- it 'might not create a referential' do
- expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Referential.count}
- end
- end
- end
-
- it_behaves_like 'illegal attributes', :workbench_id
-
- # TODO Create a specific test when referential is not created
- # context 'name already taken' do
- # before do
- # create :referential, name: 'already taken'
- # end
- # it_behaves_like 'illegal attributes', name: 'already taken'
- # end
- end
- end
-end
+# RSpec.describe "Import::Netex", type: :request do
+
+# describe 'POST netex_imports' do
+
+# let( :referential ){ create :workbench_referential }
+# let( :workbench ){ referential.workbench }
+# let( :workbench_import ){ create :workbench_import }
+
+# let( :file_path ){ fixtures_path 'single_reference_import.zip' }
+# let( :file ){ fixture_file_upload( file_path ) }
+
+# let( :post_request ) do
+# -> (attributes) do
+# post api_v1_netex_imports_path(format: :json),
+# attributes,
+# authorization
+# end
+# end
+
+# let( :legal_attributes ) do
+# {
+# name: 'offre1',
+# file: file,
+# workbench_id: workbench.id,
+# parent_id: workbench_import.id,
+# parent_type: workbench_import.class.name
+# }
+# end
+
+
+# context 'with correct credentials and correct request' do
+# let( :authorization ){ authorization_token_header( get_api_key.token ) }
+# #TODO Check why referential_id is nil
+# it 'succeeds' do
+# # skip "Problem with referential_id" do
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
+
+# post_request.(netex_import: legal_attributes)
+# expect( response ).to be_success
+# expect( json_response_body ).to eq(
+# 'id' => Import::Netex.last.id,
+# 'referential_id' => Referential.last.id,
+# 'workbench_id' => workbench.id
+# )
+# # end
+# end
+
+
+# it 'creates a NetexImport object in the DB' do
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
+
+# expect{ post_request.(netex_import: legal_attributes) }.to change{Import::Netex.count}.by(1)
+# end
+
+# it 'creates a correct Referential', pending: 'see #5073' do
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108', line_referential: workbench.line_referential)
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109', line_referential: workbench.line_referential)
+
+# legal_attributes # force object creation for correct to change behavior
+# expect{post_request.(netex_import: legal_attributes)}.to change{Referential.count}.by(1)
+# Referential.last.tap do | ref |
+# expect( ref.workbench_id ).to eq(workbench.id)
+# expect( ref.organisation_id ).to eq(workbench.organisation_id)
+# end
+# end
+# end
+
+
+# context 'with incorrect credentials and correct request', pending: "see #4311 & #5072" do
+# let( :authorization ){ authorization_token_header( "#{referential.id}-incorrect_token") }
+
+# it 'does not create any DB object and does not succeed' do
+# legal_attributes # force object creation for correct to change behavior
+# expect{ post_request.(netex_import: legal_attributes) }.not_to change{Referential.count}
+# expect( response.status ).to eq(401)
+# end
+
+# end
+
+# context 'with correct credentials and incorrect request' do
+# let( :authorization ){ authorization_token_header( get_api_key.token ) }
+
+# shared_examples_for 'illegal attributes' do |bad_attribute, illegal_value=nil|
+# context "missing #{bad_attribute}" do
+# let!( :illegal_attributes ){ legal_attributes.merge( bad_attribute => illegal_value ) }
+# it 'does not succeed' do
+# # TODO: Handle better when `ReferentialMetadataKludge` is reworked
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00108')
+# create(:line, objectid: 'STIF:CODIFLIGNE:Line:C00109')
+
+# post_request.(netex_import: illegal_attributes)
+# expect( response.status ).to eq(406)
+# expect( json_response_body['errors'][bad_attribute.to_s] ).not_to be_empty
+# end
+
+# it 'does not create an Import object' do
+# expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Import::Base.count}
+# end
+
+# it 'might not create a referential' do
+# expect{ post_request.(netex_import: illegal_attributes) }.not_to change{Referential.count}
+# end
+# end
+# end
+
+# it_behaves_like 'illegal attributes', :workbench_id
+
+# # TODO Create a specific test when referential is not created
+# # context 'name already taken' do
+# # before do
+# # create :referential, name: 'already taken'
+# # end
+# # it_behaves_like 'illegal attributes', name: 'already taken'
+# # end
+# end
+# end
+# end
diff --git a/spec/services/route_way_cost_calculator_spec.rb b/spec/services/route_way_cost_calculator_spec.rb
index d210a6b6e..d11db2950 100644
--- a/spec/services/route_way_cost_calculator_spec.rb
+++ b/spec/services/route_way_cost_calculator_spec.rb
@@ -3,13 +3,15 @@ RSpec.describe RouteWayCostCalculator do
it "calculates and stores WayCosts in the given route's #cost field" do
route = create(:route)
+ allow(TomTom).to receive(:api_key).and_return('dummy')
+
# Fake the request to the TomTom API, but don't actually send the right
# things in the request or response. This is just to fake the request so
# we don't actually call their API in tests. The test doesn't test
# anything given in the response.
stub_request(
:post,
- "https://api.tomtom.com/routing/1/matrix/json?key&routeType=shortest&traffic=false&travelMode=bus"
+ "https://api.tomtom.com/routing/1/matrix/json?key=dummy&routeType=shortest&traffic=false&travelMode=bus"
)
.with(
headers: {
diff --git a/spec/views/line_referentials/show.html.slim_spec.rb b/spec/views/line_referentials/show.html.slim_spec.rb
index 533b92523..1d93555e6 100644
--- a/spec/views/line_referentials/show.html.slim_spec.rb
+++ b/spec/views/line_referentials/show.html.slim_spec.rb
@@ -2,20 +2,26 @@ require 'spec_helper'
describe "/line_referentials/show", :type => :view do
- let!(:line_referential) { assign :line_referential, create(:line_referential) }
+ let(:line_referential) do
+ line_referential = create(:line_referential)
+ assign :line_referential, line_referential.decorate
+ end
before :each do
- render
+ controller.request.path_parameters[:id] = line_referential.id
+ allow(view).to receive(:params).and_return({action: :show})
+ allow(view).to receive(:resource).and_return(line_referential)
+
+ render template: "line_referentials/show", layout: "layouts/application"
end
- # FIXME See #6647
- # it "should not present syncing infos and button" do
- # expect(view.content_for(:page_header_actions)).to_not have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]")
- # end
+ it "should not present syncing infos and button" do
+ expect(rendered).to_not have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]")
+ end
- # with_permission "line_referentials.synchronize" do
- # it "should present syncing infos and button" do
- # expect(view.content_for(:page_header_actions)).to have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]", count: 1)
- # end
- # end
+ with_permission "line_referentials.synchronize" do
+ it "should present syncing infos and button" do
+ expect(rendered).to have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]", count: 1)
+ end
+ end
end
diff --git a/spec/views/stop_area_referentials/show.html.slim_spec.rb b/spec/views/stop_area_referentials/show.html.slim_spec.rb
index 42e2d761b..42569321c 100644
--- a/spec/views/stop_area_referentials/show.html.slim_spec.rb
+++ b/spec/views/stop_area_referentials/show.html.slim_spec.rb
@@ -2,20 +2,25 @@ require 'spec_helper'
describe "/stop_area_referentials/show", :type => :view do
- let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) }
+ let(:stop_area_referential) do
+ stop_area_referential = create(:stop_area_referential)
+ assign :stop_area_referential, stop_area_referential.decorate
+ end
before :each do
- render
+ controller.request.path_parameters[:id] = stop_area_referential.id
+ allow(view).to receive(:params).and_return({action: :show})
+ allow(view).to receive(:resource).and_return(stop_area_referential)
+ render template: "stop_area_referentials/show", layout: "layouts/application"
end
- # FIXME See #6647
- # it "should not present syncing infos and button" do
- # expect(view.content_for(:page_header_actions)).to_not have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]")
- # end
+ it "should not present syncing infos and button" do
+ expect(rendered).to_not have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]")
+ end
- # with_permission "stop_area_referentials.synchronize" do
- # it "should present syncing infos and button" do
- # expect(view.content_for(:page_header_actions)).to have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]", count: 1)
- # end
- # end
+ with_permission "stop_area_referentials.synchronize" do
+ it "should present syncing infos and button" do
+ expect(rendered).to have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]", count: 1)
+ end
+ end
end