aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-11-23 17:14:05 +0100
committercedricnjanga2017-11-23 17:14:05 +0100
commit0a9b5cd19dc52e00c9516e2a4cf204580d889862 (patch)
tree265d7db92bd9d2b560c0856b9c9f2f5b5b8ae81d
parentcf72b3c73db85b1a5b7c2381c3afddd98290691d (diff)
downloadchouette-core-0a9b5cd19dc52e00c9516e2a4cf204580d889862.tar.bz2
Add spec for stif_netex objectid_format
-rw-r--r--app/models/chouette/objectid/stif_reflex.rb2
-rw-r--r--db/schema.rb2
-rw-r--r--spec/factories/chouette_lines.rb5
-rw-r--r--spec/factories/chouette_routes.rb7
-rw-r--r--spec/models/concerns/objectid_support_spec.rb88
5 files changed, 102 insertions, 2 deletions
diff --git a/app/models/chouette/objectid/stif_reflex.rb b/app/models/chouette/objectid/stif_reflex.rb
index cd0f62298..770f3c433 100644
--- a/app/models/chouette/objectid/stif_reflex.rb
+++ b/app/models/chouette/objectid/stif_reflex.rb
@@ -19,7 +19,7 @@ module Chouette
"#{self.country_code}:#{self.zip_code}:#{self.object_type}:#{self.local_id}:#{self.provider_id}"
end
- def short_id
+ def short_id
local_id
end
end
diff --git a/db/schema.rb b/db/schema.rb
index 21aa73cd8..58521fc40 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20171114102438) do
+ActiveRecord::Schema.define(version: 20171123110204) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index f6542bf82..95f760174 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -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/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb
new file mode 100644
index 000000000..656e42d8e
--- /dev/null
+++ b/spec/models/concerns/objectid_support_spec.rb
@@ -0,0 +1,88 @@
+RSpec.describe ObjectidSupport do
+
+ context 'when referential has an objectid format of stif_netex' do
+ let(:route) { create(:route_with_after_commit, objectid: nil) }
+
+ context "#objectid_format" do
+ it "should be stif_netex" do
+ expect(route.objectid_format).to eq('stif_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::StifNetex" do
+ expect(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)
+ 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
+ # 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
+
+
+end \ No newline at end of file