diff options
| author | cedricnjanga | 2017-11-24 12:32:09 +0100 | 
|---|---|---|
| committer | cedricnjanga | 2017-11-24 12:32:09 +0100 | 
| commit | 4ee768d80cc5374c84ed0b06a43eb4f4bda0f825 (patch) | |
| tree | deea0d202e15a781fba98a5949bd84e879cc533e | |
| parent | 5b9351272ec0f02c2c76fd8b3168cbbc6acdedff (diff) | |
| download | chouette-core-4ee768d80cc5374c84ed0b06a43eb4f4bda0f825.tar.bz2 | |
Take into account code review
60 files changed, 487 insertions, 872 deletions
| diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index a95f90128..9416c73ae 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -1,52 +1,52 @@ -  class CompanyDecorator < Draper::Decorator -    decorates Chouette::Company +class CompanyDecorator < Draper::Decorator +  decorates Chouette::Company -    delegate_all +  delegate_all -    def self.collection_decorator_class -      PaginatingDecorator -    end +  def self.collection_decorator_class +    PaginatingDecorator +  end + +  def linecount +    object.lines.count +  end -    def linecount -      object.lines.count +  # Requires: +  #   context: { +  #     referential: +  #   } +  def action_links +    links = [] + +    if h.policy(Chouette::Company).create? +      links << Link.new( +        content: h.t('companies.actions.new'), +        href: h.new_line_referential_company_path(context[:referential]) +      )      end -    # Requires: -    #   context: { -    #     referential: -    #   } -    def action_links -      links = [] - -      if h.policy(Chouette::Company).create? -        links << Link.new( -          content: h.t('companies.actions.new'), -          href: h.new_line_referential_company_path(context[:referential]) +    if h.policy(object).update? +      links << Link.new( +        content: h.t('companies.actions.edit'), +        href: h.edit_line_referential_company_path( +          context[:referential], +          object          ) -      end - -      if h.policy(object).update? -        links << Link.new( -          content: h.t('companies.actions.edit'), -          href: h.edit_line_referential_company_path( -            context[:referential], -            object -          ) -        ) -      end - -      if h.policy(object).destroy? -        links << Link.new( -          content: t('companies.actions.destroy'), -          href: h.line_referential_company_path( -            context[:referential], -            object -          ), -          method: :delete, -          data: { confirm: h.t('companies.actions.destroy_confirm') } -        ) -      end +      ) +    end -      links +    if h.policy(object).destroy? +      links << Link.new( +        content: t('companies.actions.destroy'), +        href: h.line_referential_company_path( +          context[:referential], +          object +        ), +        method: :delete, +        data: { confirm: h.t('companies.actions.destroy_confirm') } +      )      end + +    links    end +end diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index d465f9321..f351103b2 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -1,45 +1,45 @@ -  class LineDecorator < Draper::Decorator -    decorates Chouette::Line +class LineDecorator < Draper::Decorator +  decorates Chouette::Line -    delegate_all +  delegate_all -    # Requires: -    #   context: { -    #     line_referential: , -    #     current_organisation: -    #   } -    def action_links -      links = [] +  # Requires: +  #   context: { +  #     line_referential: , +  #     current_organisation: +  #   } +  def action_links +    links = [] +    links << Link.new( +      content: h.t('lines.actions.show_network'), +      href: [context[:line_referential], object.network] +    ) + +    links << Link.new( +      content: h.t('lines.actions.show_company'), +      href: [context[:line_referential], object.company] +    ) + +    if h.policy(Chouette::Line).create? && +        context[:line_referential].organisations.include?( +          context[:current_organisation] +        )        links << Link.new( -        content: h.t('lines.actions.show_network'), -        href: [context[:line_referential], object.network] +        content: h.t('lines.actions.new'), +        href: h.new_line_referential_line_path(context[:line_referential])        ) +    end +    if h.policy(object).destroy?        links << Link.new( -        content: h.t('lines.actions.show_company'), -        href: [context[:line_referential], object.company] +        content: h.destroy_link_content('lines.actions.destroy_confirm'), +        href: h.line_referential_line_path(context[:line_referential], object), +        method: :delete, +        data: { confirm: h.t('lines.actions.destroy_confirm') }        ) - -      if h.policy(Chouette::Line).create? && -          context[:line_referential].organisations.include?( -            context[:current_organisation] -          ) -        links << Link.new( -          content: h.t('lines.actions.new'), -          href: h.new_line_referential_line_path(context[:line_referential]) -        ) -      end - -      if h.policy(object).destroy? -        links << Link.new( -          content: h.destroy_link_content('lines.actions.destroy_confirm'), -          href: h.line_referential_line_path(context[:line_referential], object), -          method: :delete, -          data: { confirm: h.t('lines.actions.destroy_confirm') } -        ) -      end - -      links      end + +    links    end +end diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb index 4f22141e0..1f62fe512 100644 --- a/app/decorators/network_decorator.rb +++ b/app/decorators/network_decorator.rb @@ -1,44 +1,44 @@ -  class NetworkDecorator < Draper::Decorator -    decorates Chouette::Network +class NetworkDecorator < Draper::Decorator +  decorates Chouette::Network -    delegate_all +  delegate_all -    # Requires: -    #   context: { -    #     line_referential: , -    #   } -    def action_links -      links = [] +  # Requires: +  #   context: { +  #     line_referential: , +  #   } +  def action_links +    links = [] -      if h.policy(Chouette::Network).create? -        links << Link.new( -          content: h.t('networks.actions.new'), -          href: h.new_line_referential_network_path(context[:line_referential]) -        ) -      end - -      if h.policy(object).update? -        links << Link.new( -          content: h.t('networks.actions.edit'), -          href: h.edit_line_referential_network_path( -            context[:line_referential], -            object -          ) -        ) -      end +    if h.policy(Chouette::Network).create? +      links << Link.new( +        content: h.t('networks.actions.new'), +        href: h.new_line_referential_network_path(context[:line_referential]) +      ) +    end -      if h.policy(object).destroy? -        links << Link.new( -          content: h.destroy_link_content('networks.actions.destroy'), -          href: h.line_referential_network_path( -            context[:line_referential], -            object -          ), -          method: :delete, -          data: { confirm: t('networks.actions.destroy_confirm') } +    if h.policy(object).update? +      links << Link.new( +        content: h.t('networks.actions.edit'), +        href: h.edit_line_referential_network_path( +          context[:line_referential], +          object          ) -      end +      ) +    end -      links +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content('networks.actions.destroy'), +        href: h.line_referential_network_path( +          context[:line_referential], +          object +        ), +        method: :delete, +        data: { confirm: t('networks.actions.destroy_confirm') } +      )      end + +    links    end +end diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index ca35c2dde..510c941a3 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -1,75 +1,75 @@ -  class RouteDecorator < Draper::Decorator -    decorates Chouette::Route +class RouteDecorator < Draper::Decorator +  decorates Chouette::Route -    delegate_all +  delegate_all -    # Requires: -    #   context: { -    #     referential: , -    #     line: -    #   } -    def action_links -      links = [] +  # Requires: +  #   context: { +  #     referential: , +  #     line: +  #   } +  def action_links +    links = [] -      if object.stop_points.any? -        links << Link.new( -          content: h.t('journey_patterns.index.title'), -          href: [ -            context[:referential], -            context[:line], -            object, -            :journey_patterns_collection -          ] -        ) -      end - -      if object.journey_patterns.present? -        links << Link.new( -          content: h.t('vehicle_journeys.actions.index'), -          href: [ -            context[:referential], -            context[:line], -            object, -            :vehicle_journeys -          ] -        ) -      end +    if object.stop_points.any? +      links << Link.new( +        content: h.t('journey_patterns.index.title'), +        href: [ +          context[:referential], +          context[:line], +          object, +          :journey_patterns_collection +        ] +      ) +    end +    if object.journey_patterns.present?        links << Link.new( -        content: h.t('vehicle_journey_exports.new.title'), -        href: h.referential_line_route_vehicle_journey_exports_path( +        content: h.t('vehicle_journeys.actions.index'), +        href: [            context[:referential],            context[:line],            object, -          format: :zip -        ) +          :vehicle_journeys +        ]        ) +    end -      if h.policy(object).duplicate? -        links << Link.new( -          content: h.t('routes.duplicate.title'), -          href: h.duplicate_referential_line_route_path( -            context[:referential], -            context[:line], -            object -          ), -          method: :post -        ) -      end +    links << Link.new( +      content: h.t('vehicle_journey_exports.new.title'), +      href: h.referential_line_route_vehicle_journey_exports_path( +        context[:referential], +        context[:line], +        object, +        format: :zip +      ) +    ) -      if h.policy(object).destroy? -        links << Link.new( -          content: h.destroy_link_content, -          href: h.referential_line_route_path( -            context[:referential], -            context[:line], -            object -          ), -          method: :delete, -          data: { confirm: h.t('routes.actions.destroy_confirm') } -        ) -      end +    if h.policy(object).duplicate? +      links << Link.new( +        content: h.t('routes.duplicate.title'), +        href: h.duplicate_referential_line_route_path( +          context[:referential], +          context[:line], +          object +        ), +        method: :post +      ) +    end -      links +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content, +        href: h.referential_line_route_path( +          context[:referential], +          context[:line], +          object +        ), +        method: :delete, +        data: { confirm: h.t('routes.actions.destroy_confirm') } +      )      end + +    links    end +end diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb index 1d12cfc25..0b438a554 100644 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ b/app/decorators/routing_constraint_zone_decorator.rb @@ -1,42 +1,42 @@ -  class RoutingConstraintZoneDecorator < Draper::Decorator -    decorates Chouette::RoutingConstraintZone +class RoutingConstraintZoneDecorator < Draper::Decorator +  decorates Chouette::RoutingConstraintZone -    delegate_all +  delegate_all -    # Requires: -    #   context: { -    #     referential: , -    #     line: -    #   } -    def action_links -      links = [] +  # Requires: +  #   context: { +  #     referential: , +  #     line: +  #   } +  def action_links +    links = [] -      if h.policy(object).update? -        links << Link.new( -          content: h.t('actions.edit'), -          href: h.edit_referential_line_routing_constraint_zone_path( -            context[:referential], -            context[:line], -            object -          ) +    if h.policy(object).update? +      links << Link.new( +        content: h.t('actions.edit'), +        href: h.edit_referential_line_routing_constraint_zone_path( +          context[:referential], +          context[:line], +          object          ) -      end - -      if h.policy(object).destroy? -        links << Link.new( -          content: h.destroy_link_content, -          href: h.referential_line_routing_constraint_zone_path( -            context[:referential], -            context[:line], -            object -          ), -          method: :delete, -          data: { -            confirm: h.t('routing_constraint_zones.actions.destroy_confirm') -          } -        ) -      end +      ) +    end -      links +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content, +        href: h.referential_line_routing_constraint_zone_path( +          context[:referential], +          context[:line], +          object +        ), +        method: :delete, +        data: { +          confirm: h.t('routing_constraint_zones.actions.destroy_confirm') +        } +      )      end + +    links    end +end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index c64ecc9e3..4e777292d 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -1,43 +1,43 @@ -  class StopAreaDecorator < Draper::Decorator -    decorates Chouette::StopArea +class StopAreaDecorator < Draper::Decorator +  decorates Chouette::StopArea -    delegate_all +  delegate_all -    def action_links(stop_area = nil) -      links = [] -      stop_area ||= object +  def action_links(stop_area = nil) +    links = [] +    stop_area ||= object -      if h.policy(Chouette::StopArea).new? -        links << Link.new( -          content: h.t('stop_areas.actions.new'), -          href: h.new_stop_area_referential_stop_area_path( -            stop_area.stop_area_referential -          ) +    if h.policy(Chouette::StopArea).new? +      links << Link.new( +        content: h.t('stop_areas.actions.new'), +        href: h.new_stop_area_referential_stop_area_path( +          stop_area.stop_area_referential          ) -      end - -      if h.policy(stop_area).update? -        links << Link.new( -          content: h.t('stop_areas.actions.edit'), -          href: h.edit_stop_area_referential_stop_area_path( -            stop_area.stop_area_referential, -            stop_area -          ) -        ) -      end +      ) +    end -      if h.policy(stop_area).destroy? -        links << Link.new( -          content: h.destroy_link_content('stop_areas.actions.destroy'), -          href: h.stop_area_referential_stop_area_path( -            stop_area.stop_area_referential, -            stop_area -          ), -          method: :delete, -          data: { confirm: t('stop_areas.actions.destroy_confirm') } +    if h.policy(stop_area).update? +      links << Link.new( +        content: h.t('stop_areas.actions.edit'), +        href: h.edit_stop_area_referential_stop_area_path( +          stop_area.stop_area_referential, +          stop_area          ) -      end +      ) +    end -      links +    if h.policy(stop_area).destroy? +      links << Link.new( +        content: h.destroy_link_content('stop_areas.actions.destroy'), +        href: h.stop_area_referential_stop_area_path( +          stop_area.stop_area_referential, +          stop_area +        ), +        method: :delete, +        data: { confirm: t('stop_areas.actions.destroy_confirm') } +      )      end + +    links    end +end diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb index f87db73e8..196d6d490 100644 --- a/app/decorators/stop_point_decorator.rb +++ b/app/decorators/stop_point_decorator.rb @@ -1,9 +1,9 @@ -  class StopPointDecorator < StopAreaDecorator -    decorates Chouette::StopPoint +class StopPointDecorator < StopAreaDecorator +  decorates Chouette::StopPoint -    delegate_all +  delegate_all -    def action_links -      super(object.stop_area) -    end +  def action_links +    super(object.stop_area)    end +end diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index e2a5a7a97..c6eeac176 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -1,55 +1,55 @@ -  class TimeTableDecorator < Draper::Decorator -    decorates Chouette::TimeTable +class TimeTableDecorator < Draper::Decorator +  decorates Chouette::TimeTable -    delegate_all +  delegate_all -    # Requires: -    #   context: { -    #     referential: , -    #   } -    def action_links -      links = [] +  # Requires: +  #   context: { +  #     referential: , +  #   } +  def action_links +    links = [] -      if object.calendar -        links << Link.new( -          content: h.t('actions.actualize'), -          href: h.actualize_referential_time_table_path( -            context[:referential], -            object -          ), -          method: :post -        ) -      end - -      if h.policy(object).edit? -        links << Link.new( -          content: h.t('actions.combine'), -          href: h.new_referential_time_table_time_table_combination_path( -            context[:referential], -            object -          ) -        ) -      end +    if object.calendar +      links << Link.new( +        content: h.t('actions.actualize'), +        href: h.actualize_referential_time_table_path( +          context[:referential], +          object +        ), +        method: :post +      ) +    end -      if h.policy(object).duplicate? -        links << Link.new( -          content: h.t('actions.duplicate'), -          href: h.duplicate_referential_time_table_path( -            context[:referential], -            object -          ) +    if h.policy(object).edit? +      links << Link.new( +        content: h.t('actions.combine'), +        href: h.new_referential_time_table_time_table_combination_path( +          context[:referential], +          object          ) -      end +      ) +    end -      if h.policy(object).destroy? -        links << Link.new( -          content: h.destroy_link_content, -          href: h.referential_time_table_path(context[:referential], object), -          method: :delete, -          data: { confirm: h.t('time_tables.actions.destroy_confirm') } +    if h.policy(object).duplicate? +      links << Link.new( +        content: h.t('actions.duplicate'), +        href: h.duplicate_referential_time_table_path( +          context[:referential], +          object          ) -      end +      ) +    end -      links +    if h.policy(object).destroy? +      links << Link.new( +        content: h.destroy_link_content, +        href: h.referential_time_table_path(context[:referential], object), +        method: :delete, +        data: { confirm: h.t('time_tables.actions.destroy_confirm') } +      )      end + +    links    end +end diff --git a/app/models/chouette.rb b/app/models/chouette.rb deleted file mode 100644 index fe49300d4..000000000 --- a/app/models/chouette.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Chouette -  def self.use_relative_model_naming? -    true -  end -end
\ No newline at end of file diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index a06bf5d91..d79e5ff59 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -8,7 +8,6 @@ module Chouette      validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true      validates_presence_of :name -    validates_presence_of :objectid_format      validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true      def self.nullable_attributes diff --git a/app/models/chouette/journey_pattern_section.rb b/app/models/chouette/journey_pattern_section.rb deleted file mode 100644 index 226a50c27..000000000 --- a/app/models/chouette/journey_pattern_section.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Chouette -  class JourneyPatternSection < Chouette::ActiveRecord -    belongs_to :journey_pattern -    belongs_to :route_section - -    validates :journey_pattern_id, presence: true -    validates :route_section_id, presence: true -    validates :rank, presence: true, numericality: :only_integer -    validates :journey_pattern_id, uniqueness: { scope: [:route_section_id, :rank] } - -    default_scope { order(:rank) } - -    def self.update_by_journey_pattern_rank(journey_pattern_id, route_section_id, rank) -      jps = self.find_or_initialize_by(journey_pattern_id: journey_pattern_id, rank: rank) -      if route_section_id.present? -        jps.update_attributes(route_section_id: route_section_id) -      else -        jps.destroy -      end -    end -  end -end
\ No newline at end of file diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index c51de3984..3f07ebe0c 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -12,7 +12,6 @@ module Chouette      validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true      validates_presence_of :name -    validates_presence_of :objectid_format      def self.object_id_key        "PTNetwork" diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb index 80208af56..5bff21dbf 100644 --- a/app/models/chouette/objectid/stif_netex.rb +++ b/app/models/chouette/objectid/stif_netex.rb @@ -8,7 +8,7 @@ module Chouette        end        def short_id -        local_id.try(:split, "-").try(:[], -1) +        local_id.try(:split, "-").try(:last)        end      end    end diff --git a/app/models/chouette/objectid_formatter/netex.rb b/app/models/chouette/objectid_formatter/netex.rb index 7279fdaa5..b8a903757 100644 --- a/app/models/chouette/objectid_formatter/netex.rb +++ b/app/models/chouette/objectid_formatter/netex.rb @@ -2,7 +2,7 @@ module Chouette    module ObjectidFormatter      class Netex        def before_validation(model) -        model.update_attributes(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub(/Chouette::/,'')).to_s) unless model.read_attribute(:objectid) +        model.update(objectid: Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::','')).to_s)        end        def after_commit(model) @@ -11,7 +11,7 @@ module Chouette        def get_objectid(definition)          parts = definition.try(:split, ":") -        Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil +        Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3])        end      end    end diff --git a/app/models/chouette/objectid_formatter/stif_codifligne.rb b/app/models/chouette/objectid_formatter/stif_codifligne.rb index aaa07ed6f..eafd2a090 100644 --- a/app/models/chouette/objectid_formatter/stif_codifligne.rb +++ b/app/models/chouette/objectid_formatter/stif_codifligne.rb @@ -11,7 +11,7 @@ module Chouette        def get_objectid(definition)          parts = definition.try(:split, ":") -        Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3]) rescue nil +        Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3])        end      end    end diff --git a/app/models/chouette/objectid_formatter/stif_netex.rb b/app/models/chouette/objectid_formatter/stif_netex.rb index 57d126983..4678cb337 100644 --- a/app/models/chouette/objectid_formatter/stif_netex.rb +++ b/app/models/chouette/objectid_formatter/stif_netex.rb @@ -2,16 +2,16 @@ module Chouette    module ObjectidFormatter      class StifNetex        def before_validation(model) -        model.attributes = {objectid: "__pending_id__#{SecureRandom.uuid}"} unless model.read_attribute(:objectid) +        model.attributes = {objectid: "__pending_id__#{SecureRandom.uuid}"}        end        def after_commit(model) -        model.update_attributes(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub(/Chouette::/,''), local_id: model.local_id).to_s) +        model.update(objectid: Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id).to_s)        end        def get_objectid(definition)          parts = definition.try(:split, ":") -        Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) rescue nil +        Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3])        end      end    end diff --git a/app/models/chouette/objectid_formatter/stif_reflex.rb b/app/models/chouette/objectid_formatter/stif_reflex.rb index e7e9f5611..5bfb21ecd 100644 --- a/app/models/chouette/objectid_formatter/stif_reflex.rb +++ b/app/models/chouette/objectid_formatter/stif_reflex.rb @@ -11,7 +11,7 @@ module Chouette        def get_objectid(definition)          parts = definition.try(:split, ":") -        Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4]) rescue nil +        Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4])        end      end    end diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index d8e6533c4..1f4088aa7 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -183,12 +183,6 @@ module Chouette        return true      end -    def journey_patterns_control_route_sections -      self.journey_patterns.each do |jp| -        jp.control_route_sections -      end -    end -      protected      def self.vehicle_journeys_timeless(stop_point_id) diff --git a/app/models/chouette/route_section.rb b/app/models/chouette/route_section.rb deleted file mode 100644 index e4b4347e7..000000000 --- a/app/models/chouette/route_section.rb +++ /dev/null @@ -1,83 +0,0 @@ -module Chouette -  class RouteSection < Chouette::TridentActiveRecord -    belongs_to :departure, class_name: 'Chouette::StopArea' -    belongs_to :arrival, class_name: 'Chouette::StopArea' -    has_many :journey_pattern_sections -    has_many :journey_patterns, through: :journey_pattern_sections, dependent: :destroy - -    validates :departure, :arrival, :processed_geometry, presence: true - -    scope :by_endpoint_name, ->(endpoint, name) do -      joins("INNER JOIN stop_areas #{endpoint} ON #{endpoint}.id = route_sections.#{endpoint}_id").where(["#{endpoint}.name ilike ?", "%#{name}%"]) -    end -    scope :by_line_id, ->(line_id) do -      joins(:journey_pattern_sections, :journey_patterns).joins('INNER JOIN routes ON journey_patterns.route_id = routes.id').where("routes.line_id = #{line_id}") -    end - -    def stop_areas -      [departure, arrival].compact -    end - -    def default_geometry -      points = stop_areas.collect(&:geometry).compact -      GeoRuby::SimpleFeatures::LineString.from_points(points) if points.many? -    end - -    def name -      stop_areas.map do |stop_area| -        stop_area.try(:name) or '?' -      end.join(' - ') + " (#{geometry_description})" -    end - -    def via_count -      input_geometry ? [ input_geometry.points.count - 2, 0 ].max : 0 -    end - -    def geometry_description -      if input_geometry || processed_geometry -        [ "#{distance.to_i}m" ].tap do |parts| -          parts << "#{via_count} #{'via'.pluralize(via_count)}" if via_count > 0 -        end.join(' - ') -      else -        "-" -      end -    end - -    DEFAULT_PROCESSOR = Proc.new { |section| section.input_geometry || section.default_geometry.try(:to_rgeo) } - -    @@processor = DEFAULT_PROCESSOR -    cattr_accessor :processor - -    def instance_processor -      no_processing || processor.nil? ? DEFAULT_PROCESSOR : processor -    end - -    def process_geometry -      if input_geometry_changed? || processed_geometry.nil? -        self.processed_geometry = instance_processor.call(self) -        self.distance = processed_geometry.to_georuby.to_wgs84.spherical_distance if processed_geometry -      end - -      true -    end -    before_validation :process_geometry - -    def editable_geometry=(geometry) -      self.input_geometry = geometry -    end - -    def editable_geometry -      input_geometry.try(:to_georuby) or default_geometry -    end - -    def editable_geometry_before_type_cast -      editable_geometry.to_ewkt -    end - -    def geometry(mode = nil) -      mode ||= :processed -      mode == :editable ? editable_geometry : processed_geometry.to_georuby -    end - -  end -end
\ No newline at end of file diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index d4ba8b94b..70b016a48 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -6,7 +6,7 @@ module Chouette      belongs_to :route      has_array_of :stop_points, class_name: 'Chouette::StopPoint' -    validates_presence_of :name, :stop_points, :route, :objectid_format +    validates_presence_of :name, :stop_points, :route      # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }      validate :stop_points_belong_to_route, :not_all_stop_points_selected diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index d96381ee8..5d8b5033f 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -3,11 +3,6 @@ require 'geo_ruby'  module Chouette    class StopArea < Chouette::ActiveRecord -    # FIXME http://jira.codehaus.org/browse/JRUBY-6358 -    self.primary_key = "id" - -    include Geokit::Mappable -    # include StifReflexAttributesSupport      include ProjectionFields      include StopAreaRestrictions      include StopAreaReferentialSupport @@ -25,8 +20,6 @@ module Chouette      has_and_belongs_to_many :routing_lines, :class_name => 'Chouette::Line', :foreign_key => "stop_area_id", :association_foreign_key => "line_id", :join_table => "routing_constraints_lines", :order => "lines.number"      has_and_belongs_to_many :routing_stops, :class_name => 'Chouette::StopArea', :foreign_key => "parent_id", :association_foreign_key => "child_id", :join_table => "stop_areas_stop_areas", :order => "stop_areas.name" -    belongs_to :stop_area_referential -      acts_as_tree :foreign_key => 'parent_id', :order => "name"      attr_accessor :stop_area_type diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 172b73101..09d3e2244 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -53,7 +53,6 @@ module Chouette      accepts_nested_attributes_for :periods, :allow_destroy => :true      validates_presence_of :comment -    validates_presence_of :objectid_format      validates_associated :dates      validates_associated :periods diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb index ec3ad43b9..21c81ab1c 100644 --- a/app/models/chouette/timeband.rb +++ b/app/models/chouette/timeband.rb @@ -15,9 +15,6 @@ module Chouette      validates :start_time, :end_time, presence: true      validates_with Chouette::TimebandValidator -    validates :start_time, :end_time, presence: true -    validates_with Chouette::TimebandValidator -      default_scope { order(:start_time) }      def self.object_id_key diff --git a/app/models/concerns/line_referential_support.rb b/app/models/concerns/line_referential_support.rb index 406730ddb..5eade3557 100644 --- a/app/models/concerns/line_referential_support.rb +++ b/app/models/concerns/line_referential_support.rb @@ -3,6 +3,7 @@ module LineReferentialSupport    included do      belongs_to :line_referential +    validates_presence_of :line_referential      alias_method :referential, :line_referential    end diff --git a/app/models/concerns/netex_attributes_support.rb b/app/models/concerns/netex_attributes_support.rb deleted file mode 100644 index d78528dbf..000000000 --- a/app/models/concerns/netex_attributes_support.rb +++ /dev/null @@ -1,72 +0,0 @@ -module NetexAttributesSupport -  extend ActiveSupport::Concern - -  included do -    before_validation :prepare_auto_columns - -    validates_presence_of :objectid -    validates_uniqueness_of :objectid -    validates_numericality_of :object_version -    validate :objectid_format_compliance - -    before_validation :default_values, :on => :create -  end - -  module ClassMethods -    def object_id_key -      model_name -    end - -    def model_name -      ActiveModel::Name.new self, Chouette, self.name.demodulize -    end -  end - -  def objectid -    Chouette::NetexObjectId.new read_attribute(:objectid) -  end - -  def prepare_auto_columns -    if object_version.nil? -      self.object_version = 1 -    else -      self.object_version += 1 -    end -    self.creator_id = 'chouette' -  end - -  def fix_uniq_objectid -    base_objectid = objectid.rpartition(":").first -    self.objectid = "#{base_objectid}:#{id}" -    if !valid? -      base_objectid="#{objectid}_" -      cnt=1 -      while !valid? -        self.objectid = "#{base_objectid}#{cnt}" -        cnt += 1 -      end -    end - -  end - -  def objectid_format_compliance -    if !objectid.valid? -      errors.add :objectid, I18n.t("activerecord.errors.models.trident.invalid_object_id", type: self.class.object_id_key) -    end -  end - -  def uniq_objectid -    # OPTIMIZEME -    i = 0 -    baseobjectid = objectid -    while self.class.exists?(:objectid => objectid) -      i += 1 -      self.objectid = baseobjectid+"_"+i.to_s -    end -  end - -  def default_values -    self.object_version ||= 1 -  end - -end diff --git a/app/models/concerns/objectid_formatter_support.rb b/app/models/concerns/objectid_formatter_support.rb index 2138ac89e..34a51740f 100644 --- a/app/models/concerns/objectid_formatter_support.rb +++ b/app/models/concerns/objectid_formatter_support.rb @@ -2,13 +2,15 @@ module ObjectidFormatterSupport    extend ActiveSupport::Concern    included do -    validates_presence_of :objectid_formater_class +    extend Enumerize +    enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex' +    validates_presence_of :objectid_format -    def objectid_formater -      objectid_formater_class.new +    def objectid_formatter +      objectid_formatter_class.new      end -    def objectid_formater_class +    def objectid_formatter_class        "Chouette::ObjectidFormatter::#{read_attribute(:objectid_format).camelcase}".constantize if read_attribute(:objectid_format)      end    end diff --git a/app/models/concerns/objectid_support.rb b/app/models/concerns/objectid_support.rb index 6822912f1..85b5da3a8 100644 --- a/app/models/concerns/objectid_support.rb +++ b/app/models/concerns/objectid_support.rb @@ -2,21 +2,21 @@ module ObjectidSupport    extend ActiveSupport::Concern    included do -    before_validation :before_validation_objectid +    before_validation :before_validation_objectid, unless: Proc.new {|model| model.read_attribute(:objectid)}      after_commit :after_commit_objectid, on: :create, if: Proc.new {|model| model.read_attribute(:objectid).try(:include?, '__pending_id__')} -    validates_presence_of :objectid_format, :objectid +    validates_presence_of :objectid      validates_uniqueness_of :objectid, skip_validation: Proc.new {|model| model.read_attribute(:objectid).nil?}      def before_validation_objectid -      self.referential.objectid_formater.before_validation self +      self.referential.objectid_formatter.before_validation self      end      def after_commit_objectid -      self.referential.objectid_formater.after_commit self +      self.referential.objectid_formatter.after_commit self      end      def get_objectid -      self.referential.objectid_formater.get_objectid read_attribute(:objectid) if objectid_format && read_attribute(:objectid) +      self.referential.objectid_formatter.get_objectid read_attribute(:objectid) if self.referential.objectid_format && read_attribute(:objectid)      end      def objectid @@ -26,9 +26,5 @@ module ObjectidSupport      def objectid_class        get_objectid.try(:class)      end - -    def objectid_format -      self.referential.objectid_format -    end    end  end
\ No newline at end of file diff --git a/app/models/concerns/stif_codifligne_attributes_support.rb b/app/models/concerns/stif_codifligne_attributes_support.rb deleted file mode 100644 index 0cd2cccc4..000000000 --- a/app/models/concerns/stif_codifligne_attributes_support.rb +++ /dev/null @@ -1,21 +0,0 @@ -module StifCodifligneAttributesSupport -  extend ActiveSupport::Concern - -  included do -    validates_presence_of :objectid -  end - -  module ClassMethods -    def object_id_key -      model_name -    end - -    def model_name -      ActiveModel::Name.new self, Chouette, self.name.demodulize -    end -  end - -  def objectid -    Chouette::StifCodifligneObjectid.new read_attribute(:objectid) -  end -end diff --git a/app/models/concerns/stif_netex_attributes_support.rb b/app/models/concerns/stif_netex_attributes_support.rb deleted file mode 100644 index 076acf491..000000000 --- a/app/models/concerns/stif_netex_attributes_support.rb +++ /dev/null @@ -1,58 +0,0 @@ -module StifNetexAttributesSupport -  extend ActiveSupport::Concern - -  included do -    validates_numericality_of :object_version -    validates :objectid, uniqueness: true, presence: true -    validate :objectid_format_compliance - -    after_save :build_objectid -    before_validation :default_values, on: :create -  end - -  module ClassMethods -    def object_id_key -      model_name -    end - -    def model_name -      ActiveModel::Name.new self, Chouette, self.name.demodulize -    end -  end - -  def objectid_format_compliance -    errors.add :objectid, I18n.t("activerecord.errors.models.trident.invalid_object_id") if !objectid.valid? -  end - -  def local_id -    "IBOO-#{self.referential.id}-#{self.id}" -  end - -  def build_objectid -    if objectid.include? ':__pending_id__' -      self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, self.local_id, self.boiv_id) -      self.save -    end -  end - -  def default_values -    self.object_version ||= 1 - -    if self.objectid.to_s.empty? -      local_id = "__pending_id__#{rand(50)+ rand(50)}" -      self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, local_id, self.boiv_id) -    end -  end - -  def objectid -    Chouette::StifNetexObjectid.new read_attribute(:objectid) -  end - -  def provider_id -    self.referential.workbench.organisation.code.underscore.parameterize -  end - -  def boiv_id -    'LOC' -  end -end diff --git a/app/models/concerns/stif_reflex_attributes_support.rb b/app/models/concerns/stif_reflex_attributes_support.rb deleted file mode 100644 index 9dfd21f94..000000000 --- a/app/models/concerns/stif_reflex_attributes_support.rb +++ /dev/null @@ -1,21 +0,0 @@ -module StifReflexAttributesSupport -  extend ActiveSupport::Concern - -  included do -    validates_presence_of :objectid -  end - -  module ClassMethods -    def object_id_key -      model_name -    end - -    def model_name -      ActiveModel::Name.new self, Chouette, self.name.demodulize -    end -  end - -  def objectid -    Chouette::StifReflexObjectid.new read_attribute(:objectid) -  end -end diff --git a/app/models/concerns/stop_area_referential_support.rb b/app/models/concerns/stop_area_referential_support.rb index aa59cbd35..f29397b3a 100644 --- a/app/models/concerns/stop_area_referential_support.rb +++ b/app/models/concerns/stop_area_referential_support.rb @@ -3,6 +3,7 @@ module StopAreaReferentialSupport    included do      belongs_to :stop_area_referential +    validates_presence_of :stop_area_referential      alias_method :referential, :stop_area_referential    end diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index d8cf74bda..15b2f6276 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -1,7 +1,6 @@  class LineReferential < ActiveRecord::Base    include ObjectidFormatterSupport    extend StifTransportModeEnumerations -  extend Enumerize    has_many :line_referential_memberships    has_many :organisations, through: :line_referential_memberships @@ -11,7 +10,6 @@ class LineReferential < ActiveRecord::Base    has_many :networks, class_name: 'Chouette::Network'    has_many :line_referential_syncs, -> { order created_at: :desc }    has_many :workbenches -  enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex'    def add_member(organisation, options = {})      attributes = options.merge organisation: organisation @@ -22,7 +20,6 @@ class LineReferential < ActiveRecord::Base    validates :sync_interval, presence: true    # need to define precise validation rules    validates_inclusion_of :sync_interval, :in => 1..30 -  validates_presence_of :objectid_format    def operating_lines      lines.where(deactivated: false) diff --git a/app/models/referential.rb b/app/models/referential.rb index fa6bcbcf1..ee74bd9f5 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,12 +1,10 @@  class Referential < ActiveRecord::Base    include DataFormatEnumerations    include ObjectidFormatterSupport -  extend Enumerize    validates_presence_of :name    validates_presence_of :slug    validates_presence_of :prefix -  validates_presence_of :objectid_format    # Fixme #3657    # validates_presence_of :time_zone    # validates_presence_of :upper_corner @@ -56,7 +54,6 @@ class Referential < ActiveRecord::Base    belongs_to :referential_suite -  enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex'    scope :ready, -> { where(ready: true) }    scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) } diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 159ee07b3..54e895cd0 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -1,5 +1,4 @@  class StopAreaReferential < ActiveRecord::Base -  extend Enumerize    include ObjectidFormatterSupport    has_many :stop_area_referential_memberships    has_many :organisations, through: :stop_area_referential_memberships @@ -7,8 +6,6 @@ class StopAreaReferential < ActiveRecord::Base    has_many :stop_areas, class_name: 'Chouette::StopArea'    has_many :stop_area_referential_syncs, -> {order created_at: :desc}    has_many :workbenches -  enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex' -  validates_presence_of :objectid_format    def add_member(organisation, options = {})      attributes = options.merge organisation: organisation diff --git a/app/models/workbench.rb b/app/models/workbench.rb index 95e4d1b68..e36589210 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,11 +1,9 @@  class Workbench < ActiveRecord::Base    include ObjectidFormatterSupport -  extend Enumerize    belongs_to :organisation    belongs_to :line_referential    belongs_to :stop_area_referential    belongs_to :output, class_name: 'ReferentialSuite' -  enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex'    has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential    has_many :networks, through: :line_referential @@ -20,7 +18,6 @@ class Workbench < ActiveRecord::Base    validates :name, presence: true    validates :organisation, presence: true    validates :output, presence: true -  validates_presence_of :objectid_format    has_many :referentials    has_many :referential_metadatas, through: :referentials, source: :metadatas diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb index 2b974ee71..1f1147f60 100644 --- a/app/policies/access_link_policy.rb +++ b/app/policies/access_link_policy.rb @@ -1,19 +1,19 @@ -  class AccessLinkPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class AccessLinkPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('access_links.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('access_links.create') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('access_links.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('access_links.update') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('access_links.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('access_links.destroy')    end +end diff --git a/app/policies/access_point_policy.rb b/app/policies/access_point_policy.rb index 368cf14e7..41436e77c 100644 --- a/app/policies/access_point_policy.rb +++ b/app/policies/access_point_policy.rb @@ -1,19 +1,19 @@ -  class AccessPointPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class AccessPointPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('access_points.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('access_points.create') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('access_points.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('access_points.update') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('access_points.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('access_points.destroy')    end +end diff --git a/app/policies/company_policy.rb b/app/policies/company_policy.rb index d29836e07..45386aba4 100644 --- a/app/policies/company_policy.rb +++ b/app/policies/company_policy.rb @@ -1,7 +1,7 @@ -  class CompanyPolicy < ApplicationPolicy -      class Scope < Scope -        def resolve -          scope -        end +class CompanyPolicy < ApplicationPolicy +    class Scope < Scope +      def resolve +        scope        end      end +  end diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb index 7cf0b7131..240c2a804 100644 --- a/app/policies/connection_link_policy.rb +++ b/app/policies/connection_link_policy.rb @@ -1,19 +1,19 @@ -  class ConnectionLinkPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class ConnectionLinkPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('connection_links.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('connection_links.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('connection_links.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('connection_links.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('connection_links.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('connection_links.update')    end +end diff --git a/app/policies/group_of_line_policy.rb b/app/policies/group_of_line_policy.rb index 60c60184c..03e94449d 100644 --- a/app/policies/group_of_line_policy.rb +++ b/app/policies/group_of_line_policy.rb @@ -1,7 +1,7 @@ -  class GroupOfLinePolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class GroupOfLinePolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end    end +end diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb index c0c9218c2..12bcced17 100644 --- a/app/policies/journey_pattern_policy.rb +++ b/app/policies/journey_pattern_policy.rb @@ -1,20 +1,20 @@ -  class JourneyPatternPolicy < ApplicationPolicy +class JourneyPatternPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('journey_patterns.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('journey_patterns.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('journey_patterns.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('journey_patterns.update')    end +end diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb index 559f4e2f8..acb0d79e7 100644 --- a/app/policies/line_policy.rb +++ b/app/policies/line_policy.rb @@ -1,23 +1,23 @@ -  class LinePolicy < ApplicationPolicy +class LinePolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end -    end - -    def create_footnote? -      !archived? && organisation_match? && user.has_permission?('footnotes.create') +  class Scope < Scope +    def resolve +      scope      end +  end -    def edit_footnote? -      !archived? && organisation_match? && user.has_permission?('footnotes.update') -    end +  def create_footnote? +    !archived? && organisation_match? && user.has_permission?('footnotes.create') +  end -    def destroy_footnote? -      !archived? && organisation_match? && user.has_permission?('footnotes.destroy') -    end +  def edit_footnote? +    !archived? && organisation_match? && user.has_permission?('footnotes.update') +  end -    def update_footnote?  ; edit_footnote? end -    def new_footnote?     ; create_footnote? end +  def destroy_footnote? +    !archived? && organisation_match? && user.has_permission?('footnotes.destroy')    end + +  def update_footnote?  ; edit_footnote? end +  def new_footnote?     ; create_footnote? end +end diff --git a/app/policies/network_policy.rb b/app/policies/network_policy.rb index 75105b7f8..9f86451a5 100644 --- a/app/policies/network_policy.rb +++ b/app/policies/network_policy.rb @@ -1,7 +1,7 @@ -  class NetworkPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class NetworkPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end    end +end diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb index b49f7bca7..7e9fe251a 100644 --- a/app/policies/route_policy.rb +++ b/app/policies/route_policy.rb @@ -1,23 +1,23 @@ -  class RoutePolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class RoutePolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('routes.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('routes.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('routes.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('routes.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('routes.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('routes.update') +  end -    def duplicate? -      create? -    end +  def duplicate? +    create?    end +end diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb index 6bdc69d5c..3cfcf46ff 100644 --- a/app/policies/routing_constraint_zone_policy.rb +++ b/app/policies/routing_constraint_zone_policy.rb @@ -1,19 +1,19 @@ -  class RoutingConstraintZonePolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class RoutingConstraintZonePolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update')    end +end diff --git a/app/policies/stop_area_policy.rb b/app/policies/stop_area_policy.rb index eaf4efe60..de8ecda8d 100644 --- a/app/policies/stop_area_policy.rb +++ b/app/policies/stop_area_policy.rb @@ -1,7 +1,7 @@ -  class StopAreaPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class StopAreaPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end    end +end diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb index 4638eabd8..92d3aef3e 100644 --- a/app/policies/time_table_policy.rb +++ b/app/policies/time_table_policy.rb @@ -1,32 +1,32 @@ -  class TimeTablePolicy < ApplicationPolicy +class TimeTablePolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('time_tables.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('time_tables.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('time_tables.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('time_tables.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('time_tables.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('time_tables.update') +  end -    def actualize? -      !archived? && organisation_match? && edit? -    end +  def actualize? +    !archived? && organisation_match? && edit? +  end -    def duplicate? -      !archived? && organisation_match? && create? -    end +  def duplicate? +    !archived? && organisation_match? && create? +  end -    def month? -      update? -    end +  def month? +    update?    end +end diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb index 1aa7a812e..24040455f 100644 --- a/app/policies/vehicle_journey_policy.rb +++ b/app/policies/vehicle_journey_policy.rb @@ -1,19 +1,19 @@ -  class VehicleJourneyPolicy < ApplicationPolicy -    class Scope < Scope -      def resolve -        scope -      end +class VehicleJourneyPolicy < ApplicationPolicy +  class Scope < Scope +    def resolve +      scope      end +  end -    def create? -      !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') -    end +  def create? +    !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create') +  end -    def destroy? -      !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') -    end +  def destroy? +    !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy') +  end -    def update? -      !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update') -    end +  def update? +    !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update')    end +end diff --git a/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb b/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb index bd498a0ff..c85a63b6e 100644 --- a/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb +++ b/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb @@ -1,8 +1,14 @@  class UpdateObjectidFormatValueToReferentials < ActiveRecord::Migration -  def change +  # Migration in the context of the STIF +  # Not a definitive choice since it cannot be used for Chouette +  def up      Workbench.update_all(objectid_format: 'stif_netex')      Referential.update_all(objectid_format: 'stif_netex')      LineReferential.update_all(objectid_format: 'stif_codifligne')      StopAreaReferential.update_all(objectid_format: 'stif_reflex')    end + +  def down +    raise ActiveRecord::IrreversibleMigration +  end  end diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index 067501c85..a3101d79c 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -4,12 +4,6 @@ describe Chouette::Company, :type => :model do    subject { create(:company) }    it { should validate_presence_of :name } -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    describe "#nullables empty" do      it "should set null empty nullable attributes" do        subject.organizational_unit = '' diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index d631511a3..047022ade 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -30,12 +30,6 @@ describe Chouette::JourneyPattern, :type => :model do    #   end    # end -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    describe "state_update" do      def journey_pattern_to_state jp        jp.attributes.slice('name', 'published_name', 'registration_number').tap do |item| diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb index eee672574..bc7b6e0c7 100644 --- a/spec/models/chouette/line_spec.rb +++ b/spec/models/chouette/line_spec.rb @@ -15,17 +15,6 @@ describe Chouette::Line, :type => :model do      end    end -  describe '#objectid' do -    subject { super().get_objectid } -    it { is_expected.to be_kind_of(Chouette::Objectid::StifCodifligne) } -  end - -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    # it { should validate_numericality_of :objectversion }    # describe ".last_stop_areas_parents" do diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index 75fc17587..32bacc512 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -3,12 +3,6 @@ require 'spec_helper'  describe Chouette::Network, :type => :model do    subject { create(:network) }    it { should validate_presence_of :name } -   -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end    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 ff86eefb6..79daeb6c2 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -5,17 +5,6 @@ RSpec.describe Chouette::Route, :type => :model do      it_behaves_like 'checksum support', :route    end -  describe '#objectid' do -    subject { super().get_objectid } -    it { is_expected.to be_kind_of(Chouette::Objectid::StifNetex) } -  end - -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) }    it { is_expected.to enumerize(:wayback).in(:outbound, :inbound) } diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index 32c3410a4..c344642e6 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -8,12 +8,6 @@ describe Chouette::RoutingConstraintZone, type: :model do    # shoulda matcher to validate length of array ?    xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    describe 'checksum' do      it_behaves_like 'checksum support', :routing_constraint_zone    end diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index 92fff4726..1e0b4af84 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -7,17 +7,6 @@ describe Chouette::StopArea, :type => :model do    let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" }    let!(:stop_place) { create :stop_area, :area_type => "zdlp" } -  describe '#objectid' do -    subject { super().get_objectid } -    it { should be_kind_of(Chouette::Objectid::StifReflex) } -  end - -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    it { should belong_to(:stop_area_referential) }    it { should validate_presence_of :name }    it { should validate_numericality_of :latitude } diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index b68d231b4..f48173e65 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -13,12 +13,6 @@ describe StopPoint, :type => :model do      it { is_expected.to be_kind_of(Chouette::Objectid::StifNetex) }    end -  describe "#objectid_format" do -    it "sould not be nil" do -      expect(subject.objectid_format).not_to be_nil -    end -  end -    describe "#destroy" do      before(:each) do        @vehicle = create(:vehicle_journey) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 74809fa58..761c39e5b 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -6,12 +6,6 @@ describe Chouette::TimeTable, :type => :model do    it { is_expected.to validate_presence_of :comment }    it { is_expected.to validate_uniqueness_of :objectid } -   -    describe "#objectid_format" do -      it "sould not be nil" do -        expect(subject.objectid_format).not_to be_nil -      end -    end      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/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index ca438ffcc..fce0a5f73 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -2,12 +2,6 @@ require 'spec_helper'  describe Chouette::VehicleJourney, :type => :model do -    describe "#objectid_format" do -      it "sould not be nil" do -        expect(subject.objectid_format).not_to be_nil -      end -    end -    it "must be valid with an at-stop day offset of 1" do      vehicle_journey = create(        :vehicle_journey, diff --git a/spec/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb index 656e42d8e..3829b2106 100644 --- a/spec/models/concerns/objectid_support_spec.rb +++ b/spec/models/concerns/objectid_support_spec.rb @@ -5,11 +5,8 @@ RSpec.describe ObjectidSupport do      context "#objectid_format" do         it "should be stif_netex" do -        expect(route.objectid_format).to eq('stif_netex') -      end - -      it "should be the same as the referential" do -        expect(route.objectid_format).to eq(route.referential.objectid_format) +        expect(route.referential.objectid_format).not_to be_nil +        expect(route.referential.objectid_format).to eq('stif_netex')        end      end | 
