diff options
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/chouette/stop_area_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/trident_active_record_spec.rb | 58 | ||||
| -rw-r--r-- | spec/models/line_spec.rb | 53 |
3 files changed, 34 insertions, 79 deletions
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index f522d02bd..674af2f53 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -12,7 +12,7 @@ describe Chouette::StopArea, :type => :model do it { is_expected.to be_kind_of(Chouette::ObjectId) } end - it { is_expected.to belong_to(:line_referential) } + it { is_expected.to belong_to(:stop_area_referential) } it { is_expected.to validate_presence_of :name } it { is_expected.to validate_presence_of :area_type } it { is_expected.to validate_numericality_of :latitude } diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb index 654dd6685..76544f85d 100644 --- a/spec/models/chouette/trident_active_record_spec.rb +++ b/spec/models/chouette/trident_active_record_spec.rb @@ -28,32 +28,38 @@ describe Chouette::TridentActiveRecord, :type => :model do end + def create_object(options = {}) + options = {name: "merge1"}.merge options + attributes = { comment: options[:name], objectid: options[:objectid] } + Chouette::TimeTable.new attributes + end + describe "#prepare_auto_columns" do it "should left objectid" do - tm = Chouette::TimeTable.new :comment => "merge1" , :objectid => "first:Timetable:merge1" + tm = create_object :objectid => "first:Timetable:merge1" tm.prepare_auto_columns expect(tm.objectid).to eq("first:Timetable:merge1") end it "should add pending_id to objectid" do - tm = Chouette::TimeTable.new :comment => "merge1" + tm = create_object tm.prepare_auto_columns expect(tm.objectid.start_with?("first:Timetable:__pending_id__")).to be_truthy end it "should set id to objectid" do - tm = Chouette::TimeTable.new :comment => "merge1" + tm = create_object tm.save expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s) end it "should detect objectid conflicts" do - tm = Chouette::TimeTable.new :comment => "merge1" + tm = create_object tm.save tm.objectid = "first:Timetable:"+(tm.id+1).to_s tm.save - tm = Chouette::TimeTable.new :comment => "merge1" + tm = create_object tm.save expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s+"_1") end @@ -63,53 +69,51 @@ describe Chouette::TridentActiveRecord, :type => :model do describe "objectid" do it "should build automatic objectid when empty" do - g1 = Chouette::GroupOfLine.new( :name => "g1") + g1 = create_object g1.save - expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s) + expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) end it "should build automatic objectid with fixed when only suffix given" do - g1 = Chouette::GroupOfLine.new( :name => "g1") + g1 = create_object g1.objectid = "toto" g1.save - expect(g1.objectid).to eq("first:GroupOfLine:toto") + expect(g1.objectid).to eq("first:Timetable:toto") end - + it "should build automatic objectid with extension when already exists" do - g1 = Chouette::GroupOfLine.new( :name => "g1") + g1 = create_object g1.save cnt = g1.id + 1 - g1.objectid = "first:GroupOfLine:"+cnt.to_s + g1.objectid = "first:Timetable:"+cnt.to_s g1.save - g2 = Chouette::GroupOfLine.new( :name => "g2") + g2 = create_object g2.save - expect(g2.objectid).to eq("first:GroupOfLine:"+g2.id.to_s+"_1") + expect(g2.objectid).to eq("first:Timetable:"+g2.id.to_s+"_1") end - + it "should build automatic objectid with extension when already exists" do - g1 = Chouette::GroupOfLine.new( :name => "g1") + g1 = create_object g1.save cnt = g1.id + 2 - g1.objectid = "first:GroupOfLine:"+cnt.to_s + g1.objectid = "first:Timetable:"+cnt.to_s g1.save - g2 = Chouette::GroupOfLine.new( :name => "g2") - g2.objectid = "first:GroupOfLine:"+cnt.to_s+"_1" + g2 = create_object + g2.objectid = "first:Timetable:"+cnt.to_s+"_1" g2.save - g3 = Chouette::GroupOfLine.new( :name => "g3") + g3 = create_object g3.save - expect(g3.objectid).to eq("first:GroupOfLine:"+g3.id.to_s+"_2") + expect(g3.objectid).to eq("first:Timetable:"+g3.id.to_s+"_2") end - + it "should build automatic objectid when id cleared" do - g1 = Chouette::GroupOfLine.new( :name => "g1") - g1.objectid = "first:GroupOfLine:xxxx" + g1 = create_object + g1.objectid = "first:Timetable:xxxx" g1.save g1.objectid = nil g1.save - expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s) + expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) end end end - - diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb index 024bfac07..259c7035a 100644 --- a/spec/models/line_spec.rb +++ b/spec/models/line_spec.rb @@ -1,58 +1,9 @@ require 'spec_helper' -describe "sdflkjskdjf" do +describe Chouette::Line, type: :model do subject { create(:line) } - def set_large_object_id( line) - line.update_attributes :objectid => "AA:Line:123456789012345" - end + it { is_expected.to belong_to(:line_referential) } - describe "validation objectid unique constraint" do - let(:referential){subject.referential} - let(:objectid_a){ "A:Line:1234" } - let(:objectid_b){ "B:Line:1234" } - let!(:second_line){ create( :line, :objectid => objectid_a, :registration_number => "123456") } - context "when referential works with HUB" do - before( :each) do - referential.update_attributes :data_format => "hub" - subject.update_attributes :objectid => objectid_a - end - it "should have objectid with a third part shorter than 14 char" do - subject.update_attributes :objectid => objectid_b - subject.should_not be_valid - end - end - context "when referential doesn't works with HUB" do - before( :each) do - referential.update_attributes :data_format => "hub" - end - #it "should have objectid with a third part shorter than 14 char" do - # subject.update_attributes :objectid => objectid_b, :registration_number => '324' - # subject.should be_valid - #end - end - end - describe "validation objectid size" do - let(:referential){subject.referential} - context "when referential works with HUB" do - before( :each) do - referential.update_attributes :data_format => "hub" - end - it "should have objectid with a third part shorter than 14 char" do - set_large_object_id( subject) - subject.should_not be_valid - end - end - context "when referential doesn't works with HUB" do - before( :each) do - referential.update_attributes :data_format => "hub" - end - #it "should have objectid with a third part shorter than 14 char" do - # set_large_object_id( subject) - # subject.should be_valid - #end - end - end end - |
