aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorXinhui2017-01-10 17:23:43 +0100
committerXinhui2017-01-10 17:23:49 +0100
commit60bd5e945f959c080b3c478b0495dc39466ca80f (patch)
treec226e853a55a92d1e339ec23b1aeafe87e78f9a8 /spec
parentc8a2a6d8711d93168337266e630cffdcdc803859 (diff)
downloadchouette-core-60bd5e945f959c080b3c478b0495dc39466ca80f.tar.bz2
Rspec journey_pattern state_update
Diffstat (limited to 'spec')
-rw-r--r--spec/models/chouette/journey_pattern_spec.rb46
1 files changed, 43 insertions, 3 deletions
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index 68c221c9a..9c4e2f540 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -1,11 +1,51 @@
require 'spec_helper'
describe Chouette::JourneyPattern, :type => :model do
+
+ describe "state_update" do
+ def journey_pattern_to_state jp
+ jp.attributes.slice('name', 'published_name', 'registration_number').tap do |item|
+ item['object_id'] = jp.objectid
+ item['stop_points'] = jp.stop_points.map do |sp|
+ { 'id' => sp.stop_area_id }
+ end
+ end
+ end
+
+ let(:journey_pattern) { create(:journey_pattern) }
+ let(:route) { journey_pattern.route }
+ let(:state) { journey_pattern_to_state(journey_pattern) }
+
+ it 'should delete unchecked stop_points' do
+ # Of 5 stop_points 2 are checked
+ state['stop_points'].take(2).each{|sp| sp['checked'] = true}
+ journey_pattern.state_stop_points_update(state)
+ expect(journey_pattern.stop_points.count).to eq(2)
+ end
+
+ it 'should attach checked stop_points' do
+ state['stop_points'].each{|sp| sp['checked'] = true}
+ # Make sure journey_pattern has no stop_points
+ journey_pattern.stop_points.delete_all
+ expect(journey_pattern.reload.stop_points).to be_empty
+
+ journey_pattern.state_stop_points_update(state)
+ expect(journey_pattern.reload.stop_points.count).to eq(5)
+ end
+
+ it 'should do create now instance' do
+ new_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil))
+ Chouette::JourneyPattern.state_create_instance route, new_state
+ expect(new_state['object_id']).to be_truthy
+ expect(new_state['new_record']).to be_truthy
+ end
+ end
+
describe "#stop_point_ids" do
context "for a journey_pattern using only route's stop on odd position" do
let!(:journey_pattern){ create( :journey_pattern_odd)}
let!(:vehicle_journey){ create( :vehicle_journey_odd, :journey_pattern => journey_pattern)}
-
+
# workaroud
#subject { journey_pattern}
subject { Chouette::JourneyPattern.find(vehicle_journey.journey_pattern_id)}
@@ -23,7 +63,7 @@ describe Chouette::JourneyPattern, :type => :model do
expect(subject.departure_stop_point_id).to be_nil
end
end
-
+
context "when a route's stop has been removed from journey_pattern" do
let!(:last_stop_id){ subject.stop_point_ids.last}
before(:each) do
@@ -41,7 +81,7 @@ describe Chouette::JourneyPattern, :type => :model do
expect(subject.departure_stop_point_id).to eq(ordered.first.id)
end
end
-
+
context "when a route's stop has been added in journey_pattern" do
let!(:new_stop){ subject.route.stop_points[1]}
before(:each) do