aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorvlatka pavisic2016-11-09 15:04:07 +0100
committervlatka pavisic2016-11-09 15:04:07 +0100
commit56c0f55d2d8d566b931664b85c76dbe3a58e31cc (patch)
tree717b761de93b13a72f6fde9fa05b5b7cf57131ec /spec/models
parentd67ed4c32b338070e4e4ff33f89fe64011e14c3b (diff)
downloadchouette-core-56c0f55d2d8d566b931664b85c76dbe3a58e31cc.tar.bz2
Refs #1872 : Route direction and wayback enumerations
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/chouette/route_spec.rb78
1 files changed, 6 insertions, 72 deletions
diff --git a/spec/models/chouette/route_spec.rb b/spec/models/chouette/route_spec.rb
index 1acc5a0f7..0392485d8 100644
--- a/spec/models/chouette/route_spec.rb
+++ b/spec/models/chouette/route_spec.rb
@@ -3,17 +3,21 @@ require 'spec_helper'
describe Chouette::Route, :type => :model do
subject { create(:route) }
- it { is_expected.to validate_uniqueness_of :objectid }
-
describe '#objectid' do
subject { super().objectid }
it { is_expected.to be_kind_of(Chouette::ObjectId) }
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(:straight_forward, :backward) }
+
#it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :line }
+ it { is_expected.to validate_uniqueness_of :objectid }
#it { is_expected.to validate_presence_of :wayback_code }
#it { is_expected.to validate_presence_of :direction_code }
+ it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) }
+ it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(straight_forward backward)) }
context "reordering methods" do
let( :bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}}
@@ -165,74 +169,4 @@ describe Chouette::Route, :type => :model do
end
end
end
-
- describe "#direction_code" do
- def self.legacy_directions
- %w{A R ClockWise CounterClockWise North NorthWest West SouthWest
- South SouthEast East NorthEast}
- end
- legacy_directions.each do |direction|
- context "when direction is #{direction}" do
- direction_code = Chouette::Direction.new( Chouette::Route.direction_binding[ direction])
- it "should be #{direction_code}" do
- subject.direction = direction
- expect(subject.direction_code).to eq(direction_code)
- end
- end
- end
- context "when direction is nil" do
- it "should be nil" do
- subject.direction = nil
- expect(subject.direction_code).to be_nil
- end
- end
- end
- describe "#direction_code=" do
- context "when unknown direction is provided" do
- it "should change direction to nil" do
- subject.direction_code = "dummy"
- expect(subject.direction).to be_nil
- end
- end
- context "when an existing direction (west) is provided" do
- it "should change direction Direction.west" do
- subject.direction_code = "west"
- expect(subject.direction).to eq("West")
- end
- end
- end
- describe "#wayback_code" do
- def self.legacy_waybacks
- %w{A R}
- end
- legacy_waybacks.each do |wayback|
- context "when wayback is #{wayback}" do
- wayback_code = Chouette::Wayback.new( Chouette::Route.wayback_binding[ wayback])
- it "should be #{wayback_code}" do
- subject.wayback = wayback
- expect(subject.wayback_code).to eq(wayback_code)
- end
- end
- end
- context "when wayback is nil" do
- it "should be nil" do
- subject.wayback = nil
- expect(subject.wayback_code).to be_nil
- end
- end
- end
- describe "#wayback_code=" do
- context "when unknown wayback is provided" do
- it "should change wayback to nil" do
- subject.wayback_code = "dummy"
- expect(subject.wayback).to be_nil
- end
- end
- context "when an existing wayback (straight_forward) is provided" do
- it "should change wayback Wayback.straight_forward" do
- subject.wayback_code = "straight_forward"
- expect(subject.wayback).to eq("A")
- end
- end
- end
end