aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/routes_controller_spec.rb8
-rw-r--r--spec/decorators/company_decorator_spec.rb2
-rw-r--r--spec/fabricators/user_fabricator.rb2
-rw-r--r--spec/factories/chouette_lines.rb7
-rw-r--r--spec/factories/chouette_routes.rb7
-rw-r--r--spec/factories/line_referentials.rb1
-rw-r--r--spec/factories/referentials.rb1
-rw-r--r--spec/factories/stop_area_referentials.rb1
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/helpers/table_builder_helper_spec.rb8
-rw-r--r--spec/models/chouette/access_link_spec.rb6
-rw-r--r--spec/models/chouette/access_point_spec.rb5
-rw-r--r--spec/models/chouette/connection_link_spec.rb6
-rw-r--r--spec/models/chouette/line_spec.rb7
-rw-r--r--spec/models/chouette/object_id_spec.rb149
-rw-r--r--spec/models/chouette/objectid/netex_spec.rb10
-rw-r--r--spec/models/chouette/objectid/stif_codifligne_spec.rb10
-rw-r--r--spec/models/chouette/objectid/stif_netex_spec.rb10
-rw-r--r--spec/models/chouette/objectid/stif_reflex_spec.rb11
-rw-r--r--spec/models/chouette/route/route_base_spec.rb5
-rw-r--r--spec/models/chouette/route/route_duplication_spec.rb15
-rw-r--r--spec/models/chouette/stop_area_spec.rb5
-rw-r--r--spec/models/chouette/stop_point_spec.rb4
-rw-r--r--spec/models/chouette/trident_active_record_spec.rb57
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb2
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb8
-rw-r--r--spec/models/concerns/objectid_support_spec.rb138
-rw-r--r--spec/models/line_referential_spec.rb1
-rw-r--r--spec/models/referential_spec.rb6
-rw-r--r--spec/models/stop_area_referential_spec.rb1
-rw-r--r--spec/models/workbench_spec.rb1
-rw-r--r--spec/policies/network_policy_spec.rb2
-rw-r--r--spec/policies/route_policy_spec.rb2
-rw-r--r--spec/support/referential.rb5
34 files changed, 244 insertions, 260 deletions
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb
index fb29c8d73..f8e8697ec 100644
--- a/spec/controllers/routes_controller_spec.rb
+++ b/spec/controllers/routes_controller_spec.rb
@@ -1,5 +1,3 @@
-Route = Chouette::Route
-
RSpec.describe RoutesController, type: :controller do
login_user
@@ -87,10 +85,10 @@ RSpec.describe RoutesController, type: :controller do
referential_id: route.line.line_referential_id,
line_id: route.line_id,
id: route.id
- end.to change { Route.count }.by(1)
+ end.to change { Chouette::Route.count }.by(1)
- expect(Route.last.name).to eq( I18n.t('activerecord.copy', name: route.name))
- expect(Route.last.published_name).to eq(route.published_name)
+ expect(Chouette::Route.last.name).to eq(I18n.t('activerecord.copy', name: route.name))
+ expect(Chouette::Route.last.published_name).to eq(route.published_name)
end
end
end
diff --git a/spec/decorators/company_decorator_spec.rb b/spec/decorators/company_decorator_spec.rb
index a1df03449..557d98da1 100644
--- a/spec/decorators/company_decorator_spec.rb
+++ b/spec/decorators/company_decorator_spec.rb
@@ -1,2 +1,2 @@
-describe CompanyDecorator do
+describe Chouette::CompanyDecorator do
end
diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb
index 04c1c6279..62eb82d51 100644
--- a/spec/fabricators/user_fabricator.rb
+++ b/spec/fabricators/user_fabricator.rb
@@ -5,4 +5,4 @@ Fabricator :user do
password { 'password' }
username { "#{FFaker::Name.first_name.parameterize}.#{FFaker::Name.last_name.parameterize}" }
-end \ No newline at end of file
+end
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 423ab99f2..95f760174 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -8,7 +8,7 @@ FactoryGirl.define do
association :network, :factory => :network
association :company, :factory => :company
-
+
before(:create) do |line|
line.line_referential ||= LineReferential.find_by! name: "first"
end
@@ -44,6 +44,11 @@ FactoryGirl.define do
end
+ factory :line_with_after_commit do |line|
+ line.run_callbacks(:commit)
+
+ end
+
end
end
diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb
index 4986ab70e..4e20059fe 100644
--- a/spec/factories/chouette_routes.rb
+++ b/spec/factories/chouette_routes.rb
@@ -33,6 +33,13 @@ FactoryGirl.define do
end
end
+ factory :route_with_after_commit do
+ sequence(:objectid) {nil}
+ after(:create) do |route|
+ route.run_callbacks(:commit)
+ end
+ end
+
end
end
diff --git a/spec/factories/line_referentials.rb b/spec/factories/line_referentials.rb
index cfce1399f..e9e6dce5a 100644
--- a/spec/factories/line_referentials.rb
+++ b/spec/factories/line_referentials.rb
@@ -1,5 +1,6 @@
FactoryGirl.define do
factory :line_referential do
sequence(:name) { |n| "Line Referential #{n}" }
+ objectid_format 'stif_codifligne'
end
end
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
index a4155d181..0276a47be 100644
--- a/spec/factories/referentials.rb
+++ b/spec/factories/referentials.rb
@@ -8,6 +8,7 @@ FactoryGirl.define do
association :organisation
time_zone "Europe/Paris"
ready { true }
+ objectid_format "stif_netex"
factory :workbench_referential do
association :workbench
diff --git a/spec/factories/stop_area_referentials.rb b/spec/factories/stop_area_referentials.rb
index c88819010..fcba996e4 100644
--- a/spec/factories/stop_area_referentials.rb
+++ b/spec/factories/stop_area_referentials.rb
@@ -1,5 +1,6 @@
FactoryGirl.define do
factory :stop_area_referential, :class => StopAreaReferential do
sequence(:name) { |n| "StopArea Referential #{n}" }
+ objectid_format 'stif_reflex'
end
end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 57bef2203..0f26559d8 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -1,6 +1,7 @@
FactoryGirl.define do
factory :workbench do
name "Gestion de l'offre"
+ objectid_format 'stif_netex'
association :organisation
association :line_referential
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index a8854bf97..3b0a18379 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -214,7 +214,7 @@ describe TableBuilderHelper, type: :helper do
</thead>
<tbody>
<tr>
- <td>#{company.objectid.local_id}</td>
+ <td>#{company.get_objectid.local_id}</td>
<td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>
<td></td>
<td></td>
@@ -237,7 +237,7 @@ describe TableBuilderHelper, type: :helper do
[
TableBuilderHelper::Column.new(
name: 'ID Codif',
- attribute: Proc.new { |n| n.try(:objectid).try(:local_id) },
+ attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) },
sortable: false
),
TableBuilderHelper::Column.new(
@@ -327,7 +327,7 @@ describe TableBuilderHelper, type: :helper do
</thead>
<tbody>
<tr>
- <td>#{company.objectid.local_id}</td>
+ <td>#{company.get_objectid.local_id}</td>
<td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>
<td></td>
<td></td>
@@ -350,7 +350,7 @@ describe TableBuilderHelper, type: :helper do
[
TableBuilderHelper::Column.new(
name: 'ID Codif',
- attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }
+ attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) }
),
TableBuilderHelper::Column.new(
key: :name,
diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb
index 5a31b8f0c..d0f351480 100644
--- a/spec/models/chouette/access_link_spec.rb
+++ b/spec/models/chouette/access_link_spec.rb
@@ -5,9 +5,9 @@ describe Chouette::AccessLink, :type => :model do
it { is_expected.to validate_uniqueness_of :objectid }
- describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) }
+ describe '#get_objectid' do
+ subject { super().get_objectid }
+ it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)}
end
it { is_expected.to validate_presence_of :name }
diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb
index e0f4b1501..a6798ec3b 100644
--- a/spec/models/chouette/access_point_spec.rb
+++ b/spec/models/chouette/access_point_spec.rb
@@ -4,8 +4,9 @@ describe Chouette::AccessPoint, :type => :model do
subject { create(:access_point) }
describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifReflexObjectid) }
+ it "should have the same class as stop_area objectid" do
+ expect(subject.objectid.class).to eq(subject.stop_area.objectid.class)
+ end
end
it { is_expected.to validate_presence_of :name }
diff --git a/spec/models/chouette/connection_link_spec.rb b/spec/models/chouette/connection_link_spec.rb
index 57eb7d66c..04c15b42e 100644
--- a/spec/models/chouette/connection_link_spec.rb
+++ b/spec/models/chouette/connection_link_spec.rb
@@ -9,9 +9,9 @@ describe Chouette::ConnectionLink, :type => :model do
it { is_expected.to validate_uniqueness_of :objectid }
- describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) }
+ describe '#get_objectid' do
+ subject { super().get_objectid }
+ it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)}
end
it { is_expected.to validate_presence_of :name }
diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb
index 2e5882012..bc7b6e0c7 100644
--- a/spec/models/chouette/line_spec.rb
+++ b/spec/models/chouette/line_spec.rb
@@ -10,16 +10,11 @@ describe Chouette::Line, :type => :model do
describe '#display_name' do
it 'should display local_id, number, name and company name' do
- display_name = "#{subject.objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}"
+ display_name = "#{subject.get_objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}"
expect(subject.display_name).to eq(display_name)
end
end
- describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifCodifligneObjectid) }
- end
-
# it { should validate_numericality_of :objectversion }
# describe ".last_stop_areas_parents" do
diff --git a/spec/models/chouette/object_id_spec.rb b/spec/models/chouette/object_id_spec.rb
deleted file mode 100644
index dd8b66388..000000000
--- a/spec/models/chouette/object_id_spec.rb
+++ /dev/null
@@ -1,149 +0,0 @@
-require 'spec_helper'
-
-describe Chouette::ObjectId, :type => :model do
-
- def objectid(value = "abc:StopArea:abc123")
- Chouette::ObjectId.new value
- end
-
- subject { objectid }
-
- context "when invalid" do
-
- subject { objectid("abc") }
-
- it { is_expected.not_to be_valid }
-
- describe '#parts' do
- subject { super().parts }
- it { is_expected.to be_nil }
- end
-
- describe '#system_id' do
- subject { super().system_id }
- it { is_expected.to be_nil }
- end
-
- end
-
- context "when with spaces in last part" do
-
- subject { objectid("abc:Line:Aze toto") }
-
- it { is_expected.not_to be_valid }
-
-
- end
-
- context "when with spaces in first part" do
-
- subject { objectid("ae abc:Line:Aze") }
-
- it { is_expected.not_to be_valid }
-
-
- end
-
- context "when with spaces in middle part" do
-
- subject { objectid("aeabc:Li ne:Aze") }
-
- it { is_expected.not_to be_valid }
-
-
- end
-
- context "when invalid in first part" do
-
- subject { objectid("Abc_+19:Line:Abc") }
-
- it { is_expected.not_to be_valid }
- end
-
- context "when invalid in middle part" do
-
- subject { objectid("Abc_19:Li56ne:Abc") }
-
- it { is_expected.not_to be_valid }
- end
-
- context "when invalid in last part" do
-
- subject { objectid("Abc_19:Line:Ab+c") }
-
- it { is_expected.not_to be_valid }
- end
- context "when valid" do
-
- subject { objectid("Abc_19:Line:Abc_12-") }
-
- it { is_expected.to be_valid }
- end
-
- describe "#parts" do
-
- it "should be the 3 parts of the ObjectId" do
- expect(objectid("abc:StopArea:abc123").parts).to eq(%w{abc StopArea abc123})
- end
-
- end
-
- describe "#system_id" do
-
- it "should be the first ObjectId parts" do
- expect(objectid("first:second:third").system_id).to eq("first")
- end
-
- end
-
- describe "#object_type" do
-
- it "should be the second ObjectId parts" do
- expect(objectid("first:second:third").object_type).to eq("second")
- end
-
- end
-
- describe "#local_id" do
-
- it "should be the third ObjectId parts" do
- expect(objectid("first:second:third").local_id).to eq("third")
- end
-
- end
-
- it "should be valid when parts are found" do
- allow(subject).to receive_messages :parts => "dummy"
- expect(subject).to be_valid
- end
-
- describe ".create" do
-
- let(:given_system_id) { "systemId" }
- let(:given_object_type) { "objectType" }
- let(:given_local_id) { "localId" }
-
- subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) }
-
- it "should return ObjectId attributes" do
- expect(subject.send(:system_id)).to eq(given_system_id)
- expect(subject.send(:object_type)).to eq(given_object_type)
- expect(subject.send(:local_id)).to eq(given_local_id)
- end
-
- end
-
- describe ".new" do
-
- it "should return an existing ObjectId" do
- expect(Chouette::ObjectId.new(objectid)).to eq(objectid)
- end
-
- it "should create an empty ObjectId with nil" do
- expect(Chouette::ObjectId.new(nil)).to be_empty
- end
-
- end
-
-
-end
diff --git a/spec/models/chouette/objectid/netex_spec.rb b/spec/models/chouette/objectid/netex_spec.rb
new file mode 100644
index 000000000..3aee13624
--- /dev/null
+++ b/spec/models/chouette/objectid/netex_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Chouette::Objectid::Netex, :type => :model do
+ subject { Chouette::Objectid::Netex.new(object_type: 'Route', local_id: SecureRandom.uuid) }
+ it { should validate_presence_of :provider_id }
+ it { should validate_presence_of :object_type }
+ it { should validate_presence_of :local_id }
+ it { should validate_presence_of :creation_id }
+ it { is_expected.to be_valid }
+end \ No newline at end of file
diff --git a/spec/models/chouette/objectid/stif_codifligne_spec.rb b/spec/models/chouette/objectid/stif_codifligne_spec.rb
new file mode 100644
index 000000000..533af3556
--- /dev/null
+++ b/spec/models/chouette/objectid/stif_codifligne_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Chouette::Objectid::StifCodifligne, :type => :model do
+ subject { Chouette::Objectid::StifCodifligne.new(object_type: 'Line', local_id: 'C02008', sync_id: 'CODIFLIGNE', provider_id: 'STIF') }
+ it { should validate_presence_of :provider_id }
+ it { should validate_presence_of :object_type }
+ it { should validate_presence_of :local_id }
+ it { should validate_presence_of :sync_id }
+ it { is_expected.to be_valid }
+end \ No newline at end of file
diff --git a/spec/models/chouette/objectid/stif_netex_spec.rb b/spec/models/chouette/objectid/stif_netex_spec.rb
new file mode 100644
index 000000000..1d361ca86
--- /dev/null
+++ b/spec/models/chouette/objectid/stif_netex_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Chouette::Objectid::StifNetex, :type => :model do
+ subject { Chouette::Objectid::StifNetex.new(object_type: 'Route', local_id: '13') }
+ it { should validate_presence_of :provider_id }
+ it { should validate_presence_of :object_type }
+ it { should validate_presence_of :local_id }
+ it { should validate_presence_of :creation_id }
+ it { is_expected.to be_valid }
+end \ No newline at end of file
diff --git a/spec/models/chouette/objectid/stif_reflex_spec.rb b/spec/models/chouette/objectid/stif_reflex_spec.rb
new file mode 100644
index 000000000..0846f27fa
--- /dev/null
+++ b/spec/models/chouette/objectid/stif_reflex_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Chouette::Objectid::StifReflex, :type => :model do
+ subject { Chouette::Objectid::StifReflex.new(country_code: 'FR', zip_code: '78517', object_type: 'ZDL', local_id: '50015386', provider_id: 'STIF') }
+ it { should validate_presence_of :provider_id }
+ it { should validate_presence_of :object_type }
+ it { should validate_presence_of :local_id }
+ it { should validate_presence_of :country_code }
+ it { should validate_presence_of :zip_code }
+ it { is_expected.to be_valid }
+end \ No newline at end of file
diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb
index cac2880e8..79daeb6c2 100644
--- a/spec/models/chouette/route/route_base_spec.rb
+++ b/spec/models/chouette/route/route_base_spec.rb
@@ -5,11 +5,6 @@ RSpec.describe Chouette::Route, :type => :model do
it_behaves_like 'checksum support', :route
end
- describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) }
- end
-
it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) }
it { is_expected.to enumerize(:wayback).in(:outbound, :inbound) }
diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb
index 5bcd13fc8..ee45b5005 100644
--- a/spec/models/chouette/route/route_duplication_spec.rb
+++ b/spec/models/chouette/route/route_duplication_spec.rb
@@ -1,9 +1,4 @@
-# From Chouette import what we need ™
-Route = Chouette::Route
-StopArea = Chouette::StopArea
-StopPoint = Chouette::StopPoint
-
-RSpec.describe Route do
+RSpec.describe Chouette::Route do
let!( :route ){ create :route }
@@ -11,7 +6,7 @@ RSpec.describe Route do
describe 'properties' do
it 'same attribute values' do
route.duplicate
- expect( values_for_create(Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) )
+ expect( values_for_create(Chouette::Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) )
end
it 'and others cannot' do
expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError)
@@ -23,13 +18,13 @@ RSpec.describe Route do
describe 'side_effects' do
it {
- expect{ route.duplicate }.to change{Route.count}.by(1)
+ expect{ route.duplicate }.to change{Chouette::Route.count}.by(1)
}
it 'duplicates its stop points' do
- expect{ route.duplicate }.to change{StopPoint.count}.by(route.stop_points.count)
+ expect{ route.duplicate }.to change{Chouette::StopPoint.count}.by(route.stop_points.count)
end
it 'does bot duplicate the stop areas' do
- expect{ route.duplicate }.not_to change{StopArea.count}
+ expect{ route.duplicate }.not_to change{Chouette::StopArea.count}
end
end
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index a3a398bfb..1e0b4af84 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -7,11 +7,6 @@ describe Chouette::StopArea, :type => :model do
let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" }
let!(:stop_place) { create :stop_area, :area_type => "zdlp" }
- describe '#objectid' do
- subject { super().objectid }
- it { should be_kind_of(Chouette::StifReflexObjectid) }
- end
-
it { should belong_to(:stop_area_referential) }
it { should validate_presence_of :name }
it { should validate_numericality_of :latitude }
diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb
index 329e76a75..f48173e65 100644
--- a/spec/models/chouette/stop_point_spec.rb
+++ b/spec/models/chouette/stop_point_spec.rb
@@ -9,8 +9,8 @@ describe StopPoint, :type => :model do
it { is_expected.to validate_presence_of :stop_area }
describe '#objectid' do
- subject { super().objectid }
- it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) }
+ subject { super().get_objectid }
+ it { is_expected.to be_kind_of(Chouette::Objectid::StifNetex) }
end
describe "#destroy" do
diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb
deleted file mode 100644
index d5e30594d..000000000
--- a/spec/models/chouette/trident_active_record_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-require 'spec_helper'
-
-describe Chouette::TridentActiveRecord, :type => :model do
- subject { create(:time_table) }
-
- it { should validate_presence_of :objectid }
- it { should validate_uniqueness_of :objectid }
-
- describe "#default_values" do
- let(:object) { build(:time_table, objectid: nil) }
-
- it 'should fill __pending_id__' do
- object.default_values
- expect(object.objectid.include?('__pending_id__')).to be_truthy
- end
- end
-
- describe "#objectid" do
- let(:object) { build(:time_table, objectid: nil) }
-
- it 'should build objectid on create' do
- object.save
- id = "#{object.provider_id}:#{object.model_name}:#{object.local_id}:#{object.boiv_id}"
- expect(object.objectid).to eq(id)
- end
-
- it 'should call build_objectid on after save' do
- expect(object).to receive(:build_objectid)
- object.save
- end
-
- it 'should not build new objectid is already set' do
- id = "first:TimeTable:1-1:LOC"
- object.objectid = id
- object.save
- expect(object.objectid).to eq(id)
- end
-
- it 'should call default_values on create' do
- expect(object).to receive(:default_values)
- object.save
- end
-
- it 'should not call default_values on update' do
- object = create(:time_table)
- expect(object).to_not receive(:default_values)
- object.touch
- end
-
- it 'should create a new objectid when cleared' do
- object.save
- object.objectid = nil
- object.save
- expect(object.objectid).to be_truthy
- end
- end
-end
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
index 03e6fcb7d..df8a630fe 100644
--- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
)
error_message = I18n.t(
'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
- short_id: at_stop.vehicle_journey.objectid.short_id,
+ short_id: at_stop.vehicle_journey.get_objectid.short_id,
max: bad_offset
)
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 52f2ab42d..86aa475f0 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Chouette::VehicleJourney, :type => :model do
+
it "must be valid with an at-stop day offset of 1" do
vehicle_journey = create(
:vehicle_journey,
@@ -94,10 +95,13 @@ describe Chouette::VehicleJourney, :type => :model do
expect {
Chouette::VehicleJourney.state_update(route, collection)
}.to change {Chouette::VehicleJourney.count}.by(1)
+
expect(collection.last['objectid']).not_to be_nil
- vj = Chouette::VehicleJourney.find_by(objectid: collection.last['objectid'])
- expect(vj.published_journey_name).to eq 'dummy'
+ obj = Chouette::VehicleJourney.last
+ obj.run_callbacks(:commit)
+
+ expect(obj.published_journey_name).to eq 'dummy'
end
it 'should save vehicle_journey_at_stops of newly created vj' do
diff --git a/spec/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb
new file mode 100644
index 000000000..fabeeec11
--- /dev/null
+++ b/spec/models/concerns/objectid_support_spec.rb
@@ -0,0 +1,138 @@
+RSpec.describe ObjectidSupport do
+
+ context 'when referential has an objectid format of stif_netex' do
+ let(:object) { create(:time_table, objectid: nil) }
+
+ context "#objectid_format" do
+ it "should be stif_netex" do
+ expect(object.referential.objectid_format).to eq('stif_netex')
+ end
+ end
+
+ it 'should fill __pending_id__' do
+ expect(object.objectid.include?('__pending_id__')).to be_truthy
+ end
+
+ context "#get_objectid" do
+
+ before(:each) do
+ object.run_callbacks(:commit)
+ end
+
+ it "should be valid" do
+ expect(object.get_objectid).to be_valid
+ end
+
+ it "should have the same local id than the object" do
+ expect(object.get_objectid.local_id).to eq(object.local_id)
+ end
+
+ it "should be a Chouette::Objectid::StifNetex" do
+ expect(object.get_objectid).to be_kind_of(Chouette::Objectid::StifNetex)
+ end
+
+ context "#to_s" do
+ it "should return a string" do
+ expect(object.get_objectid.to_s).to be_kind_of(String)
+ end
+
+ it "should be the same as the db attribute" do
+ expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid))
+ expect(object.get_objectid.to_s).to eq(object.objectid)
+ end
+
+ context "#objectid" do
+
+ it 'should build objectid on create' do
+ object.save
+ object.run_callbacks(:commit)
+ objectid = object.get_objectid
+ id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}"
+ expect(object.read_attribute(:objectid)).to eq(id)
+ end
+
+ it 'should not build new objectid is already set' do
+ id = "first:TimeTable:1-1:LOC"
+ object.attributes = {objectid: id}
+ object.save
+ expect(object.objectid).to eq(id)
+ end
+
+ it 'should create a new objectid when cleared' do
+ object.save
+ object.attributes = { objectid: nil}
+ object.save
+ expect(object.objectid).to be_truthy
+ end
+ end
+ end
+ end
+ end
+
+ context 'when referential has an objectid format of netex' do
+ before(:all) do
+ Referential.first.update(objectid_format: 'netex')
+ end
+
+ let(:object) { create(:time_table, objectid: nil) }
+
+
+ context "#objectid_format" do
+ it "should be netex" do
+ expect(object.referential.objectid_format).to eq('netex')
+ end
+ end
+
+ context "#get_objectid" do
+
+ it "should be valid" do
+ expect(object.get_objectid).to be_valid
+ end
+
+ it "should have the same local id than the object" do
+ expect(object.get_objectid.local_id).to match(/\w+-\w+-\w+-\w+-\w+/)
+ end
+
+ it "should be a Chouette::Objectid::StifNetex" do
+ expect(object.get_objectid).to be_kind_of(Chouette::Objectid::Netex)
+ end
+
+ context "#to_s" do
+ it "should return a string" do
+ expect(object.get_objectid.to_s).to be_kind_of(String)
+ end
+
+ it "should be the same as the db attribute" do
+ expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid))
+ expect(object.get_objectid.to_s).to eq(object.objectid)
+ end
+
+ context "#objectid" do
+
+ it 'should build objectid on create' do
+ object.save
+ object.run_callbacks(:commit)
+ objectid = object.get_objectid
+ id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}"
+ expect(object.read_attribute(:objectid)).to eq(id)
+ end
+
+ it 'should not build new objectid is already set' do
+ id = "first:TimeTable:1-1:LOC"
+ object.attributes = {objectid: id}
+ object.save
+ expect(object.objectid).to eq(id)
+ end
+
+ it 'should create a new objectid when cleared' do
+ object.save
+ object.attributes = { objectid: nil}
+ object.save
+ expect(object.objectid).to be_truthy
+ end
+ end
+ end
+ end
+ end
+
+end \ No newline at end of file
diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb
index 8f8714f8f..46434a7ab 100644
--- a/spec/models/line_referential_spec.rb
+++ b/spec/models/line_referential_spec.rb
@@ -7,5 +7,6 @@ RSpec.describe LineReferential, type: :model do
it { is_expected.to have_many(:line_referential_syncs) }
it { is_expected.to have_many(:workbenches) }
it { should validate_presence_of(:sync_interval) }
+ it { should validate_presence_of(:objectid_format) }
end
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index ad9c43010..d0b1d6447 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -12,6 +12,12 @@ describe Referential, :type => :model do
it { should belong_to(:workbench) }
it { should belong_to(:referential_suite) }
+ context "validation" do
+ subject { build_stubbed(:referential) }
+
+ it { should validate_presence_of(:objectid_format) }
+ end
+
context ".referential_ids_in_periode" do
it 'should retrieve referential id in periode range' do
range = ref.metadatas.first.periodes.sample
diff --git a/spec/models/stop_area_referential_spec.rb b/spec/models/stop_area_referential_spec.rb
index 271badff8..dd2bdce20 100644
--- a/spec/models/stop_area_referential_spec.rb
+++ b/spec/models/stop_area_referential_spec.rb
@@ -7,4 +7,5 @@ RSpec.describe StopAreaReferential, :type => :model do
it { is_expected.to have_many(:stop_area_referential_syncs) }
it { is_expected.to have_many(:workbenches) }
+ it { should validate_presence_of(:objectid_format) }
end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index 037537b60..3b9ed6b07 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Workbench, :type => :model do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:organisation) }
+ it { should validate_presence_of(:objectid_format) }
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb
index ae4ffa03a..c09546c22 100644
--- a/spec/policies/network_policy_spec.rb
+++ b/spec/policies/network_policy_spec.rb
@@ -1,4 +1,4 @@
-RSpec.describe NetworkPolicy, type: :policy do
+RSpec.describe Chouette::NetworkPolicy, type: :policy do
let( :record ){ build_stubbed :network }
before { stub_policy_scope(record) }
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
index d7edceaef..df2e41a89 100644
--- a/spec/policies/route_policy_spec.rb
+++ b/spec/policies/route_policy_spec.rb
@@ -1,4 +1,4 @@
-RSpec.describe RoutePolicy, type: :policy do
+RSpec.describe Chouette::RoutePolicy, type: :policy do
let( :record ){ build_stubbed :route }
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 6f60bd86b..b615491da 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -46,9 +46,11 @@ RSpec.configure do |config|
organisation = Organisation.create!(code: "first", name: "first")
line_referential = LineReferential.find_or_create_by(name: "first") do |referential|
+ referential.objectid_format = "stif_codifligne"
referential.add_member organisation, owner: true
end
stop_area_referential = StopAreaReferential.find_or_create_by(name: "first") do |referential|
+ referential.objectid_format = "stif_reflex"
referential.add_member organisation, owner: true
end
@@ -65,7 +67,8 @@ RSpec.configure do |config|
name: "first",
slug: "first",
organisation: organisation,
- workbench: workbench
+ workbench: workbench,
+ objectid_format: "stif_netex"
)
end