diff options
144 files changed, 569 insertions, 267 deletions
| @@ -33,9 +33,6 @@ gem 'spring', group: :development  # ActiveRecord associations on top of PostgreSQL arrays  gem 'has_array_of', af83: 'has_array_of' -# Track changes to your models' data. Good for auditing or versioning. -gem 'paper_trail' -  gem 'rails-observers'  # Use SeedBank for spliting seeds diff --git a/Gemfile.lock b/Gemfile.lock index 4e3c76690..0c1243593 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -337,10 +337,6 @@ GEM        mini_portile2 (~> 2.3.0)      open4 (1.3.4)      orm_adapter (0.5.0) -    paper_trail (4.1.0) -      activerecord (>= 3.0, < 6.0) -      activesupport (>= 3.0, < 6.0) -      request_store (~> 1.1)      parser (2.4.0.0)        ast (~> 2.2)      pg (0.20.0) @@ -652,7 +648,6 @@ DEPENDENCIES    map_layers (= 0.0.4)    mimemagic    newrelic_rpm -  paper_trail    pg    phantomjs    poltergeist diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a83394e2..8b66e6097 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@  class ApplicationController < ActionController::Base -  include PaperTrailSupport +  include MetadataControllerSupport    include Pundit    include FeatureChecker @@ -10,7 +10,6 @@ class ApplicationController < ActionController::Base    before_action :authenticate_user!    before_action :set_locale -    # Load helpers in rails engine    helper LanguageEngine::Engine.helpers diff --git a/app/controllers/chouette_controller.rb b/app/controllers/chouette_controller.rb index 3e4f3af27..e6e7c0a8a 100644 --- a/app/controllers/chouette_controller.rb +++ b/app/controllers/chouette_controller.rb @@ -1,4 +1,3 @@  class ChouetteController < InheritedResources::Base -  include PaperTrailSupport    include ApplicationHelper  end diff --git a/app/controllers/concerns/metadata_controller_support.rb b/app/controllers/concerns/metadata_controller_support.rb new file mode 100644 index 000000000..db83e79ae --- /dev/null +++ b/app/controllers/concerns/metadata_controller_support.rb @@ -0,0 +1,26 @@ +module MetadataControllerSupport +  extend ActiveSupport::Concern + +  included do +    after_action :set_creator_metadata, only: :create +    after_action :set_modifier_metadata, only: :update +  end + +  def user_for_metadata +    current_user ? current_user.username : '' +  end + +  def set_creator_metadata +    if resource.valid? +      resource.try(:set_metadata!, :creator_username, user_for_metadata) +      resource.try(:set_metadata!, :modifier_username, user_for_metadata) +    end +  end + +  def set_modifier_metadata +    _resource = @resources || [resource] +    _resource.flatten.each do |r| +      r.try :set_metadata!, :modifier_username, user_for_metadata +    end +  end +end diff --git a/app/controllers/concerns/paper_trail_support.rb b/app/controllers/concerns/paper_trail_support.rb deleted file mode 100644 index 4b0b1a7c7..000000000 --- a/app/controllers/concerns/paper_trail_support.rb +++ /dev/null @@ -1,11 +0,0 @@ -module PaperTrailSupport -  extend ActiveSupport::Concern - -  included do -    before_action :set_paper_trail_whodunnit - -    def user_for_paper_trail -      current_user ? current_user.name : '' -    end -  end -end diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index da567779e..db92d48f3 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -74,6 +74,7 @@ class JourneyPatternsCollectionsController < ChouetteController    def update      state  = JSON.parse request.raw_post      Chouette::JourneyPattern.state_update route, state +    @resources = route.journey_patterns      errors = state.any? {|item| item['errors']}      respond_to do |format| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a0c6796ea..702ca0ffc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,7 +14,7 @@ module ApplicationHelper    def page_header_title(object)      # Unwrap from decorator, we want to know the object model name      object = object.object if object.try(:object) -     +      if Referential === object        return object.full_name      end @@ -36,8 +36,8 @@ module ApplicationHelper      display = policy(object).synchronize? if policy(object).respond_to?(:synchronize?) rescue false      if display        info = t('last_update', time: l(object.updated_at, format: :short)) -      if object.try(:versions) -        author = object.versions.try(:last).try(:whodunnit) || t('default_whodunnit') +      if object.has_metadata? +        author = object.metadata.modifier_username || t('default_whodunnit')          info   = "#{info} <br/> #{t('whodunnit', author: author)}"        end        out += content_tag :div, info.html_safe, class: 'small last-update' diff --git a/app/helpers/compliance_controls_helper.rb b/app/helpers/compliance_controls_helper.rb index 297ae3afa..abf909929 100644 --- a/app/helpers/compliance_controls_helper.rb +++ b/app/helpers/compliance_controls_helper.rb @@ -11,7 +11,7 @@ module ComplianceControlsHelper    def compliance_control_metadatas(compliance_control)      attributes = resource.class.dynamic_attributes -    attributes.push(*resource.control_attributes.keys) if resource.respond_to? :control_attributes +    attributes.push(*resource.control_attributes.keys) if resource&.control_attributes&.keys      {}.tap do |hash|        attributes.each do |attribute| @@ -19,4 +19,4 @@ module ComplianceControlsHelper        end      end    end -end  +end diff --git a/app/javascript/time_tables/components/ConfirmModal.js b/app/javascript/time_tables/components/ConfirmModal.js index 4e8583bc0..e4219348d 100644 --- a/app/javascript/time_tables/components/ConfirmModal.js +++ b/app/javascript/time_tables/components/ConfirmModal.js @@ -2,7 +2,7 @@ import React from 'react'  import PropTypes from 'prop-types' -export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCancel, timetable, metas}, {I18n}) { +export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCancel, timetable, metas}) {    return (      <div className={'modal fade ' + ((modal.type == 'confirm') ? 'in' : '')} id='ConfirmModal'>        <div className='modal-container'> @@ -45,8 +45,4 @@ ConfirmModal.propTypes = {    modal: PropTypes.object.isRequired,    onModalAccept: PropTypes.func.isRequired,    onModalCancel: PropTypes.func.isRequired -} - -ConfirmModal.contextTypes = { -  I18n: PropTypes.object -} +}
\ No newline at end of file diff --git a/app/javascript/time_tables/components/ErrorModal.js b/app/javascript/time_tables/components/ErrorModal.js index 8af12f1d1..a512d28fd 100644 --- a/app/javascript/time_tables/components/ErrorModal.js +++ b/app/javascript/time_tables/components/ErrorModal.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'  import actions from '../actions' -export default function ErrorModal({dispatch, modal, onModalClose}, {I18n}) { +export default function ErrorModal({dispatch, modal, onModalClose}) {    return (      <div className={'modal fade ' + ((modal.type == 'error') ? 'in' : '')} id='ErrorModal'>        <div className='modal-container'> @@ -37,8 +37,4 @@ export default function ErrorModal({dispatch, modal, onModalClose}, {I18n}) {  ErrorModal.propTypes = {    modal: PropTypes.object.isRequired,    onModalClose: PropTypes.func.isRequired -} - -ErrorModal.contextTypes = { -  I18n: PropTypes.object -} +}
\ No newline at end of file diff --git a/app/javascript/time_tables/components/Metas.js b/app/javascript/time_tables/components/Metas.js index 08a6e26fe..d9746a379 100644 --- a/app/javascript/time_tables/components/Metas.js +++ b/app/javascript/time_tables/components/Metas.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'  import actions from '../actions'  import TagsSelect2 from './TagsSelect2' -export default function Metas({metas, onUpdateDayTypes, onUpdateComment, onUpdateColor, onSelect2Tags, onUnselect2Tags}, {I18n}) { +export default function Metas({metas, onUpdateDayTypes, onUpdateComment, onUpdateColor, onSelect2Tags, onUnselect2Tags}) {    let colorList = ["", "#9B9B9B", "#FFA070", "#C67300", "#7F551B", "#41CCE3", "#09B09C", "#3655D7",   "#6321A0", "#E796C6", "#DD2DAA"]    return (      <div className='form-horizontal'> @@ -134,8 +134,4 @@ Metas.propTypes = {    onUpdateColor: PropTypes.func.isRequired,    onSelect2Tags: PropTypes.func.isRequired,    onUnselect2Tags: PropTypes.func.isRequired -} - -Metas.contextTypes = { -  I18n: PropTypes.object -} +}
\ No newline at end of file diff --git a/app/javascript/time_tables/components/PeriodForm.js b/app/javascript/time_tables/components/PeriodForm.js index d17a246f7..36ed6cfdf 100644 --- a/app/javascript/time_tables/components/PeriodForm.js +++ b/app/javascript/time_tables/components/PeriodForm.js @@ -33,7 +33,7 @@ const makeYearsOptions = (yearSelected) => {    return arr  } -export default function PeriodForm({modal, timetable, metas, onOpenAddPeriodForm, onClosePeriodForm, onUpdatePeriodForm, onValidatePeriodForm}, {I18n}) { +export default function PeriodForm({modal, timetable, metas, onOpenAddPeriodForm, onClosePeriodForm, onUpdatePeriodForm, onValidatePeriodForm}) {    return (      <div className="container-fluid">        <div className="row"> @@ -143,8 +143,4 @@ PeriodForm.propTypes = {    onUpdatePeriodForm: PropTypes.func.isRequired,    onValidatePeriodForm: PropTypes.func.isRequired,    timetable: PropTypes.object.isRequired -} - -PeriodForm.contextTypes = { -  I18n: PropTypes.object -} +}
\ No newline at end of file diff --git a/app/javascript/time_tables/components/PeriodManager.js b/app/javascript/time_tables/components/PeriodManager.js index 6b817fe73..6871d0b9b 100644 --- a/app/javascript/time_tables/components/PeriodManager.js +++ b/app/javascript/time_tables/components/PeriodManager.js @@ -55,7 +55,7 @@ export default class PeriodManager extends Component {                  type='button'                  onClick={() => this.props.onOpenEditPeriodForm(this.props.value, this.props.index)}                > -                Modifier +                {I18n.t('actions.edit')}                </button>              </li>              <li className='delete-action'> @@ -64,7 +64,7 @@ export default class PeriodManager extends Component {                  onClick={() => this.props.onDeletePeriod(this.props.index, this.props.metas.day_types)}                >                  <span className='fa fa-trash'></span> -                Supprimer +                {I18n.t('actions.destroy')}                </button>              </li>            </ul> @@ -79,8 +79,4 @@ PeriodManager.propTypes = {    currentDate: PropTypes.object.isRequired,    onDeletePeriod: PropTypes.func.isRequired,    onOpenEditPeriodForm: PropTypes.func.isRequired -} - -PeriodManager.contextTypes = { -  I18n: PropTypes.object  }
\ No newline at end of file diff --git a/app/javascript/time_tables/components/TagsSelect2.js b/app/javascript/time_tables/components/TagsSelect2.js index 43cf59fdf..dd8d6e9c0 100644 --- a/app/javascript/time_tables/components/TagsSelect2.js +++ b/app/javascript/time_tables/components/TagsSelect2.js @@ -40,7 +40,7 @@ export default class TagsSelect2 extends Component {            allowClear: true,            theme: 'bootstrap',            width: '100%', -          placeholder: this.context.I18n.t('time_tables.edit.select2.tag.placeholder'), +          placeholder: I18n.t('time_tables.edit.select2.tag.placeholder'),            ajax: {              url: origin + path + '/tags.json',              dataType: 'json', @@ -74,8 +74,4 @@ export default class TagsSelect2 extends Component {  const formatRepo = (props) => {    if(props.name) return props.name -} - -TagsSelect2.contextTypes = { -  I18n: PropTypes.object  }
\ No newline at end of file diff --git a/app/javascript/time_tables/components/Timetable.js b/app/javascript/time_tables/components/Timetable.js index 991f31435..3779fa2d0 100644 --- a/app/javascript/time_tables/components/Timetable.js +++ b/app/javascript/time_tables/components/Timetable.js @@ -31,11 +31,11 @@ export default class Timetable extends Component {          <div className="table table-2entries mb-sm">            <div className="t2e-head w20">              <div className="th"> -              <div className="strong">{this.context.I18n.t('time_tables.edit.synthesis')}</div> +              <div className="strong">{I18n.t('time_tables.edit.synthesis')}</div>              </div> -            <div className="td"><span>{this.context.I18n.t('time_tables.edit.day_types')}</span></div> -            <div className="td"><span>{this.context.I18n.t('time_tables.edit.periods')}</span></div> -            <div className="td"><span>{this.context.I18n.t('time_tables.edit.exceptions')}</span></div> +            <div className="td"><span>{I18n.t('time_tables.edit.day_types')}</span></div> +            <div className="td"><span>{I18n.t('time_tables.edit.periods')}</span></div> +            <div className="td"><span>{I18n.t('time_tables.edit.exceptions')}</span></div>            </div>            <div className="t2e-item-list w80">              <div> @@ -109,8 +109,4 @@ Timetable.propTypes = {    onDeletePeriod: PropTypes.func.isRequired,    onExcludeDateFromPeriod: PropTypes.func.isRequired,    onIncludeDateInPeriod: PropTypes.func.isRequired -} - -Timetable.contextTypes = { -  I18n: PropTypes.object -} +}
\ No newline at end of file diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index e00e9b1b0..537dcfc06 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -113,14 +113,9 @@ const actions = {      type : 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL',      vehicleJourneys    }), -  selectPurchaseWindowsModal: (selectedWindow) =>({ +  selectPurchaseWindowsModal: (selectedItem) =>({      type: 'SELECT_PURCHASE_WINDOW_MODAL', -    selectedItem:{ -      id: selectedWindow.id, -      name: selectedWindow.name, -      color: selectedWindow.color, -      objectid: selectedWindow.objectid -    } +    selectedItem    }),    addSelectedPurchaseWindow: () => ({      type: 'ADD_SELECTED_PURCHASE_WINDOW' diff --git a/app/javascript/vehicle_journeys/components/Filters.js b/app/javascript/vehicle_journeys/components/Filters.js index ae3ab3476..93fe015a8 100644 --- a/app/javascript/vehicle_journeys/components/Filters.js +++ b/app/javascript/vehicle_journeys/components/Filters.js @@ -145,12 +145,12 @@ export default function Filters({filters, pagination, missions, onFilter, onRese              <span                className='btn btn-link'                onClick={(e) => onResetFilters(e, pagination)}> -              Effacer +              {I18n.t('actions.erase')}              </span>              <span                className='btn btn-default'                onClick={(e) => onFilter(e, pagination)}> -              Filtrer +              {I18n.t('actions.filter')}              </span>            </div>          </div> diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js index b7e9691c1..60ad439b8 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js @@ -31,7 +31,7 @@ export default class BSelect4 extends Component {            theme: 'bootstrap',            width: '100%',            placeholder: I18n.t('vehicle_journeys.vehicle_journeys_matrix.affect_company'), -          language: require('./fr'), +          language: require('./language'),            ajax: {              url: origin + path + '/companies.json' + '?line_id=' + line,              dataType: 'json', diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js index 96b34125d..cec39ab4e 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js @@ -75,7 +75,7 @@ export default class BSelect4 extends Component {        escapeMarkup: function (markup) { return markup; },        templateResult: formatRepo,        placeholder: I18n.t('vehicle_journeys.vehicle_journeys_matrix.filters.journey_pattern'), -      language: require('./fr'), +      language: require('./language'),        allowClear: false,        escapeMarkup: function (markup) { return markup; },      } diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js index 9a345b464..d5aad20d0 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js @@ -27,7 +27,7 @@ export default class BSelect4 extends Component {            theme: 'bootstrap',            width: '100%',            placeholder: I18n.t('vehicle_journeys.vehicle_journeys_matrix.filters.timetable'), -          language: require('./fr'), +          language: require('./language'),            ajax: {              url: origin + path + this.props.chunkURL,              dataType: 'json', diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js index f5881cef7..50a941b6d 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js @@ -27,7 +27,7 @@ export default class BSelect4b extends Component {            theme: 'bootstrap',            placeholder: I18n.t('vehicle_journeys.vehicle_journeys_matrix.filters.id'),            width: '100%', -          language: require('./fr'), +          language: require('./language'),            ajax: {              url: origin + path + '/vehicle_journeys.json',              dataType: 'json', diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/fr.js b/app/javascript/vehicle_journeys/components/tools/select2s/fr.js deleted file mode 100644 index 20154d412..000000000 --- a/app/javascript/vehicle_journeys/components/tools/select2s/fr.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { -  errorLoading:function(){return"Les rĂ©sultats ne peuvent pas ĂȘtre chargĂ©s."}, -  inputTooLong:function(e){var t=e.input.length-e.maximum,n="Supprimez "+t+" caractĂšre";return t!==1&&(n+="s"),n}, -  inputTooShort:function(e){var t=e.minimum-e.input.length,n="Saisissez "+t+" caractĂšre";return t!==1&&(n+="s"),n}, -  loadingMore:function(){return"Chargement de rĂ©sultats supplĂ©mentairesâŠ"}, -  maximumSelected:function(e){var t="Vous pouvez seulement sĂ©lectionner "+e.maximum+" Ă©lĂ©ment";return e.maximum!==1&&(t+="s"),t}, -  noResults:function(){return"Aucun rĂ©sultat trouvĂ©"}, -  searching:function(){return"Recherche en coursâŠ"} -} diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/language.js b/app/javascript/vehicle_journeys/components/tools/select2s/language.js new file mode 100644 index 000000000..9d587f96e --- /dev/null +++ b/app/javascript/vehicle_journeys/components/tools/select2s/language.js @@ -0,0 +1,9 @@ +module.exports = { +  errorLoading: () => I18n.t('select2.error_loading'), +  inputTooLong: (e) => I18n.t('select2.input_too_short', { count: e.input.length - e.maximum}), +  inputTooShort: (e) => I18n.t('select2.input_too_long', { count: e.minimum - e.input.length }), +  loadingMore: () => I18n.t('select2.loading_more'), +  maximumSelected: (e) => I18n.t('select2.maximum_selected', {count: e.maximum}), +  noResults: () => I18n.t('select2.no_results'), +  searching: () => I18n.t('select2.searching') +} diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb index 09c6f77ac..e6ceb977a 100644 --- a/app/models/api/v1/api_key.rb +++ b/app/models/api/v1/api_key.rb @@ -1,7 +1,8 @@  module Api    module V1 -    class ApiKey < ::ActiveRecord::Base -      has_paper_trail +    class ApiKey < ::ApplicationModel +      has_metadata +              before_create :generate_access_token        belongs_to :referential, :class_name => '::Referential'        belongs_to :organisation, :class_name => '::Organisation' @@ -47,4 +48,3 @@ module Api      end    end  end - diff --git a/app/models/application_model.rb b/app/models/application_model.rb new file mode 100644 index 000000000..1a2a5099d --- /dev/null +++ b/app/models/application_model.rb @@ -0,0 +1,5 @@ +class ApplicationModel < ::ActiveRecord::Base +  include MetadataSupport + +  self.abstract_class = true +end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 32eedf9ea..39e2b2cff 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -2,13 +2,13 @@ require 'range_ext'  require_relative 'calendar/date_value'  require_relative 'calendar/period' -class Calendar < ActiveRecord::Base +class Calendar < ApplicationModel    include DateSupport    include PeriodSupport    include ApplicationDaysSupport    include TimetableSupport -  has_paper_trail class_name: 'PublicVersion' +  has_metadata    belongs_to :organisation    belongs_to :workgroup diff --git a/app/models/calendar/date_value.rb b/app/models/calendar/date_value.rb index a4a405d43..f50b4237c 100644 --- a/app/models/calendar/date_value.rb +++ b/app/models/calendar/date_value.rb @@ -1,4 +1,4 @@ -class Calendar < ActiveRecord::Base +class Calendar < ApplicationModel    class DateValue      include ActiveAttr::Model diff --git a/app/models/calendar/period.rb b/app/models/calendar/period.rb index 8b3e4109b..07926e818 100644 --- a/app/models/calendar/period.rb +++ b/app/models/calendar/period.rb @@ -1,4 +1,4 @@ -class Calendar < ActiveRecord::Base +class Calendar < ApplicationModel    class Period      include ActiveAttr::Model diff --git a/app/models/chouette/access_link.rb b/app/models/chouette/access_link.rb index 6b08443be..7ab8ca715 100644 --- a/app/models/chouette/access_link.rb +++ b/app/models/chouette/access_link.rb @@ -1,6 +1,6 @@  module Chouette    class AccessLink < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ObjectidSupport      attr_accessor :access_link_type, :link_orientation_type, :link_key diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb index ac6580015..884460881 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -4,7 +4,7 @@ require 'geo_ruby'  module Chouette    class AccessPoint < Chouette::ActiveRecord -    has_paper_trail +    has_metadata      include Geokit::Mappable      include ProjectionFields diff --git a/app/models/chouette/active_record.rb b/app/models/chouette/active_record.rb index c2aab9d50..27f5426b3 100644 --- a/app/models/chouette/active_record.rb +++ b/app/models/chouette/active_record.rb @@ -1,7 +1,8 @@  #require "active_record"  require 'deep_cloneable'  module Chouette -  class ActiveRecord < ::ActiveRecord::Base +  class ActiveRecord < ::ApplicationModel +      self.abstract_class = true      before_save :nil_if_blank, :set_data_source_ref diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index 8d6dbee92..cb2266a3d 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -1,12 +1,12 @@  module Chouette    class Company < Chouette::ActiveRecord +    has_metadata +      include CompanyRestrictions      include LineReferentialSupport      include ObjectidSupport      include CustomFieldsSupport -    has_paper_trail class_name: 'PublicVersion' -      has_many :lines      validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true diff --git a/app/models/chouette/connection_link.rb b/app/models/chouette/connection_link.rb index c53d6f5f1..fb93e5f90 100644 --- a/app/models/chouette/connection_link.rb +++ b/app/models/chouette/connection_link.rb @@ -1,6 +1,6 @@  module Chouette    class ConnectionLink < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ObjectidSupport      include ConnectionLinkRestrictions diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb index 3b6a7cea7..a30c34ce7 100644 --- a/app/models/chouette/group_of_line.rb +++ b/app/models/chouette/group_of_line.rb @@ -1,6 +1,6 @@  module Chouette    class GroupOfLine < Chouette::ActiveRecord -    has_paper_trail +    has_metadata      include ObjectidSupport      include GroupOfLineRestrictions      include LineReferentialSupport diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index 5a5132200..830a6a808 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -1,6 +1,6 @@  module Chouette    class JourneyPattern < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ChecksumSupport      include JourneyPatternRestrictions      include ObjectidSupport diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index c8a02da1f..51851fc2e 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -1,6 +1,6 @@  module Chouette    class Line < Chouette::ActiveRecord -    has_paper_trail class_name: 'PublicVersion' +    has_metadata      include LineRestrictions      include LineReferentialSupport      include ObjectidSupport diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index 942fc5d67..4802d7592 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -1,6 +1,6 @@  module Chouette    class Network < Chouette::ActiveRecord -    has_paper_trail class_name: 'PublicVersion' +    has_metadata      include NetworkRestrictions      include LineReferentialSupport      include ObjectidSupport diff --git a/app/models/chouette/pt_link.rb b/app/models/chouette/pt_link.rb index 399539d44..680632a14 100644 --- a/app/models/chouette/pt_link.rb +++ b/app/models/chouette/pt_link.rb @@ -2,7 +2,7 @@ require 'geokit'  module Chouette    class PtLink < Chouette::ActiveRecord -    has_paper_trail +    has_metadata      include Geokit::Mappable      def geometry diff --git a/app/models/chouette/purchase_window.rb b/app/models/chouette/purchase_window.rb index 4c8014780..e10b106ec 100644 --- a/app/models/chouette/purchase_window.rb +++ b/app/models/chouette/purchase_window.rb @@ -11,7 +11,7 @@ module Chouette      enumerize :color, in: %w(#9B9B9B #FFA070 #C67300 #7F551B #41CCE3 #09B09C #3655D7 #6321A0 #E796C6 #DD2DAA) -    has_paper_trail +    has_metadata      belongs_to :referential      has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 65947c392..9c7a3e6d9 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -1,6 +1,7 @@  module Chouette    class Route < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata +      include RouteRestrictions      include ChecksumSupport      include ObjectidSupport @@ -9,7 +10,6 @@ module Chouette      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(outbound inbound), default: :outbound -      def self.nullable_attributes        [:published_name, :comment, :number, :name, :direction, :wayback]      end diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 58703598e..886eadc6c 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -1,6 +1,6 @@  module Chouette    class RoutingConstraintZone < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ChecksumSupport      include ObjectidSupport diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index c263fa987..9f28b7ee6 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -2,7 +2,7 @@ require 'geokit'  require 'geo_ruby'  module Chouette    class StopArea < Chouette::ActiveRecord -    has_paper_trail class_name: 'PublicVersion' +    has_metadata      include ProjectionFields      include StopAreaRestrictions      include StopAreaReferentialSupport diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb index da2da998a..1df1a664a 100644 --- a/app/models/chouette/stop_point.rb +++ b/app/models/chouette/stop_point.rb @@ -1,6 +1,6 @@  module Chouette    class StopPoint < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      def self.policy_class        RoutePolicy      end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 506e498b8..b59c95665 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -1,6 +1,6 @@  module Chouette    class TimeTable < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ChecksumSupport      include TimeTableRestrictions      include ObjectidSupport diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb index 5a4e17b98..38260b755 100644 --- a/app/models/chouette/timeband.rb +++ b/app/models/chouette/timeband.rb @@ -9,7 +9,7 @@ module Chouette    class Timeband < Chouette::TridentActiveRecord      include ObjectidSupport -    has_paper_trail +    has_metadata      validates :start_time, :end_time, presence: true      validates_with Chouette::TimebandValidator diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index be05d4053..54aad290c 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -1,7 +1,7 @@  # coding: utf-8  module Chouette    class VehicleJourney < Chouette::TridentActiveRecord -    has_paper_trail +    has_metadata      include ChecksumSupport      include CustomFieldsSupport      include VehicleJourneyRestrictions diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index 7aab7f32e..ec47489e9 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -1,4 +1,4 @@ -class CleanUp < ActiveRecord::Base +class CleanUp < ApplicationModel    extend Enumerize    include AASM    belongs_to :referential diff --git a/app/models/clean_up_result.rb b/app/models/clean_up_result.rb index 24d262deb..dff4f5acd 100644 --- a/app/models/clean_up_result.rb +++ b/app/models/clean_up_result.rb @@ -1,3 +1,3 @@ -class CleanUpResult < ActiveRecord::Base +class CleanUpResult < ApplicationModel    belongs_to :clean_up  end diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb index 9d817e146..4ef6170e9 100644 --- a/app/models/compliance_check.rb +++ b/app/models/compliance_check.rb @@ -1,4 +1,4 @@ -class ComplianceCheck < ActiveRecord::Base +class ComplianceCheck < ApplicationModel    include ComplianceItemSupport    self.inheritance_column = nil diff --git a/app/models/compliance_check_block.rb b/app/models/compliance_check_block.rb index 059547e1b..e4f4c1c37 100644 --- a/app/models/compliance_check_block.rb +++ b/app/models/compliance_check_block.rb @@ -1,4 +1,4 @@ -class ComplianceCheckBlock < ActiveRecord::Base +class ComplianceCheckBlock < ApplicationModel    include StifTransportModeEnumerations    include StifTransportSubmodeEnumerations diff --git a/app/models/compliance_check_message.rb b/app/models/compliance_check_message.rb index 738bd4a4b..a4b1062f6 100644 --- a/app/models/compliance_check_message.rb +++ b/app/models/compliance_check_message.rb @@ -1,4 +1,4 @@ -class ComplianceCheckMessage < ActiveRecord::Base +class ComplianceCheckMessage < ApplicationModel    extend Enumerize    belongs_to :compliance_check_set diff --git a/app/models/compliance_check_resource.rb b/app/models/compliance_check_resource.rb index 777254aaf..d2f782e2b 100644 --- a/app/models/compliance_check_resource.rb +++ b/app/models/compliance_check_resource.rb @@ -1,4 +1,4 @@ -class ComplianceCheckResource < ActiveRecord::Base +class ComplianceCheckResource < ApplicationModel    extend Enumerize    belongs_to :compliance_check_set diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 49d324c53..8b1dbdd68 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -1,6 +1,7 @@ -class ComplianceCheckSet < ActiveRecord::Base +class ComplianceCheckSet < ApplicationModel    extend Enumerize -  has_paper_trail class_name: 'PublicVersion' + +  has_metadata    belongs_to :referential    belongs_to :compliance_control_set diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 1cc06f927..672fb128c 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -1,4 +1,4 @@ -class ComplianceControl < ActiveRecord::Base +class ComplianceControl < ApplicationModel    include ComplianceItemSupport    class << self diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb index bc5d6fd4a..6a3c8a34e 100644 --- a/app/models/compliance_control_block.rb +++ b/app/models/compliance_control_block.rb @@ -1,4 +1,4 @@ -class ComplianceControlBlock < ActiveRecord::Base +class ComplianceControlBlock < ApplicationModel    include StifTransportModeEnumerations    include StifTransportSubmodeEnumerations diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb index c0ea692f2..4f0f86d08 100644 --- a/app/models/compliance_control_set.rb +++ b/app/models/compliance_control_set.rb @@ -1,5 +1,6 @@ -class ComplianceControlSet < ActiveRecord::Base -  has_paper_trail class_name: 'PublicVersion' +class ComplianceControlSet < ApplicationModel +  has_metadata +    belongs_to :organisation    has_many :compliance_control_blocks, dependent: :destroy    has_many :compliance_controls, dependent: :destroy diff --git a/app/models/concerns/metadata_support.rb b/app/models/concerns/metadata_support.rb new file mode 100644 index 000000000..c4bedbcda --- /dev/null +++ b/app/models/concerns/metadata_support.rb @@ -0,0 +1,107 @@ +module MetadataSupport +  extend ActiveSupport::Concern + +  included do +    class << self +      def has_metadata? +        !!@has_metadata +      end + +      def has_metadata opts={} +        @has_metadata = true + +        define_method :metadata do +          attr_name = opts[:attr_name] || :metadata +          @wrapped_metadata ||= begin +            wrapped = MetadataSupport::MetadataWrapper.new self.read_attribute(attr_name) +            wrapped.attribute_name = attr_name +            wrapped.owner = self +            wrapped +          end +        end + +        define_method :metadata= do |val| +          @wrapped_metadata = nil +          super val +        end + +        define_method :set_metadata! do |name, value| +          self.metadata.send "#{name}=", value +          self.save! +        end +      end +    end +  end + +  def has_metadata? +    self.class.has_metadata? +  end + +  def merge_metadata_from source +    return unless source.has_metadata? +    source_metadata = source.metadata +    res = {} +    self.metadata.each do |k, v| +      unless self.metadata.is_timestamp_attr?(k) +        ts = self.metadata.timestamp_attr(k) +        if source_metadata[ts] && source_metadata[ts] > self.metadata[ts] +          res[k] = source_metadata[k] +        else +          res[k] = v +        end +      end +    end +    self.metadata = res +    self +  end + +  class MetadataWrapper < OpenStruct +    attr_accessor :attribute_name, :owner + +    def is_timestamp_attr? name +      name =~ /_updated_at$/ +    end + +    def timestamp_attr name +      "#{name}_updated_at".to_sym +    end + +    def method_missing(mid, *args) +      out = super(mid, *args) +      owner.send :write_attribute, attribute_name, @table +      out = out&.to_time if args.length == 0 && is_timestamp_attr?(mid) +      out +    end + +    def each +      @table.each do |k,v| +        yield k, v +      end +    end + +    def new_ostruct_member name +      unless is_timestamp_attr?(name) +        timestamp_attr_name = timestamp_attr(name) +      end + +      name = name.to_sym +      unless respond_to?(name) +        if timestamp_attr_name +          define_singleton_method(timestamp_attr_name) { @table[timestamp_attr_name]&.to_time } +          define_singleton_method(name) { @table[name] } +        else +          # we are defining an accessor for a timestamp +          define_singleton_method(name) { @table[name]&.to_time } +        end + +        define_singleton_method("#{name}=") do |x| +          modifiable[timestamp_attr_name] = Time.now if timestamp_attr_name +          modifiable[name] = x +          owner.send :write_attribute, attribute_name, @table +        end +        modifiable[timestamp_attr_name] = Time.now if timestamp_attr_name +      end +      name +    end +  end +end diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 8347d84f9..22118a15a 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -1,4 +1,4 @@ -class CustomField < ActiveRecord::Base +class CustomField < ApplicationModel    extend Enumerize    belongs_to :workgroup diff --git a/app/models/export/message.rb b/app/models/export/message.rb index b64b524ac..223429900 100644 --- a/app/models/export/message.rb +++ b/app/models/export/message.rb @@ -1,4 +1,4 @@ -class Export::Message < ActiveRecord::Base +class Export::Message < ApplicationModel    self.table_name = :export_messages    include IevInterfaces::Message diff --git a/app/models/export/resource.rb b/app/models/export/resource.rb index 98f103be4..2a63c14a8 100644 --- a/app/models/export/resource.rb +++ b/app/models/export/resource.rb @@ -1,4 +1,4 @@ -class Export::Resource < ActiveRecord::Base +class Export::Resource < ApplicationModel    self.table_name = :export_resources    include IevInterfaces::Resource diff --git a/app/models/import/base.rb b/app/models/import/base.rb index 62494c92e..82494b1dc 100644 --- a/app/models/import/base.rb +++ b/app/models/import/base.rb @@ -1,4 +1,4 @@ -class Import::Base < ActiveRecord::Base +class Import::Base < ApplicationModel    self.table_name = "imports"    validates :file, presence: true diff --git a/app/models/import/message.rb b/app/models/import/message.rb index c1900a718..30b76ec5c 100644 --- a/app/models/import/message.rb +++ b/app/models/import/message.rb @@ -1,4 +1,4 @@ -class Import::Message < ActiveRecord::Base +class Import::Message < ApplicationModel    self.table_name = :import_messages    include IevInterfaces::Message diff --git a/app/models/import/resource.rb b/app/models/import/resource.rb index 5bd011039..1951daacd 100644 --- a/app/models/import/resource.rb +++ b/app/models/import/resource.rb @@ -1,4 +1,4 @@ -class Import::Resource < ActiveRecord::Base +class Import::Resource < ApplicationModel    self.table_name = :import_resources    include IevInterfaces::Resource diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 89700c06f..08193c960 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -1,4 +1,4 @@ -class LineReferential < ActiveRecord::Base +class LineReferential < ApplicationModel    include ObjectidFormatterSupport    extend StifTransportModeEnumerations diff --git a/app/models/line_referential_membership.rb b/app/models/line_referential_membership.rb index dcada25bf..8371bdc32 100644 --- a/app/models/line_referential_membership.rb +++ b/app/models/line_referential_membership.rb @@ -1,4 +1,4 @@ -class LineReferentialMembership < ActiveRecord::Base +class LineReferentialMembership < ApplicationModel    belongs_to :organisation    belongs_to :line_referential diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb index 75c1e48a2..39e3846f0 100644 --- a/app/models/line_referential_sync.rb +++ b/app/models/line_referential_sync.rb @@ -1,4 +1,4 @@ -class LineReferentialSync < ActiveRecord::Base +class LineReferentialSync < ApplicationModel    include AASM    belongs_to :line_referential    has_many :line_referential_sync_messages, :dependent => :destroy diff --git a/app/models/line_referential_sync_message.rb b/app/models/line_referential_sync_message.rb index 3b6cf3367..00a2b58a3 100644 --- a/app/models/line_referential_sync_message.rb +++ b/app/models/line_referential_sync_message.rb @@ -1,4 +1,4 @@ -class LineReferentialSyncMessage < ActiveRecord::Base +class LineReferentialSyncMessage < ApplicationModel    belongs_to :line_referential_sync    enum criticity: [:info, :warning, :error] diff --git a/app/models/merge.rb b/app/models/merge.rb index e72c794fe..6e2a7036a 100644 --- a/app/models/merge.rb +++ b/app/models/merge.rb @@ -1,4 +1,4 @@ -class Merge < ActiveRecord::Base +class Merge < ApplicationModel    extend Enumerize    belongs_to :workbench @@ -138,7 +138,9 @@ class Merge < ActiveRecord::Base      new.switch do        referential_routes.each do |route|          existing_route = new.routes.find_by line_id: route.line_id, checksum: route.checksum -        unless existing_route +        if existing_route +          existing_route.merge_metadata_from route +        else            objectid = Chouette::Route.where(objectid: route.objectid).exists? ? nil : route.objectid            attributes = route.attributes.merge(              id: nil, @@ -196,7 +198,9 @@ class Merge < ActiveRecord::Base          existing_journey_pattern = new.journey_patterns.find_by route_id: existing_associated_route.id, checksum: journey_pattern.checksum -        unless existing_journey_pattern +        if existing_journey_pattern +          existing_journey_pattern.merge_metadata_from journey_pattern +        else            objectid = Chouette::JourneyPattern.where(objectid: journey_pattern.objectid).exists? ? nil : journey_pattern.objectid            attributes = journey_pattern.attributes.merge(              id: nil, @@ -241,7 +245,9 @@ class Merge < ActiveRecord::Base          existing_vehicle_journey = new.vehicle_journeys.find_by journey_pattern_id: existing_associated_journey_pattern.id, checksum: vehicle_journey.checksum -        unless existing_vehicle_journey +        if existing_vehicle_journey +          existing_vehicle_journey.merge_metadata_from vehicle_journey +        else            objectid = Chouette::VehicleJourney.where(objectid: vehicle_journey.objectid).exists? ? nil : vehicle_journey.objectid            attributes = vehicle_journey.attributes.merge(              id: nil, @@ -338,7 +344,9 @@ class Merge < ActiveRecord::Base            existing_time_table = line.time_tables.find_by checksum: candidate_time_table.checksum -          unless existing_time_table +          if existing_time_table +            existing_time_table.merge_metadata_from candidate_time_table +          else              objectid = Chouette::TimeTable.where(objectid: time_table.objectid).exists? ? nil : time_table.objectid              candidate_time_table.objectid = objectid diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 5bef67941..5742c81e8 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,5 +1,5 @@  # coding: utf-8 -class Organisation < ActiveRecord::Base +class Organisation < ApplicationModel    include DataFormatEnumerations    has_many :users, :dependent => :destroy diff --git a/app/models/public_version.rb b/app/models/public_version.rb deleted file mode 100644 index 4dbf6ce27..000000000 --- a/app/models/public_version.rb +++ /dev/null @@ -1,4 +0,0 @@ -class PublicVersion < PaperTrail::Version -  # custom behaviour, e.g: -  self.table_name = :'public.versions' -end diff --git a/app/models/referential.rb b/app/models/referential.rb index 0e48be43f..3304108d0 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,5 +1,5 @@  # coding: utf-8 -class Referential < ActiveRecord::Base +class Referential < ApplicationModel    include DataFormatEnumerations    include ObjectidFormatterSupport diff --git a/app/models/referential_cloning.rb b/app/models/referential_cloning.rb index d4b74bd52..f2c81009a 100644 --- a/app/models/referential_cloning.rb +++ b/app/models/referential_cloning.rb @@ -1,4 +1,4 @@ -class ReferentialCloning < ActiveRecord::Base +class ReferentialCloning < ApplicationModel    include AASM    belongs_to :source_referential, class_name: 'Referential'    belongs_to :target_referential, class_name: 'Referential' diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb index 017eb1449..7a8a01774 100644 --- a/app/models/referential_metadata.rb +++ b/app/models/referential_metadata.rb @@ -1,7 +1,7 @@  require 'activeattr_ext.rb'  require 'range_ext' -class ReferentialMetadata < ActiveRecord::Base +class ReferentialMetadata < ApplicationModel    belongs_to :referential, touch: true    belongs_to :referential_source, class_name: 'Referential'    has_array_of :lines, class_name: 'Chouette::Line' diff --git a/app/models/referential_suite.rb b/app/models/referential_suite.rb index 4f825628c..f4a72f22c 100644 --- a/app/models/referential_suite.rb +++ b/app/models/referential_suite.rb @@ -1,4 +1,4 @@ -class ReferentialSuite < ActiveRecord::Base +class ReferentialSuite < ApplicationModel    belongs_to :new, class_name: 'Referential'    validate def validate_consistent_new      return true if new_id.nil? || new.nil? diff --git a/app/models/simple_interface.rb b/app/models/simple_interface.rb index 43c740b57..7b04a07df 100644 --- a/app/models/simple_interface.rb +++ b/app/models/simple_interface.rb @@ -1,4 +1,4 @@ -class SimpleInterface < ActiveRecord::Base +class SimpleInterface < ApplicationModel    attr_accessor :configuration, :interfaces_group    class << self diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 4706cdd77..6c339547c 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -1,4 +1,4 @@ -class StopAreaReferential < ActiveRecord::Base +class StopAreaReferential < ApplicationModel    validates :registration_number_format, format: { with: /\AX*\z/ }    include ObjectidFormatterSupport diff --git a/app/models/stop_area_referential_membership.rb b/app/models/stop_area_referential_membership.rb index fbed1c004..d507bc50e 100644 --- a/app/models/stop_area_referential_membership.rb +++ b/app/models/stop_area_referential_membership.rb @@ -1,4 +1,4 @@ -class StopAreaReferentialMembership < ActiveRecord::Base +class StopAreaReferentialMembership < ApplicationModel    belongs_to :organisation    belongs_to :stop_area_referential diff --git a/app/models/stop_area_referential_sync.rb b/app/models/stop_area_referential_sync.rb index e6cf2ecbc..8b48d35e6 100644 --- a/app/models/stop_area_referential_sync.rb +++ b/app/models/stop_area_referential_sync.rb @@ -1,4 +1,4 @@ -class StopAreaReferentialSync < ActiveRecord::Base +class StopAreaReferentialSync < ApplicationModel    include AASM    belongs_to :stop_area_referential    has_many :stop_area_referential_sync_messages, :dependent => :destroy diff --git a/app/models/stop_area_referential_sync_message.rb b/app/models/stop_area_referential_sync_message.rb index cd2e62405..642ccfc38 100644 --- a/app/models/stop_area_referential_sync_message.rb +++ b/app/models/stop_area_referential_sync_message.rb @@ -1,4 +1,4 @@ -class StopAreaReferentialSyncMessage < ActiveRecord::Base +class StopAreaReferentialSyncMessage < ApplicationModel    belongs_to :stop_area_referential_sync    enum criticity: [:info, :warning, :error] diff --git a/app/models/user.rb b/app/models/user.rb index eca7ede0c..29148d9e9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationModel    # Include default devise modules. Others available are:    # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable, :database_authenticatable diff --git a/app/models/workbench.rb b/app/models/workbench.rb index b5f4673bb..ef0b2eaa4 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,4 +1,4 @@ -class Workbench < ActiveRecord::Base +class Workbench < ApplicationModel    DEFAULT_WORKBENCH_NAME = "Gestion de l'offre"    include ObjectidFormatterSupport diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 7e3e857ec..3e8409634 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -1,4 +1,4 @@ -class Workgroup < ActiveRecord::Base +class Workgroup < ApplicationModel    belongs_to :line_referential    belongs_to :stop_area_referential diff --git a/app/views/autocomplete_purchase_windows/index.rabl b/app/views/autocomplete_purchase_windows/index.rabl index 1d0287602..bdc513c31 100644 --- a/app/views/autocomplete_purchase_windows/index.rabl +++ b/app/views/autocomplete_purchase_windows/index.rabl @@ -2,11 +2,12 @@ collection @purchase_windows, :object_root => false  node do |window|    { -    :id => window.id, -    :name => window.name, -    :objectid => window.objectid, -    :color => window.color, -    :short_id => window.get_objectid.short_id, -    :text => "<strong><span class='fa fa-circle' style='color:" + (window.color ? window.color : '#4b4b4b') + "'></span> " + window.name + " - " + window.get_objectid.short_id + "</strong>" +    id: window.id, +    name: window.name, +    objectid: window.objectid, +    color: window.color, +    short_id: window.get_objectid.short_id, +    bounding_dates: window.bounding_dates, +    text: "<strong><span class='fa fa-circle' style='color:" + (window.color ? window.color : '#4b4b4b') + "'></span> " + window.name + " - " + window.get_objectid.short_id + "</strong>"    }  end diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim index da0539bd0..f745d10a4 100644 --- a/app/views/lines/_filters.html.slim +++ b/app/views/lines/_filters.html.slim @@ -44,5 +44,5 @@    .actions -    = link_to 'Effacer', @workbench, class: 'btn btn-link' -    = f.submit 'Filtrer', class: 'btn btn-default' +    = link_to t('actions.erase'), @workbench, class: 'btn btn-link' +    = f.submit t('actions.filter'), class: 'btn btn-default' diff --git a/app/views/referential_lines/_filters.html.slim b/app/views/referential_lines/_filters.html.slim index 501f61c16..15db0e33e 100644 --- a/app/views/referential_lines/_filters.html.slim +++ b/app/views/referential_lines/_filters.html.slim @@ -1,7 +1,7 @@  = search_form_for @q, url: referential_line_path(@referential, @line), class: 'form form-filter' do |f|    .ffg-row      .input-group.search_bar class=filter_item_class(params[:q], :name_or_objectid_cont) -      = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'itinĂ©raire ou un ID..." +      = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: t('.name_or_objectid_cont')        span.input-group-btn          button.btn.btn-default#search-btn type='submit'            span.fa.fa-search @@ -12,5 +12,5 @@        = f.input :wayback_eq_any, class: 'form-control', collection: Chouette::Route.wayback.values, as: :check_boxes, label: false, required: false, wrapper_html: { class: 'checkbox_list'}, label_method: lambda{|l| ("<span>" + t("enumerize.route.wayback.#{l}") + "</span>").html_safe}    .actions -    = link_to 'Effacer', referential_line_path(@referential, @line), class: 'btn btn-link' -    = f.submit 'Filtrer', class: 'btn btn-default' +    = link_to t('actions.erase'), referential_line_path(@referential, @line), class: 'btn btn-link' +    = f.submit t('actions.filter'), class: 'btn btn-default' diff --git a/app/views/referential_vehicle_journeys/_filters.html.slim b/app/views/referential_vehicle_journeys/_filters.html.slim index f1fbdb5d8..f9fa4fcf7 100644 --- a/app/views/referential_vehicle_journeys/_filters.html.slim +++ b/app/views/referential_vehicle_journeys/_filters.html.slim @@ -68,5 +68,5 @@    .actions -    = link_to 'Effacer', referential_vehicle_journeys_path(@referential), class: 'btn btn-link' -    = f.submit 'Filtrer', class: 'btn btn-default' +    = link_to t('actions.erase'), referential_vehicle_journeys_path(@referential), class: 'btn btn-link' +    = f.submit t('actions.filter'), class: 'btn btn-default' diff --git a/app/views/referentials/select_compliance_control_set.html.slim b/app/views/referentials/select_compliance_control_set.html.slim index 3550bb202..7be82364d 100644 --- a/app/views/referentials/select_compliance_control_set.html.slim +++ b/app/views/referentials/select_compliance_control_set.html.slim @@ -8,7 +8,7 @@            .row              .col-lg-12                .form-group -                = label_tag 'name', nil, class: 'string required col-sm-4 col-xs-5 control-label' +                = label_tag ComplianceControlSet.ts, nil, class: 'string required col-sm-4 col-xs-5 control-label'                  .col-sm-8.col-xs-7                    = select_tag :compliance_control_set, options_from_collection_for_select(@compliance_control_sets, "id", "name"), class: 'select optional form-control'                .separator diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index d2e750fb0..d4571c173 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -34,7 +34,7 @@                  end \                ), \                TableBuilderHelper::Column.new( \ -                key: :deleted_at, \ +                name: Chouette::Line.tmf('activated'), \                  attribute: Proc.new { |s| line_status(s.try(:stop_area).deleted_at) } \                ), \                TableBuilderHelper::Column.new( \ diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim index a32638567..c698eaaa5 100644 --- a/app/views/stop_areas/_filters.html.slim +++ b/app/views/stop_areas/_filters.html.slim @@ -41,5 +41,5 @@              input_html: { checked: @status.try(:[], :deactivated) }    .actions -    = link_to 'Effacer', @workbench, class: 'btn btn-link' -    = f.submit 'Filtrer', class: 'btn btn-default' +    = link_to t('actions.erase'), @workbench, class: 'btn btn-link' +    = f.submit t('actions.filter'), class: 'btn btn-default' diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 587efbdaa..fbdb54e02 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -32,7 +32,7 @@                  attribute: 'registration_number' \                ), \                TableBuilderHelper::Column.new( \ -                name: t('activerecord.attributes.stop_area.state'), \ +                name: Chouette::StopArea.tmf('state'), \                  attribute: Proc.new { |s| stop_area_status(s) } \                ), \                TableBuilderHelper::Column.new( \ diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim index c92fb7bae..7fcee545f 100644 --- a/app/views/vehicle_journeys/index.html.slim +++ b/app/views/vehicle_journeys/index.html.slim @@ -7,7 +7,7 @@        - if has_feature? :purchase_windows          = link_to I18n.t("purchase_windows.index.title"), [@referential, :purchase_windows], class: 'btn btn-primary sticky-action', target: :blank        - if @route.opposite_route.present? -        = link_to(t('routes.actions.opposite_route_timetable'), [@referential, @route.line, @route.opposite_route, :vehicle_journeys], class: 'btn btn-primary sticky-action') +        = link_to(t('routes.actions.reversed_vehicle_journey'), [@referential, @route.line, @route.opposite_route, :vehicle_journeys], class: 'btn btn-primary sticky-action')  .page_content diff --git a/app/views/workbench_outputs/show.html.slim b/app/views/workbench_outputs/show.html.slim index a9e106dbb..b310119e6 100644 --- a/app/views/workbench_outputs/show.html.slim +++ b/app/views/workbench_outputs/show.html.slim @@ -6,7 +6,8 @@    .row.mb-sm      .col-lg-12.text-right        = link_to t('.see_current_output'), referential_path(@workbench.output.current), class: 'btn btn-primary' if @workbench.output&.current -      = link_to t('merges.actions.create'), new_workbench_merge_path(@workbench), class: 'btn btn-primary' +      - if policy(Merge).create? +        = link_to t('merges.actions.create'), new_workbench_merge_path(@workbench), class: 'btn btn-primary'  .page_content    .container-fluid diff --git a/config/database/ci.yml b/config/database/ci.yml index 44103454a..fcc17d8b0 100644 --- a/config/database/ci.yml +++ b/config/database/ci.yml @@ -9,3 +9,7 @@ test:    database: <%= ENV.fetch 'RAILS_DB_NAME', 'stif_boiv_test' %>    username: <%= ENV['RAILS_DB_USER'] || ENV['POSTGRESQL_ENV_POSTGRES_USER'] || 'jenkins' %>    password: <%= ENV['RAILS_DB_PASSWORD'] || ENV['POSTGRESQL_ENV_POSTGRES_PASSWORD'] %> + +# Only used to build assets +production: +  <<: *default diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index 3d16e7c05..696ae2734 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -69,7 +69,7 @@ en:          date_ranges: Date ranges          dates: Dates          shared: Shared -        organisation: Organisation +        organisation: Organization          monday: "Monday"          tuesday: "Tuesday"          wednesday: "Wednesday" diff --git a/config/locales/companies.en.yml b/config/locales/companies.en.yml index becb087b1..f2b19bc19 100644 --- a/config/locales/companies.en.yml +++ b/config/locales/companies.en.yml @@ -16,7 +16,7 @@ en:      index:        title: "Companies"        name: "Search by name..." -      name_or_objectid: "Search by name or by Codifligne ID..." +      name_or_objectid: "Search by name or by ID..."        advanced_search: "Advanced search"    activerecord:      models: diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml index 63708328b..73ecf8996 100644 --- a/config/locales/compliance_check_sets.en.yml +++ b/config/locales/compliance_check_sets.en.yml @@ -23,7 +23,7 @@ en:        table_state: "%{lines_status} lines imported out of %{lines_in_compliance_check_set} in the archive"        table_explanation: "These controls apply to all imported data and condition the construction of your organization's offer."        table_title: Analysed lines state -      metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" +      metrics: "%{error_count} errors, %{warning_count} warnings"        metadatas:          referential: "Object analysed"          referential_type: "Apply to" diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml index 20bf11d85..045fed4ce 100644 --- a/config/locales/compliance_check_sets.fr.yml +++ b/config/locales/compliance_check_sets.fr.yml @@ -19,7 +19,7 @@ fr:        table_state: "%{lines_status} lignes valides sur %{lines_in_compliance_check_set} prĂ©sentes dans l'offre de transport"        table_explanation: Ces contrĂŽles sâappliquent pour toutes les donnĂ©es importĂ©es et conditionnent la construction de lâoffre de votre organisation        table_title: Ătat des lignes analysĂ©es -      metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" +      metrics: "%{error_count} errors, %{warning_count} warnings"        metadatas:          referential: "Objet analysĂ©"          referential_type: "AppliquĂ© Ă " diff --git a/config/locales/import_resources.en.yml b/config/locales/import_resources.en.yml index 386039319..4b1f9c394 100644 --- a/config/locales/import_resources.en.yml +++ b/config/locales/import_resources.en.yml @@ -6,7 +6,7 @@ en:          table_state: "%{lines_imported} line(s) imported on %{lines_in_zipfile} presents in zipfile"          table_title: "Satus of anlyzed files"          table_explanation: "When calendriers.xml and/or commun.xml are not imported, then all lines file are not processed." -        metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" +        metrics: "%{error_count} errors, %{warning_count} warnings"    import_resources:      <<: *resources    activerecord: diff --git a/config/locales/import_resources.fr.yml b/config/locales/import_resources.fr.yml index 50fb7f1ca..93a576f01 100644 --- a/config/locales/import_resources.fr.yml +++ b/config/locales/import_resources.fr.yml @@ -6,7 +6,7 @@ fr:          table_state: "%{lines_imported} ligne(s) importĂ©e(s) sur %{lines_in_zipfile} prĂ©sente(s) dans l'archive"          table_title: "Etat des fichiers analysĂ©s"          table_explanation: "Dans le cas ou le(s) fichiers calendriers.xml et/ou commun.xml sont dans un Ă©tat non importĂ©, alors tous les fichiers lignes sont automatiquement dans un Ă©tat non traitĂ©." -        metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" +        metrics: "%{error_count} errors, %{warning_count} warnings"    import_resources:      <<: *resources    activerecord: diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml index 5663ed691..18ff28c24 100644 --- a/config/locales/line_referentials.en.yml +++ b/config/locales/line_referentials.en.yml @@ -7,7 +7,7 @@ en:      edit:        title: "Edit %{name} referential"      show: -      title: "iLICO synchronization" +      title: Line referential        synchronized: Synchronized        status: Status        message: Message diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index e61013725..1cd5150db 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -1,6 +1,5 @@  en:    lines: &en_lines -    search_no_results: "No line matching your query"      actions:        new: "Add a new line"        edit: "Edit this line" @@ -20,6 +19,8 @@ en:        show: 'Show'        show_network: 'Show network'        show_company: 'Show company' +    filters: +      name_or_objectid_cont: "Search by name or objectid"      new:        title: "Add a new line"      create: @@ -33,11 +34,12 @@ en:        routes:          title: "Routes list"        group_of_lines: "Groups of lines" +      search_no_results: "No line matching your query"      index:        deactivated: "Disabled line"        title: "Lines"        line: "Line %{line}" -      name_or_number_or_objectid: "Search by name, short name or ID Codif..." +      name_or_number_or_objectid: "Search by name, short name or ID..."        no_networks: "No networks"        no_companies: "No companies"        no_group_of_lines: "No group of lines" @@ -115,7 +117,7 @@ en:          creator_id: "Created by"          footnotes: "Footnotes"          stable_id: External permanent idenifier" -        state: State +        state: Status          activated: Activated          deactivated: Deactivated    formtastic: diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index d3069f1d1..058238710 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -1,6 +1,5 @@  fr:    lines: &fr_lines -    search_no_results: "Aucune ligne ne correspond Ă  votre recherche"      actions:        new: "Ajouter une ligne"        edit: "Editer cette ligne" @@ -20,6 +19,8 @@ fr:        show: 'Consulter'        show_network: 'Voir le rĂ©seau'        show_company: 'Voir le transporteur principal' +    filters: +      name_or_objectid_cont: "Indiquez un nom d'itinĂ©raire ou un ID..."      new:        title: "Ajouter une ligne"      create: @@ -34,6 +35,7 @@ fr:          title: "Liste des ItinĂ©raires"        itineraries: "Liste des sĂ©quences d'arrĂȘts de la ligne"        group_of_lines: "Groupes de lignes" +      search_no_results: "Aucune ligne ne correspond Ă  votre recherche"      index:        deactivated: "Ligne dĂ©sactivĂ©e"        title: "Lignes" diff --git a/config/locales/networks.en.yml b/config/locales/networks.en.yml index 94a8d9df0..2046a30ae 100644 --- a/config/locales/networks.en.yml +++ b/config/locales/networks.en.yml @@ -15,7 +15,7 @@ en:      index:        title: "Networks"        name: "Search by name..." -      name_or_objectid: "Search by name or by Codifligne ID..." +      name_or_objectid: "Search by name or by ID..."        advanced_search: "Advanced search"    activerecord:      models: diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index ec6c7c643..cf012ef8e 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -32,7 +32,7 @@ fr:          title: 'Dupliquer un jeu de donnĂ©es'        submit: "Valider"      select_compliance_control_set: -      title: "SĂ©lection du jeu de contĂŽles" +      title: "SĂ©lection du jeu de contrĂŽles"      actions:        new: "CrĂ©er un jeu de donnĂ©es"        destroy_confirm: "Etes vous sĂ»r de vouloir supprimer ce jeu de donnĂ©es ?" diff --git a/config/locales/routes.en.yml b/config/locales/routes.en.yml index 58869b895..66805e050 100644 --- a/config/locales/routes.en.yml +++ b/config/locales/routes.en.yml @@ -15,7 +15,7 @@ en:        export_hub_all: "Export HUB routes"        add_stop_point: "Add stop point"        new_stop_point: "Create new stop" -      opposite_route_timetable: "Timetable back" +      reversed_vehicle_journey: "Reversed vehicle journeys"      new:        title: "Add a new route"      edit: diff --git a/config/locales/routes.fr.yml b/config/locales/routes.fr.yml index 9539a2ee3..f4eefa10d 100644 --- a/config/locales/routes.fr.yml +++ b/config/locales/routes.fr.yml @@ -15,7 +15,7 @@ fr:        export_hub_all: "Export HUB des itinĂ©raires"        add_stop_point: "Ajouter un arrĂȘt"        new_stop_point: "CrĂ©er un arrĂȘt pour l'ajouter" -      opposite_route_timetable: "Horaires retour" +      reversed_vehicle_journey: "Horaires retour"      opposite: "%{name} (retour)"      new:        title: "Ajouter un itinĂ©raire" diff --git a/config/locales/select2.en.yml b/config/locales/select2.en.yml new file mode 100644 index 000000000..308540af0 --- /dev/null +++ b/config/locales/select2.en.yml @@ -0,0 +1,15 @@ +en: +  select2: +    error_loading: The results cannot be loaded. +    input_too_long: +      one: Remove %{count} letter +      other: Remove %{count} letters +    input_too_short: +      one: Type %{count} letter +      other: Type %{count} letters +    loading_more: Loading more⊠+    maximum_selected: +      one: You can select %{count} element +      other: You can select %{count} elements +    no_results: No Results +    searching: Searching... diff --git a/config/locales/select2.fr.yml b/config/locales/select2.fr.yml new file mode 100644 index 000000000..4a37a3d78 --- /dev/null +++ b/config/locales/select2.fr.yml @@ -0,0 +1,15 @@ +fr: +  select2: +    error_loading: Les rĂ©sultats ne peuvent pas ĂȘtre chargĂ©s. +    input_too_long: +      one: Supprimez %{count} caractĂšre +      other: Supprimez %{count} caractĂšres +    input_too_short: +      one: Saisissez %{count} caractĂšre +      other: Saisissez %{count} caractĂšres +    loading_more: Chargement de rĂ©sultats supplĂ©mentaires⊠+    maximum_selected: +      one: Vous pouvez sĂ©lectionner %{count} Ă©lĂ©ment +      other: Vous pouvez sĂ©lectionner %{count} Ă©lĂ©ment +    no_results: Aucun rĂ©sultat trouvĂ© +    searching: Recherche en cours...
\ No newline at end of file diff --git a/config/locales/stop_area_referentials.en.yml b/config/locales/stop_area_referentials.en.yml index 11baf67e2..9d49d7c5d 100644 --- a/config/locales/stop_area_referentials.en.yml +++ b/config/locales/stop_area_referentials.en.yml @@ -4,7 +4,7 @@ en:        sync: "Launch a new reflex synchronization"        cancel_sync: "Cancel reflex synchronization"      show: -      title: 'Synchronization iCAR' +      title: 'Stop area referential'    activerecord:      models:        stop_area_referential: diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml index ddb2d940c..1da4b58b4 100644 --- a/config/locales/stop_areas.en.yml +++ b/config/locales/stop_areas.en.yml @@ -48,9 +48,9 @@ en:        export_hub_physical: "Export HUB physical"      filters:        name_or_objectid: "Search by name or by objectid..." -      zip_code: Type a zip code... -      city_name: Type a city name... -      area_type: Type an area type... +      zip_code: Enter a zip code... +      city_name: Enter a city name... +      area_type: Enter an area type...      new:        title: "Add a new stop"      update: @@ -70,7 +70,7 @@ en:        stop_managment: "Parent-child relations"        access_managment: "Access Points and Links managment"        access_points: "Access Points" -      not_editable: "Le type d'arrĂȘt est non modifiable" +      not_editable: "The area type is not editable"        state:          active: Active          deactivated: Deactivated @@ -148,7 +148,7 @@ en:          zip_code: "Zip code"          city_name: "City"          waiting_time: Waiting time (minutes) -        state: State +        state: Status    formtastic:      titles:        stop_area: diff --git a/config/locales/stop_points.en.yml b/config/locales/stop_points.en.yml index 72e138270..76e142ba1 100644 --- a/config/locales/stop_points.en.yml +++ b/config/locales/stop_points.en.yml @@ -43,8 +43,8 @@ en:          created_at: Created          updated_at: Updated          deleted_at: "Activated" -        for_boarding: "For boarding" -        for_alighting: "For alighting" +        for_boarding: "Boarding" +        for_alighting: "Alighting"          area_type: "Area type"          city_name: "City name"          zip_code: "Zip code" diff --git a/config/locales/vehicle_journeys.en.yml b/config/locales/vehicle_journeys.en.yml index 79e805ee8..12d8d0da4 100644 --- a/config/locales/vehicle_journeys.en.yml +++ b/config/locales/vehicle_journeys.en.yml @@ -3,8 +3,8 @@ en:      vehicle_journeys_matrix:        filters:          id: Filter by ID... -        timetable: Filter by journey pattern... -        timetable: Filter by timetable... +        journey_pattern: Filter by journey pattern... +        timetable: Filter by timetable...                  cancel_selection: "Cancel Selection"        fetching_error: "There has been a problem fetching the data. Please reload the page to try again."        line_routes: "Line's routes" diff --git a/db/migrate/20150219175300_insert_default_organisation.rb b/db/migrate/20150219175300_insert_default_organisation.rb index 2734893f5..ac8ecb9b6 100644 --- a/db/migrate/20150219175300_insert_default_organisation.rb +++ b/db/migrate/20150219175300_insert_default_organisation.rb @@ -1,5 +1,5 @@  class InsertDefaultOrganisation < ActiveRecord::Migration -  class Organisation  < ActiveRecord::Base +  class Organisation  < ApplicationModel      attr_accessor :name    end diff --git a/db/migrate/20180330074336_add_metadata_to_routes.rb b/db/migrate/20180330074336_add_metadata_to_routes.rb new file mode 100644 index 000000000..1a35dbb65 --- /dev/null +++ b/db/migrate/20180330074336_add_metadata_to_routes.rb @@ -0,0 +1,5 @@ +class AddMetadataToRoutes < ActiveRecord::Migration +  def change +    add_column :routes, :metadata, :jsonb +  end +end diff --git a/db/migrate/20180330124436_add_metadata_to_other_models.rb b/db/migrate/20180330124436_add_metadata_to_other_models.rb new file mode 100644 index 000000000..c808a660c --- /dev/null +++ b/db/migrate/20180330124436_add_metadata_to_other_models.rb @@ -0,0 +1,28 @@ +class AddMetadataToOtherModels < ActiveRecord::Migration +  def change +    [ +      Api::V1::ApiKey, +      Calendar, +      Chouette::AccessLink, +      Chouette::AccessPoint, +      Chouette::Company, +      Chouette::ConnectionLink, +      Chouette::GroupOfLine, +      Chouette::JourneyPattern, +      Chouette::Line, +      Chouette::Network, +      Chouette::PtLink, +      Chouette::PurchaseWindow, +      Chouette::RoutingConstraintZone, +      Chouette::StopArea, +      Chouette::StopPoint, +      Chouette::TimeTable, +      Chouette::Timeband, +      Chouette::VehicleJourney, +      ComplianceCheckSet, +      ComplianceControlSet, +    ].each do |model| +      add_column model.table_name, :metadata, :jsonb, default: {} +    end +  end +end diff --git a/db/migrate/20180403065419_remove_papertrail_tables.rb b/db/migrate/20180403065419_remove_papertrail_tables.rb new file mode 100644 index 000000000..8494058e1 --- /dev/null +++ b/db/migrate/20180403065419_remove_papertrail_tables.rb @@ -0,0 +1,5 @@ +class RemovePapertrailTables < ActiveRecord::Migration +  def change +    drop_table :versions +  end +end diff --git a/db/schema.rb b/db/schema.rb index 023cdc7eb..7e0e9c2b5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180405133659) do +ActiveRecord::Schema.define(version: 20180319043333) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -22,7 +22,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "access_links", id: :bigserial, force: :cascade do |t|      t.integer  "access_point_id",                        limit: 8      t.integer  "stop_area_id",                           limit: 8 -    t.string   "objectid",                                                                  null: false +    t.string   "objectid",                                                                               null: false      t.integer  "object_version",                         limit: 8      t.string   "name"      t.string   "comment" @@ -39,6 +39,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.string   "link_orientation"      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                                                                  default: {}    end    add_index "access_links", ["objectid"], name: "access_links_objectid_key", unique: true, using: :btree @@ -66,6 +67,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "import_xml"      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                                                            default: {}    end    add_index "access_points", ["objectid"], name: "access_points_objectid_key", unique: true, using: :btree @@ -77,6 +79,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.datetime "created_at"      t.datetime "updated_at"      t.integer  "organisation_id", limit: 8 +    t.jsonb    "metadata",                  default: {}    end    add_index "api_keys", ["organisation_id"], name: "index_api_keys_on_organisation_id", using: :btree @@ -89,9 +92,10 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.integer   "organisation_id", limit: 8      t.datetime  "created_at"      t.datetime  "updated_at" +    t.integer   "workgroup_id",    limit: 8      t.integer   "int_day_types"      t.date      "excluded_dates",                            array: true -    t.integer   "workgroup_id",    limit: 8 +    t.jsonb     "metadata",                  default: {}    end    add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree @@ -139,7 +143,8 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "import_xml"      t.datetime "created_at"      t.datetime "updated_at" -    t.jsonb    "custom_field_values",                 default: {} +    t.jsonb    "custom_field_values" +    t.jsonb    "metadata",                            default: {}    end    add_index "companies", ["line_referential_id"], name: "index_companies_on_line_referential_id", using: :btree @@ -192,14 +197,15 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.string   "status"      t.integer  "parent_id",                 limit: 8      t.string   "parent_type" -    t.datetime "created_at",                          null: false -    t.datetime "updated_at",                          null: false +    t.datetime "created_at",                                       null: false +    t.datetime "updated_at",                                       null: false      t.string   "current_step_id"      t.float    "current_step_progress"      t.string   "name"      t.datetime "started_at"      t.datetime "ended_at"      t.datetime "notified_parent_at" +    t.jsonb    "metadata",                            default: {}    end    add_index "compliance_check_sets", ["compliance_control_set_id"], name: "index_compliance_check_sets_on_compliance_control_set_id", using: :btree @@ -238,8 +244,9 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "compliance_control_sets", id: :bigserial, force: :cascade do |t|      t.string   "name"      t.integer  "organisation_id", limit: 8 -    t.datetime "created_at",                null: false -    t.datetime "updated_at",                null: false +    t.datetime "created_at",                             null: false +    t.datetime "updated_at",                             null: false +    t.jsonb    "metadata",                  default: {}    end    add_index "compliance_control_sets", ["organisation_id"], name: "index_compliance_control_sets_on_organisation_id", using: :btree @@ -265,7 +272,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "connection_links", id: :bigserial, force: :cascade do |t|      t.integer  "departure_id",                           limit: 8      t.integer  "arrival_id",                             limit: 8 -    t.string   "objectid",                                                                  null: false +    t.string   "objectid",                                                                               null: false      t.integer  "object_version",                         limit: 8      t.string   "name"      t.string   "comment" @@ -281,6 +288,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.integer  "int_user_needs"      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                                                                  default: {}    end    add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree @@ -398,7 +406,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    end    create_table "group_of_lines", id: :bigserial, force: :cascade do |t| -    t.string   "objectid",                      null: false +    t.string   "objectid",                                   null: false      t.integer  "object_version",      limit: 8      t.string   "name"      t.string   "comment" @@ -407,6 +415,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "import_xml"      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                      default: {}    end    add_index "group_of_lines", ["line_referential_id"], name: "index_group_of_lines_on_line_referential_id", using: :btree @@ -485,7 +494,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "journey_patterns", id: :bigserial, force: :cascade do |t|      t.integer  "route_id",                limit: 8 -    t.string   "objectid",                          null: false +    t.string   "objectid",                                       null: false      t.integer  "object_version",          limit: 8      t.string   "name"      t.string   "comment" @@ -499,6 +508,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "checksum_source"      t.string   "data_source_ref"      t.json     "costs" +    t.jsonb    "metadata",                          default: {}    end    add_index "journey_patterns", ["objectid"], name: "journey_patterns_objectid_key", unique: true, using: :btree @@ -572,6 +582,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.datetime "created_at"      t.datetime "updated_at"      t.boolean  "seasonal" +    t.jsonb    "metadata",                                  default: {}    end    add_index "lines", ["line_referential_id"], name: "index_lines_on_line_referential_id", using: :btree @@ -593,7 +604,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    add_index "merges", ["workbench_id"], name: "index_merges_on_workbench_id", using: :btree    create_table "networks", id: :bigserial, force: :cascade do |t| -    t.string   "objectid",                      null: false +    t.string   "objectid",                                   null: false      t.integer  "object_version",      limit: 8      t.date     "version_date"      t.string   "description" @@ -607,6 +618,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.integer  "line_referential_id", limit: 8      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                      default: {}    end    add_index "networks", ["line_referential_id"], name: "index_networks_on_line_referential_id", using: :btree @@ -631,13 +643,14 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.integer  "start_of_link_id", limit: 8      t.integer  "end_of_link_id",   limit: 8      t.integer  "route_id",         limit: 8 -    t.string   "objectid",                                            null: false +    t.string   "objectid",                                                         null: false      t.integer  "object_version",   limit: 8      t.string   "name"      t.string   "comment"      t.decimal  "link_distance",              precision: 19, scale: 2      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                                            default: {}    end    add_index "pt_links", ["objectid"], name: "pt_links_objectid_key", unique: true, using: :btree @@ -645,13 +658,14 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "purchase_windows", id: :bigserial, force: :cascade do |t|      t.string    "name"      t.string    "color" -    t.daterange "date_ranges",                            array: true -    t.datetime  "created_at",                null: false -    t.datetime  "updated_at",                null: false +    t.daterange "date_ranges",                                         array: true +    t.datetime  "created_at",                             null: false +    t.datetime  "updated_at",                             null: false      t.string    "objectid"      t.string    "checksum"      t.text      "checksum_source"      t.integer   "referential_id",  limit: 8 +    t.jsonb     "metadata",                  default: {}    end    add_index "purchase_windows", ["referential_id"], name: "index_purchase_windows_on_referential_id", using: :btree @@ -742,6 +756,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "checksum_source"      t.string   "data_source_ref"      t.json     "costs" +    t.jsonb    "metadata"    end    add_index "routes", ["objectid"], name: "routes_objectid_key", unique: true, using: :btree @@ -750,13 +765,14 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.string   "name"      t.datetime "created_at"      t.datetime "updated_at" -    t.string   "objectid",                  null: false +    t.string   "objectid",                               null: false      t.integer  "object_version",  limit: 8      t.integer  "route_id",        limit: 8 -    t.integer  "stop_point_ids",  limit: 8,              array: true +    t.integer  "stop_point_ids",  limit: 8,                           array: true      t.string   "checksum"      t.text     "checksum_source"      t.string   "data_source_ref" +    t.jsonb    "metadata",                  default: {}    end    create_table "routing_constraints_lines", id: false, force: :cascade do |t| @@ -810,7 +826,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "stop_areas", id: :bigserial, force: :cascade do |t|      t.integer  "parent_id",                       limit: 8 -    t.string   "objectid",                                                            null: false +    t.string   "objectid",                                                                         null: false      t.integer  "object_version",                  limit: 8      t.string   "name"      t.string   "comment" @@ -843,6 +859,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.jsonb    "localized_names"      t.datetime "confirmed_at"      t.jsonb    "custom_field_values" +    t.jsonb    "metadata",                                                            default: {}    end    add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -858,13 +875,14 @@ ActiveRecord::Schema.define(version: 20180405133659) do    create_table "stop_points", id: :bigserial, force: :cascade do |t|      t.integer  "route_id",       limit: 8      t.integer  "stop_area_id",   limit: 8 -    t.string   "objectid",                 null: false +    t.string   "objectid",                              null: false      t.integer  "object_version", limit: 8      t.integer  "position"      t.string   "for_boarding"      t.string   "for_alighting"      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                 default: {}    end    add_index "stop_points", ["objectid"], name: "stop_points_objectid_key", unique: true, using: :btree @@ -912,7 +930,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do    add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree    create_table "time_tables", id: :bigserial, force: :cascade do |t| -    t.string   "objectid",                              null: false +    t.string   "objectid",                               null: false      t.integer  "object_version",  limit: 8, default: 1      t.string   "version"      t.string   "comment" @@ -927,6 +945,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.string   "checksum"      t.text     "checksum_source"      t.string   "data_source_ref" +    t.jsonb    "metadata",                  default: {}    end    add_index "time_tables", ["calendar_id"], name: "index_time_tables_on_calendar_id", using: :btree @@ -942,13 +961,14 @@ ActiveRecord::Schema.define(version: 20180405133659) do    add_index "time_tables_vehicle_journeys", ["vehicle_journey_id"], name: "index_time_tables_vehicle_journeys_on_vehicle_journey_id", using: :btree    create_table "timebands", id: :bigserial, force: :cascade do |t| -    t.string   "objectid",                 null: false +    t.string   "objectid",                              null: false      t.integer  "object_version", limit: 8      t.string   "name" -    t.time     "start_time",               null: false -    t.time     "end_time",                 null: false +    t.time     "start_time",                            null: false +    t.time     "end_time",                              null: false      t.datetime "created_at"      t.datetime "updated_at" +    t.jsonb    "metadata",                 default: {}    end    create_table "users", id: :bigserial, force: :cascade do |t| @@ -1031,6 +1051,7 @@ ActiveRecord::Schema.define(version: 20180405133659) do      t.text     "checksum_source"      t.string   "data_source_ref"      t.jsonb    "custom_field_values",                       default: {} +    t.jsonb    "metadata",                                  default: {}    end    add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree diff --git a/db/seeds/stif.seeds.rb b/db/seeds/stif.seeds.rb index bb73b0b9c..98192385f 100644 --- a/db/seeds/stif.seeds.rb +++ b/db/seeds/stif.seeds.rb @@ -12,7 +12,7 @@ stop_area_referential = StopAreaReferential.seed_by(name: "Reflex") do |r|  end  line_referential = LineReferential.seed_by(name: "CodifLigne") do |r| -  r.objectid_format = "stif_netex" +  r.objectid_format = "stif_codifligne"    r.add_member stif, owner: true  end diff --git a/lib/route_way_cost_unit_converter.rb b/lib/route_way_cost_unit_converter.rb index 45edbf538..52515e52c 100644 --- a/lib/route_way_cost_unit_converter.rb +++ b/lib/route_way_cost_unit_converter.rb @@ -8,18 +8,24 @@ class RouteWayCostUnitConverter      end    end -  private -    # Round to 2 decimal places to appease JavaScript validation    def self.meters_to_kilometers(num)      return 0 unless num -    (num / 1000.0).to_i +    snap_to_one(num / 1000.0).to_i    end    def self.seconds_to_minutes(num)      return 0 unless num -    num / 60 +    snap_to_one(num / 60.0).to_i +  end + +  private + +  def self.snap_to_one(decimal) +    return 1 if decimal > 0 && decimal <= 1 + +    decimal    end  end diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 5b2c8ae3c..d025a9bf1 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -10,6 +10,7 @@ namespace :ci do    desc "Prepare CI build"    task :setup do +    cp "config/database.yml", "config/database.yml.orig"      cp "config/database/ci.yml", "config/database.yml"      puts "Use #{database_name} database"      sh "RAILS_ENV=test rake db:drop db:create db:migrate" @@ -28,6 +29,7 @@ namespace :ci do    end    def deploy_env +    return ENV["DEPLOY_ENV"] if ENV["DEPLOY_ENV"]      if git_branch == "master"        "dev"      elsif git_branch.in?(deploy_envs) @@ -54,12 +56,12 @@ namespace :ci do    desc "Deploy after CI"    task :deploy do -    return if ENV["CHOUETTE_DEPLOY_DISABLED"] - -    if deploy_env -      sh "cap #{deploy_env} deploy:migrations" -    else -      puts "No deploy for branch #{git_branch}" +    unless ENV["CHOUETTE_DEPLOY_DISABLED"] +      if deploy_env +        sh "cap #{deploy_env} deploy:migrations deploy:seed" +      else +        puts "No deploy for branch #{git_branch}" +      end      end    end @@ -75,6 +77,9 @@ namespace :ci do      task :clean do        puts "Drop #{database_name} database"        sh "RAILS_ENV=test rake db:drop" + +      # Restore projet config/database.yml +      cp "config/database.yml.orig", "config/database.yml" if File.exists?("config/database.yml.orig")      end    end diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index a001a942d..b7cb66b46 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -42,11 +42,14 @@ RSpec.describe RoutesController, type: :controller do      before(:each) do        post :create, line_id: route.line_id,            referential_id: referential.id, -          route: { name: "changed"} +          route: { name: "changed", published_name: "published_name"}      end      it_behaves_like "line and referential linked"      it_behaves_like "redirected to referential_line_path(referential,line)" +    it "sets metadata" do +      expect(Chouette::Route.last.metadata.creator_username).to eq @user.username +    end    end    describe "PUT /update" do @@ -58,6 +61,9 @@ RSpec.describe RoutesController, type: :controller do      it_behaves_like "route, line and referential linked"      it_behaves_like "redirected to referential_line_path(referential,line)" +    it "sets metadata" do +      expect(Chouette::Route.last.metadata.modifier_username).to eq @user.username +    end    end    describe "GET /show" do diff --git a/spec/lib/route_way_cost_unit_converter_spec.rb b/spec/lib/route_way_cost_unit_converter_spec.rb index 3c5e51710..aa25d57d2 100644 --- a/spec/lib/route_way_cost_unit_converter_spec.rb +++ b/spec/lib/route_way_cost_unit_converter_spec.rb @@ -35,4 +35,32 @@ RSpec.describe RouteWayCostUnitConverter do        })      end    end + +  describe ".meters_to_kilometers" do +    it "converts meters to integer kilometres" do +      expect( +        RouteWayCostUnitConverter.meters_to_kilometers(6350) +      ).to eq(6) +    end + +    it "snaps values between 0 and 1 to 1" do +      expect( +        RouteWayCostUnitConverter.meters_to_kilometers(50) +      ).to eq(1) +    end +  end + +  describe ".seconds_to_minutes" do +    it "converts seconds to minutes" do +      expect( +        RouteWayCostUnitConverter.seconds_to_minutes(300) +      ).to eq(5) +    end + +    it "snaps values between 0 and 1 to 1" do +      expect( +        RouteWayCostUnitConverter.seconds_to_minutes(3) +      ).to eq(1) +    end +  end  end diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index cc483a118..5c5a6bde1 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Api::V1::ApiKey, type: :model do    subject { create(:api_key) }    it { should validate_presence_of :organisation } -  it { is_expected.to be_versioned } +    it 'should have a valid factory' do      expect(build(:api_key)).to be_valid diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index 09ac0e416..e57eee3b2 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Calendar, :type => :model do    it { is_expected.to validate_presence_of(:organisation) }    it { is_expected.to validate_presence_of(:name) } -  it { is_expected.to be_versioned } +      describe '#to_time_table' do      let(:calendar) { create(:calendar, int_day_types: Calendar::MONDAY | Calendar::SUNDAY, date_ranges: [Date.today...(Date.today + 1.month)]) } diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb index ced99eb1d..448c22d33 100644 --- a/spec/models/chouette/access_link_spec.rb +++ b/spec/models/chouette/access_link_spec.rb @@ -4,7 +4,7 @@ describe Chouette::AccessLink, :type => :model do    subject { create(:access_link) }    it { is_expected.to validate_uniqueness_of :objectid } -  it { is_expected.to be_versioned } +       describe '#get_objectid' do      subject { super().get_objectid } diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb index 2184c6ec2..9c637cf41 100644 --- a/spec/models/chouette/access_point_spec.rb +++ b/spec/models/chouette/access_point_spec.rb @@ -12,7 +12,7 @@ describe Chouette::AccessPoint, :type => :model do    it { is_expected.to validate_presence_of :name }    it { is_expected.to validate_numericality_of :latitude }    it { is_expected.to validate_numericality_of :longitude } -  it { is_expected.to be_versioned } +      describe ".latitude" do      it "should accept -90 value" do diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index 34b19eeda..677c60dd9 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper'  describe Chouette::Company, :type => :model do    subject { create(:company) }    it { should validate_presence_of :name } -  it { is_expected.to be_versioned } +      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 4ab67d007..4486e348c 100644 --- a/spec/models/chouette/connection_link_spec.rb +++ b/spec/models/chouette/connection_link_spec.rb @@ -8,7 +8,7 @@ describe Chouette::ConnectionLink, :type => :model do    subject { create(:connection_link) }    it { is_expected.to validate_uniqueness_of :objectid } -  it { is_expected.to be_versioned } +      describe '#get_objectid' do      subject { super().get_objectid } diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index d43d75374..8b2df69e5 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -4,7 +4,7 @@ describe Chouette::GroupOfLine, :type => :model do    subject { create(:group_of_line) }    it { should validate_presence_of :name } -  it { is_expected.to be_versioned } +      describe "#stop_areas" do      let!(:line){create(:line, :group_of_lines => [subject])} diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index dac45d6b5..078e3c1f1 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -1,7 +1,7 @@  require 'spec_helper'  describe Chouette::JourneyPattern, :type => :model do -  it { is_expected.to be_versioned } +      subject { create(:journey_pattern) }    describe 'checksum' do diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb index 056d5da9e..cd7cdcb09 100644 --- a/spec/models/chouette/line_spec.rb +++ b/spec/models/chouette/line_spec.rb @@ -7,7 +7,7 @@ describe Chouette::Line, :type => :model do    # it { is_expected.to validate_presence_of :network }    # it { is_expected.to validate_presence_of :company }    it { should validate_presence_of :name } -  it { is_expected.to be_versioned } +      describe '#display_name' do      it 'should display local_id, number, name and company name' do diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index 78a4150df..11ad7cacb 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper'  describe Chouette::Network, :type => :model do    subject { create(:network) }    it { should validate_presence_of :name } -  it { is_expected.to be_versioned } +      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 d24ad6348..3d4a87791 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -15,8 +15,7 @@ RSpec.describe Chouette::Route, :type => :model do    #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(outbound inbound)) } -  it { is_expected.to be_versioned } - +      context "reordering methods" do      let(:bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}}      let(:ident){subject.stop_points.map(&:id)} diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index bda6bb04a..321b41b7b 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -8,7 +8,7 @@ describe Chouette::RoutingConstraintZone, type: :model do    it { is_expected.to validate_presence_of :route_id }    # shoulda matcher to validate length of array ?    xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } -  it { is_expected.to be_versioned } +      describe 'checksum' do      it_behaves_like 'checksum support' diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index e35300caf..185820388 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -13,7 +13,7 @@ describe Chouette::StopArea, :type => :model do    it { should validate_presence_of :kind }    it { should validate_numericality_of :latitude }    it { should validate_numericality_of :longitude } -  it { is_expected.to be_versioned } +      describe "#area_type" do      it "should validate the value is correct regarding to the kind" do diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index 6b9e7727f..ba3799619 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -4,7 +4,7 @@ describe Chouette::StopPoint, :type => :model do    it { is_expected.to validate_uniqueness_of :objectid }    it { is_expected.to validate_presence_of :stop_area } -  it { is_expected.to be_versioned } +      describe '#objectid' do      subject { super().get_objectid } diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index bb88877b9..a3354facb 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -6,7 +6,7 @@ describe Chouette::TimeTable, :type => :model do    it { is_expected.to validate_presence_of :comment }    it { is_expected.to validate_uniqueness_of :objectid } -  it { is_expected.to be_versioned } +        def create_time_table_periode time_table, start_date, end_date        create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date) diff --git a/spec/models/chouette/timeband_spec.rb b/spec/models/chouette/timeband_spec.rb index b960c203f..fa7c8f06e 100644 --- a/spec/models/chouette/timeband_spec.rb +++ b/spec/models/chouette/timeband_spec.rb @@ -1,7 +1,7 @@  require 'spec_helper'  describe Chouette::Timeband, :type => :model do -  it { is_expected.to be_versioned } +      describe '#create' do      context 'when valid' do diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 41ac5d7d0..6d44eeb2f 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper'  describe Chouette::VehicleJourney, :type => :model do    subject { create(:vehicle_journey) } -  it { is_expected.to be_versioned } +      it { should have_and_belong_to_many(:purchase_windows) }    it "must be valid with an at-stop day offset of 1" do diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 61421287a..b6f854829 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -12,7 +12,7 @@ RSpec.describe ComplianceCheckSet, type: :model do    it { should have_many :compliance_checks }    it { should have_many :compliance_check_blocks } -  it { is_expected.to be_versioned } +      describe "#update_status" do      it "updates :status to successful when all resources are OK" do diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index c157dcaf3..a66e7f030 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -10,5 +10,5 @@ RSpec.describe ComplianceControlSet, type: :model do    it { should have_many(:compliance_control_blocks).dependent(:destroy) }    it { should validate_presence_of :name } -  it { is_expected.to be_versioned } +    end diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb new file mode 100644 index 000000000..b407cd866 --- /dev/null +++ b/spec/models/route_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +RSpec.describe Chouette::Route, :type => :model do +  subject(:route){ create :route } +  context "metadatas" do +    it "should be empty at first" do +      expect(Chouette::Route.has_metadata?).to be_truthy +      expect(route.has_metadata?).to be_truthy +      expect(route.metadata.creator_username).to be_nil +      expect(route.metadata.modifier_username).to be_nil +    end + +    context "once set" do +      it "should set the correct values" do +        Timecop.freeze(Time.now) do +          route.metadata.creator_username = "john.doe" +          route.save! +          id = route.id +          route = Chouette::Route.find id +          expect(route.metadata.creator_username).to eq "john.doe" +          expect(route.metadata.creator_username_updated_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') +        end +      end +    end + +    describe "#merge_metadata_from" do +      let(:source){ create :route } +      let(:metadata){ target.merge_metadata_from(source).metadata } +      let(:target){ create :route } +      before do +        target.metadata.creator_username = "john" +        target.metadata.modifier_username = "john" +      end +      context "when the source has no metadata" do +        it "should do nothing" do +          expect(metadata.creator_username).to eq "john" +          expect(metadata.modifier_username).to eq "john" +        end +      end + +      context "when the source has older metadata" do +        before do +          source.metadata.creator_username = "jane" +          source.metadata.modifier_username = "jane" +          source.metadata.creator_username_updated_at = 1.month.ago +          source.metadata.modifier_username_updated_at = 1.month.ago +        end +        it "should do nothing" do +          expect(metadata.creator_username).to eq "john" +          expect(metadata.modifier_username).to eq "john" +        end +      end + +      context "when the source has new metadata" do +        before do +          source.metadata.creator_username = "jane" +          source.metadata.modifier_username = "jane" +          target.metadata.creator_username_updated_at = 1.month.ago +          target.metadata.modifier_username_updated_at = 1.month.ago +        end +        it "should update metadata" do +          expect(metadata.creator_username).to eq "jane" +          expect(metadata.modifier_username).to eq "jane" +        end +      end +    end +  end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cde252236..947efd602 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,7 +34,6 @@ require 'webmock/rspec'  require 'simplecov'  require 'sidekiq/testing'  Sidekiq::Testing.fake! -require 'paper_trail/frameworks/rspec'  # Requires supporting ruby files with custom matchers and macros, etc, in  # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are | 
