diff options
| author | vlatka pavisic | 2016-11-09 15:04:07 +0100 |
|---|---|---|
| committer | vlatka pavisic | 2016-11-09 15:04:07 +0100 |
| commit | 56c0f55d2d8d566b931664b85c76dbe3a58e31cc (patch) | |
| tree | 717b761de93b13a72f6fde9fa05b5b7cf57131ec | |
| parent | d67ed4c32b338070e4e4ff33f89fe64011e14c3b (diff) | |
| download | chouette-core-56c0f55d2d8d566b931664b85c76dbe3a58e31cc.tar.bz2 | |
Refs #1872 : Route direction and wayback enumerations
24 files changed, 124 insertions, 194 deletions
diff --git a/.gitignore b/.gitignore index 31b5d928c..b6a61fd27 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ coverage # IDE .idea + +bin/ diff --git a/app/controllers/api/v1/routes_controller.rb b/app/controllers/api/v1/routes_controller.rb index e3694725f..fbc589355 100644 --- a/app/controllers/api/v1/routes_controller.rb +++ b/app/controllers/api/v1/routes_controller.rb @@ -3,11 +3,11 @@ class Api::V1::RoutesController < Api::V1::ChouetteController defaults :resource_class => Chouette::Route, :finder => :find_by_objectid! belongs_to :line, :parent_class => Chouette::Line, :optional => true, :finder => :find_by_objectid!, :param => :line_id - + protected def collection @routes ||= parent.routes - end + end end diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 59c129867..a7e8e32a6 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -77,7 +77,7 @@ class RoutesController < ChouetteController private def route_params - params.require(:route).permit( :direction_code, :wayback_code, :line_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, { stop_points_attributes: [ :id, :_destroy, :position, :stop_area_id, :for_boarding, :for_alighting ] } ) + params.require(:route).permit( :line_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, { stop_points_attributes: [ :id, :_destroy, :position, :stop_area_id, :for_boarding, :for_alighting ] } ) end end diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb index b3d79262e..159c93054 100644 --- a/app/helpers/routes_helper.rb +++ b/app/helpers/routes_helper.rb @@ -6,11 +6,11 @@ module RoutesHelper end def fonticon_wayback(wayback) - if wayback == "A" + if wayback == 'straight_forward' return '<i class="fa fa-arrow-right"></i>'.html_safe else - return '<i class="fa fa-arrow-left"></i>'.html_safe + return '<i class="fa fa-arrow-left"></i>'.html_safe end end - + end diff --git a/app/inputs/search_stop_area_input.rb b/app/inputs/search_stop_area_input.rb index e5cfafc34..c7e21e921 100644 --- a/app/inputs/search_stop_area_input.rb +++ b/app/inputs/search_stop_area_input.rb @@ -1,5 +1,5 @@ class SearchStopAreaInput < Formtastic::Inputs::SearchInput - + def search if options[:json] tokenLimit = options[:tokenLimit].present? ? options[:tokenLimit] : "null" @@ -16,19 +16,19 @@ class SearchStopAreaInput < Formtastic::Inputs::SearchInput var item_localization = function( item){ var localization = item.zip_code + ' ' + item.short_city_name; - return localization; + return localization; }; - var item_format = function( item ){ - var name = item_name( item ); + var item_format = function( item ){ + var name = item_name( item ); var localization = item_localization( item ); - + html_result = '<li>'; html_result += '<span><image src=\"' + item.stop_area_path + '\" height=\"25px\" width=\"25px\"></span>' if(name != '') { - html_result += '<span style=\"height:25px; line-height:25px; margin-left: 5px; \">' + name + '</span>' ; - } + html_result += '<span style=\"height:25px; line-height:25px; margin-left: 5px; \">' + name + '</span>' ; + } if(localization != '') { html_result += '<small style=\"height:25px; line-height:25px; margin-left: 10px; color: #555; \">' + localization + '</small>'; @@ -48,7 +48,7 @@ class SearchStopAreaInput < Formtastic::Inputs::SearchInput noResultsText: '#{options[:no_result_text]}', searchingText: '#{options[:searching_text]}', resultsFormatter: item_format, - tokenFormatter: item_format, + tokenFormatter: item_format, }); });").html_safe) end @@ -62,7 +62,7 @@ class SearchStopAreaInput < Formtastic::Inputs::SearchInput end end - def input_html_options + def input_html_options css_class = super[:class] super.merge({ :required => nil, diff --git a/app/models/chouette/for_alighting_enumerations.rb b/app/models/chouette/for_alighting_enumerations.rb index 4f34927d3..ab07a670d 100644 --- a/app/models/chouette/for_alighting_enumerations.rb +++ b/app/models/chouette/for_alighting_enumerations.rb @@ -2,7 +2,7 @@ module Chouette module ForAlightingEnumerations extend Enumerize extend ActiveModel::Naming - + enumerize :for_alighting, in: %w[normal forbidden request_stop is_flexible] end end diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 8949a6bc2..446eb5f70 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -1,14 +1,17 @@ class Chouette::Route < Chouette::TridentActiveRecord include RouteRestrictions + extend Enumerize + extend ActiveModel::Naming + + enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east) + enumerize :wayback, in: %i(straight_forward backward) + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" - attr_accessor :wayback_code - attr_accessor :direction_code - def self.nullable_attributes - [:published_name, :comment, :number, :name] + [:published_name, :comment, :number, :name, :direction, :wayback] end belongs_to :line @@ -61,8 +64,11 @@ class Chouette::Route < Chouette::TridentActiveRecord # validates_presence_of :name validates_presence_of :line - # validates_presence_of :direction_code - # validates_presence_of :wayback_code + # validates_presence_of :direction + # validates_presence_of :wayback + + validates :direction, inclusion: { in: self.direction.values } + validates :wayback, inclusion: { in: self.wayback.values } before_destroy :dereference_opposite_route @@ -96,52 +102,6 @@ class Chouette::Route < Chouette::TridentActiveRecord .order( "vehicle_journey_at_stops.departure_time") end - def self.direction_binding - { "A" => "straight_forward", - "R" => "backward", - "ClockWise" => "clock_wise", - "CounterClockWise" => "counter_clock_wise", - "North" => "north", - "NorthWest" => "north_west", - "West" => "west", - "SouthWest" => "south_west", - "South" => "south", - "SouthEast" => "south_east", - "East" => "east", - "NorthEast" => "north_east"} - end - def direction_code - return nil if self.class.direction_binding[direction].nil? - Chouette::Direction.new( self.class.direction_binding[direction]) - end - def direction_code=(direction_code) - self.direction = nil - self.class.direction_binding.each do |k,v| - self.direction = k if v==direction_code - end - end - @@directions = nil - def self.directions - @@directions ||= Chouette::Direction.all - end - def self.wayback_binding - { "A" => "straight_forward", "R" => "backward"} - end - def wayback_code - return nil if self.class.wayback_binding[wayback].nil? - Chouette::Wayback.new( self.class.wayback_binding[wayback]) - end - def wayback_code=(wayback_code) - self.wayback = nil - self.class.wayback_binding.each do |k,v| - self.wayback = k if v==wayback_code - end - end - @@waybacks = nil - def self.waybacks - @@waybacks ||= Chouette::Wayback.all - end - def stop_point_permutation?( stop_point_ids) stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort end diff --git a/app/models/concerns/route_restrictions.rb b/app/models/concerns/route_restrictions.rb index 5a098d86f..4a21cbccf 100644 --- a/app/models/concerns/route_restrictions.rb +++ b/app/models/concerns/route_restrictions.rb @@ -8,7 +8,7 @@ module RouteRestrictions # HUB-37 def wayback_code_limitation return unless hub_restricted? - errors.add( :wayback_code, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) + errors.add( :wayback, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback).include?( wayback) end # HUB-37 diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 7d3b638cb..e1f048fd8 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -6,7 +6,7 @@ class LineReferential < ActiveRecord::Base has_many :group_of_lines, class_name: 'Chouette::GroupOfLine' has_many :companies, class_name: 'Chouette::Company' has_many :networks, class_name: 'Chouette::Network' - has_many :line_referential_syncs, -> { order created_at: :desc} + has_many :line_referential_syncs, -> { order created_at: :desc } has_many :workbenches def add_member(organisation, options = {}) diff --git a/app/views/api/kml/routes/show.kml.slim b/app/views/api/kml/routes/show.kml.slim index 3b08d81ce..51d2817c8 100644 --- a/app/views/api/kml/routes/show.kml.slim +++ b/app/views/api/kml/routes/show.kml.slim @@ -6,11 +6,11 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{@route.objectid}" name = h(@route.name) extendeddata - - [:direction_code, :wayback_code, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :published_name, :number, :direction, :wayback].each do |prop| + - [:direction, :wayback, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :published_name, :number, :direction_text, :wayback_text].each do |prop| data name="#{prop.to_s}" value = h(@route.send( prop)) data name="line_objectid" value = h(@route.line.objectid) - = @route.geometry_presenter.geometry.kml_representation.html_safe
\ No newline at end of file + = @route.geometry_presenter.geometry.kml_representation.html_safe diff --git a/app/views/footnotes/_footnote_fields.html.slim b/app/views/footnotes/_footnote_fields.html.slim index ab006cfa9..c1944ed2d 100644 --- a/app/views/footnotes/_footnote_fields.html.slim +++ b/app/views/footnotes/_footnote_fields.html.slim @@ -1,4 +1,4 @@ = f.inputs :class => 'nested-fields footnote' do = f.input :code, :wrapper_html => { class: 'col-md-3' } = f.input :label, :wrapper_html => { class: 'col-md-7' } - = link_to_remove_association t('actions.destroy'), f, class: 'col-md-2 remove'
\ No newline at end of file + = link_to_remove_association t('actions.destroy'), f, class: 'col-md-2 remove' diff --git a/app/views/lines/_form.html.slim b/app/views/lines/_form.html.slim index 113a5c46c..ace0c4548 100644 --- a/app/views/lines/_form.html.slim +++ b/app/views/lines/_form.html.slim @@ -19,11 +19,11 @@ .footnotes_block h3 = t("footnotes.index.title") - + #footnotes = form.semantic_fields_for :footnotes do |f| = render "footnotes/footnote_fields", :f => f - + .add_footnote = link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes , :partial => "footnotes/footnote_fields", :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#footnotes", class: 'add' @@ -32,7 +32,7 @@ = form.action :cancel, as: :link javascript: - $(function() { + $(function() { $("#line_group_of_line_tokens").tokenInput("#{name_filter_referential_group_of_lines_path(@line_referential, format: :json)}", { crossDomain: false, prePopulate: $('#group_of_line_tokens').data('pre'), @@ -42,4 +42,4 @@ javascript: noResultsText: "#{I18n.t('no_result_text')}", searchingText: "#{I18n.t('searching_term')}" }); - });
\ No newline at end of file + }); diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index d5fed0344..044a745ec 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -44,7 +44,7 @@ h2 - if @referential.api_keys.present? h3.api_keys = t('.api_keys') - + .api_keys.paginated_content = paginated_content(@referential.api_keys, "api_keys/api_key") @@ -70,4 +70,4 @@ h2 h4 = t('.clean_up') - == render 'clean'
\ No newline at end of file + == render 'clean' diff --git a/app/views/routes/_form.html.slim b/app/views/routes/_form.html.slim index 329862955..d23188fa1 100644 --- a/app/views/routes/_form.html.slim +++ b/app/views/routes/_form.html.slim @@ -5,8 +5,8 @@ = form.input :number = form.input :comment = form.input :opposite_route, as: :select, :collection => @line.routes.select { |r| r.id != @route.id } - = form.input :direction_code, as: :select, :collection => Chouette::Route.directions, :include_blank => false, :member_label => Proc.new { |mode| t("directions.label.#{mode}") } - = form.input :wayback_code, as: :select, :collection => Chouette::Route.waybacks, :include_blank => false, :member_label => Proc.new { |mode| t("waybacks.label.#{mode}") } + = form.input :direction, :include_blank => false + = form.input :wayback, :include_blank => false = form.input :objectid, :required => !@route.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.route.objectid")} #stop_points @@ -88,4 +88,4 @@ javascript: write_stop_point_ids(); order_position(); }); - });
\ No newline at end of file + }); diff --git a/app/views/routes/_route.html.slim b/app/views/routes/_route.html.slim index fd740fa9b..5a377761f 100644 --- a/app/views/routes/_route.html.slim +++ b/app/views/routes/_route.html.slim @@ -11,9 +11,9 @@ h5 = link_to [@referential, @line, route], class: 'preview', title: "#{Chouette::Route.model_name.human.capitalize} #{route.name}" do span.name - - if route.wayback_code + - if route.wayback = fonticon_wayback(route.wayback) - + = truncate(route.name, length: 20) .panel-body @@ -38,6 +38,6 @@ p - if !route.direction.blank? - = "#{route.human_attribute_name('direction_code')} : #{t('directions.label.'+route.direction_code)}" + => "#{route.human_attribute_name('direction')} : #{route.direction_text}" - else - br
\ No newline at end of file + br diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index a4e1aa90f..f71a01cef 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -21,16 +21,16 @@ = @route.comment p - label = "#{@route.human_attribute_name(:direction_code)} : " - - if @route.direction_code - = t("directions.label.#{@route.direction_code}").capitalize + label = "#{@route.human_attribute_name(:direction)} : " + - if @route.direction + = @route.direction_text - else = t(".undefined") p - label = "#{@route.human_attribute_name(:wayback_code)} : " - - if @route.wayback_code - = t("waybacks.label.#{@route.wayback_code}").capitalize + label = "#{@route.human_attribute_name(:wayback)} : " + - if @route.wayback + = @route.wayback_text - else = t(".undefined") @@ -76,10 +76,10 @@ p.after_map ul.actions - if @route.stop_points.size >= 2 li = link_to t('journey_patterns.actions.new'), new_referential_line_route_journey_pattern_path(@referential, @line, @route), class: 'add' - + - if @route.stop_points.present? li = link_to t('routes.actions.edit_boarding_alighting'), edit_boarding_alighting_referential_line_route_path(@referential, @line, @route), class: 'edit' - + - if @route.journey_patterns.size > 0 li = link_to t('vehicle_journeys.actions.index'), [@referential, @line, @route, :vehicle_journeys], class: 'clock' @@ -87,4 +87,4 @@ p.after_map li = link_to t('vehicle_journey_imports.new.title'), new_referential_line_route_vehicle_journey_import_path( @referential, @line, @route ), class: 'import' li = link_to t('vehicle_journey_exports.new.title'), referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, format: :zip), class: 'export' - = creation_tag(@route)
\ No newline at end of file + = creation_tag(@route) diff --git a/config/locales/directions.en.yml b/config/locales/directions.en.yml index 575ffe90d..05bc29da3 100644 --- a/config/locales/directions.en.yml +++ b/config/locales/directions.en.yml @@ -3,7 +3,7 @@ en: label: straight_forward: "straight forward" backward: "backward" - clock_wise: "clockwise" + clockwise: "clockwise" counter_clock_wise: "counterclockwise" north: "north" north_west: "north west" diff --git a/config/locales/enumerize.en.yml b/config/locales/enumerize.en.yml index 99e2edb75..aab0bcf32 100644 --- a/config/locales/enumerize.en.yml +++ b/config/locales/enumerize.en.yml @@ -33,3 +33,20 @@ en: netex: "Experimental" hub: "Specific Transdev Format" kml: "line, route, ... drawings on Keyhole Markup Language format" + route: + direction: + straight_forward: 'Straight Forward' + backward: 'Backward' + clockwise: 'ClockWise' + counter_clockwise: 'Counter Clockwise' + north: 'North' + north_west: 'North West' + west: 'West' + south_west: 'South West' + south: 'South' + south_east: 'South East' + east: 'East' + north_east: 'North East' + wayback: + straight_forward: 'Straight Forward' + backward: 'Backward' diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index 4bfd71d28..b800521e3 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -1,6 +1,6 @@ fr: - simple_form: - include_blanks: + simple_form: + include_blanks: defaults: for_boarding: "Non défini" for_alighting: "Non défini" @@ -9,7 +9,7 @@ fr: normal: "Montée autorisée" forbidden: "Montée interdite" request_stop: "Montée sur demande au conducteur" - is_flexible: "Montée sur réservation" + is_flexible: "Montée sur réservation" for_alighting: normal: "Descente autorisée" forbidden: "Descente interdite" @@ -32,4 +32,21 @@ fr: gtfs: "General Transit Feed Specification défini par Google" netex: "Expérimental" hub: "Format spécifique Transdev" - kml: "Tracés de lignes, séquences d'arrêts, ... en 'Keyhole Markup Language'" + kml: "Tracés de lignes, séquences d'arrêts, ... en 'Keyhole Markup Language'" + route: + direction: + straight_forward: 'Aller' + backward: 'Retour' + clockwise: 'Sens horaire' + counter_clockwise: 'Sens anti horaire' + north: 'Nord' + north_west: 'Nord Ouest' + west: 'Ouest' + south_west: 'Sud Ouest' + south: 'Sud' + south_east: 'Sud Est' + east: 'Est' + north_east: 'Nord Est' + wayback: + straight_forward: 'Aller' + backward: 'Retour' diff --git a/config/locales/routes.en.yml b/config/locales/routes.en.yml index a3a26cb8c..b78feff0f 100644 --- a/config/locales/routes.en.yml +++ b/config/locales/routes.en.yml @@ -18,8 +18,8 @@ en: title: "Update route %{route}" show: title: "Route %{route}" - stop_points: "Stop point on route list" - journey_patterns: "Route journey patterns list" + stop_points: "Stop point on route list" + journey_patterns: "Route journey patterns list" no_opposite_route: "No reversed route associated" undefined: "Undefined" index: @@ -33,37 +33,37 @@ en: for_alighting: "Alighting" route: no_journey_pattern: "No Journey pattern" - wayback: + wayback: positive: "forward" negative: "backward" opposite: "Opposite route" no_opposite: "No opposite route" - activerecord: - models: - route: + activerecord: + models: + route: zero: "route" one: "route" other: "routes" attributes: route: - wayback: + wayback: positive: "forward" negative: "backward" line: "Line" vehicle_journeys: "Vehicle journeys" journey_patterns: "Journey patterns" name: "Name" - published_name: "Published name" + published_name: "Published name" comment: "Comments" number: "Number" - direction_code: "Direction" - wayback_code: "Wayback" + direction: "Direction" + wayback: "Wayback" opposite_route: "Reversed route" objectid: "Neptune identifier" object_version: "Version" creation_time: "Created on" creator_id: "Created by" - no_journey_pattern: "No journey pattern" + no_journey_pattern: "No journey pattern" formtastic: titles: route: diff --git a/config/locales/routes.fr.yml b/config/locales/routes.fr.yml index ea190e6e2..f80693b8b 100644 --- a/config/locales/routes.fr.yml +++ b/config/locales/routes.fr.yml @@ -56,8 +56,8 @@ fr: published_name: "Nom public" number: "Indice" comment: "Commentaire" - direction_code: "Direction" - wayback_code: "Sens" + direction: "Direction" + wayback: "Sens" opposite_route: "Séquence d'arrêts associée en sens opposé" objectid: "Identifiant Neptune" object_version: "Version" diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 047c35912..e872d24f5 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -4,23 +4,23 @@ FactoryGirl.define do sequence(:name) { |n| "Route #{n}" } sequence(:published_name) { |n| "Long route #{n}" } sequence(:number) { |n| "#{n}" } - sequence(:wayback_code) { |n| Chouette::Wayback.new( n % 2) } - sequence(:direction_code) { |n| Chouette::Direction.new( n % 12) } + sequence(:wayback) { |n| Chouette::Route.wayback.values[n % 2] } + sequence(:direction) { |n| Chouette::Route.direction.values[n % 12] } sequence(:objectid) { |n| "test:Route:#{n}" } - + association :line, :factory => :line - + factory :route do transient do stop_points_count 5 end - + after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) end - + end end - + end diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb index c50ff50bc..bb4b8ae3b 100644 --- a/spec/features/routes_spec.rb +++ b/spec/features/routes_spec.rb @@ -34,8 +34,8 @@ describe "Routes", :type => :feature do click_link "Ajouter une séquence d'arrêts" fill_in "route_name", :with => "A to B" fill_in "Indice", :with => "AB" - select 'aller', :from => "route_direction_code" - select 'aller', :from => "route_wayback_code" + select 'Aller', :from => "route_direction" + select 'Aller', :from => "route_wayback" click_button("Créer séquence d'arrêts") expect(page).to have_content("A to B") end 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 |
