diff options
| author | Alban Peignier | 2016-05-13 12:40:26 +0200 |
|---|---|---|
| committer | Alban Peignier | 2016-05-13 12:40:26 +0200 |
| commit | 58b9e12ec090a5ec6d9e78626574acc1cbb1a515 (patch) | |
| tree | a13e2cc079690997e509b49cc0d85f5267909f01 | |
| parent | 020cf3b06409acae569c23636ee91085fbeb5699 (diff) | |
| parent | 93ba001567f4455c09560f1af5b4bfb6dc782229 (diff) | |
| download | chouette-core-58b9e12ec090a5ec6d9e78626574acc1cbb1a515.tar.bz2 | |
Merge branch 'lines_lines_referentials_association'
45 files changed, 552 insertions, 512 deletions
@@ -127,6 +127,7 @@ group :development do end group :test, :development do + gem 'awesome_print' gem 'pry-rails' gem 'rspec-rails', '~> 3.1.0' gem 'fakeweb' diff --git a/Gemfile.lock b/Gemfile.lock index a1f6e8b70..3b97d82ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,6 +53,7 @@ GEM ast (2.0.0) astrolabe (1.3.0) parser (>= 2.2.0.pre.3, < 3.0) + awesome_print (1.6.1) bcrypt (3.1.10) bcrypt (3.1.10-java) better_errors (2.1.1) @@ -472,6 +473,7 @@ DEPENDENCIES acts_as_list (~> 0.6.0) acts_as_tree (~> 2.1.0) apartment (~> 1.0.0) + awesome_print better_errors binding_of_caller breadcrumbs_on_rails 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/access_point.rb b/app/models/chouette/access_point.rb index 317b19b26..da1f9524a 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -9,10 +9,10 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord has_many :access_links, :dependent => :destroy belongs_to :stop_area - + attr_accessor :access_point_type attr_writer :coordinates - + validates_presence_of :name validates_presence_of :access_type @@ -33,14 +33,14 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord if self.latitude.nil? || self.longitude.nil? "" else - self.latitude.to_s+","+self.longitude.to_s + self.latitude.to_s+","+self.longitude.to_s end end - + def coordinates @coordinates || combine_lat_lng end - + def coordinates_to_lat_lng if ! @coordinates.nil? if @coordinates.empty? @@ -50,9 +50,9 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord self.latitude = BigDecimal.new(@coordinates.split(",").first) self.longitude = BigDecimal.new(@coordinates.split(",").last) end - @coordinates = nil + @coordinates = nil end - end + end def to_lat_lng Geokit::LatLng.new(latitude, longitude) if latitude and longitude @@ -67,7 +67,7 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" end - def position + def position geometry end @@ -78,7 +78,7 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord self.longitude = position.lng end - def default_position + def default_position stop_area.geometry or stop_area.default_position end @@ -87,7 +87,7 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord access_type && Chouette::AccessPointType.new(access_type.underscore) end - def access_point_type=(access_point_type) + def access_point_type=(access_point_type) self.access_type = (access_point_type ? access_point_type.camelcase : nil) end diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb index f00db3164..0b91f3442 100644 --- a/app/models/chouette/group_of_line.rb +++ b/app/models/chouette/group_of_line.rb @@ -1,18 +1,21 @@ -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" - + has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name' validates_presence_of :name attr_reader :line_tokens - + def self.nullable_attributes [:comment] end - + def commercial_stop_areas Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq end @@ -20,10 +23,9 @@ class Chouette::GroupOfLine < Chouette::TridentActiveRecord def stop_areas Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id}) end - + def line_tokens=(ids) self.line_ids = ids.split(",") end end - diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index b1e9940d3..351cb0b0e 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" @@ -17,8 +21,9 @@ class Chouette::Line < Chouette::TridentActiveRecord attr_reader :group_of_line_tokens attr_accessor :transport_mode - validates_presence_of :network - validates_presence_of :company + # FIXME #825 + #validates_presence_of :network + #validates_presence_of :company validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true validates_format_of :stable_id, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true 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/line_referentials/show.html.erb b/app/views/line_referentials/show.html.erb index e952cd9ed..807010986 100644 --- a/app/views/line_referentials/show.html.erb +++ b/app/views/line_referentials/show.html.erb @@ -2,6 +2,20 @@ <%= title_tag "Référentiel de lignes #{@line_referential.name}" %> <div class="summary"> + +</div> + +<div class="panel panel-default"> + <ul class="list-group" width="75%"> + <li class="list-group-item"> + <span class="badge"><%= @line_referential.group_of_lines.size %></span> + <%= link_to Referential.human_attribute_name("group_of_lines"), line_referential_group_of_lines_path(@line_referential) %> + </li> + <li class="list-group-item"> + <span class="badge"><%= @line_referential.lines.size %></span> + <%= link_to Referential.human_attribute_name("lines"), line_referential_lines_path(@line_referential) %> + </li> + </ul> </div> <% content_for :sidebar do %> 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> <%= @line.human_attribute_name("number_of_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count %> <br> <%= @line.human_attribute_name("number_of_non_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count %> <br> <%= @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 9b8d3c6a6..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"] + 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 dfa9f4655..7bbc070f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,7 +45,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/20160511094753_disable_line_foreign_keys.rb b/db/migrate/20160511094753_disable_line_foreign_keys.rb new file mode 100644 index 000000000..ffc665344 --- /dev/null +++ b/db/migrate/20160511094753_disable_line_foreign_keys.rb @@ -0,0 +1,21 @@ +class DisableLineForeignKeys < ActiveRecord::Migration + def change + disable_foreign_key :lines, :line_company_fkey + disable_foreign_key :lines, :line_ptnetwork_fkey + disable_foreign_key :routing_constraints_lines, :routingconstraint_line_fkey + disable_foreign_key :routes, :route_line_fkey + disable_foreign_key :group_of_lines_lines, :groupofline_line_fkey + end + + def disable_foreign_key(table, name) + if foreign_key?(table, name) + remove_foreign_key table, name: name + end + end + + def foreign_key?(table, name) + @connection.foreign_keys(table).any? do |foreign_key| + foreign_key.options[:name] == name.to_s + end + 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 0f7a5d74b..dadead9e5 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: 20160512105643) 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: 20160512105643) 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| @@ -209,6 +211,18 @@ ActiveRecord::Schema.define(version: 20160512105643) do t.integer "line_id", limit: 8 end + create_table "jobs", force: true do |t| + t.string "action" + t.datetime "created" + t.string "filename" + t.text "parameters" + t.string "referential" + t.datetime "started" + t.string "status" + t.string "type" + t.datetime "updated" + end + create_table "journey_frequencies", force: true do |t| t.integer "vehicle_journey_id", limit: 8 t.time "scheduled_headway_interval", null: false @@ -237,7 +251,7 @@ ActiveRecord::Schema.define(version: 20160512105643) do create_table "journey_patterns", force: true do |t| t.integer "route_id", limit: 8 - t.string "objectid", null: false + t.string "objectid", null: false t.integer "object_version" t.datetime "creation_time" t.string "creator_id" @@ -247,10 +261,12 @@ ActiveRecord::Schema.define(version: 20160512105643) do t.string "published_name" t.integer "departure_stop_point_id", limit: 8 t.integer "arrival_stop_point_id", limit: 8 - t.integer "section_status", default: 0, null: false + t.integer "route_section_ids", default: [], array: true + t.integer "section_status", default: 0, null: false end add_index "journey_patterns", ["objectid"], :name => "journey_patterns_objectid_key", :unique => true + add_index "journey_patterns", ["route_section_ids"], :name => "index_journey_patterns_on_route_section_ids" create_table "journey_patterns_stop_points", id: false, force: true do |t| t.integer "journey_pattern_id", limit: 8 @@ -291,11 +307,19 @@ ActiveRecord::Schema.define(version: 20160512105643) 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" + create_table "links", id: false, force: true do |t| + t.integer "job_id", limit: 8, null: false + t.string "rel" + t.string "type" + end + create_table "networks", force: true do |t| t.string "objectid", null: false t.integer "object_version" @@ -362,8 +386,8 @@ ActiveRecord::Schema.define(version: 20160512105643) do end create_table "route_sections", force: true do |t| - t.integer "departure_id", limit: 8 - t.integer "arrival_id", limit: 8 + t.integer "departure_id" + t.integer "arrival_id" t.string "objectid", null: false t.integer "object_version" t.datetime "creation_time" @@ -614,51 +638,12 @@ ActiveRecord::Schema.define(version: 20160512105643) do add_index "vehicle_journeys", ["route_id"], :name => "index_vehicle_journeys_on_route_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 "group_of_lines_lines", "lines", name: "groupofline_line_fkey", dependent: :delete - add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", dependent: :nullify add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", dependent: :nullify add_foreign_key "journey_pattern_sections", "journey_patterns", name: "journey_pattern_sections_journey_pattern_id_fk", dependent: :delete add_foreign_key "journey_pattern_sections", "route_sections", name: "journey_pattern_sections_route_section_id_fk", dependent: :delete - add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", dependent: :delete - add_foreign_key "journey_patterns", "stop_points", name: "arrival_point_fkey", column: "arrival_stop_point_id", dependent: :nullify - add_foreign_key "journey_patterns", "stop_points", name: "departure_point_fkey", column: "departure_stop_point_id", dependent: :nullify - - add_foreign_key "journey_patterns_stop_points", "journey_patterns", name: "jpsp_jp_fkey", dependent: :delete - add_foreign_key "journey_patterns_stop_points", "stop_points", name: "jpsp_stoppoint_fkey", dependent: :delete - - add_foreign_key "lines", "companies", name: "line_company_fkey", dependent: :nullify - add_foreign_key "lines", "networks", name: "line_ptnetwork_fkey", dependent: :nullify - - add_foreign_key "routes", "lines", name: "route_line_fkey", dependent: :delete - add_foreign_key "routes", "routes", name: "route_opposite_route_fkey", column: "opposite_route_id", dependent: :nullify - - add_foreign_key "routing_constraints_lines", "lines", name: "routingconstraint_line_fkey", dependent: :delete - - add_foreign_key "stop_areas", "stop_areas", name: "area_parent_fkey", column: "parent_id", dependent: :nullify - - add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_child_fkey", column: "child_id", dependent: :delete - add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_parent_fkey", column: "parent_id", dependent: :delete - - add_foreign_key "stop_points", "routes", name: "stoppoint_route_fkey", dependent: :delete - - add_foreign_key "time_table_dates", "time_tables", name: "tm_date_fkey", dependent: :delete - - add_foreign_key "time_table_periods", "time_tables", name: "tm_period_fkey", dependent: :delete - - add_foreign_key "time_tables_vehicle_journeys", "time_tables", name: "vjtm_tm_fkey", dependent: :delete - add_foreign_key "time_tables_vehicle_journeys", "vehicle_journeys", name: "vjtm_vj_fkey", dependent: :delete - - add_foreign_key "vehicle_journey_at_stops", "stop_points", name: "vjas_sp_fkey", dependent: :delete - add_foreign_key "vehicle_journey_at_stops", "vehicle_journeys", name: "vjas_vj_fkey", dependent: :delete - - add_foreign_key "vehicle_journeys", "companies", name: "vj_company_fkey", dependent: :nullify - add_foreign_key "vehicle_journeys", "journey_patterns", name: "vj_jp_fkey", dependent: :delete - add_foreign_key "vehicle_journeys", "routes", name: "vj_route_fkey", dependent: :delete + add_foreign_key "links", "jobs", name: "fk_n5ypxycc1stckgkm6ust2l6on" end diff --git a/db/seeds.rb b/db/seeds.rb index a035d1518..9cfcc17db 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,6 +10,11 @@ stif = Organisation.find_or_create_by(name: "STIF") StopAreaReferential.find_or_create_by(name: "Reflex") do |referential| referential.add_member stif, owner: true end -LineReferential.find_or_create_by(name: "CodifLigne") do |referential| + +line_referential = LineReferential.find_or_create_by(name: "CodifLigne") do |referential| referential.add_member stif, owner: true end + +10.times do |n| + line_referential.lines.find_or_create_by name: "Ligne Test #{n}" +end 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/active_record_spec.rb b/spec/models/chouette/active_record_spec.rb index 087e41576..110807e51 100644 --- a/spec/models/chouette/active_record_spec.rb +++ b/spec/models/chouette/active_record_spec.rb @@ -7,9 +7,9 @@ describe Chouette::ActiveRecord, :type => :model do describe "table_name" do it "should return line for Chouette::Line" do - expect(Chouette::Line.table_name).to eq("lines") + expect(Chouette::Line.table_name).to eq("public.lines") end - + it "should return ptnetwork for Chouette::Network" do expect(Chouette::Network.table_name).to eq("networks") end @@ -25,7 +25,7 @@ describe Chouette::ActiveRecord, :type => :model do end describe "method_missing" do - + it "should support method with additionnal underscores" do stop_area = Chouette::StopArea.new expect(stop_area.area_type).to eq(stop_area.area_type) @@ -35,7 +35,7 @@ describe Chouette::ActiveRecord, :type => :model do describe "respond_to?" do - + it "should respond to method with additionnal underscores" do stop_area = Chouette::StopArea.new expect(stop_area.respond_to?(:area_type)).to be_truthy @@ -49,7 +49,7 @@ describe Chouette::ActiveRecord, :type => :model do # let(:name) { :lines } # let(:options) { {} } # let(:active_record) { Chouette::Network } - + # let(:modified_options) { {:modified => true} } # it "should invoke create_reflection_without_chouette_naming with modified options" do @@ -87,7 +87,7 @@ end # end # describe "class_name" do - + # it "should be Chouette::Line when name is line" do # allow(subject).to receive_messages :name => "line" # expect(subject.class_name).to eq("Chouette::Line") @@ -102,7 +102,7 @@ end # describe "options" do - + # it "should define class_name if not" do # allow(subject).to receive_messages :options => {}, :class_name => "class_name" # expect(subject.options_with_default[:class_name]).to eq("class_name") @@ -114,7 +114,7 @@ end # end # end - + # end diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index 66932cfd6..d49329118 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -16,7 +16,7 @@ describe Chouette::GroupOfLine, :type => :model do expect(subject.stop_areas.count).to eq(route.stop_points.count) end end - + context "#line_tokens=" do let!(:line1){create(:line)} let!(:line2){create(:line)} diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index 3b19aa17c..674af2f53 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -12,12 +12,13 @@ describe Chouette::StopArea, :type => :model do it { is_expected.to be_kind_of(Chouette::ObjectId) } end + 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 } it { is_expected.to validate_numericality_of :longitude } - + describe ".latitude" do it "should accept -90 value" do subject = create :stop_area, :area_type => "BoardingPosition" @@ -89,20 +90,20 @@ describe Chouette::StopArea, :type => :model do subject.latitude = nil expect(subject.valid?).to be_falsey end - end - + end + describe ".children_in_depth" do it "should return all the deepest children from stop area" do subject = create :stop_area, :area_type => "StopPlace" - commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject + commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point quay = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" expect(subject.children_in_depth).to match_array([commercial_stop_point, commercial_stop_point2, quay]) end it "should return only the deepest children from stop area" do subject = create :stop_area, :area_type => "StopPlace" - commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject + commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint", :parent => subject commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint", :parent => commercial_stop_point quay = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" expect(subject.children_at_base).to match_array([quay]) @@ -139,31 +140,31 @@ describe Chouette::StopArea, :type => :model do end end - describe ".possible_children" do - + describe ".possible_children" do + it "should find no possible descendant for stop area type quay" do subject = create :stop_area, :area_type => "Quay" - expect(subject.possible_children).to eq([]) + expect(subject.possible_children).to eq([]) end it "should find no possible descendant for stop area type boarding position" do subject = create :stop_area, :area_type => "BoardingPosition" - expect(subject.possible_children).to eq([]) + expect(subject.possible_children).to eq([]) end it "should find descendant of type quay or boarding position for stop area type commercial stop point" do subject = create :stop_area, :area_type => "CommercialStopPoint" - expect(subject.possible_children).to match_array([quay, boarding_position]) + expect(subject.possible_children).to match_array([quay, boarding_position]) end it "should find no children of type stop place or commercial stop point for stop area type stop place" do subject = create :stop_area, :area_type => "StopPlace" - expect(subject.possible_children).to match_array([stop_place, commercial_stop_point]) + expect(subject.possible_children).to match_array([stop_place, commercial_stop_point]) end it "should find no children of type ITL for stop area type ITL" do subject = create :stop_area, :area_type => "ITL" - expect(subject.possible_children).to match_array([stop_place, commercial_stop_point, quay, boarding_position]) + expect(subject.possible_children).to match_array([stop_place, commercial_stop_point, quay, boarding_position]) end end @@ -172,23 +173,23 @@ describe Chouette::StopArea, :type => :model do it "should find parent type commercial stop point for stop area type boarding position" do subject = create :stop_area, :area_type => "BoardingPosition" - expect(subject.possible_parents).to eq([commercial_stop_point]) + expect(subject.possible_parents).to eq([commercial_stop_point]) end it "should find parent type commercial stop point for stop area type quay" do subject = create :stop_area, :area_type => "Quay" - expect(subject.possible_parents).to eq([commercial_stop_point]) - end + expect(subject.possible_parents).to eq([commercial_stop_point]) + end it "should find parent type stop place for stop area type commercial stop point" do subject = create :stop_area, :area_type => "CommercialStopPoint" - expect(subject.possible_parents).to eq([stop_place]) - end + expect(subject.possible_parents).to eq([stop_place]) + end it "should find parent type stop place for stop area type stop place" do subject = create :stop_area, :area_type => "StopPlace" - expect(subject.possible_parents).to eq([stop_place]) - end + expect(subject.possible_parents).to eq([stop_place]) + end end @@ -197,7 +198,7 @@ describe Chouette::StopArea, :type => :model do let(:stop_area) { create :stop_area, :latitude => 1, :longitude => 1 } let(:stop_area2) { create :stop_area, :latitude => 1, :longitude => 1 } - + it "should find a StopArea at 300m from given origin" do expect(Chouette::StopArea.near(stop_area.to_lat_lng.endpoint(0, 0.250, :units => :kms))).to eq([stop_area]) end @@ -209,7 +210,7 @@ describe Chouette::StopArea, :type => :model do end describe "#to_lat_lng" do - + it "should return nil if latitude is nil" do subject.latitude = nil expect(subject.to_lat_lng).to be_nil @@ -223,7 +224,7 @@ describe Chouette::StopArea, :type => :model do end describe "#geometry" do - + it "should be nil when to_lat_lng is nil" do allow(subject).to receive_messages :to_lat_lng => nil expect(subject.geometry).to be_nil @@ -232,7 +233,7 @@ describe Chouette::StopArea, :type => :model do end describe ".bounds" do - + it "should return transform coordinates in floats" do allow(Chouette::StopArea.connection).to receive_messages :select_rows => [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]] expect(GeoRuby::SimpleFeatures::Envelope).to receive(:from_coordinates).with([[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]]) @@ -242,7 +243,7 @@ describe Chouette::StopArea, :type => :model do end describe "#default_position" do - + it "should return referential center point when StopArea.bounds is nil" do allow(Chouette::StopArea).to receive_messages :bounds => nil expect(subject.default_position).not_to be_nil @@ -257,39 +258,39 @@ describe Chouette::StopArea, :type => :model do describe "#children_at_base" do it "should have 2 children_at_base" do - subject = create :stop_area, :area_type => "StopPlace" + subject = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" expect(subject.children_at_base.size).to eq(2) end - end + end describe "#generic_access_link_matrix" do it "should have no access_links in matrix with no access_point" do - subject = create :stop_area, :area_type => "StopPlace" + subject = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject expect(subject.generic_access_link_matrix.size).to eq(0) end it "should have 4 generic_access_links in matrix with 2 access_points" do - subject = create :stop_area, :area_type => "StopPlace" + subject = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject access_point1 = create :access_point, :stop_area => subject access_point2 = create :access_point, :stop_area => subject expect(subject.generic_access_link_matrix.size).to eq(4) end - end + end describe "#detail_access_link_matrix" do it "should have no access_links in matrix with no access_point" do - subject = create :stop_area, :area_type => "StopPlace" + subject = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" expect(subject.detail_access_link_matrix.size).to eq(0) end it "should have 8 detail_access_links in matrix with 2 children_at_base and 2 access_points" do - subject = create :stop_area, :area_type => "StopPlace" + subject = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => subject quay1 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" quay2 = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" @@ -297,10 +298,10 @@ describe Chouette::StopArea, :type => :model do access_point2 = create :access_point, :stop_area => subject expect(subject.detail_access_link_matrix.size).to eq(8) end - end + end describe "#parents" do it "should return parent hireachy list" do - stop_place = create :stop_area, :area_type => "StopPlace" + stop_place = create :stop_area, :area_type => "StopPlace" commercial_stop_point = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place subject = create :stop_area, :parent => commercial_stop_point, :area_type => "Quay" expect(subject.parents.size).to eq(2) @@ -310,24 +311,24 @@ describe Chouette::StopArea, :type => :model do expect(subject.parents.size).to eq(0) end end - + describe "#clean_invalid_access_links" do it "should remove invalid access links" do # subject is a CSP with a SP as parent, a quay as child # 2 access_points of SP have access_link, one on subject, one on subject child # when detaching subject from SP, both access_links must be deleted - stop_place = create :stop_area, :area_type => "StopPlace" + stop_place = create :stop_area, :area_type => "StopPlace" subject = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place access_point1 = create :access_point, :stop_area => stop_place access_point2 = create :access_point, :stop_area => stop_place quay = create :stop_area, :parent => subject, :area_type => "Quay" access_link1 = create :access_link, :stop_area => subject, :access_point => access_point1 access_link2 = create :access_link, :stop_area => quay, :access_point => access_point2 - subject.save + subject.save expect(subject.access_links.size).to eq(1) expect(quay.access_links.size).to eq(1) subject.parent=nil - subject.save + subject.save subject.reload expect(subject.access_links.size).to eq(0) expect(quay.access_links.size).to eq(0) @@ -337,7 +338,7 @@ describe Chouette::StopArea, :type => :model do # 2 access_points, one of SP, one of CSP have access_link on subject # when changing subject CSP to another CSP of same SP # one access_links must be kept - stop_place = create :stop_area, :area_type => "StopPlace" + stop_place = create :stop_area, :area_type => "StopPlace" commercial_stop_point1 = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place commercial_stop_point2 = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place access_point1 = create :access_point, :stop_area => stop_place @@ -345,15 +346,15 @@ describe Chouette::StopArea, :type => :model do subject = create :stop_area, :parent => commercial_stop_point1, :area_type => "Quay" access_link1 = create :access_link, :stop_area => subject, :access_point => access_point1 access_link2 = create :access_link, :stop_area => subject, :access_point => access_point2 - subject.save + subject.save expect(subject.access_links.size).to eq(2) subject.parent=commercial_stop_point2 - subject.save + subject.save subject.reload expect(subject.access_links.size).to eq(1) end end - + describe "#coordinates" do it "should convert coordinates into latitude/longitude" do subject = create :stop_area, :area_type => "BoardingPosition", :coordinates => "45.123,120.456" @@ -422,7 +423,7 @@ describe Chouette::StopArea, :type => :model do describe "#duplicate" do it "should be a copy of" do - stop_place = create :stop_area, :area_type => "StopPlace" + stop_place = create :stop_area, :area_type => "StopPlace" subject = create :stop_area, :area_type => "CommercialStopPoint" ,:parent => stop_place, :coordinates => "45.123,120.456" access_point1 = create :access_point, :stop_area => subject access_point2 = create :access_point, :stop_area => subject 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 - |
