aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/group_of_lines_controller.rb34
-rw-r--r--app/controllers/lines_controller.rb12
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/breadcrumb_helper.rb9
-rw-r--r--app/maps/line_map.rb2
-rw-r--r--app/models/chouette/group_of_line.rb6
-rw-r--r--app/models/chouette/line.rb6
-rw-r--r--app/models/chouette/stop_area.rb1
-rw-r--r--app/models/chouette/trident_active_record.rb138
-rw-r--r--app/models/concerns/default_attributes_support.rb113
-rw-r--r--app/models/concerns/line_referential_support.rb20
-rw-r--r--app/models/concerns/objectid_restrictions.rb1
-rw-r--r--app/models/line_referential.rb3
-rw-r--r--app/views/group_of_lines/_form.erb8
-rw-r--r--app/views/group_of_lines/_group_of_line.erb14
-rw-r--r--app/views/group_of_lines/index.html.erb10
-rw-r--r--app/views/group_of_lines/show.html.erb8
-rw-r--r--app/views/lines/_form.erb12
-rw-r--r--app/views/lines/_line.erb23
-rw-r--r--app/views/lines/index.html.erb15
-rw-r--r--app/views/lines/show.html.erb30
-rw-r--r--config/initializers/apartment.rb2
-rw-r--r--config/routes.rb5
-rw-r--r--db/migrate/20160511082825_add_line_referential_to_lines.rb5
-rw-r--r--db/migrate/20160511082825_add_line_referential_to_stop_areas.rb5
-rw-r--r--db/migrate/20160512110510_add_line_referential_to_group_of_lines.rb5
-rw-r--r--db/schema.rb12
-rw-r--r--spec/factories/chouette_group_of_lines.rb2
-rw-r--r--spec/factories/chouette_lines.rb14
-rw-r--r--spec/features/group_of_lines_spec.rb26
-rw-r--r--spec/features/lines_spec.rb31
-rw-r--r--spec/features/routes_spec.rb108
-rw-r--r--spec/models/chouette/stop_area_spec.rb2
-rw-r--r--spec/models/chouette/trident_active_record_spec.rb58
-rw-r--r--spec/models/line_spec.rb53
-rw-r--r--spec/views/lines/edit.html.erb_spec.rb5
-rw-r--r--spec/views/lines/index.html.erb_spec.rb14
-rw-r--r--spec/views/lines/new.html.erb_spec.rb5
-rw-r--r--spec/views/lines/show.html.erb_spec.rb9
39 files changed, 417 insertions, 411 deletions
diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb
index 78d3f64c0..f8b5301d3 100644
--- a/app/controllers/group_of_lines_controller.rb
+++ b/app/controllers/group_of_lines_controller.rb
@@ -1,4 +1,6 @@
-class GroupOfLinesController < ChouetteController
+class GroupOfLinesController < BreadcrumbController
+ include ApplicationHelper
+
defaults :resource_class => Chouette::GroupOfLine
respond_to :html
respond_to :xml
@@ -6,7 +8,7 @@ class GroupOfLinesController < ChouetteController
respond_to :kml, :only => :show
respond_to :js, :only => :index
- belongs_to :referential
+ belongs_to :line_referential
def show
@map = GroupOfLineMap.new(resource).with_helpers(self)
@@ -16,7 +18,7 @@ class GroupOfLinesController < ChouetteController
end
end
- def index
+ def index
index! do |format|
format.html {
if collection.out_of_bounds?
@@ -24,17 +26,16 @@ class GroupOfLinesController < ChouetteController
end
build_breadcrumb :index
}
- end
+ end
end
-
def name_filter
- respond_to do |format|
- format.json { render :json => filtered_group_of_lines_maps}
- end
+ respond_to do |format|
+ format.json { render :json => filtered_group_of_lines_maps}
+ end
end
-
+
protected
def filtered_group_of_lines_maps
@@ -42,29 +43,30 @@ class GroupOfLinesController < ChouetteController
{ :id => group_of_line.id, :name => group_of_line.name }
end
end
-
+
def filtered_group_of_lines
- referential.group_of_lines.select{ |t| t.name =~ /#{params[:q]}/i }
+ line_referential.group_of_lines.select{ |t| t.name =~ /#{params[:q]}/i }
end
- def collection
- @q = referential.group_of_lines.search(params[:q])
+ def collection
+ @q = line_referential.group_of_lines.search(params[:q])
@group_of_lines ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page])
end
def resource_url(group_of_line = nil)
- referential_group_of_line_path(referential, group_of_line || resource)
+ line_referential_group_of_line_path(line_referential, group_of_line || resource)
end
def collection_url
- referential_group_of_lines_path(referential)
+ line_referential_group_of_lines_path(line_referential)
end
+ alias_method :line_referential, :parent
private
def group_of_line_params
params.require(:group_of_line).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :lines, :registration_number, :line_tokens)
end
-
+
end
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 50d8dcee3..8c14de06d 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -1,4 +1,6 @@
-class LinesController < ChouetteController
+class LinesController < BreadcrumbController
+ include ApplicationHelper
+
defaults :resource_class => Chouette::Line
respond_to :html
respond_to :xml
@@ -6,7 +8,7 @@ class LinesController < ChouetteController
respond_to :kml, :only => :show
respond_to :js, :only => :index
- belongs_to :referential
+ belongs_to :line_referential
def index
index! do |format|
@@ -57,7 +59,7 @@ class LinesController < ChouetteController
end
def filtered_lines
- referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e } }
+ line_referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e } }
end
def collection
@@ -76,10 +78,12 @@ class LinesController < ChouetteController
params[:q]["group_of_lines_id_blank"] = "1"
end
- @q = referential.lines.search(params[:q])
+ @q = line_referential.lines.search(params[:q])
@lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
end
+ alias_method :line_referential, :parent
+
private
def line_params
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e40093da9..0aa106028 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -15,7 +15,7 @@ module ApplicationHelper
end
def format_restriction_for_locales(referential)
- if referential.data_format.blank?
+ if !referential.respond_to?(:data_format) or referential.data_format.blank?
""
else
"."+referential.data_format
diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb
index 69494321b..3c595f86b 100644
--- a/app/helpers/breadcrumb_helper.rb
+++ b/app/helpers/breadcrumb_helper.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
module BreadcrumbHelper
def build_breadcrumb(action)
@@ -72,8 +73,8 @@ module BreadcrumbHelper
def group_of_line_breadcrumb(action)
referential_breadcrumb
- add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2), referential_group_of_lines_path(@referential) unless action == :index
- add_breadcrumb breadcrumb_label(@group_of_line), referential_group_of_line_path(@referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit
+ add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2), line_referential_group_of_lines_path(@line_referential) unless action == :index
+ add_breadcrumb breadcrumb_label(@group_of_line), line_referential_group_of_line_path(@line_referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit
end
def stop_area_breadcrumb(action)
@@ -123,8 +124,8 @@ module BreadcrumbHelper
def line_breadcrumb(action)
referential_breadcrumb
- add_breadcrumb Chouette::Line.model_name.human(:count => 2), referential_lines_path(@referential) unless action == :index
- add_breadcrumb breadcrumb_label(@line), referential_line_path(@referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit
+ add_breadcrumb Chouette::Line.model_name.human(:count => 2), line_referential_lines_path(@line.line_referential) unless action == :index
+ add_breadcrumb breadcrumb_label(@line), line_referential_line_path(@line.line_referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit
end
def route_breadcrumb(action)
diff --git a/app/maps/line_map.rb b/app/maps/line_map.rb
index 8d79bfe0b..1acde11ff 100644
--- a/app/maps/line_map.rb
+++ b/app/maps/line_map.rb
@@ -10,7 +10,7 @@ class LineMap < ApplicationMap
def customize_map(map, page)
page << map.add_layer(kml_layer(line, :styleMap => Design::LineStyleMap.new( :style => line_style).style_map))
- page.assign "stop_areas_layer", kml_layer([line.referential, line], :styleMap => Design::StopAreasStyleMap.new(helpers).style_map)
+ page.assign "stop_areas_layer", kml_layer([line.line_referential, line], :styleMap => Design::StopAreasStyleMap.new(helpers).style_map)
page << map.add_layer(:stop_areas_layer)
diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb
index 9443a34e5..0b91f3442 100644
--- a/app/models/chouette/group_of_line.rb
+++ b/app/models/chouette/group_of_line.rb
@@ -1,5 +1,8 @@
-class Chouette::GroupOfLine < Chouette::TridentActiveRecord
+class Chouette::GroupOfLine < Chouette::ActiveRecord
+ include DefaultAttributesSupport
include GroupOfLineRestrictions
+ include LineReferentialSupport
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -26,4 +29,3 @@ class Chouette::GroupOfLine < Chouette::TridentActiveRecord
end
end
-
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index b1e9940d3..ddd6fc37d 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -1,5 +1,9 @@
-class Chouette::Line < Chouette::TridentActiveRecord
+class Chouette::Line < Chouette::ActiveRecord
+ include DefaultAttributesSupport
include LineRestrictions
+
+ include LineReferentialSupport
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 84ea47693..588014fff 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -15,7 +15,6 @@ class Chouette::StopArea < Chouette::TridentActiveRecord
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
- belongs_to :line_referential
validates_presence_of :stop_area_referential_id
acts_as_tree :foreign_key => 'parent_id',:order => "name"
diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb
index 225d7bb4b..cf7a59c0c 100644
--- a/app/models/chouette/trident_active_record.rb
+++ b/app/models/chouette/trident_active_record.rb
@@ -1,141 +1,19 @@
class Chouette::TridentActiveRecord < Chouette::ActiveRecord
- before_validation :prepare_auto_columns
- after_validation :reset_auto_columns
-
- after_save :build_objectid
+ include DefaultAttributesSupport
- self.abstract_class = true
- #
- # triggers to generate objectId and objectVersion
- # TODO setting prefix in referential object
-
- def self.object_id_key
- model_name
- end
+ self.abstract_class = true
- def referential
- @referential ||= Referential.where(:slug => Apartment::Tenant.current).first!
- end
-
- def hub_restricted?
- referential.data_format == "hub"
- end
-
- def prefix
- self.referential.prefix
- end
-
- def prepare_auto_columns
- # logger.info 'calling before_validation'
- # logger.info 'start before_validation : '+self.objectid.to_s
- if self.objectid.nil? || self.objectid.blank?
- # if empty, generate a pending objectid which will be completed after creation
- if self.id.nil?
- self.objectid = "#{prefix}:#{self.class.object_id_key}:__pending_id__#{rand(1000)}"
- else
- self.objectid = "#{prefix}:#{self.class.object_id_key}:#{self.id}"
- fix_uniq_objectid
- end
- elsif not self.objectid.include? ':'
- # if one token : technical token : completed by prefix and key
- self.objectid = "#{prefix}:#{self.class.object_id_key}:#{self.objectid}"
- end
- # logger.info 'end before_validation : '+self.objectid
- # initialize or update version
- if self.object_version.nil?
- self.object_version = 1
- else
- self.object_version += 1
- end
- self.creation_time = Time.now
- self.creator_id = 'chouette'
- end
-
- def reset_auto_columns
- clean_object_id unless self.errors.nil? || self.errors.empty?
- end
-
- def clean_object_id
- if self.objectid.include?("__pending_id__")
- self.objectid=nil
- end
- end
-
- def fix_uniq_objectid
- base_objectid = self.objectid.rpartition(":").first
- self.objectid = "#{base_objectid}:#{self.id}"
- if !self.valid?
- base_objectid="#{self.objectid}_"
- cnt=1
- while !self.valid?
- self.objectid = "#{base_objectid}#{cnt}"
- cnt += 1
- end
- end
-
- end
-
- def build_objectid
- #logger.info 'start after_create : '+self.objectid
- if self.objectid.include? ':__pending_id__'
- fix_uniq_objectid
- self.update_attributes( :objectid => self.objectid, :object_version => (self.object_version - 1) )
- end
- #logger.info 'end after_create : '+self.objectid
- end
-
- validates_presence_of :objectid
- validates_uniqueness_of :objectid
- validates_numericality_of :object_version
- validate :objectid_format_compliance
-
- def objectid_format_compliance
- if !self.objectid.valid?
- #errors.add(:objectid, "is not a valid ObjectId object")
- errors.add(:objectid,I18n.t("activerecord.errors.models.trident.invalid_object_id",:type => self.class.object_id_key))
-# else
-# unless self.objectid.object_type==self.class.object_id_key
-# errors.add(:objectid,I18n.t("activerecord.errors.models.trident.invalid_object_id_type",:type => self.class.object_id_key))
-# end
- end
- end
-
- def uniq_objectid
- i = 0
- baseobjectid = self.objectid
- while self.class.exists?(:objectid => self.objectid)
- i += 1
- self.objectid = baseobjectid+"_"+i.to_s
- end
+ def referential
+ @referential ||= Referential.where(:slug => Apartment::Tenant.current).first!
end
- def self.model_name
- ActiveModel::Name.new self, Chouette, self.name.demodulize
+ def hub_restricted?
+ referential.data_format == "hub"
end
- def objectid
- Chouette::ObjectId.new read_attribute(:objectid)
+ def prefix
+ self.referential.prefix
end
-# def version
-# self.object_version
-# end
-
-# def version=(version)
-# self.object_version = version
-# end
-
- before_validation :default_values, :on => :create
- def default_values
- self.object_version ||= 1
- end
-
- def timestamp_attributes_for_update #:nodoc:
- [:creation_time]
- end
-
- def timestamp_attributes_for_create #:nodoc:
- [:creation_time]
- end
end
diff --git a/app/models/concerns/default_attributes_support.rb b/app/models/concerns/default_attributes_support.rb
new file mode 100644
index 000000000..ba5611fe3
--- /dev/null
+++ b/app/models/concerns/default_attributes_support.rb
@@ -0,0 +1,113 @@
+module DefaultAttributesSupport
+ extend ActiveSupport::Concern
+
+ included do
+ before_validation :prepare_auto_columns
+ after_validation :reset_auto_columns
+
+ after_save :build_objectid
+
+ 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::ObjectId.new read_attribute(:objectid)
+ end
+
+ def prepare_auto_columns
+ if objectid.nil? || objectid.blank?
+ if id.nil?
+ self.objectid = "#{prefix}:#{self.class.object_id_key}:__pending_id__#{rand(1000)}"
+ else
+ self.objectid = "#{prefix}:#{self.class.object_id_key}:#{id}"
+ fix_uniq_objectid
+ end
+ elsif not objectid.include? ':'
+ # if one token : technical token : completed by prefix and key
+ self.objectid = "#{prefix}:#{self.class.object_id_key}:#{objectid}"
+ end
+
+ if object_version.nil?
+ self.object_version = 1
+ else
+ self.object_version += 1
+ end
+ self.creation_time = Time.now
+ self.creator_id = 'chouette'
+ end
+
+ def reset_auto_columns
+ clean_object_id unless errors.nil? || errors.empty?
+ end
+
+ def clean_object_id
+ if objectid.include?("__pending_id__")
+ self.objectid=nil
+ end
+ 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 build_objectid
+ if objectid.include? ':__pending_id__'
+ fix_uniq_objectid
+ update_attributes( :objectid => objectid, :object_version => (object_version - 1) )
+ 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
+
+ def timestamp_attributes_for_update #:nodoc:
+ [:creation_time]
+ end
+
+ def timestamp_attributes_for_create #:nodoc:
+ [:creation_time]
+ end
+
+end
diff --git a/app/models/concerns/line_referential_support.rb b/app/models/concerns/line_referential_support.rb
new file mode 100644
index 000000000..4ad437fed
--- /dev/null
+++ b/app/models/concerns/line_referential_support.rb
@@ -0,0 +1,20 @@
+module LineReferentialSupport
+ extend ActiveSupport::Concern
+
+ included do
+ belongs_to :line_referential
+ # validates_presence_of :line_referential_id
+
+ alias_method :referential, :line_referential
+ end
+
+ def hub_restricted?
+ false
+ end
+
+ def prefix
+ # FIXME #825
+ "dummy"
+ end
+
+end
diff --git a/app/models/concerns/objectid_restrictions.rb b/app/models/concerns/objectid_restrictions.rb
index 4e905bdc2..49cc772c7 100644
--- a/app/models/concerns/objectid_restrictions.rb
+++ b/app/models/concerns/objectid_restrictions.rb
@@ -25,4 +25,3 @@ module ObjectidRestrictions
likes.size.zero? || ( likes.size==1 && likes.first.id==self.id)
end
end
-
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index b5ba56d7b..9c6f324e8 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -2,6 +2,9 @@ class LineReferential < ActiveRecord::Base
has_many :line_referential_memberships
has_many :organisations, through: :line_referential_memberships
+ has_many :lines, class_name: 'Chouette::Line'
+ has_many :group_of_lines, class_name: 'Chouette::GroupOfLine'
+
def add_member(organisation, options = {})
attributes = options.merge organisation: organisation
line_referential_memberships.build attributes
diff --git a/app/views/group_of_lines/_form.erb b/app/views/group_of_lines/_form.erb
index 0f92897ca..d8417466a 100644
--- a/app/views/group_of_lines/_form.erb
+++ b/app/views/group_of_lines/_form.erb
@@ -1,7 +1,7 @@
-<%= semantic_form_for [@referential, @group_of_line] do |form| %>
+<%= semantic_form_for [@line_referential, @group_of_line] do |form| %>
<%= form.inputs do %>
- <%= form.input :name, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.name") } %>
- <%= form.input :registration_number, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.registration_number") } %>
+ <%= form.input :name, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.group_of_line.name") } %>
+ <%= form.input :registration_number, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.group_of_line.registration_number") } %>
<%= form.input :comment %>
<%= form.input :objectid, :required => !@group_of_line.new_record?, :input_html => { :title => I18n.t("formtastic.titles#{format_restriction_for_locales(@referential)}.group_of_line.objectid") } %>
<% end %>
@@ -18,7 +18,7 @@
<script>
$(function() {
- $( "#group_of_line_line_tokens" ).tokenInput('<%= name_filter_referential_lines_path(@referential, :format => :json) %>', {
+ $( "#group_of_line_line_tokens" ).tokenInput('<%= name_filter_referential_lines_path(@line_referential, :format => :json) %>', {
crossDomain: false,
prePopulate: $('#line_tokens').data('pre'),
minChars: 1,
diff --git a/app/views/group_of_lines/_group_of_line.erb b/app/views/group_of_lines/_group_of_line.erb
index 98a1e03d2..c88a3835b 100644
--- a/app/views/group_of_lines/_group_of_line.erb
+++ b/app/views/group_of_lines/_group_of_line.erb
@@ -1,24 +1,24 @@
<div id="index_item" class="panel panel-default">
<div class="panel-heading">
<div class="panel-title clearfix">
- <span class="pull-right">
- <%= link_to edit_referential_group_of_line_path(@referential, group_of_line), :class => "btn btn-default btn-sm" do %>
+ <span class="pull-right">
+ <%= link_to edit_referential_group_of_line_path(@line_referential, group_of_line), :class => "btn btn-default btn-sm" do %>
<span class="fa fa-pencil"></span>
<% end if edit %>
- <%= link_to('<span class="fa fa-trash-o"></span>'.html_safe, referential_group_of_line_path(@referential, group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm") if delete %>
+ <%= link_to('<span class="fa fa-trash-o"></span>'.html_safe, line_referential_group_of_line_path(@line_referential, group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm") if delete %>
</span>
<h5>
- <%= link_to([@referential, group_of_line], :class => "preview", :title => "#{Chouette::GroupOfLine.model_name.human.capitalize} #{group_of_line.name}") do %>
+ <%= link_to([@line_referential, group_of_line], :class => "preview", :title => "#{Chouette::GroupOfLine.model_name.human.capitalize} #{group_of_line.name}") do %>
<span class="name">
- <%= truncate(group_of_line.name, :length => 20) %>
+ <%= truncate(group_of_line.name, :length => 20) %>
</span>
<% end %>
</h5>
- </div>
+ </div>
</div>
<div class="panel-body">
<p>
- <%= group_of_line.human_attribute_name('line_count') %> <%= group_of_line.lines.count %>
+ <%= group_of_line.human_attribute_name('line_count') %> <%= group_of_line.lines.count %>
</p>
</div>
</div>
diff --git a/app/views/group_of_lines/index.html.erb b/app/views/group_of_lines/index.html.erb
index 2257096bd..0f34128f4 100644
--- a/app/views/group_of_lines/index.html.erb
+++ b/app/views/group_of_lines/index.html.erb
@@ -1,9 +1,9 @@
-<%= title_tag t('group_of_lines.index.title') %>
+<%= title_tag t('group_of_lines.index.title') %>
-<%= search_form_for @q, :url => referential_group_of_lines_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
+<%= search_form_for @q, :url => referential_group_of_lines_path(@line_referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
<div class="panel panel-default">
- <div class="panel-heading">
- <div class="input-group col-md-12">
+ <div class="panel-heading">
+ <div class="input-group col-md-12">
<%= f.text_field :name_cont, :placeholder => "#{t('.name')}", :class => "form-control" %>
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
@@ -20,7 +20,7 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('group_of_lines.actions.new'), new_referential_group_of_line_path(@referential), :class => "add" %></li>
+ <li><%= link_to t('group_of_lines.actions.new'), new_line_referential_group_of_line_path(@line_referential), :class => "add" %></li>
<br>
</ul>
<% end %>
diff --git a/app/views/group_of_lines/show.html.erb b/app/views/group_of_lines/show.html.erb
index 3369f284d..557d8c82b 100644
--- a/app/views/group_of_lines/show.html.erb
+++ b/app/views/group_of_lines/show.html.erb
@@ -12,7 +12,7 @@
<%= @group_of_line.comment %>
</p>
</div>
-
+
<p class="after_map" />
<h3 class="group_of_line_lines"><%= t('.lines') %></h3>
<div class="lines_detail">
@@ -22,9 +22,9 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('group_of_lines.actions.new'), new_referential_group_of_line_path(@referential), :class => "add" %></li>
- <li><%= link_to t('group_of_lines.actions.edit'), edit_referential_group_of_line_path(@referential, @group_of_line), :class => "edit" %></li>
- <li><%= link_to t('group_of_lines.actions.destroy'), referential_group_of_line_path(@referential, @group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')} , :class => "remove" %></li>
+ <li><%= link_to t('group_of_lines.actions.new'), new_line_referential_group_of_line_path(@line_referential), :class => "add" %></li>
+ <li><%= link_to t('group_of_lines.actions.edit'), edit_line_referential_group_of_line_path(@line_referential, @group_of_line), :class => "edit" %></li>
+ <li><%= link_to t('group_of_lines.actions.destroy'), line_referential_group_of_line_path(@line_referential, @group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')} , :class => "remove" %></li>
<br>
</ul>
<%= creation_tag(@group_of_line) %>
diff --git a/app/views/lines/_form.erb b/app/views/lines/_form.erb
index 442434d3b..c2af9d6b8 100644
--- a/app/views/lines/_form.erb
+++ b/app/views/lines/_form.erb
@@ -1,11 +1,11 @@
-<%= semantic_form_for [@referential, @line] do |form| %>
+<%= semantic_form_for [@line_referential, @line] do |form| %>
<%= form.inputs do %>
<%= form.input :network, :as => :select, :collection => Chouette::Network.all, :include_blank => false %>
<%= form.input :company, :as => :select, :collection => Chouette::Company.all, :include_blank => false%>
- <%= form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.name") } %>
+ <%= form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.name") } %>
<%= form.input :published_name %>
- <%= form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.registration_number")} %>
- <%= form.input :number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.number") } %>
+ <%= form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.registration_number")} %>
+ <%= form.input :number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.number") } %>
<%= form.input :transport_mode, :as => :select, :collection => Chouette::Line.transport_modes, :include_blank => false, :member_label => Proc.new { |mode| t("transport_modes.label.#{mode}") } %>
<%= form.input :color, :as => :string %>
<%= form.input :text_color %>
@@ -14,7 +14,7 @@
<%= form.input :mobility_restricted_suitability, :as => :select, :collection => [[@line.human_attribute_name("accessible"), true], [@line.human_attribute_name("not_accessible"), false]], :include_blank => true %>
<%= form.input :flexible_service, :as => :select, :collection => [[@line.human_attribute_name("on_demaond_fs"), true], [@line.human_attribute_name("regular_fs"), false]], :include_blank => true %>
<%= form.input :comment %>
- <%= form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.objectid")} %>
+ <%= form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.objectid")} %>
<%= form.input :group_of_line_tokens, :label => t('.group_of_lines'), :as => :text, :input_html => { :"data-pre" => ( @line.group_of_lines.map { |group_of_line| { :id => group_of_line.id, :name => group_of_line.name } } ).to_json } %>
<div class="footnotes_block">
@@ -41,7 +41,7 @@
<script>
$(function() {
- $( "#line_group_of_line_tokens" ).tokenInput('<%= name_filter_referential_group_of_lines_path(@referential, :format => :json) %>', {
+ $( "#line_group_of_line_tokens" ).tokenInput('<%= name_filter_referential_group_of_lines_path(@line_referential, :format => :json) %>', {
crossDomain: false,
prePopulate: $('#group_of_line_tokens').data('pre'),
minChars: 3,
diff --git a/app/views/lines/_line.erb b/app/views/lines/_line.erb
index 20bdb9563..bd3a79d0e 100644
--- a/app/views/lines/_line.erb
+++ b/app/views/lines/_line.erb
@@ -8,15 +8,15 @@
<% end %>
</li>
<li>
- <%= link_to([@referential, line], class: 'preview', title: "#{Chouette::Line.model_name.human.capitalize} #{line.name}") do %>
+ <%= link_to([line.line_referential, line], class: 'preview', title: "#{Chouette::Line.model_name.human.capitalize} #{line.name}") do %>
<h5 class="ce-LineBlock-header-title"><%= truncate(line.name, length: 24) %></h5>
<% end %>
</li>
<li>
- <%= link_to edit_referential_line_path(@referential, line), class: 'btn btn-default btn-sm' do %>
+ <%= link_to edit_line_referential_line_path(line.line_referential, line), class: 'btn btn-default btn-sm' do %>
<span class="fa fa-pencil"></span>
<% end if edit %>
- <%= link_to referential_line_path(@referential, line), method: :delete, data: { confirm: t('lines.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do %>
+ <%= link_to line_referential_line_path(line.line_referential, line), method: :delete, data: { confirm: t('lines.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do %>
<span class="fa fa-trash-o"></span>
<% end if delete %>
</li>
@@ -25,24 +25,25 @@
<div class="panel-body">
<p>
<% if line.network.nil? %>
- <%= line.human_attribute_name('network') %> <%= t('lines.index.unset') %>
+ <%= line.human_attribute_name('network') %> <%= t('lines.index.unset') %>
<% else %>
- <%= line.human_attribute_name('network') %> <%= link_to_if line.network, line.network.name, referential_network_path(@referential, line.network), :title => "#{line.human_attribute_name('network')} #{line.network.name}" %>
+ <!-- FIXME #825 -->
+ <%= line.human_attribute_name('network') %> <%#= link_to_if line.network, line.network.name, line_referential_network_path(line.line_referential, line.network), :title => "#{line.human_attribute_name('network')} #{line.network.name}" %>
<% end %>
</p>
<p>
<% if line.company.nil? %>
- <%= line.human_attribute_name('company') %> <%= t('lines.index.unset') %>
+ <%= line.human_attribute_name('company') %> <%= t('lines.index.unset') %>
<% else %>
- <%= line.human_attribute_name('company') %> <%= link_to_if( line.company, line.company.name, referential_company_path(@referential, line.company), :title => "#{line.human_attribute_name('company')} #{line.company.name}" ) %>
+ <%= line.human_attribute_name('company') %> <%#= link_to_if( line.company, line.company.name, line_referential_company_path(line.line_referential, line.company), :title => "#{line.human_attribute_name('company')} #{line.company.name}" ) %>
<% end %>
- </p>
+ </p>
<p>
- <% if line.group_of_lines.count == 0 %>
+ <% if line.group_of_lines.count == 0 %>
<br><%# t('lines.form.no_group_of_line') %>
<% elsif line.group_of_lines.count == 1 %>
- <%= line.human_attribute_name('group_of_line') %>
- <%= link_to_if( line.group_of_lines.first, line.group_of_lines.first.name, referential_group_of_line_path(@referential, line.group_of_lines.first), :title => "#{line.human_attribute_name('group_of_line')} #{line.group_of_lines.first.name}") %>
+ <%= line.human_attribute_name('group_of_line') %>
+ <%= link_to_if( line.group_of_lines.first, line.group_of_lines.first.name, line_referential_group_of_line_path(line.line_referential, line.group_of_lines.first), :title => "#{line.human_attribute_name('group_of_line')} #{line.group_of_lines.first.name}") %>
<% else %>
<%= t('lines.form.several_group_of_lines', :count => line.group_of_lines.count) %>
<% end %>
diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb
index ae0cbabf7..0995d0021 100644
--- a/app/views/lines/index.html.erb
+++ b/app/views/lines/index.html.erb
@@ -1,6 +1,6 @@
<%= title_tag t('lines.index.title') %>
-<%= search_form_for @q, :url => referential_lines_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
+<%= search_form_for @q, :url => line_referential_lines_path(@line_referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
<div class="panel panel-default">
<div class="panel-heading">
<div class="input-group col-md-9">
@@ -16,9 +16,10 @@
<div id="advanced_search" class="panel-collapse collapse">
<div class="panel-body">
- <%= f.select(:network_id_eq, @referential.networks.collect {|n| [ n.name, n.id ] }.unshift([t('.no_networks'), -1]), {include_blank: t('.all_networks')}, { :class => 'form-control' }) %>
- <%= f.select(:company_id_eq, @referential.companies.collect {|c| [ c.name, c.id ] }.unshift([t('.no_companies'), -1]), { include_blank: t('.all_companies')}, { :class => 'form-control' }) %>
- <%= f.select(:group_of_lines_id_eq, @referential.group_of_lines.collect {|c| [ c.name, c.id ] }.unshift([t('.no_group_of_lines'), -1]), {include_blank: t('.all_group_of_lines')}, { :class => 'form-control' }) %>
+ <!-- FIXME #825 -->
+ <%#= f.select(:network_id_eq, @line_referential.networks.collect {|n| [ n.name, n.id ] }.unshift([t('.no_networks'), -1]), {include_blank: t('.all_networks')}, { :class => 'form-control' }) %>
+ <%#= f.select(:company_id_eq, @line_referential.companies.collect {|c| [ c.name, c.id ] }.unshift([t('.no_companies'), -1]), { include_blank: t('.all_companies')}, { :class => 'form-control' }) %>
+ <%#= f.select(:group_of_lines_id_eq, @line_referential.group_of_lines.collect {|c| [ c.name, c.id ] }.unshift([t('.no_group_of_lines'), -1]), {include_blank: t('.all_group_of_lines')}, { :class => 'form-control' }) %>
</div>
</div>
</div>
@@ -28,7 +29,7 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li>
+ <li><%= link_to t('lines.actions.new'), new_line_referential_line_path(@line_referential), :class => "add" %></li>
</ul>
<div id="multiple_selection_menu">
@@ -41,7 +42,7 @@
<a class="disable" href="#"><%= t(".multi_selection_disable") %></a>
<ul class="actions">
- <%= link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove", "confirmation-text" => t("lines.actions.destroy_selection_confirm") %>
+ <%= link_to t(".delete_selected"), line_referential_lines_path(@line_referential), "data-multiple-method" => "delete", :class => "remove", "confirmation-text" => t("lines.actions.destroy_selection_confirm") %>
</ul>
<a class="select_all" href="#"><%= t(".select_all") %></a> | <a class="deselect_all" href="#"><%= t(".deselect_all") %></a>
@@ -49,5 +50,3 @@
</div>
<% end %>
-
-
diff --git a/app/views/lines/show.html.erb b/app/views/lines/show.html.erb
index 7cfbf8b23..8426319b6 100644
--- a/app/views/lines/show.html.erb
+++ b/app/views/lines/show.html.erb
@@ -13,14 +13,15 @@
<p>
<label><%= t('lines.index.color') %>: </label>
<label class="color" style='<%="#{number_style(@line)}"%>'><%= line_sticker(@line) %></label>
- </p>
+ </p>
<% end %>
<p>
<label><%= @line.human_attribute_name(:network) %>: </label>
<% if @line.network.nil? %>
- <%= t('lines.index.unset') %>
+ <%= t('lines.index.unset') %>
<% else %>
- <%= link_to @line.network.name, [@referential, @line.network] %>
+ <!-- FIXME #825 -->
+ <%#= link_to @line.network.name, [@referential, @line.network] %>
<% end %>
</p>
<p>
@@ -28,7 +29,8 @@
<% if @line.company.nil? %>
<%= t('lines.index.unset') %>
<% else %>
- <%= link_to @line.company.name, [@referential, @line.company] %>
+ <!-- FIXME #825 -->
+ <%#= link_to @line.company.name, [@referential, @line.company] %>
<% end %>
</p>
<p>
@@ -69,7 +71,7 @@
<br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count %>
<br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_non_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count %>
<br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_null_mrs_vj") %> : <%= @line.vehicle_journeys.count -
- (@line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count +
+ (@line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count +
@line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count) %>
</p>
<p>
@@ -87,15 +89,15 @@
<% if @line.flexible_service.nil? %>
(<%= @line.human_attribute_name("default_fs_msg") %>)
<% end %>
- : <%= @line.vehicle_journeys.count -
- (@line.vehicle_journeys.where("flexible_service = ?", true).count +
+ : <%= @line.vehicle_journeys.count -
+ (@line.vehicle_journeys.where("flexible_service = ?", true).count +
@line.vehicle_journeys.where("flexible_service = ?", false).count) %>
</p>
<p>
<label><%= @line.human_attribute_name("footnotes") %>: </label>
<ul>
<% @line.footnotes.each do |footnote| %>
- <li><%= footnote.code %> : <%= footnote.label %></li>
+ <li><%= footnote.code %> : <%= footnote.label %></li>
<% end %>
</ul>
</p>
@@ -114,7 +116,8 @@
<p class="after_map" />
<h3 class="routes"><%= t('.itineraries') %></h3>
<div class="routes paginated_content">
- <%= paginated_content @routes, "routes/route" %>
+ <!-- FIXME #825 -->
+ <%#= paginated_content @routes, "routes/route" %>
</div>
<% if @line.group_of_lines.any? %>
@@ -126,11 +129,12 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li>
- <li><%= link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), :class => "edit" %></li>
- <li><%= link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), :method => :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, :class => "remove" %></li>
+ <li><%= link_to t('lines.actions.new'), new_line_referential_line_path(@line_referential), :class => "add" %></li>
+ <li><%= link_to t('lines.actions.edit'), edit_line_referential_line_path(@line_referential, @line), :class => "edit" %></li>
+ <li><%= link_to t('lines.actions.destroy'), line_referential_line_path(@line_referential, @line), :method => :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, :class => "remove" %></li>
<% if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2) %>
- <li><%= link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), :class => "add" %></li>
+ <!-- FIXME #825 -->
+ <li><%#= link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), :class => "add" %></li>
<% end %>
</ul>
<%= creation_tag(@line) %>
diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb
index 1a309f718..e3e5c5d5d 100644
--- a/config/initializers/apartment.rb
+++ b/config/initializers/apartment.rb
@@ -17,7 +17,7 @@ Apartment.configure do |config|
#
# config.excluded_models = %w{Tenant}
#
- config.excluded_models = ["Referential", "Organisation", "User", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey", "RuleParameterSet", "StopAreaReferential", "Chouette::StopArea", "LineReferential", "Chouette::Line"]
+ config.excluded_models = ["Referential", "Organisation", "User", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey", "RuleParameterSet", "StopAreaReferential", "Chouette::StopArea", "LineReferential", "Chouette::Line", "Chouette::GroupOfLine"]
# use postgres schemas?
config.use_schemas = true
diff --git a/config/routes.rb b/config/routes.rb
index 19cb60538..60318aeb0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -43,7 +43,10 @@ ChouetteIhm::Application.routes.draw do
end
resources :stop_area_referentials
- resources :line_referentials, :only => [:show]
+ resources :line_referentials, :only => [:show] do
+ resources :lines
+ resources :group_of_lines
+ end
resources :referentials do
resources :api_keys
diff --git a/db/migrate/20160511082825_add_line_referential_to_lines.rb b/db/migrate/20160511082825_add_line_referential_to_lines.rb
new file mode 100644
index 000000000..e44ca4689
--- /dev/null
+++ b/db/migrate/20160511082825_add_line_referential_to_lines.rb
@@ -0,0 +1,5 @@
+class AddLineReferentialToLines < ActiveRecord::Migration
+ def change
+ add_reference :lines, :line_referential, index: true
+ end
+end
diff --git a/db/migrate/20160511082825_add_line_referential_to_stop_areas.rb b/db/migrate/20160511082825_add_line_referential_to_stop_areas.rb
deleted file mode 100644
index f71f5ee45..000000000
--- a/db/migrate/20160511082825_add_line_referential_to_stop_areas.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class AddLineReferentialToStopAreas < ActiveRecord::Migration
- def change
- add_reference :stop_areas, :line_referential, index: true
- end
-end
diff --git a/db/migrate/20160512110510_add_line_referential_to_group_of_lines.rb b/db/migrate/20160512110510_add_line_referential_to_group_of_lines.rb
new file mode 100644
index 000000000..f0081448b
--- /dev/null
+++ b/db/migrate/20160512110510_add_line_referential_to_group_of_lines.rb
@@ -0,0 +1,5 @@
+class AddLineReferentialToGroupOfLines < ActiveRecord::Migration
+ def change
+ add_reference :group_of_lines, :line_referential, index: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index dcd0e162f..f7245dd98 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: 20160511094753) do
+ActiveRecord::Schema.define(version: 20160512110510) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -200,8 +200,10 @@ ActiveRecord::Schema.define(version: 20160511094753) do
t.string "name"
t.string "comment"
t.string "registration_number"
+ t.integer "line_referential_id"
end
+ add_index "group_of_lines", ["line_referential_id"], :name => "index_group_of_lines_on_line_referential_id"
add_index "group_of_lines", ["objectid"], :name => "group_of_lines_objectid_key", :unique => true
create_table "group_of_lines_lines", id: false, force: true do |t|
@@ -291,8 +293,10 @@ ActiveRecord::Schema.define(version: 20160511094753) do
t.string "color", limit: 6
t.string "text_color", limit: 6
t.string "stable_id"
+ t.integer "line_referential_id"
end
+ add_index "lines", ["line_referential_id"], :name => "index_lines_on_line_referential_id"
add_index "lines", ["objectid"], :name => "lines_objectid_key", :unique => true
add_index "lines", ["registration_number"], :name => "lines_registration_number_key"
@@ -359,10 +363,10 @@ ActiveRecord::Schema.define(version: 20160511094753) do
t.integer "object_version"
t.datetime "creation_time"
t.string "creator_id"
- t.spatial "input_geometry", limit: {:srid=>4326, :type=>"line_string"}
- t.spatial "processed_geometry", limit: {:srid=>4326, :type=>"line_string"}
t.float "distance"
t.boolean "no_processing"
+ t.spatial "input_geometry", limit: {:srid=>4326, :type=>"line_string"}
+ t.spatial "processed_geometry", limit: {:srid=>4326, :type=>"line_string"}
end
create_table "routes", force: true do |t|
@@ -433,10 +437,8 @@ ActiveRecord::Schema.define(version: 20160511094753) do
t.string "url"
t.string "time_zone"
t.integer "stop_area_referential_id"
- t.integer "line_referential_id"
end
- add_index "stop_areas", ["line_referential_id"], :name => "index_stop_areas_on_line_referential_id"
add_index "stop_areas", ["objectid"], :name => "stop_areas_objectid_key", :unique => true
add_index "stop_areas", ["parent_id"], :name => "index_stop_areas_on_parent_id"
add_index "stop_areas", ["stop_area_referential_id"], :name => "index_stop_areas_on_stop_area_referential_id"
diff --git a/spec/factories/chouette_group_of_lines.rb b/spec/factories/chouette_group_of_lines.rb
index 3309674e3..75fef2ce9 100644
--- a/spec/factories/chouette_group_of_lines.rb
+++ b/spec/factories/chouette_group_of_lines.rb
@@ -4,6 +4,8 @@ FactoryGirl.define do
sequence(:name) { |n| "Group Of Line #{n}" }
sequence(:objectid) { |n| "test:GroupOfLine:#{n}" }
sequence(:registration_number) { |n| "#{n}" }
+
+ association :line_referential
end
end
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 9a5842458..35de831b1 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -8,25 +8,27 @@ FactoryGirl.define do
association :network, :factory => :network
association :company, :factory => :company
+ association :line_referential
+
sequence(:registration_number) { |n| "test-#{n}" }
-
+
factory :line_with_stop_areas do
-
+
transient do
routes_count 2
stop_areas_count 5
end
-
+
after(:create) do |line, evaluator|
create_list(:route, evaluator.routes_count, :line => line) do |route|
create_list(:stop_area, evaluator.stop_areas_count, area_type: "Quay") do |stop_area|
create(:stop_point, :stop_area => stop_area, :route => route)
- end
+ end
end
end
-
+
factory :line_with_stop_areas_having_parent do
-
+
after(:create) do |line|
line.routes.each do |route|
route.stop_points.each do |stop_point|
diff --git a/spec/features/group_of_lines_spec.rb b/spec/features/group_of_lines_spec.rb
index 213806ed6..202f9f1c4 100644
--- a/spec/features/group_of_lines_spec.rb
+++ b/spec/features/group_of_lines_spec.rb
@@ -7,38 +7,40 @@ describe "Group of lines", :type => :feature do
let!(:network) { create(:network) }
let!(:company) { create(:company) }
let!(:line) { create(:line_with_stop_areas, :network => network, :company => company) }
- let!(:group_of_lines) { Array.new(2) { create(:group_of_line) } }
+ let!(:group_of_lines) { Array.new(2) { create(:group_of_line, line_referential: line_referential) } }
subject { group_of_lines.first }
+ let(:line_referential) { create :line_referential }
+
before :each do
- subject.lines << line
+ subject.lines << line
end
describe "list" do
it "display group of lines" do
- visit referential_group_of_lines_path(referential)
+ visit line_referential_group_of_lines_path(line_referential)
expect(page).to have_content(group_of_lines.first.name)
expect(page).to have_content(group_of_lines.last.name)
- end
+ end
end
- describe "show" do
+ describe "show" do
it "display group of line" do
- visit referential_group_of_lines_path(referential)
+ visit line_referential_group_of_lines_path(line_referential)
click_link "#{subject.name}"
expect(page).to have_content(subject.name)
end
it "display map" do
- visit referential_group_of_lines_path(referential)
+ visit line_referential_group_of_lines_path(line_referential)
click_link "#{subject.name}"
expect(page).to have_selector("#map.group_of_line")
end
end
- describe "new" do
+ describe "new" do
it "creates group of line and return to show" do
- visit referential_group_of_lines_path(referential)
+ visit line_referential_group_of_lines_path(line_referential)
click_link I18n.t('group_of_lines.actions.new')
fill_in "group_of_line[name]", :with => "Group of lines 1"
fill_in "group_of_line[registration_number]", :with => "1"
@@ -48,9 +50,9 @@ describe "Group of lines", :type => :feature do
end
end
- describe "edit and return to show" do
+ describe "edit and return to show" do
it "edit line" do
- visit referential_group_of_line_path(referential, subject)
+ visit line_referential_group_of_line_path(line_referential, subject)
click_link I18n.t('group_of_lines.actions.edit')
fill_in "group_of_line[name]", :with => "Group of lines Modified"
fill_in "group_of_line[registration_number]", :with => "test-1"
@@ -58,5 +60,5 @@ describe "Group of lines", :type => :feature do
expect(page).to have_content("Group of lines Modified")
end
end
-
+
end
diff --git a/spec/features/lines_spec.rb b/spec/features/lines_spec.rb
index cdf38f97a..91185c22e 100644
--- a/spec/features/lines_spec.rb
+++ b/spec/features/lines_spec.rb
@@ -4,39 +4,40 @@ require 'spec_helper'
describe "Lines", :type => :feature do
login_user
+ let(:line_referential) { create :line_referential }
let!(:network) { create(:network) }
let!(:company) { create(:company) }
- let!(:lines) { Array.new(2) { create(:line_with_stop_areas, :network => network, :company => company) } }
- let!(:group_of_line) { create(:group_of_line) }
+ let!(:lines) { Array.new(2) { create :line_with_stop_areas, network: network, company: company, line_referential: line_referential } }
+ let!(:group_of_line) { create(:group_of_line) }
subject { lines.first }
describe "list" do
it "display lines" do
- visit referential_lines_path(referential)
+ visit line_referential_lines_path(line_referential)
expect(page).to have_content(lines.first.name)
expect(page).to have_content(lines.last.name)
end
-
- end
- describe "show" do
+ end
+
+ describe "show" do
it "display line" do
- visit referential_lines_path(referential)
+ visit line_referential_lines_path(line_referential)
click_link "#{lines.first.name}"
expect(page).to have_content(lines.first.name)
end
it "display map" do
- visit referential_lines_path(referential)
+ visit line_referential_lines_path(line_referential)
click_link "#{lines.first.name}"
expect(page).to have_selector("#map.line")
end
-
+
end
- describe "new" do
+ describe "new" do
it "creates line and return to show" do
- visit referential_lines_path(referential)
+ visit line_referential_lines_path(line_referential)
click_link "Ajouter une ligne"
fill_in "line_name", :with => "Line 1"
fill_in "Numéro d'enregistrement", :with => "1"
@@ -46,9 +47,9 @@ describe "Lines", :type => :feature do
end
end
- describe "new with group of line", :js => true do
+ describe "new with group of line", :js => true do
it "creates line and return to show" do
- visit new_referential_line_path(referential)
+ visit new_line_referential_line_path(line_referential)
fill_in "line_name", :with => "Line 1"
fill_in "Numéro d'enregistrement", :with => "1"
fill_in "Identifiant Neptune", :with => "test:Line:999"
@@ -59,9 +60,9 @@ describe "Lines", :type => :feature do
end
end
- describe "edit and return to show" do
+ describe "edit and return to show" do
it "edit line" do
- visit referential_line_path(referential, subject)
+ visit line_referential_line_path(line_referential, subject)
click_link "Modifier cette ligne"
fill_in "line_name", :with => "Line Modified"
fill_in "Numéro d'enregistrement", :with => "test-1"
diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb
index f512e6a83..25bb1680c 100644
--- a/spec/features/routes_spec.rb
+++ b/spec/features/routes_spec.rb
@@ -9,58 +9,62 @@ describe "Routes", :type => :feature do
let!(:route2) { create(:route, :line => line) }
#let!(:stop_areas) { Array.new(4) { create(:stop_area) } }
let!(:stop_points) { Array.new(4) { create(:stop_point, :route => route) } }
-
- describe "from lines page to a line page" do
- it "display line's routes" do
- visit referential_lines_path(referential)
- click_link "#{line.name}"
- expect(page).to have_content(route.name)
- expect(page).to have_content(route2.name)
- end
- end
-
- describe "from line's page to route's page" do
- it "display route properties" do
- visit referential_line_path(referential,line)
- click_link "#{route.name}"
- expect(page).to have_content(route.name)
- expect(page).to have_content(route.number)
- end
- end
-
- describe "from line's page, create a new route" do
- it "return to line's page that display new route" do
- visit referential_line_path(referential,line)
- click_link "Ajouter une séquence d'arrêts"
- fill_in "route_name", :with => "A to B"
- fill_in "Indice", :with => "AB"
- select 'aller', :from => "route_direction_code"
- select 'aller', :from => "route_wayback_code"
- click_button("Créer séquence d'arrêts")
- expect(page).to have_content("A to B")
- end
- end
-
- describe "from line's page, select a route and edit it" do
- it "return to line's page with changed name" do
- visit referential_line_path(referential,line)
- click_link "#{route.name}"
- click_link "Modifier cette séquence d'arrêts"
- fill_in "route_name", :with => "#{route.name}-changed"
- click_button("Modifier séquence d'arrêts")
- expect(page).to have_content("#{route.name}-changed")
- end
- end
-
- describe "from line's page, select a route and delete it" do
- it "return to line's page without route name" do
- visit referential_line_path(referential,line)
- click_link "#{route.name}"
- click_link "Supprimer cette séquence d'arrêts"
- expect(page).not_to have_content(route.name)
- end
- end
+ # FIXME #825
+ # describe "from lines page to a line page" do
+ # it "display line's routes" do
+ # visit referential_lines_path(referential)
+ # click_link "#{line.name}"
+ # expect(page).to have_content(route.name)
+ # expect(page).to have_content(route2.name)
+ # end
+ # end
+
+ # FIXME #825
+ # describe "from line's page to route's page" do
+ # it "display route properties" do
+ # visit referential_line_path(referential,line)
+ # click_link "#{route.name}"
+ # expect(page).to have_content(route.name)
+ # expect(page).to have_content(route.number)
+ # end
+ # end
+
+ # FIXME #825
+ # describe "from line's page, create a new route" do
+ # it "return to line's page that display new route" do
+ # visit referential_line_path(referential,line)
+ # click_link "Ajouter une séquence d'arrêts"
+ # fill_in "route_name", :with => "A to B"
+ # fill_in "Indice", :with => "AB"
+ # select 'aller', :from => "route_direction_code"
+ # select 'aller', :from => "route_wayback_code"
+ # click_button("Créer séquence d'arrêts")
+ # expect(page).to have_content("A to B")
+ # end
+ # end
+
+ # FIXME #825
+ # describe "from line's page, select a route and edit it" do
+ # it "return to line's page with changed name" do
+ # visit referential_line_path(referential,line)
+ # click_link "#{route.name}"
+ # click_link "Modifier cette séquence d'arrêts"
+ # fill_in "route_name", :with => "#{route.name}-changed"
+ # click_button("Modifier séquence d'arrêts")
+ # expect(page).to have_content("#{route.name}-changed")
+ # end
+ # end
+
+ # FIXME #825
+ # describe "from line's page, select a route and delete it" do
+ # it "return to line's page without route name" do
+ # visit referential_line_path(referential,line)
+ # click_link "#{route.name}"
+ # click_link "Supprimer cette séquence d'arrêts"
+ # expect(page).not_to have_content(route.name)
+ # end
+ # end
describe "from route's page, select edit boarding/alighting and update it" do
it "Edits boarding/alighting properties on route stops" do
@@ -88,5 +92,5 @@ describe "Routes", :type => :feature do
click_button(I18n.t('helpers.submit.update', model: I18n.t('activerecord.models.route.one')))
end
end
-
+
end
diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb
index f522d02bd..674af2f53 100644
--- a/spec/models/chouette/stop_area_spec.rb
+++ b/spec/models/chouette/stop_area_spec.rb
@@ -12,7 +12,7 @@ describe Chouette::StopArea, :type => :model do
it { is_expected.to be_kind_of(Chouette::ObjectId) }
end
- it { is_expected.to belong_to(:line_referential) }
+ it { is_expected.to belong_to(:stop_area_referential) }
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :area_type }
it { is_expected.to validate_numericality_of :latitude }
diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb
index 654dd6685..76544f85d 100644
--- a/spec/models/chouette/trident_active_record_spec.rb
+++ b/spec/models/chouette/trident_active_record_spec.rb
@@ -28,32 +28,38 @@ describe Chouette::TridentActiveRecord, :type => :model do
end
+ def create_object(options = {})
+ options = {name: "merge1"}.merge options
+ attributes = { comment: options[:name], objectid: options[:objectid] }
+ Chouette::TimeTable.new attributes
+ end
+
describe "#prepare_auto_columns" do
it "should left objectid" do
- tm = Chouette::TimeTable.new :comment => "merge1" , :objectid => "first:Timetable:merge1"
+ tm = create_object :objectid => "first:Timetable:merge1"
tm.prepare_auto_columns
expect(tm.objectid).to eq("first:Timetable:merge1")
end
it "should add pending_id to objectid" do
- tm = Chouette::TimeTable.new :comment => "merge1"
+ tm = create_object
tm.prepare_auto_columns
expect(tm.objectid.start_with?("first:Timetable:__pending_id__")).to be_truthy
end
it "should set id to objectid" do
- tm = Chouette::TimeTable.new :comment => "merge1"
+ tm = create_object
tm.save
expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s)
end
it "should detect objectid conflicts" do
- tm = Chouette::TimeTable.new :comment => "merge1"
+ tm = create_object
tm.save
tm.objectid = "first:Timetable:"+(tm.id+1).to_s
tm.save
- tm = Chouette::TimeTable.new :comment => "merge1"
+ tm = create_object
tm.save
expect(tm.objectid).to eq("first:Timetable:"+tm.id.to_s+"_1")
end
@@ -63,53 +69,51 @@ describe Chouette::TridentActiveRecord, :type => :model do
describe "objectid" do
it "should build automatic objectid when empty" do
- g1 = Chouette::GroupOfLine.new( :name => "g1")
+ g1 = create_object
g1.save
- expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s)
+ expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s)
end
it "should build automatic objectid with fixed when only suffix given" do
- g1 = Chouette::GroupOfLine.new( :name => "g1")
+ g1 = create_object
g1.objectid = "toto"
g1.save
- expect(g1.objectid).to eq("first:GroupOfLine:toto")
+ expect(g1.objectid).to eq("first:Timetable:toto")
end
-
+
it "should build automatic objectid with extension when already exists" do
- g1 = Chouette::GroupOfLine.new( :name => "g1")
+ g1 = create_object
g1.save
cnt = g1.id + 1
- g1.objectid = "first:GroupOfLine:"+cnt.to_s
+ g1.objectid = "first:Timetable:"+cnt.to_s
g1.save
- g2 = Chouette::GroupOfLine.new( :name => "g2")
+ g2 = create_object
g2.save
- expect(g2.objectid).to eq("first:GroupOfLine:"+g2.id.to_s+"_1")
+ expect(g2.objectid).to eq("first:Timetable:"+g2.id.to_s+"_1")
end
-
+
it "should build automatic objectid with extension when already exists" do
- g1 = Chouette::GroupOfLine.new( :name => "g1")
+ g1 = create_object
g1.save
cnt = g1.id + 2
- g1.objectid = "first:GroupOfLine:"+cnt.to_s
+ g1.objectid = "first:Timetable:"+cnt.to_s
g1.save
- g2 = Chouette::GroupOfLine.new( :name => "g2")
- g2.objectid = "first:GroupOfLine:"+cnt.to_s+"_1"
+ g2 = create_object
+ g2.objectid = "first:Timetable:"+cnt.to_s+"_1"
g2.save
- g3 = Chouette::GroupOfLine.new( :name => "g3")
+ g3 = create_object
g3.save
- expect(g3.objectid).to eq("first:GroupOfLine:"+g3.id.to_s+"_2")
+ expect(g3.objectid).to eq("first:Timetable:"+g3.id.to_s+"_2")
end
-
+
it "should build automatic objectid when id cleared" do
- g1 = Chouette::GroupOfLine.new( :name => "g1")
- g1.objectid = "first:GroupOfLine:xxxx"
+ g1 = create_object
+ g1.objectid = "first:Timetable:xxxx"
g1.save
g1.objectid = nil
g1.save
- expect(g1.objectid).to eq("first:GroupOfLine:"+g1.id.to_s)
+ expect(g1.objectid).to eq("first:Timetable:"+g1.id.to_s)
end
end
end
-
-
diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb
index 024bfac07..259c7035a 100644
--- a/spec/models/line_spec.rb
+++ b/spec/models/line_spec.rb
@@ -1,58 +1,9 @@
require 'spec_helper'
-describe "sdflkjskdjf" do
+describe Chouette::Line, type: :model do
subject { create(:line) }
- def set_large_object_id( line)
- line.update_attributes :objectid => "AA:Line:123456789012345"
- end
+ it { is_expected.to belong_to(:line_referential) }
- describe "validation objectid unique constraint" do
- let(:referential){subject.referential}
- let(:objectid_a){ "A:Line:1234" }
- let(:objectid_b){ "B:Line:1234" }
- let!(:second_line){ create( :line, :objectid => objectid_a, :registration_number => "123456") }
- context "when referential works with HUB" do
- before( :each) do
- referential.update_attributes :data_format => "hub"
- subject.update_attributes :objectid => objectid_a
- end
- it "should have objectid with a third part shorter than 14 char" do
- subject.update_attributes :objectid => objectid_b
- subject.should_not be_valid
- end
- end
- context "when referential doesn't works with HUB" do
- before( :each) do
- referential.update_attributes :data_format => "hub"
- end
- #it "should have objectid with a third part shorter than 14 char" do
- # subject.update_attributes :objectid => objectid_b, :registration_number => '324'
- # subject.should be_valid
- #end
- end
- end
- describe "validation objectid size" do
- let(:referential){subject.referential}
- context "when referential works with HUB" do
- before( :each) do
- referential.update_attributes :data_format => "hub"
- end
- it "should have objectid with a third part shorter than 14 char" do
- set_large_object_id( subject)
- subject.should_not be_valid
- end
- end
- context "when referential doesn't works with HUB" do
- before( :each) do
- referential.update_attributes :data_format => "hub"
- end
- #it "should have objectid with a third part shorter than 14 char" do
- # set_large_object_id( subject)
- # subject.should be_valid
- #end
- end
- end
end
-
diff --git a/spec/views/lines/edit.html.erb_spec.rb b/spec/views/lines/edit.html.erb_spec.rb
index 08f7a547b..6cd2940f5 100644
--- a/spec/views/lines/edit.html.erb_spec.rb
+++ b/spec/views/lines/edit.html.erb_spec.rb
@@ -1,15 +1,16 @@
require 'spec_helper'
describe "/lines/edit", :type => :view do
- assign_referential
+
let!(:network) { create(:network) }
let!(:company) { create(:company) }
let!(:line) { assign(:line, create(:line, :network => network, :company => company)) }
let!(:lines) { Array.new(2) { create(:line, :network => network, :company => company) } }
+ let!(:line_referential) { assign :line_referential, line.line_referential }
describe "test" do
it "should render h2 with the group name" do
- render
+ render
expect(rendered).to have_selector("h2", :text => Regexp.new(line.name))
end
end
diff --git a/spec/views/lines/index.html.erb_spec.rb b/spec/views/lines/index.html.erb_spec.rb
index 83b981a5a..494f58040 100644
--- a/spec/views/lines/index.html.erb_spec.rb
+++ b/spec/views/lines/index.html.erb_spec.rb
@@ -2,26 +2,26 @@ require 'spec_helper'
describe "/lines/index", :type => :view do
- assign_referential
+ let!(:line_referential) { assign :line_referential, create(:line_referential) }
let!(:network) { create :network }
let!(:company) { create :company }
- let!(:lines) { assign :lines, Array.new(2) { create(:line, :network => network, :company => company) }.paginate }
+ let!(:lines) { assign :lines, Array.new(2) { create(:line, line_referential: line_referential, network: network, company: company) }.paginate }
let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
before :each do
allow(view).to receive(:link_with_search).and_return("#")
end
- it "should render a show link for each group" do
- render
- lines.each do |line|
- expect(rendered).to have_selector(".line a[href='#{view.referential_line_path(referential, line)}']", :text => line.name)
+ it "should render a show link for each group" do
+ render
+ lines.each do |line|
+ expect(rendered).to have_selector(".line a[href='#{view.line_referential_line_path(line_referential, line)}']", :text => line.name)
end
end
it "should render a link to create a new group" do
render
- expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_line_path(referential)}']")
+ expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_line_path(line_referential)}']")
end
end
diff --git a/spec/views/lines/new.html.erb_spec.rb b/spec/views/lines/new.html.erb_spec.rb
index f0321fd64..8b09f9ce9 100644
--- a/spec/views/lines/new.html.erb_spec.rb
+++ b/spec/views/lines/new.html.erb_spec.rb
@@ -1,13 +1,14 @@
require 'spec_helper'
describe "/lines/new", :type => :view do
- assign_referential
+
let!(:network) { create(:network) }
let!(:company) { create(:company) }
let!(:line) { assign(:line, build(:line, :network => network, :company => company )) }
+ let!(:line_referential) { assign :line_referential, line.line_referential }
describe "form" do
-
+
it "should render input for name" do
render
expect(rendered).to have_selector("form") do
diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb
index 8ff4357ac..4b809c268 100644
--- a/spec/views/lines/show.html.erb_spec.rb
+++ b/spec/views/lines/show.html.erb_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
describe "/lines/show", :type => :view do
-
- assign_referential
+
let!(:line) { assign :line, create(:line) }
+ let!(:line_referential) { assign :line_referential, line.line_referential }
let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate }
let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }
@@ -19,13 +19,12 @@ describe "/lines/show", :type => :view do
it "should render a link to edit the line" do
render
- expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_line_path(referential, line)}']")
+ expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_line_referential_line_path(line_referential, line)}']")
end
it "should render a link to remove the line" do
render
- expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_line_path(referential, line)}'][class='remove']")
+ expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.line_referential_line_path(line_referential, line)}'][class='remove']")
end
end
-