diff options
47 files changed, 495 insertions, 247 deletions
diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js index 3577df2b6..34689070d 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js @@ -90,10 +90,7 @@ const actions = { resetValidation: (target) => { $(target).parent().removeClass('has-error').children('.help-block').remove() }, - humanOID : (oid) => { - var a = oid.split(':') - return a[a.length - 1] - }, + humanOID : (oid) => oid.split(':')[2], validateFields : (fields) => { const test = [] diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index 2fde0d76f..de87c14af 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -269,10 +269,7 @@ const actions = { type: 'RECEIVE_TOTAL_COUNT', total }), - humanOID : (oid) => { - var a = oid.split(':') - return a[a.length - 1] - }, + humanOID: (oid) => oid.split(':')[2], fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString) => { if(currentPage == undefined){ currentPage = 1 diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb index 476f13c08..4a1ae8a0e 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -4,6 +4,7 @@ require 'geo_ruby' class Chouette::AccessPoint < Chouette::ActiveRecord # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" + include StifReflexAttributesSupport include Geokit::Mappable include ProjectionFields @@ -23,12 +24,15 @@ class Chouette::AccessPoint < Chouette::ActiveRecord validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true - + before_save :coordinates_to_lat_lng def self.nullable_attributes [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name] end - before_save :coordinates_to_lat_lng + + def referential + @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! + end def referential @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index 7b96e875e..a472020e1 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -1,6 +1,6 @@ class Chouette::Company < Chouette::ActiveRecord include CompanyRestrictions - include DefaultNetexAttributesSupport + include StifCodifligneAttributesSupport include LineReferentialSupport has_many :lines diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb index d954c6699..a987d6311 100644 --- a/app/models/chouette/group_of_line.rb +++ b/app/models/chouette/group_of_line.rb @@ -1,5 +1,5 @@ class Chouette::GroupOfLine < Chouette::ActiveRecord - include DefaultNetexAttributesSupport + include StifCodifligneAttributesSupport include GroupOfLineRestrictions include LineReferentialSupport diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index fa5fba26d..2b62d5c7f 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -21,6 +21,11 @@ class Chouette::JourneyPattern < Chouette::TridentActiveRecord attr_accessor :control_checked after_update :control_route_sections, :unless => "control_checked" + + def local_id + "IBOO-#{self.try(:route).try(:line).try(:objectid).try(:local_id)}-#{self.referential.id}-#{self.id}" + end + def checksum_attributes values = self.slice(*['name', 'published_name', 'registration_number']).values values << self.stop_points.map(&:stop_area).map(&:user_objectid) diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index 690c39344..8df205789 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -1,5 +1,5 @@ class Chouette::Network < Chouette::ActiveRecord - include DefaultNetexAttributesSupport + include StifCodifligneAttributesSupport include NetworkRestrictions include LineReferentialSupport # FIXME http://jira.codehaus.org/browse/JRUBY-6358 diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 6774e8a86..5b89fbbe8 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -75,6 +75,10 @@ class Chouette::Route < Chouette::TridentActiveRecord after_commit :journey_patterns_control_route_sections + def local_id + "IBOO-#{self.line.objectid.local_id}-#{self.referential.id}-#{self.id}" + end + def geometry_presenter Chouette::Geometry::RoutePresenter.new self end diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 9931748b2..21efa2539 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -8,6 +8,10 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } validate :stop_points_belong_to_route, :not_all_stop_points_selected + def local_id + "IBOO-#{self.route.line.objectid.local_id}-#{self.route.objectid.local_id}-#{self.referential.id}-#{self.id}" + end + scope :order_by_stop_points_count, ->(direction) do order("array_length(stop_point_ids, 1) #{direction}") end diff --git a/app/models/chouette/stif_netex_objectid.rb b/app/models/chouette/stif_netex_objectid.rb new file mode 100644 index 000000000..3b11691d9 --- /dev/null +++ b/app/models/chouette/stif_netex_objectid.rb @@ -0,0 +1,38 @@ +class Chouette::StifNetexObjectid < String + def valid? + parts.present? + end + + @@format = /^([A-Za-z_]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + cattr_reader :format + + def parts + match(format).try(:captures) + end + + def provider_id + parts.try(:first) + end + + def object_type + parts.try(:second) + end + + def local_id + parts.try(:third) + end + + def boiv_id + parts.try(:fourth) + end + + def self.create(provider_id, object_type, local_id, boiv_id) + new [provider_id, object_type, local_id, boiv_id].join(":") + end + + def self.new(string) + string ||= "" + self === string ? string : super + end + +end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 8aff3bf36..8821a5201 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -31,6 +31,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord after_save :save_shortcuts + def local_id + "IBOO-#{self.referential.id}-#{self.id}" + end + def checksum_attributes [].tap do |attrs| attrs << self.int_day_types @@ -557,8 +561,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord end def duplicate - tt = self.deep_clone :include => [:periods, :dates], :except => :object_version - tt.uniq_objectid + tt = self.deep_clone :include => [:periods, :dates], :except => [:object_version, :objectid] tt.tag_list.add(*self.tag_list) unless self.tag_list.empty? tt.created_from = self tt.comment = I18n.t("activerecord.copy", :name => self.comment) diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb index c1bc0172b..e8223e3d6 100644 --- a/app/models/chouette/trident_active_record.rb +++ b/app/models/chouette/trident_active_record.rb @@ -1,5 +1,5 @@ class Chouette::TridentActiveRecord < Chouette::ActiveRecord - include DefaultAttributesSupport + include StifNetexAttributesSupport self.abstract_class = true diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index d5ca58959..e60afef6e 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -56,6 +56,10 @@ module Chouette end end + def local_id + "IBOO-#{self.route.line.objectid.local_id}-#{self.referential.id}-#{self.id}" + end + def checksum_attributes [].tap do |attrs| attrs << self.published_journey_name diff --git a/app/models/concerns/line_referential_support.rb b/app/models/concerns/line_referential_support.rb index 4ad437fed..406730ddb 100644 --- a/app/models/concerns/line_referential_support.rb +++ b/app/models/concerns/line_referential_support.rb @@ -3,18 +3,10 @@ module LineReferentialSupport included do belongs_to :line_referential - # validates_presence_of :line_referential_id - alias_method :referential, :line_referential end def hub_restricted? false end - - def prefix - # FIXME #825 - "dummy" - end - end diff --git a/app/models/concerns/stif_netex_attributes_support.rb b/app/models/concerns/stif_netex_attributes_support.rb new file mode 100644 index 000000000..795872755 --- /dev/null +++ b/app/models/concerns/stif_netex_attributes_support.rb @@ -0,0 +1,58 @@ +module StifNetexAttributesSupport + extend ActiveSupport::Concern + + included do + validates_numericality_of :object_version + validates :objectid, uniqueness: true, presence: true + validate :objectid_format_compliance + + after_save :build_objectid + before_validation :default_values, on: :create + end + + module ClassMethods + def object_id_key + model_name + end + + def model_name + ActiveModel::Name.new self, Chouette, self.name.demodulize + end + end + + def objectid_format_compliance + errors.add :objectid, I18n.t("activerecord.errors.models.trident.invalid_object_id") if !objectid.valid? + end + + def local_id + "IBOO-#{self.referential.id}-#{self.id}" + end + + def build_objectid + if objectid.include? ':__pending_id__' + self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, self.local_id, self.boiv_id) + self.save + end + end + + def default_values + self.object_version ||= 1 + + if self.objectid.to_s.empty? + local_id = "__pending_id__#{rand(50)+ rand(50)}" + self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, local_id, self.boiv_id) + end + end + + def objectid + Chouette::StifNetexObjectid.new read_attribute(:objectid) + end + + def provider_id + self.referential.workbench.organisation.name.parameterize + end + + def boiv_id + 'LOC' + end +end diff --git a/app/models/concerns/stop_area_referential_support.rb b/app/models/concerns/stop_area_referential_support.rb index 5a01ef57e..aa59cbd35 100644 --- a/app/models/concerns/stop_area_referential_support.rb +++ b/app/models/concerns/stop_area_referential_support.rb @@ -3,17 +3,10 @@ module StopAreaReferentialSupport included do belongs_to :stop_area_referential - # validates_presence_of :stop_area_referential_id - alias_method :referential, :stop_area_referential end def hub_restricted? false end - - def prefix - # FIXME #825 - "dummy" - end end diff --git a/app/models/data_format_enumerations.rb b/app/models/data_format_enumerations.rb index 94c39e152..787ab6cca 100644 --- a/app/models/data_format_enumerations.rb +++ b/app/models/data_format_enumerations.rb @@ -1,6 +1,6 @@ module DataFormatEnumerations extend Enumerize extend ActiveModel::Naming - - enumerize :data_format, in: %w[neptune netex gtfs hub], default: "neptune" + + enumerize :data_format, in: %w[neptune netex gtfs hub], default: "netex" end diff --git a/app/models/vehicle_journey_import.rb b/app/models/vehicle_journey_import.rb index 855fa2abe..44a6d457e 100644 --- a/app/models/vehicle_journey_import.rb +++ b/app/models/vehicle_journey_import.rb @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -class VehicleJourneyImport +class VehicleJourneyImport include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming @@ -8,11 +8,11 @@ class VehicleJourneyImport attr_accessor :file, :route attr_accessor :created_vehicle_journey_count,:updated_vehicle_journey_count,:deleted_vehicle_journey_count attr_accessor :created_journey_pattern_count,:error_count - + validates_presence_of :file validates_presence_of :route - def initialize(attributes = {}) + def initialize(attributes = {}) attributes.each { |name, value| send("#{name}=", value) } if attributes self.created_vehicle_journey_count = 0 self.updated_vehicle_journey_count = 0 @@ -20,15 +20,15 @@ class VehicleJourneyImport self.deleted_vehicle_journey_count = 0 self.error_count = 0 end - + def persisted? false end - + def save begin - Chouette::VehicleJourney.transaction do - if imported_vehicle_journeys.map(&:valid?).all? + Chouette::VehicleJourney.transaction do + if imported_vehicle_journeys.map(&:valid?).all? imported_vehicle_journeys.each(&:save!) true else @@ -46,8 +46,8 @@ class VehicleJourneyImport errors.add :base, I18n.t("vehicle_journey_imports.errors.exception") false end - end - + end + def imported_vehicle_journeys @imported_vehicle_journeys ||= load_imported_vehicle_journeys end @@ -61,31 +61,31 @@ class VehicleJourneyImport if stop_points_used.length == 1 errors.add :base, I18n.t("vehicle_journey_imports.errors.one_stop_point_used", :column => column) - raise + raise end - + journey_pattern_founded = route.journey_patterns.select{ |jp| jp.stop_points.collect(&:id) == stop_points_used }.first - + # If no journey pattern founded, create a new one self.created_journey_pattern_count += 1 if journey_pattern_founded.nil? journey_pattern_founded ? journey_pattern_founded : route.journey_patterns.create(:stop_points => Chouette::StopPoint.find(stop_points_used) ) end - + def as_integer(v) v.blank? ? nil : v.to_i end - + def as_boolean(v) v.blank? ? nil : (v[1..1].downcase != "n") end - + def update_time_tables(vj,tm_ids) vj.time_tables.clear return unless tm_ids.present? ids = tm_ids.split(",").map(&:to_i) vj.time_tables << Chouette::TimeTable.where(:id => ids) end - + def update_footnotes(vj,ftn_ids) vj.footnotes.clear return unless ftn_ids.present? @@ -94,13 +94,13 @@ class VehicleJourneyImport end def load_imported_vehicle_journeys - + spreadsheet = open_spreadsheet(file) - + vehicle_journeys = [] - + first_column = spreadsheet.column(1) - + # fixed rows (first = 1) number_row = 2 published_journey_name_row = 3 @@ -111,7 +111,7 @@ class VehicleJourneyImport # rows in column (first = 0) first_stop_row_index = 8 - + stop_point_ids = first_column[first_stop_row_index..spreadsheet.last_row].map(&:to_i) # blank lines at end of file will produce id = 0 ; ignore them last_stop_row_index = stop_point_ids.length + 7 @@ -119,50 +119,50 @@ class VehicleJourneyImport stop_point_ids = stop_point_ids[0..-2] last_stop_row_index -= 1 end - + unless route.stop_points.collect(&:id) == stop_point_ids errors.add :base, I18n.t("vehicle_journey_imports.errors.not_same_stop_points", :route => route.id) raise - end - + end + (3..spreadsheet.last_column).each do |i| vehicle_journey_id = spreadsheet.column(i)[0] hours_by_stop_point_ids = Hash[[stop_point_ids, spreadsheet.column(i)[first_stop_row_index..last_stop_row_index]].transpose] - + journey_pattern = find_journey_pattern_schedule(i,hours_by_stop_point_ids) - + vehicle_journey = route.vehicle_journeys.where(:id => vehicle_journey_id, :route_id => route.id).first_or_initialize if journey_pattern.nil? - if vehicle_journey.id.present? + if vehicle_journey.id.present? self.deleted_vehicle_journey_count += 1 vehicle_journey.delete end next end - if vehicle_journey.id.present? + if vehicle_journey.id.present? self.updated_vehicle_journey_count += 1 else self.created_vehicle_journey_count += 1 end - + # number vehicle_journey.number = as_integer(spreadsheet.row(number_row)[i-1]) - + # published_name vehicle_journey.published_journey_name = spreadsheet.row(published_journey_name_row)[i-1] - + # flexible_service vehicle_journey.flexible_service = as_boolean(spreadsheet.row(flexible_service_row)[i-1]) - + # mobility vehicle_journey.mobility_restricted_suitability = as_boolean(spreadsheet.row(mobility_row)[i-1]) - + # time_tables update_time_tables(vehicle_journey,spreadsheet.row(time_tables_row)[i-1]) - + update_footnotes(vehicle_journey,spreadsheet.row(footnotes_row)[i-1]) - + # journey_pattern vehicle_journey.journey_pattern = journey_pattern vehicle_journey.vehicle_journey_at_stops.clear @@ -171,7 +171,7 @@ class VehicleJourneyImport hours_by_stop_point_ids.each_pair do |key, value| line += 1 if value.present? # Create a vehicle journey at stop when time is present - begin + begin # force UTC to ignore timezone effects main_time = Time.parse(value+" UTC") if main_time.present? @@ -182,14 +182,14 @@ class VehicleJourneyImport errors.add :base, I18n.t("vehicle_journey_imports.errors.invalid_vehicle_journey_at_stop", :column => i, :line => line, :time => value) raise exception end - end + end end vehicle_journeys << vehicle_journey end - + vehicle_journeys end - + def open_spreadsheet(file) case File.extname(file.original_filename) when '.csv' then Roo::CSV.new(file.path, csv_options: {col_sep: ";"}) @@ -199,5 +199,5 @@ class VehicleJourneyImport raise "Unknown file type: #{file.original_filename}" end end - + end diff --git a/app/models/workbench.rb b/app/models/workbench.rb index c37cba858..30692e625 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -10,6 +10,7 @@ class Workbench < ActiveRecord::Base has_many :stop_areas, through: :stop_area_referential has_many :imports has_many :workbench_imports + validates :name, presence: true validates :organisation, presence: true diff --git a/db/migrate/20170808083322_change_referential_date_format_to_netex.rb b/db/migrate/20170808083322_change_referential_date_format_to_netex.rb new file mode 100644 index 000000000..dc706942c --- /dev/null +++ b/db/migrate/20170808083322_change_referential_date_format_to_netex.rb @@ -0,0 +1,9 @@ +class ChangeReferentialDateFormatToNetex < ActiveRecord::Migration + def up + execute "UPDATE referentials SET data_format = 'netex'" + end + + def down + execute "UPDATE referentials SET data_format = 'neptune'" + end +end diff --git a/db/migrate/20170808091929_change_objectid_suffix.rb b/db/migrate/20170808091929_change_objectid_suffix.rb new file mode 100644 index 000000000..da98e8b9d --- /dev/null +++ b/db/migrate/20170808091929_change_objectid_suffix.rb @@ -0,0 +1,17 @@ +class ChangeObjectidSuffix < ActiveRecord::Migration + def tables + ['routes', 'journey_patterns', 'vehicle_journeys', 'time_tables', 'routing_constraint_zones'] + end + + def up + self.tables.each do |table| + execute "UPDATE #{table} SET objectid = (objectid || ':LOC')" + end + end + + def down + self.tables.each do |table| + execute "UPDATE #{table} SET objectid = replace(objectid, ':LOC', '')" + end + end +end diff --git a/spec/factories/chouette_access_links.rb b/spec/factories/chouette_access_links.rb index 94717e95e..8b4e89be9 100644 --- a/spec/factories/chouette_access_links.rb +++ b/spec/factories/chouette_access_links.rb @@ -1,9 +1,9 @@ FactoryGirl.define do - + factory :access_link, :class => Chouette::AccessLink do sequence(:name) { |n| "Access link #{n}" } - sequence(:objectid) { |n| "test:AccessLink:#{n}" } - link_type "Mixed" + sequence(:objectid) { |n| "test:AccessLink:#{n}:loc" } + link_type "Mixed" link_orientation "AccessPointToStopArea" association :stop_area, :factory => :stop_area diff --git a/spec/factories/chouette_companies.rb b/spec/factories/chouette_companies.rb index 35ce34257..9272736cf 100644 --- a/spec/factories/chouette_companies.rb +++ b/spec/factories/chouette_companies.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :company, :class => Chouette::Company do sequence(:name) { |n| "Company #{n}" } - sequence(:objectid) { |n| "chouette:test:Company:#{n}" } + sequence(:objectid) { |n| "STIF:CODIFLIGNE:Company:#{n}" } sequence(:registration_number) { |n| "test-#{n}" } association :line_referential, :factory => :line_referential diff --git a/spec/factories/chouette_connection_links.rb b/spec/factories/chouette_connection_links.rb index f70548721..9185480ac 100644 --- a/spec/factories/chouette_connection_links.rb +++ b/spec/factories/chouette_connection_links.rb @@ -3,11 +3,11 @@ FactoryGirl.define do factory :connection_link, :class => Chouette::ConnectionLink do sequence(:name) { |n| "Connection link #{n}" } sequence(:link_type) { |n| "Mixed" } - sequence(:objectid) { |n| "test:ConnectionLink:#{n}" } + sequence(:objectid) { |n| "test:ConnectionLink:#{n}:loc" } association :departure, :factory => :stop_area association :arrival, :factory => :stop_area end - + end diff --git a/spec/factories/chouette_group_of_lines.rb b/spec/factories/chouette_group_of_lines.rb index 75739d6d3..8b359fea5 100644 --- a/spec/factories/chouette_group_of_lines.rb +++ b/spec/factories/chouette_group_of_lines.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :group_of_line, :class => Chouette::GroupOfLine do sequence(:name) { |n| "Group Of Line #{n}" } - sequence(:objectid) { |n| "chouette:test:GroupOfLine:#{n}" } + sequence(:objectid) { |n| "STIF:CODIFLIGNE:GroupOfLine:#{n}" } sequence(:registration_number) { |n| "#{n}" } association :line_referential diff --git a/spec/factories/chouette_journey_pattern.rb b/spec/factories/chouette_journey_pattern.rb index 62241f313..05d8d536a 100644 --- a/spec/factories/chouette_journey_pattern.rb +++ b/spec/factories/chouette_journey_pattern.rb @@ -5,8 +5,7 @@ FactoryGirl.define do sequence(:published_name) { |n| "jp publishedname #{n}" } sequence(:comment) { |n| "jp comment #{n}" } sequence(:registration_number) { |n| "jp registration_number #{n}" } - sequence(:objectid) { |n| "test:JourneyPattern:#{n}" } - + sequence(:objectid) { |n| "organisation:JourneyPattern:lineId-#{n}:LOC" } association :route, :factory => :route factory :journey_pattern do diff --git a/spec/factories/chouette_networks.rb b/spec/factories/chouette_networks.rb index 3ad719cd9..afeac9e28 100644 --- a/spec/factories/chouette_networks.rb +++ b/spec/factories/chouette_networks.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :network, :class => Chouette::Network do sequence(:name) { |n| "Network #{n}" } - sequence(:objectid) { |n| "chouette:test:GroupOfLine:#{n}" } + sequence(:objectid) { |n| "STIF:CODIFLIGNE:Network:#{n}" } sequence(:registration_number) { |n| "test-#{n}" } association :line_referential diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index a707bcbf6..4986ab70e 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -6,7 +6,7 @@ FactoryGirl.define do sequence(:number) { |n| "#{n}" } sequence(:wayback) { |n| Chouette::Route.wayback.values[n % 2] } sequence(:direction) { |n| Chouette::Route.direction.values[n % 12] } - sequence(:objectid) { |n| "test:Route:#{n}" } + sequence(:objectid) { |n| "organisation:Route:lineId-routeId#{n}:LOC" } association :line, :factory => :line diff --git a/spec/factories/chouette_routing_constraint_zones.rb b/spec/factories/chouette_routing_constraint_zones.rb index 8ef2ddb43..7748a4f74 100644 --- a/spec/factories/chouette_routing_constraint_zones.rb +++ b/spec/factories/chouette_routing_constraint_zones.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :routing_constraint_zone, class: Chouette::RoutingConstraintZone do sequence(:name) { |n| "Routing constraint zone #{n}" } + sequence(:objectid) { |n| "organisation:RoutingConstraintZone:lineId-routeId-#{n}:LOC" } association :route, factory: :route after(:build) do |zone| route = Chouette::Route.find(zone.route_id) diff --git a/spec/factories/chouette_stop_points.rb b/spec/factories/chouette_stop_points.rb index 690d1c688..14e08b1ac 100644 --- a/spec/factories/chouette_stop_points.rb +++ b/spec/factories/chouette_stop_points.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :stop_point, :class => Chouette::StopPoint do - sequence(:objectid) { |n| "test:StopPoint:#{n}" } + sequence(:objectid) { |n| "test:StopPoint:#{n}:loc" } association :stop_area, :factory => :stop_area end diff --git a/spec/factories/chouette_time_table.rb b/spec/factories/chouette_time_table.rb index b410d4ab8..a3ff63b2f 100644 --- a/spec/factories/chouette_time_table.rb +++ b/spec/factories/chouette_time_table.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :time_table, :class => Chouette::TimeTable do sequence(:comment) { |n| "Timetable #{n}" } - sequence(:objectid) { |n| "test:Timetable:#{n}" } + sequence(:objectid) { |n| "organisation:Timetable:#{n}:LOC" } sequence(:int_day_types) { (1..7).to_a.map{ |n| 2**(n+1)}.sum } calendar nil diff --git a/spec/factories/chouette_timeband.rb b/spec/factories/chouette_timeband.rb index 6e2825c22..010461479 100644 --- a/spec/factories/chouette_timeband.rb +++ b/spec/factories/chouette_timeband.rb @@ -4,14 +4,14 @@ FactoryGirl.define do sequence(:name) { |n| "Name: #{n}" } start_time { Time.now } end_time { Time.now + 1.hour } - sequence(:objectid) { |n| "test:Timeband:#{n}" } + sequence(:objectid) { |n| "test:Timeband:#{n}:loc" } end factory :timeband_invalid, class: Chouette::Timeband do sequence(:name) { |n| "Name: #{n}" } start_time { Time.now + 1.hour } end_time { Time.now } - sequence(:objectid) { |n| "test:Timeband:#{n}" } + sequence(:objectid) { |n| "test:Timeband:#{n}:loc" } end end diff --git a/spec/factories/chouette_vehicle_journey.rb b/spec/factories/chouette_vehicle_journey.rb index d1e00cd1d..5f64bd502 100644 --- a/spec/factories/chouette_vehicle_journey.rb +++ b/spec/factories/chouette_vehicle_journey.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :vehicle_journey_common, :class => Chouette::VehicleJourney do - sequence(:objectid) { |n| "test:VehicleJourney:#{n}" } + sequence(:objectid) { |n| "organisation:VehicleJourney:lineid-#{n}:LOC" } factory :vehicle_journey_empty do association :journey_pattern, :factory => :journey_pattern diff --git a/spec/features/connection_links_spec.rb b/spec/features/connection_links_spec.rb index 0325e6e1c..7272242fe 100644 --- a/spec/features/connection_links_spec.rb +++ b/spec/features/connection_links_spec.rb @@ -34,7 +34,7 @@ RSpec.describe "ConnectionLinks", :type => :feature do visit referential_connection_links_path(referential) click_link "Ajouter une correspondance" fill_in "Nom", :with => "ConnectionLink 1" - fill_in "Identifiant Neptune", :with => "test:ConnectionLink:1" + fill_in "Identifiant Neptune", :with => "test:ConnectionLink:1:LOC" click_button("Créer correspondance") expect(page).to have_content("ConnectionLink 1") end diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb index 0e1e91593..5a31b8f0c 100644 --- a/spec/models/chouette/access_link_spec.rb +++ b/spec/models/chouette/access_link_spec.rb @@ -7,7 +7,7 @@ describe Chouette::AccessLink, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end it { is_expected.to validate_presence_of :name } @@ -19,7 +19,7 @@ describe Chouette::AccessLink, :type => :model do def self.legacy_link_types %w{Underground Mixed Overground} end - + legacy_link_types.each do |link_type| context "when link_type is #{link_type}" do access_link_type = Chouette::ConnectionLinkType.new(link_type.underscore) @@ -32,7 +32,7 @@ describe Chouette::AccessLink, :type => :model do end describe "#access_link_type=" do - + it "should change link_type with ConnectionLinkType#name" do subject.access_link_type = "underground" expect(subject.link_type).to eq("Underground") @@ -45,7 +45,7 @@ describe Chouette::AccessLink, :type => :model do def self.legacy_link_orientations %w{AccessPointToStopArea StopAreaToAccessPoint} end - + legacy_link_orientations.each do |link_orientation| context "when link_orientation is #{link_orientation}" do link_orientation_type = Chouette::LinkOrientationType.new(link_orientation.underscore) @@ -59,7 +59,7 @@ describe Chouette::AccessLink, :type => :model do end describe "#link_orientation_type=" do - + it "should change link_orientation with LinkOrientationType#name" do subject.link_orientation_type = "access_point_to_stop_area" expect(subject.link_orientation).to eq("AccessPointToStopArea") @@ -76,7 +76,7 @@ describe Chouette::AccessLink, :type => :model do subject.link_orientation_type = "stop_area_to_access_point" expect(subject.link_key).to eq("S_#{subject.stop_area.id}-A_#{subject.access_point.id}") end - + end end diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index 3da8b4311..a3101d79c 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe Chouette::Company, :type => :model do - subject { create(:company) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } describe "#nullables empty" do it "should set null empty nullable attributes" do diff --git a/spec/models/chouette/connection_link_spec.rb b/spec/models/chouette/connection_link_spec.rb index 5921bf581..57eb7d66c 100644 --- a/spec/models/chouette/connection_link_spec.rb +++ b/spec/models/chouette/connection_link_spec.rb @@ -11,7 +11,7 @@ describe Chouette::ConnectionLink, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index d49329118..29b4433c5 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -3,11 +3,7 @@ require 'spec_helper' describe Chouette::GroupOfLine, :type => :model do subject { create(:group_of_line) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } describe "#stop_areas" do let!(:line){create(:line, :group_of_lines => [subject])} diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index c9e510e84..32bacc512 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe Chouette::Network, :type => :model do - subject { create(:network) } - - it { is_expected.to validate_presence_of :name } - - # it { should validate_presence_of :objectid } - it { is_expected.to validate_uniqueness_of :objectid } + it { should validate_presence_of :name } describe "#stop_areas" do let!(:line){create(:line, :network => subject)} diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index c93b311ff..794da4f1b 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Chouette::Route, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } 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) } diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index 054cfb9e6..c344642e6 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe Chouette::RoutingConstraintZone, type: :model do subject { create(:routing_constraint_zone) } - let!(:routing_constraint_zone) { create(:routing_constraint_zone) } it { is_expected.to validate_presence_of :name } # shoulda matcher to validate length of array ? @@ -16,38 +15,38 @@ describe Chouette::RoutingConstraintZone, type: :model do describe 'validations' do it 'validates the presence of route_id' do expect { - routing_constraint_zone.update!(route_id: nil) + subject.update!(route_id: nil) }.to raise_error(NoMethodError) end it 'validates the presence of stop_point_ids' do expect { - routing_constraint_zone.update!(stop_point_ids: []) + subject.update!(stop_point_ids: []) }.to raise_error(ActiveRecord::RecordInvalid) end it 'validates that stop points belong to the route' do route = create(:route) expect { - routing_constraint_zone.update!(route_id: route.id) + subject.update!(route_id: route.id) }.to raise_error(ActiveRecord::RecordInvalid) end xit 'validates that not all stop points from the route are selected' do routing_constraint_zone.stop_points = routing_constraint_zone.route.stop_points expect { - routing_constraint_zone.save! + subject.save! }.to raise_error(ActiveRecord::RecordInvalid) end end describe 'deleted stop areas' do it 'does not have them in stop_area_ids' do - stop_point = routing_constraint_zone.route.stop_points.last - routing_constraint_zone.stop_points << stop_point - routing_constraint_zone.save! - routing_constraint_zone.route.stop_points.last.destroy! - expect(routing_constraint_zone.stop_points.map(&:id)).not_to include(stop_point.id) + stop_point = subject.route.stop_points.last + subject.stop_points << stop_point + subject.save! + subject.route.stop_points.last.destroy! + expect(subject.stop_points.map(&:id)).not_to include(stop_point.id) end end diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index 212c32e1a..5eae8caf0 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -9,7 +9,7 @@ describe Chouette::StopPoint, :type => :model do describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } end describe "#destroy" do diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index c4eaeaaf0..761c39e5b 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -820,13 +820,13 @@ end describe "#intersects" do it "should return day if a date equal day" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1") + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) expect(time_table.intersects([Date.today])).to eq([Date.today]) end it "should return [] if a period not include days" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 12) + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) time_table.periods << Chouette::TimeTablePeriod.new( :period_start => Date.new(2013, 05, 27), :period_end => Date.new(2013, 05, 30)) @@ -834,7 +834,7 @@ end end it "should return days if a period include day" do - time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 12) # Day type monday and tuesday + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday time_table.periods << Chouette::TimeTablePeriod.new( :period_start => Date.new(2013, 05, 27), :period_end => Date.new(2013, 05, 30)) @@ -842,6 +842,207 @@ end end end + describe "#include_day?" do + it "should return true if a date equal day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") + time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) + expect(time_table.include_day?(Date.today)).to eq(true) + end + + it "should return true if a period include day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2013, 05, 27), + :period_end => Date.new(2013, 05, 29)) + expect(time_table.include_day?( Date.new(2013, 05, 27))).to eq(true) + end + end + + describe "#include_in_dates?" do + it "should return true if a date equal day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc") + time_table.dates << Chouette::TimeTableDate.new( :date => Date.today, :in_out => true) + expect(time_table.include_in_dates?(Date.today)).to eq(true) + end + + it "should return false if a period include day but that is exclued" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + excluded_date = Date.new(2013, 05, 27) + time_table.dates << Chouette::TimeTableDate.new( :date => excluded_date, :in_out => false) + expect(time_table.include_in_dates?( excluded_date)).to be_falsey + end + end + + describe "#include_in_periods?" do + it "should return true if a period include day" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + expect(time_table.include_in_periods?(Date.new(2012, 1, 2))).to eq(true) + end + + it "should return false if a period include day but that is exclued" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 12) # Day type monday and tuesday + excluded_date = Date.new(2013, 05, 27) + time_table.dates << Chouette::TimeTableDate.new( :date => excluded_date, :in_out => false) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2013, 05, 27), + :period_end => Date.new(2013, 05, 29)) + expect(time_table.include_in_periods?( excluded_date)).to be_falsey + end + end + + describe "#include_in_overlap_dates?" do + it "should return true if a day is included in overlap dates" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + time_table.dates << Chouette::TimeTableDate.new( :date => Date.new(2012, 1, 2), :in_out => true) + expect(time_table.include_in_overlap_dates?(Date.new(2012, 1, 2))).to eq(true) + end + it "should return false if the day is excluded" do + time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1:loc", :int_day_types => 4) + time_table.periods << Chouette::TimeTablePeriod.new( + :period_start => Date.new(2012, 1, 1), + :period_end => Date.new(2012, 01, 30)) + time_table.dates << Chouette::TimeTableDate.new( :date => Date.new(2012, 1, 2), :in_out => false) + expect(time_table.include_in_overlap_dates?(Date.new(2012, 1, 2))).to be_falsey + end + end + + describe "#dates" do + it "should have with position 0" do + expect(subject.dates.first.position).to eq(0) + end + context "when first date has been removed" do + before do + subject.dates.first.destroy + end + it "should begin with position 0" do + expect(subject.dates.first.position).to eq(0) + end + end + end + describe "#validity_out_between?" do + let(:empty_tm) {build(:time_table)} + it "should be false if empty calendar" do + expect(empty_tm.validity_out_between?( Date.today, Date.today + 7.day)).to be_falsey + end + it "should be true if caldendar is out during start_date and end_date period" do + start_date = subject.bounding_dates.max - 2.day + end_date = subject.bounding_dates.max + 2.day + expect(subject.validity_out_between?( start_date, end_date)).to be_truthy + end + it "should be false if calendar is out on start date" do + start_date = subject.bounding_dates.max + end_date = subject.bounding_dates.max + 2.day + expect(subject.validity_out_between?( start_date, end_date)).to be_falsey + end + it "should be false if calendar is out on end date" do + start_date = subject.bounding_dates.max - 2.day + end_date = subject.bounding_dates.max + expect(subject.validity_out_between?( start_date, end_date)).to be_truthy + end + it "should be false if calendar is out after start_date" do + start_date = subject.bounding_dates.max + 2.day + end_date = subject.bounding_dates.max + 4.day + expect(subject.validity_out_between?( start_date, end_date)).to be_falsey + end + end + describe "#validity_out_from_on?" do + let(:empty_tm) {build(:time_table)} + it "should be false if empty calendar" do + expect(empty_tm.validity_out_from_on?( Date.today)).to be_falsey + end + it "should be true if caldendar ends on expected date" do + expected_date = subject.bounding_dates.max + expect(subject.validity_out_from_on?( expected_date)).to be_truthy + end + it "should be true if calendar ends before expected date" do + expected_date = subject.bounding_dates.max + 30.day + expect(subject.validity_out_from_on?( expected_date)).to be_truthy + end + it "should be false if calendars ends after expected date" do + expected_date = subject.bounding_dates.max - 30.day + expect(subject.validity_out_from_on?( expected_date)).to be_falsey + end + end + describe "#bounding_dates" do + context "when timetable contains only periods" do + before do + subject.dates = [] + subject.save + end + it "should retreive periods.period_start.min and periods.period_end.max" do + expect(subject.bounding_dates.min).to eq(subject.periods.map(&:period_start).min) + expect(subject.bounding_dates.max).to eq(subject.periods.map(&:period_end).max) + end + end + context "when timetable contains only dates" do + before do + subject.periods = [] + subject.save + end + it "should retreive dates.min and dates.max" do + expect(subject.bounding_dates.min).to eq(subject.dates.map(&:date).min) + expect(subject.bounding_dates.max).to eq(subject.dates.map(&:date).max) + end + end + it "should contains min date" do + min_date = subject.bounding_dates.min + subject.dates.each do |tm_date| + expect(min_date <= tm_date.date).to be_truthy + end + subject.periods.each do |tm_period| + expect(min_date <= tm_period.period_start).to be_truthy + end + + end + it "should contains max date" do + max_date = subject.bounding_dates.max + subject.dates.each do |tm_date| + expect(tm_date.date <= max_date).to be_truthy + end + subject.periods.each do |tm_period| + expect(tm_period.period_end <= max_date).to be_truthy + end + + end + end + describe "#periods" do + it "should begin with position 0" do + expect(subject.periods.first.position).to eq(0) + end + context "when first period has been removed" do + before do + subject.periods.first.destroy + end + it "should begin with position 0" do + expect(subject.periods.first.position).to eq(0) + end + end + it "should have period_start before period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today + 10 + expect(period.valid?).to be_truthy + end + it "should not have period_start after period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today - 10 + expect(period.valid?).to be_falsey + end + it "should not have period_start equal to period_end" do + period = Chouette::TimeTablePeriod.new + period.period_start = Date.today + period.period_end = Date.today + expect(period.valid?).to be_falsey + end + end + # it { is_expected.to validate_presence_of :comment } # it { is_expected.to validate_uniqueness_of :objectid } @@ -964,7 +1165,6 @@ end target=subject.duplicate expect(target.id).to be_nil expect(target.comment).to eq(I18n.t("activerecord.copy", name: subject.comment)) - expect(target.objectid).to eq(subject.objectid+"_1") expect(target.int_day_types).to eq(subject.int_day_types) expect(target.dates.size).to eq(subject.dates.size) target.dates.each do |d| diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb index 76544f85d..d5e30594d 100644 --- a/spec/models/chouette/trident_active_record_spec.rb +++ b/spec/models/chouette/trident_active_record_spec.rb @@ -1,119 +1,57 @@ require 'spec_helper' describe Chouette::TridentActiveRecord, :type => :model do - - it { expect(Chouette::TridentActiveRecord.ancestors).to include(Chouette::ActiveRecord) } - subject { create(:time_table) } - describe "#uniq_objectid" do + it { should validate_presence_of :objectid } + it { should validate_uniqueness_of :objectid } - it "should rebuild objectid" do - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - expect(tm.objectid).to eq(subject.objectid+"_1") - end + describe "#default_values" do + let(:object) { build(:time_table, objectid: nil) } - it "should rebuild objectid" do - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - tm.save - tm = create(:time_table) - tm.objectid = subject.objectid - tm.uniq_objectid - expect(tm.objectid).to eq(subject.objectid+"_2") + it 'should fill __pending_id__' do + object.default_values + expect(object.objectid.include?('__pending_id__')).to be_truthy end - 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 = 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 = 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 = create_object - tm.save - expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s) - end + describe "#objectid" do + let(:object) { build(:time_table, objectid: nil) } - it "should detect objectid conflicts" do - tm = create_object - tm.save - tm.objectid = "first:Timetable:"+(tm.id+1).to_s - tm.save - tm = create_object - tm.save - expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s+"_1") + it 'should build objectid on create' do + object.save + id = "#{object.provider_id}:#{object.model_name}:#{object.local_id}:#{object.boiv_id}" + expect(object.objectid).to eq(id) end - end - - describe "objectid" do - - it "should build automatic objectid when empty" do - g1 = create_object - g1.save - expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) + it 'should call build_objectid on after save' do + expect(object).to receive(:build_objectid) + object.save end - it "should build automatic objectid with fixed when only suffix given" do - g1 = create_object - g1.objectid = "toto" - g1.save - expect(g1.objectid).to eq("first:Timetable:toto") + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.objectid = id + object.save + expect(object.objectid).to eq(id) end - it "should build automatic objectid with extension when already exists" do - g1 = create_object - g1.save - cnt = g1.id + 1 - g1.objectid = "first:Timetable:"+cnt.to_s - g1.save - g2 = create_object - g2.save - expect(g2.objectid).to eq("first:Timetable:"+g2.id.to_s+"_1") + it 'should call default_values on create' do + expect(object).to receive(:default_values) + object.save end - it "should build automatic objectid with extension when already exists" do - g1 = create_object - g1.save - cnt = g1.id + 2 - g1.objectid = "first:Timetable:"+cnt.to_s - g1.save - g2 = create_object - g2.objectid = "first:Timetable:"+cnt.to_s+"_1" - g2.save - g3 = create_object - g3.save - expect(g3.objectid).to eq("first:Timetable:"+g3.id.to_s+"_2") + it 'should not call default_values on update' do + object = create(:time_table) + expect(object).to_not receive(:default_values) + object.touch end - it "should build automatic objectid when id cleared" do - g1 = create_object - g1.objectid = "first:Timetable:xxxx" - g1.save - g1.objectid = nil - g1.save - expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s) + it 'should create a new objectid when cleared' do + object.save + object.objectid = nil + object.save + expect(object.objectid).to be_truthy end end - end diff --git a/spec/models/vehicle_journey_export_spec.rb b/spec/models/vehicle_journey_export_spec.rb index 6252a73f9..83b3bbb04 100644 --- a/spec/models/vehicle_journey_export_spec.rb +++ b/spec/models/vehicle_journey_export_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe VehicleJourneyExport, :type => :model do - + let!(:line) { create(:line) } let!(:route) { create(:route, :line => line) } let!(:other_route) { create(:route, :line => line) } @@ -10,10 +10,10 @@ describe VehicleJourneyExport, :type => :model do let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } - let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - + let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:stop_point0) { route.stop_points[0] } let!(:stop_point1) { route.stop_points[1] } let!(:stop_point2) { route.stop_points[2] } @@ -21,10 +21,10 @@ describe VehicleJourneyExport, :type => :model do let!(:stop_point4) { route.stop_points[4] } let!(:time_table) { create(:time_table)} - - subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } - describe ".tt_day_types" do + subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } + + describe ".tt_day_types" do it "should return no day_type" do time_table.int_day_types = 0 @@ -35,10 +35,10 @@ describe VehicleJourneyExport, :type => :model do time_table.int_day_types = 4|8|16|32|64|128|256 expect(subject.tt_day_types(time_table)).to eq("LuMaMeJeVeSaDi") end - + end - describe ".tt_periods" do + describe ".tt_periods" do it "should return empty period" do time_table.periods.clear @@ -50,10 +50,10 @@ describe VehicleJourneyExport, :type => :model do time_table.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8)) expect(subject.tt_periods(time_table)).to eq("[2014-08-01 -> 2014-08-08] ") end - + end - - describe ".tt_included_days" do + + describe ".tt_included_days" do it "should return empty included dates" do time_table.dates.clear @@ -65,10 +65,10 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => true) expect(subject.tt_peculiar_days(time_table)).to eq("2014-08-01 ") end - + end - describe ".tt_excluded_days" do + describe ".tt_excluded_days" do it "should return empty excluded dates" do time_table.dates.clear @@ -80,7 +80,7 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => false) expect(subject.tt_excluded_days(time_table)).to eq("2014-08-01 ") end - + end - + end diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index b01523dd9..7b31dc806 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -36,9 +36,9 @@ describe VehicleJourneyImport, :type => :model do let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } - let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } let!(:stop_point0) { route.stop_points[0] } let!(:stop_point1) { route.stop_points[1] } @@ -86,7 +86,7 @@ describe VehicleJourneyImport, :type => :model do expect(Chouette::VehicleJourneyAtStop.all.size).to eq(17) end - it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do + it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do expect(VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object).save).to be_falsey expect(Chouette::VehicleJourney.all.size).to eq(3) expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0) diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb index c9a573ae2..d30cfa03e 100644 --- a/spec/models/vehicle_translation_spec.rb +++ b/spec/models/vehicle_translation_spec.rb @@ -6,7 +6,6 @@ describe VehicleTranslation, :type => :model do # To fix : need to comment :company => company # after adding company to apartment excluded models let!(:vehicle_journey){ create(:vehicle_journey, - :objectid => "dummy", :journey_pattern => journey_pattern, :route => journey_pattern.route, # :company => company, |
