aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorcedricnjanga2017-11-24 17:06:52 +0100
committercedricnjanga2017-11-24 17:06:52 +0100
commitade8285b084529c09687e6995101b0aa651e2d4d (patch)
tree9ad1e0a9f24053cee93bfba04d58a87c428680e4 /spec/models
parent9a08dc4d028f83e43a5fba83ebf09b68f21e9d49 (diff)
downloadchouette-core-ade8285b084529c09687e6995101b0aa651e2d4d.tar.bz2
Remove specs we dont need anymore
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/chouette/object_id_spec.rb149
-rw-r--r--spec/models/chouette/trident_active_record_spec.rb53
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb5
-rw-r--r--spec/models/concerns/objectid_support_spec.rb161
-rw-r--r--spec/models/referential_spec.rb6
5 files changed, 115 insertions, 259 deletions
diff --git a/spec/models/chouette/object_id_spec.rb b/spec/models/chouette/object_id_spec.rb
deleted file mode 100644
index 7ac5fe5ca..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/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb
deleted file mode 100644
index 50ca27233..000000000
--- a/spec/models/chouette/trident_active_record_spec.rb
+++ /dev/null
@@ -1,53 +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
-# 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.objectid = id
-# object.save
-# expect(object.objectid).to eq(id)
-# end
-
-# xit 'should call default_values on create' do
-# expect(object).to receive(:default_values)
-# object.save
-# end
-
-# xit '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_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index fce0a5f73..86aa475f0 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -98,9 +98,10 @@ describe Chouette::VehicleJourney, :type => :model do
expect(collection.last['objectid']).not_to be_nil
- Chouette::VehicleJourney.last.run_callbacks(:commit)
+ obj = Chouette::VehicleJourney.last
+ obj.run_callbacks(:commit)
- expect(Chouette::VehicleJourney.last.published_journey_name).to eq 'dummy'
+ 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
index 3829b2106..fabeeec11 100644
--- a/spec/models/concerns/objectid_support_spec.rb
+++ b/spec/models/concerns/objectid_support_spec.rb
@@ -1,85 +1,138 @@
RSpec.describe ObjectidSupport do
context 'when referential has an objectid format of stif_netex' do
- let(:route) { create(:route_with_after_commit, objectid: nil) }
+ let(:object) { create(:time_table, objectid: nil) }
- context "#objectid_format" do
+ context "#objectid_format" do
it "should be stif_netex" do
- expect(route.referential.objectid_format).not_to be_nil
- expect(route.referential.objectid_format).to eq('stif_netex')
+ 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
- let(:objectid) { route.get_objectid }
+
+ before(:each) do
+ object.run_callbacks(:commit)
+ end
+
it "should be valid" do
- expect(objectid).to be_valid
+ expect(object.get_objectid).to be_valid
end
it "should have the same local id than the object" do
- expect(objectid.local_id).to eq(route.local_id)
+ expect(object.get_objectid.local_id).to eq(object.local_id)
end
it "should be a Chouette::Objectid::StifNetex" do
- expect(objectid).to be_kind_of(Chouette::Objectid::StifNetex)
+ expect(object.get_objectid).to be_kind_of(Chouette::Objectid::StifNetex)
end
context "#to_s" do
it "should return a string" do
- expect(objectid.to_s).to be_kind_of(String)
+ expect(object.get_objectid.to_s).to be_kind_of(String)
end
it "should be the same as the db attribute" do
- expect(objectid.to_s).to eq(route.read_attribute(:objectid))
- expect(objectid.to_s).to eq(route.objectid)
+ 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
- # let(:line) { create(:route_with_after_commit, objectid: nil) }
-
- # before(:all) do
- # binding.pry
- # route.referential.objectid_format = 'netex'
- # end
-
- # context "#objectid_format" do
- # it "should be netex" do
- # expect(route.objectid_format).to eq('netex')
- # end
- # it "should be the same as the referential" do
- # expect(route.objectid_format).to eq(route.referential.objectid_format)
- # end
- # end
-
- # context "#get_objectid" do
- # let(:objectid) { route.get_objectid }
- # it "should be valid" do
- # expect(objectid).to be_valid
- # end
-
- # it "should have the same local id than the object" do
- # expect(objectid.local_id).to eq(route.local_id)
- # end
-
- # it "should be a Chouette::Objectid::Netex" do
- # expect(objectid).to be_kind_of(Chouette::Objectid::Netex)
- # end
-
- # context "#to_s" do
- # it "should return a string" do
- # expect(objectid.to_s).to be_kind_of(String)
- # end
-
- # it "should be the same as the db attribute" do
- # expect(objectid.to_s).to eq(route.read_attribute(:objectid))
- # expect(objectid.to_s).to eq(route.objectid)
- # 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/referential_spec.rb b/spec/models/referential_spec.rb
index 987eea30a..d0b1d6447 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -12,7 +12,11 @@ describe Referential, :type => :model do
it { should belong_to(:workbench) }
it { should belong_to(:referential_suite) }
- # it { should validate_presence_of(:objectid_format) }
+ 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