aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuc Donnet2017-12-06 16:47:10 +0100
committerLuc Donnet2017-12-06 16:47:10 +0100
commitb85fd26e9b399b488aaf76d417e63e2a75e98689 (patch)
tree5a5099b81e5617c64bb248e71f2c4492d7700138 /spec
parent1c8cf43eb38b20dfb37508c8c731ae7bdaa320a6 (diff)
parentaf709926b6fac4fce22345a34fdf57de5b4d6cbf (diff)
downloadchouette-core-b85fd26e9b399b488aaf76d417e63e2a75e98689.tar.bz2
Merge branch 'master' into staging
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/compliance_check_sets_controller_spec.rb37
-rw-r--r--spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb52
-rw-r--r--spec/controllers/api/v1/internals/netex_imports_controller_spec.rb42
-rw-r--r--spec/controllers/compliance_check_sets_controller_spec.rb22
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb68
-rw-r--r--spec/support/random.rb9
-rw-r--r--spec/support/shared_context.rb16
7 files changed, 187 insertions, 59 deletions
diff --git a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
deleted file mode 100644
index 1c3784807..000000000
--- a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-RSpec.describe Api::V1::ComplianceCheckSetsController, type: :controller do
- include_context 'iboo authenticated api user'
-
- describe "POST #validate" do
- let(:check_set) { create(:compliance_check_set) }
-
- it "calls #update_status on the ComplianceCheckSet" do
- expect_any_instance_of(ComplianceCheckSet).to receive(:update_status)
-
- patch :validated, id: check_set.id
- end
-
- context "responds with" do
- render_views
-
- it "object JSON on #update_status true" do
- allow_any_instance_of(
- ComplianceCheckSet
- ).to receive(:update_status).and_return(true)
-
- patch :validated, id: check_set.id
-
- expect(JSON.parse(response.body)['id']).to eq(check_set.id)
- end
-
- it "error JSON on #update_status false" do
- allow_any_instance_of(
- ComplianceCheckSet
- ).to receive(:update_status).and_return(false)
-
- patch :validated, id: check_set.id
-
- expect(response.body).to include('error')
- end
- end
- end
-end
diff --git a/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb
new file mode 100644
index 000000000..e73790384
--- /dev/null
+++ b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb
@@ -0,0 +1,52 @@
+require 'rails_helper'
+
+RSpec.describe Api::V1::Internals::ComplianceCheckSetsController, type: :controller do
+ let(:check_set_1) { create :compliance_check_set }
+ let(:check_set_2) { create :compliance_check_set }
+
+ describe "GET #notify_parent" do
+ context 'unauthenticated' do
+ include_context 'iboo wrong authorisation internal api'
+
+ it 'should not be successful' do
+ get :notify_parent, id: check_set_1.id, format: :json
+ expect(response).to have_http_status 401
+ end
+ end
+
+ context 'authenticated' do
+ include_context 'iboo authenticated internal api'
+
+ describe "with existing record" do
+
+ before(:each) do
+ get :notify_parent, id: check_set_2.id, format: :json
+ end
+
+ it 'should be successful' do
+ expect(response).to have_http_status 200
+ end
+
+ describe "that has a parent" do
+ xit "calls #notify_parent on the import" do
+ expect(check_set_2.reload.notified_parent_at).not_to be_nil
+ end
+ end
+
+ describe "that does not have a parent" do
+ xit "should not be successful" do
+ expect(response.body).to include("error")
+ end
+ end
+
+ end
+
+ describe "with non existing record" do
+ it "should throw an error" do
+ get :notify_parent, id: 47, format: :json
+ expect(response.body).to include("error")
+ end
+ end
+ end
+ end
+end
diff --git a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb
new file mode 100644
index 000000000..ccdc258f4
--- /dev/null
+++ b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb
@@ -0,0 +1,42 @@
+RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do
+ let(:import_1) { create :netex_import }
+ let(:import_2) { create :netex_import }
+
+ describe "GET #notify_parent" do
+ context 'unauthenticated' do
+ include_context 'iboo wrong authorisation internal api'
+
+ it 'should not be successful' do
+ get :notify_parent, id: import_1.id, format: :json
+ expect(response).to have_http_status 401
+ end
+ end
+
+ context 'authenticated' do
+ include_context 'iboo authenticated internal api'
+
+ describe "with existing record" do
+
+ before(:each) do
+ get :notify_parent, id: import_2.id, format: :json
+ end
+
+ it 'should be successful' do
+ expect(response).to have_http_status 200
+ end
+
+ it "calls #notify_parent on the import" do
+ expect(import_2.reload.notified_parent_at).not_to be_nil
+ end
+ end
+
+ describe "with non existing record" do
+ it "should throw an error" do
+ get :notify_parent, id: 47, format: :json
+ expect(response.body).to include("error")
+ end
+ end
+ end
+ end
+end
+
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb
deleted file mode 100644
index 3ddb1dad1..000000000
--- a/spec/controllers/compliance_check_sets_controller_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe ComplianceCheckSetsController, type: :controller do
- login_user
-
- let(:compliance_check_set) { create :compliance_check_set }
-
- describe "GET executed" do
- it 'should be successful' do
- get :executed, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
- expect(response).to be_success
- end
- end
-
- describe "GET index" do
- it 'should be successful' do
- get :index, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
- expect(response).to be_success
- end
- end
-
-end
diff --git a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
new file mode 100644
index 000000000..b3ee68be3
--- /dev/null
+++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
@@ -0,0 +1,68 @@
+RSpec.describe Referential do
+
+ let( :legal_formats ){ described_class.objectid_format.values }
+
+
+ describe 'default attributes' do
+
+ context 'referential w/o an objectid_format' do
+ let( :referential ){ described_class.new }
+ let( :workbench ){ build_stubbed :workbench, objectid_format: random_element(legal_formats) }
+
+ it "but a workbench will take the format of the workbench" do
+ referential.workbench = workbench
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to eq(workbench.objectid_format)
+ end
+
+ it 'and w/o a workbench will take the default objectid_format' do
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to be_nil
+ end
+ end
+
+
+ context 'referential with an objectid_format' do
+ let( :distinct_formats ){ distinct_random_elements(legal_formats, count: 2) }
+
+ let( :referential ){ build_stubbed :referential, objectid_format: distinct_formats.first}
+ let( :workbench ){ build_stubbed :workbench, objectid_format: distinct_formats.second }
+
+ it "and a workbench will not take the format of the workbench" do
+ referential.workbench = workbench
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+
+ it 'and w/o a workbench will not take the default objectid_format' do
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+ end
+
+ end
+
+
+
+ describe 'self.new_from' do
+
+ let( :source ){ build :referential }
+ let( :functional_scope ){ double('functional scope') }
+
+ it 'copies objectid_format from source' do
+ expect( described_class )
+ .to receive(:new)
+ .with(name: I18n.t("activerecord.copy", name: source.name),
+ slug: "#{source.slug}_clone",
+ prefix: source.prefix,
+ time_zone: source.time_zone,
+ bounds: source.bounds,
+ line_referential: source.line_referential,
+ stop_area_referential: source.stop_area_referential,
+ created_from: source,
+ objectid_format: source.objectid_format,
+ metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) })
+
+ described_class.new_from( source, functional_scope )
+ end
+
+ end
+end
diff --git a/spec/support/random.rb b/spec/support/random.rb
index 0ebc2ee5e..16d8b4df3 100644
--- a/spec/support/random.rb
+++ b/spec/support/random.rb
@@ -10,6 +10,15 @@ module Support
def random_element from
from[random_int(from.size)]
end
+
+ def random_elements( from, count: )
+ (1..count).map{ |_| random_element from }
+ end
+
+ def distinct_random_elements( from, count: )
+ f = from.dup
+ (1..count).map { |_| f.delete_at( random_int(f.size) ) }
+ end
def random_int max_plus_one=PRETTY_LARGE_INT
(random_number * max_plus_one).to_i
diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb
index e9b0025a2..5e472eb85 100644
--- a/spec/support/shared_context.rb
+++ b/spec/support/shared_context.rb
@@ -13,3 +13,19 @@ shared_context 'iboo wrong authorisation api user' do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('fake code', api_key.token)
end
end
+
+shared_context 'iboo authenticated internal api' do
+ let(:api_key) { Rails.application.secrets.api_token }
+
+ before do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key)
+ end
+end
+
+shared_context 'iboo wrong authorisation internal api' do
+ let(:api_key) { "false_api_token" }
+
+ before do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key)
+ end
+end