diff options
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 30 | ||||
| -rw-r--r-- | app/decorators/stop_area_decorator.rb | 6 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 11 | ||||
| -rw-r--r-- | config/locales/stop_areas.en.yml | 2 | ||||
| -rw-r--r-- | config/locales/stop_areas.fr.yml | 4 | ||||
| -rw-r--r-- | db/migrate/20171220164059_add_waiting_time_to_stop_areas.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 16 | ||||
| -rw-r--r-- | spec/decorators/referential_decorator_spec.rb | 1 | ||||
| -rw-r--r-- | spec/decorators/stop_area_decorator_spec.rb | 25 | ||||
| -rw-r--r-- | spec/models/chouette/stop_area_spec.rb | 25 | ||||
| -rw-r--r-- | spec/support/decorator_helpers.rb | 5 | 
13 files changed, 122 insertions, 12 deletions
| diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index d4d996adb..498493f1e 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -171,7 +171,35 @@ class StopAreasController < ChouetteController    helper_method :current_referential    def stop_area_params -    params.require(:stop_area).permit( :routing_stop_ids, :routing_line_ids, :children_ids, :parent_id, :objectid, :object_version, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :coordinates, :url, :time_zone ) +    params.require(:stop_area).permit( +      :area_type, +      :children_ids, +      :city_name, +      :comment, +      :coordinates, +      :country_code, +      :fare_code, +      :int_user_needs, +      :latitude, +      :lift_availability, +      :long_lat_type, +      :longitude, +      :mobility_restricted_suitability, +      :name, +      :nearest_topic_name, +      :object_version, +      :objectid, +      :parent_id, +      :registration_number, +      :routing_line_ids, +      :routing_stop_ids, +      :stairs_availability, +      :street_name, +      :time_zone, +      :url, +      :waiting_time, +      :zip_code, +    )    end  end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 8b2ebf490..cf3612f79 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -31,4 +31,10 @@ class StopAreaDecorator < Draper::Decorator      links    end + +  def waiting_time_text +    return '-' if [nil, 0].include? waiting_time +    h.t('stop_areas.waiting_time_format', value: waiting_time) +  end +  end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index f216ce449..3a9b44d59 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -39,6 +39,8 @@ module Chouette      validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true      validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true +    validates_numericality_of :waiting_time, greater_than_or_equal_to: 0, only_integer: true, if: :waiting_time +      def self.nullable_attributes        [:registration_number, :street_name, :country_code, :fare_code,        :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index ac2cb4e87..6c8129d77 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -26,6 +26,8 @@          .stop_areas.stop_area.general_info            h3 = t("stop_areas.stop_area.general") +          = f.input :waiting_time +            = f.input :registration_number, required: format_restriction_for_locales(@referential) == '.hub', :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.registration_number")}            = f.input :fare_code            = f.input :nearest_topic_name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.nearest_topic_name")} diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index 1b1209a68..0b79f5736 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -15,12 +15,15 @@    .container-fluid      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12 -        = definition_list t('metadatas'), -          { t('id_reflex') => @stop_area.get_objectid.short_id, +        - attributes = { t('id_reflex') => @stop_area.get_objectid.short_id,              @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label),              @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number, -            'Coordonnées' => geo_data(@stop_area, @stop_area_referential), +            } +        - attributes.merge!(@stop_area.human_attribute_name(:waiting_time) => @stop_area.waiting_time_text) +        - attributes.merge!({ "Coordonnées" => geo_data(@stop_area, @stop_area_referential),              @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code,              @stop_area.human_attribute_name(:city_name) => @stop_area.city_name,              'Etat' => (@stop_area.deleted_at ? 'Supprimé' : 'Actif'), -            @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment) } +            @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment), +            }) +        = definition_list t('metadatas'), attributes diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml index 54a5ebae5..3ef3835e2 100644 --- a/config/locales/stop_areas.en.yml +++ b/config/locales/stop_areas.en.yml @@ -1,5 +1,6 @@  en:    stop_areas: &en_stop_areas +    waiting_time_format: "%{value} minutes"      search_no_results: "No stop area matching your query"      errors:        empty: Aucun stop_area_id @@ -126,6 +127,7 @@ en:          city_name: "City"          created_at: Created at          updated_at: Updated at +        waiting_time: Waiting time    formtastic:      titles:        stop_area: diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml index f96a2e564..69e3ba71e 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -1,5 +1,6 @@  fr:    stop_areas: &fr_stop_areas +    waiting_time_format: "%{value} minutes"      search_no_results: "Aucun arrêt ne correspond à votre recherche"      errors:        empty: Aucun stop_area_id @@ -37,7 +38,7 @@ fr:        name_or_objectid: "Recherche par nom ou par objectid..."        zip_code: Indiquez un code postal...        city_name: Indiquez un nom de commune... -      area_type: Indiquez un type d'arrêt... +      area_type: "Indiquez un type d'arrêt..."      new:        title: "Ajouter un arrêt"      form: @@ -126,6 +127,7 @@ fr:          city_name: "Commune"          created_at: "Créé le"          updated_at: "Edité le" +        waiting_time: Temps de desserte    formtastic:      titles:        stop_area: diff --git a/db/migrate/20171220164059_add_waiting_time_to_stop_areas.rb b/db/migrate/20171220164059_add_waiting_time_to_stop_areas.rb new file mode 100644 index 000000000..369fed3ab --- /dev/null +++ b/db/migrate/20171220164059_add_waiting_time_to_stop_areas.rb @@ -0,0 +1,5 @@ +class AddWaitingTimeToStopAreas < ActiveRecord::Migration +  def change +    add_column :stop_areas, :waiting_time, :integer +  end +end diff --git a/db/schema.rb b/db/schema.rb index e19a40aab..f5532ec57 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: 20171219170128) do +ActiveRecord::Schema.define(version: 20171220164059) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -538,6 +538,19 @@ ActiveRecord::Schema.define(version: 20171219170128) do    add_index "lines", ["registration_number"], name: "lines_registration_number_key", using: :btree    add_index "lines", ["secondary_company_ids"], name: "index_lines_on_secondary_company_ids", using: :gin +  create_table "merges", id: :bigserial, force: :cascade do |t| +    t.integer  "workbench_id",    limit: 8 +    t.integer  "referential_ids", limit: 8,              array: true +    t.string   "creator" +    t.string   "status" +    t.datetime "started_at" +    t.datetime "ended_at" +    t.datetime "created_at",                null: false +    t.datetime "updated_at",                null: false +  end + +  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.integer  "object_version",      limit: 8 @@ -759,6 +772,7 @@ ActiveRecord::Schema.define(version: 20171219170128) do      t.datetime "created_at"      t.datetime "updated_at"      t.string   "stif_type",                       limit: 255 +    t.integer  "waiting_time"    end    add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index cbeaf2407..879ab7d4b 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -1,4 +1,5 @@  RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do +  include Support::DecoratorHelpers    let( :object ){ build_stubbed :referential }    let( :referential ){ object } diff --git a/spec/decorators/stop_area_decorator_spec.rb b/spec/decorators/stop_area_decorator_spec.rb new file mode 100644 index 000000000..fd6aa207a --- /dev/null +++ b/spec/decorators/stop_area_decorator_spec.rb @@ -0,0 +1,25 @@ +require "rails_helper" + +RSpec.describe StopAreaDecorator do + +  let(:stop_area) { Chouette::StopArea.new } +  let(:decorator) { stop_area.decorate } + +  describe '#waiting_time_text' do +    it "returns '-' when waiting_time is nil" do +      stop_area.waiting_time = nil +      expect(decorator.waiting_time_text).to eq('-') +    end + +    it "returns '-' when waiting_time is zero" do +      stop_area.waiting_time = 0 +      expect(decorator.waiting_time_text).to eq('-') +    end + +    it "returns '120 minutes' when waiting_time is 120" do +      stop_area.waiting_time = 120 +      expect(decorator.waiting_time_text).to eq('120 minutes') +    end +  end + +end diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index c6aeafaf8..bec8c0868 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -426,5 +426,30 @@ describe Chouette::StopArea, :type => :model do    #     end    # end +  describe '#waiting_time' do + +    let(:stop_area) { FactoryGirl.build :stop_area } + +    it 'can be nil' do +      stop_area.waiting_time = nil +      expect(stop_area).to be_valid +    end + +    it 'can be zero' do +      stop_area.waiting_time = 0 +      expect(stop_area).to be_valid +    end + +    it 'can be positive' do +      stop_area.waiting_time = 120 +      expect(stop_area).to be_valid +    end + +    it "can't be negative" do +      stop_area.waiting_time = -1 +      expect(stop_area).to_not be_valid +    end + +  end  end diff --git a/spec/support/decorator_helpers.rb b/spec/support/decorator_helpers.rb index ffedd479b..9d450deb1 100644 --- a/spec/support/decorator_helpers.rb +++ b/spec/support/decorator_helpers.rb @@ -1,5 +1,4 @@  module Support -    module DecoratorHelpers      def self.included(into)        into.instance_eval do @@ -21,7 +20,3 @@ module Support      end    end  end - -RSpec.configure do | c | -  c.include Support::DecoratorHelpers, type: :decorator -end | 
