diff options
| -rw-r--r-- | app/controllers/routing_constraint_zones_controller.rb | 2 | ||||
| -rw-r--r-- | app/helpers/newapplication_helper.rb | 3 | ||||
| -rw-r--r-- | app/models/chouette/line.rb | 3 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/routing_constraint_zone.rb | 4 | ||||
| -rw-r--r-- | app/views/routing_constraint_zones/_form.html.slim | 3 | ||||
| -rw-r--r-- | app/views/routing_constraint_zones/index.html.slim | 2 | ||||
| -rw-r--r-- | app/views/routing_constraint_zones/show.html.slim | 4 | ||||
| -rw-r--r-- | db/migrate/20170404122930_add_route_rm_line_from_routing_constraint_zone.rb | 6 | ||||
| -rw-r--r-- | db/schema.rb | 24 | ||||
| -rw-r--r-- | spec/factories/chouette_routing_constraint_zones.rb | 2 | ||||
| -rw-r--r-- | spec/features/routing_constraint_zones_spec.rb | 3 | ||||
| -rw-r--r-- | spec/models/chouette/routing_constraint_zone_spec.rb | 2 | 
13 files changed, 26 insertions, 33 deletions
| diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index c39c50326..bc3dcdfd4 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -11,7 +11,7 @@ class RoutingConstraintZonesController < ChouetteController    private    def routing_constraint_zone_params -    params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :objectid, :object_version, :creator_id) +    params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :route_id, :objectid, :object_version, :creator_id)    end  end diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb index c9da544d1..c4b8ee7ab 100644 --- a/app/helpers/newapplication_helper.rb +++ b/app/helpers/newapplication_helper.rb @@ -30,6 +30,7 @@ module NewapplicationHelper      body = content_tag :tbody do        collection.collect do |item| +          content_tag :tr do            bcont = [] @@ -54,6 +55,7 @@ module NewapplicationHelper                  if current_referential                    lnk << current_referential                    lnk << item.line if item.respond_to? :line +                  lnk << item.route.line if item.class.to_s == 'Chouette::RoutingConstraintZone'                    lnk << item if item.class.to_s == 'Chouette::RoutingConstraintZone'                    lnk << item if item.respond_to? :line_referential                    lnk << item.stop_area if item.respond_to? :stop_area @@ -105,6 +107,7 @@ module NewapplicationHelper            if current_referential              polymorph_url << current_referential              polymorph_url << item.line if item.respond_to? :line +            polymorph_url << item.route.line if item.class.to_s == 'Chouette::RoutingConstraintZone'              polymorph_url << item if item.class.to_s == 'Chouette::RoutingConstraintZone'              polymorph_url << item if item.respond_to? :line_referential              polymorph_url << item.stop_area if item.respond_to? :stop_area diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index 27a37a7f4..50dd9b1b3 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -20,14 +20,13 @@ class Chouette::Line < Chouette::ActiveRecord    has_many :routes, :dependent => :destroy    has_many :journey_patterns, :through => :routes    has_many :vehicle_journeys, :through => :journey_patterns +  has_many :routing_constraint_zones, through: :routes    has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name'    has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy    accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true -  has_many :routing_constraint_zones -    attr_reader :group_of_line_tokens    # validates_presence_of :network diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 9de7d7470..688f8774e 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -16,6 +16,7 @@ class Chouette::Route < Chouette::TridentActiveRecord    belongs_to :line +  has_many :routing_constraint_zones    has_many :journey_patterns, :dependent => :destroy    has_many :vehicle_journeys, :dependent => :destroy do      def timeless diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 681069416..2c8583ec1 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -1,8 +1,8 @@  class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord -  belongs_to :line +  belongs_to :route    has_array_of :stop_areas, class_name: 'Chouette::StopArea' -  validates_presence_of :name, :stop_area_ids, :line_id +  validates_presence_of :name, :stop_area_ids, :route_id    validates :stop_areas, length: { minimum: 2 }    self.primary_key = 'id' diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim index afc993a0f..f72dd1471 100644 --- a/app/views/routing_constraint_zones/_form.html.slim +++ b/app/views/routing_constraint_zones/_form.html.slim @@ -4,6 +4,9 @@        = f.input :name    .row      .col-lg-6.col-sm-12 +      = f.input :route_id, collection: @line.routes +  .row +    .col-lg-6.col-sm-12        / Temporarily limit the collection to 10 items... otherwise it kills RoR        = f.input :stop_area_ids, as: :select, collection: Chouette::StopArea.limit(10), selected: @routing_constraint_zone.stop_area_ids, label: Chouette::StopArea.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'SĂ©lection de arrĂȘts', 'multiple': 'multiple', style: 'width: 100%' } diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim index 9061fbdfd..e8da0f974 100644 --- a/app/views/routing_constraint_zones/index.html.slim +++ b/app/views/routing_constraint_zones/index.html.slim @@ -1,7 +1,7 @@  = title_tag Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr)  - if policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation -  = link_to t('routing_constraint_zones.actions.new'), new_referential_line_routing_constraint_zone_path +  = link_to t('routing_constraint_zones.actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line)  - if @routing_constraint_zones.any?    = table_builder @routing_constraint_zones, diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim index 0f88f5b3f..7b7b63623 100644 --- a/app/views/routing_constraint_zones/show.html.slim +++ b/app/views/routing_constraint_zones/show.html.slim @@ -5,8 +5,8 @@ p    = @routing_constraint_zone.name  p -  label => "#{Chouette::Line.model_name.human.capitalize} : " -  = link_to @routing_constraint_zone.line.name, referential_line_path(@referential, @line) +  label => "#{Chouette::Route.model_name.human.capitalize} : " +  = link_to @routing_constraint_zone.route.name, referential_line_route_path(@referential, @line, @routing_constraint_zone.route)  p    label => "#{Chouette::StopArea.model_name.human.pluralize.capitalize} : " diff --git a/db/migrate/20170404122930_add_route_rm_line_from_routing_constraint_zone.rb b/db/migrate/20170404122930_add_route_rm_line_from_routing_constraint_zone.rb new file mode 100644 index 000000000..f53c0b503 --- /dev/null +++ b/db/migrate/20170404122930_add_route_rm_line_from_routing_constraint_zone.rb @@ -0,0 +1,6 @@ +class AddRouteRmLineFromRoutingConstraintZone < ActiveRecord::Migration +  def change +    remove_column :routing_constraint_zones, :line_id, :bigint +    add_column :routing_constraint_zones, :route_id, :bigint +  end +end diff --git a/db/schema.rb b/db/schema.rb index 479484128..53e3ad57c 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: 20170403155202) do +ActiveRecord::Schema.define(version: 20170404122930) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -165,22 +165,6 @@ ActiveRecord::Schema.define(version: 20170403155202) do    add_index "connection_links", ["objectid"], :name => "connection_links_objectid_key", :unique => true -  create_table "delayed_jobs", force: true do |t| -    t.integer  "priority",   default: 0 -    t.integer  "attempts",   default: 0 -    t.text     "handler" -    t.text     "last_error" -    t.datetime "run_at" -    t.datetime "locked_at" -    t.datetime "failed_at" -    t.string   "locked_by" -    t.string   "queue" -    t.datetime "created_at" -    t.datetime "updated_at" -  end - -  add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" -    create_table "exports", force: true do |t|      t.integer  "referential_id",  limit: 8      t.string   "status" @@ -559,16 +543,14 @@ ActiveRecord::Schema.define(version: 20170403155202) do    create_table "routing_constraint_zones", force: true do |t|      t.string   "name"      t.integer  "stop_area_ids",                         array: true -    t.integer  "line_id",        limit: 8      t.datetime "created_at"      t.datetime "updated_at"      t.string   "objectid",                 null: false      t.integer  "object_version", limit: 8      t.string   "creator_id" +    t.integer  "route_id",       limit: 8    end -  add_index "routing_constraint_zones", ["line_id"], :name => "index_routing_constraint_zones_on_line_id" -    create_table "routing_constraints_lines", id: false, force: true do |t|      t.integer "stop_area_id", limit: 8      t.integer "line_id",      limit: 8 @@ -843,8 +825,6 @@ ActiveRecord::Schema.define(version: 20170403155202) do    add_index "workbenches", ["stop_area_referential_id"], :name => "index_workbenches_on_stop_area_referential_id"    Foreigner.load -  add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey", dependent: :delete -    add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", dependent: :delete    add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", dependent: :nullify diff --git a/spec/factories/chouette_routing_constraint_zones.rb b/spec/factories/chouette_routing_constraint_zones.rb index 9a2529483..2f707e6a6 100644 --- a/spec/factories/chouette_routing_constraint_zones.rb +++ b/spec/factories/chouette_routing_constraint_zones.rb @@ -2,6 +2,6 @@ FactoryGirl.define do    factory :routing_constraint_zone, class: Chouette::RoutingConstraintZone do      sequence(:name) { |n| "Routing constraint zone #{n}" }      stop_area_ids { [create(:stop_area).id, create(:stop_area).id] } -    association :line, factory: :line +    association :route, factory: :route    end  end diff --git a/spec/features/routing_constraint_zones_spec.rb b/spec/features/routing_constraint_zones_spec.rb index d1c39e211..9e8c7dad4 100644 --- a/spec/features/routing_constraint_zones_spec.rb +++ b/spec/features/routing_constraint_zones_spec.rb @@ -6,7 +6,8 @@ describe 'RoutingConstraintZones', type: :feature do    let(:referential) { Referential.first }    let!(:line) { create :line } -  let!(:routing_constraint_zones) { Array.new(2) { create :routing_constraint_zone, line: line } } +  let!(:route) { create :route, line: line } +  let!(:routing_constraint_zones) { Array.new(2) { create :routing_constraint_zone, route: route } }    let(:routing_constraint_zone) { routing_constraint_zones.first }    describe 'index' do diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index d991538ba..f737872bf 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -6,7 +6,7 @@ describe Chouette::RoutingConstraintZone, type: :model do    it { is_expected.to validate_presence_of :name }    it { is_expected.to validate_presence_of :stop_area_ids } -  it { is_expected.to validate_presence_of :line_id } +  it { is_expected.to validate_presence_of :route_id }    # shoulda matcher to validate length of array ?    xit { is_expected.to validate_length_of(:stop_area_ids).is_at_least(2) } | 
