aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorent Peyraud2017-07-06 12:42:53 +0200
committerFlorent Peyraud2017-07-06 12:42:53 +0200
commite3f7a67d922614363fe798992af4f656b77f0eb5 (patch)
tree81c00cf3094d724c91f428035ea9e540c377a7bf
parent3c39ff76da22a410f1c81acabad626f15a63d800 (diff)
parent74e94da83d6ea64dcb1e70e69c2fef046453e4a1 (diff)
downloadchouette-core-e3f7a67d922614363fe798992af4f656b77f0eb5.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
-rw-r--r--.gitignore4
-rw-r--r--app/assets/javascripts/cleanup.coffee11
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee80
-rw-r--r--app/controllers/autocomplete_calendars_controller.rb3
-rw-r--r--app/controllers/lines_controller.rb9
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb41
-rw-r--r--app/controllers/time_tables_controller.rb4
-rw-r--r--app/controllers/workbenches_controller.rb88
-rw-r--r--app/helpers/links_helper.rb2
-rw-r--r--app/helpers/newapplication_helper.rb2
-rw-r--r--app/helpers/table_builder_helper.rb9
-rw-r--r--app/helpers/table_builder_helper/custom_links.rb5
-rw-r--r--app/helpers/table_builder_helper/url.rb7
-rw-r--r--app/models/calendar.rb2
-rw-r--r--app/models/chouette/journey_pattern.rb9
-rw-r--r--app/models/chouette/time_table.rb13
-rw-r--r--app/models/chouette/vehicle_journey.rb7
-rw-r--r--app/models/clean_up.rb22
-rw-r--r--app/views/calendars/show.html.slim2
-rw-r--r--app/views/layouts/navigation/_main_nav_left.html.slim4
-rw-r--r--app/views/lines/_filters.html.slim8
-rw-r--r--app/views/lines/index.html.slim50
-rw-r--r--app/views/referential_companies/index.html.slim4
-rw-r--r--app/views/referential_companies/show.html.slim2
-rw-r--r--app/views/referential_lines/_filters.html.slim2
-rw-r--r--app/views/referential_lines/show.html.slim4
-rw-r--r--app/views/referential_networks/index.html.slim4
-rw-r--r--app/views/referential_networks/show.html.slim2
-rw-r--r--app/views/referentials/show.html.slim4
-rw-r--r--app/views/routes/show.html.slim4
-rw-r--r--app/views/routing_constraint_zones/_filters.html.slim2
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim25
-rw-r--r--app/views/routing_constraint_zones/_stop_points.html.slim13
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim35
-rw-r--r--app/views/routing_constraint_zones/index.html.slim2
-rw-r--r--app/views/routing_constraint_zones/new.html.slim27
-rw-r--r--app/views/routing_constraint_zones/new.js.erb1
-rw-r--r--app/views/routing_constraint_zones/show.html.slim2
-rw-r--r--app/views/stop_areas/index.html.slim3
-rw-r--r--app/views/stop_areas/show.html.slim2
-rw-r--r--app/views/time_tables/index.html.slim2
-rw-r--r--app/views/workbenches/_filters.html.slim2
-rw-r--r--app/views/workbenches/show.html.slim3
-rwxr-xr-xbin/bundle3
-rwxr-xr-xbin/rails9
-rwxr-xr-xbin/rake9
-rwxr-xr-xbin/spring17
-rw-r--r--config/deploy.rb2
-rw-r--r--config/locales/actions.en.yml1
-rw-r--r--config/locales/actions.fr.yml5
-rw-r--r--config/locales/clean_ups.en.yml11
-rw-r--r--config/locales/clean_ups.fr.yml20
-rw-r--r--config/locales/companies.en.yml2
-rw-r--r--config/locales/companies.fr.yml2
-rw-r--r--config/locales/en.yml4
-rw-r--r--config/locales/fr.yml3
-rw-r--r--config/locales/networks.en.yml2
-rw-r--r--config/locales/networks.fr.yml2
-rw-r--r--config/locales/routing_constraint_zones.fr.yml8
-rw-r--r--config/locales/stop_areas.fr.yml2
-rw-r--r--spec/factories/referentials.rb1
-rw-r--r--spec/features/workbenches_permissions_spec.rb8
-rw-r--r--spec/features/workbenches_spec.rb192
-rw-r--r--spec/helpers/table_builder_helper_spec.rb6
-rw-r--r--spec/models/calendar_spec.rb6
-rw-r--r--spec/models/chouette/journey_pattern_spec.rb5
-rw-r--r--spec/models/chouette/time_table_spec.rb348
-rw-r--r--spec/models/clean_up_spec.rb32
-rw-r--r--spec/policies/application_policy_spec.rb2
-rw-r--r--spec/policies/boiv_policy_spec.rb2
-rw-r--r--spec/policies/line_policy_spec.rb3
-rw-r--r--spec/policies/route_policy_spec.rb2
-rw-r--r--spec/policies/routing_constraint_zone_policy_spec.rb3
-rw-r--r--spec/policies/time_table_policy_spec.rb3
-rw-r--r--spec/support/pundit/policies.rb4
-rw-r--r--spec/support/pundit/shared_examples.rb26
76 files changed, 617 insertions, 655 deletions
diff --git a/.gitignore b/.gitignore
index 85965b4c1..0cdaa7c9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,4 +38,6 @@ bin/
/node_modules
# Every machine shall create its binstubs
-/bin
+/bin/rake
+/bin/rails
+/bin/rspec
diff --git a/app/assets/javascripts/cleanup.coffee b/app/assets/javascripts/cleanup.coffee
index 169a006a9..7f6594018 100644
--- a/app/assets/javascripts/cleanup.coffee
+++ b/app/assets/javascripts/cleanup.coffee
@@ -2,8 +2,13 @@ $(document).on("change", 'input[name="clean_up[date_type]"]', (e) ->
type = $(this).val()
end_date = $('.cleanup_end_date_wrapper')
- if type == 'between'
- end_date.removeClass('hidden').show()
- else
+ if type == 'before'
+ end_date.hide()
+ $("label[for='clean_up_begin_date_3i']").html("Date de fin de purge");
+ else if type == 'after'
end_date.hide()
+ $("label[for='clean_up_begin_date_3i']").html("Date de début de purge");
+ else
+ $("label[for='clean_up_begin_date_3i']").html("Date de début de purge");
+ end_date.show()
)
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
index 8721dfb38..2fd83fa28 100644
--- a/app/assets/javascripts/routing_constraint_zones.coffee
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -1,73 +1,17 @@
-@ITL_stoppoints = ->
- routeID = $('#routing_constraint_zone_route_id').val()
-
- if (routeID)
- origin = window.location.origin
- path = window.location.pathname.split('/', 5).join('/')
- reqURL = origin + path + '/routes/' + routeID + '/stop_points.json'
+$ ->
+ update_stop_points = () ->
+ url = $('#routing_constraint_zone_route_id').attr("data-url")
+ route_id = $('#routing_constraint_zone_route_id').val()
$.ajax
- url: reqURL
- dataType: 'json'
+ url: url
+ dataType: 'script'
+ data: { route_id: route_id }
error: (jqXHR, textStatus, errorThrown) ->
- console.log(errorThrown)
- success: (collection, textStatus, jqXHR) ->
- html = ''
- stopAreaBaseURL = origin + window.location.pathname.split('/', 3).join('/') + '/stop_areas/'
-
- collection.forEach (item, index) ->
- html += "<div class='nested-fields'><div class='wrapper'>
- <div><a href='" + stopAreaBaseURL + item.stop_area_id + "' class='navlink' title='Voir l&#39;arrêt'><span>" + item.name + "</span></a></div>
- <div><span>" + item.city_name + " (" + item.zip_code + ")</span></div>
- <div>
- <span class='has_radio'>
- <input type='checkbox' name='routing_constraint_zone[stop_point_ids][" + index + "]' value='" + item.id + "'>
- <span class='radio-label'></span>
- </span>
- </div>
- </div></div>"
-
- $('#ITL_stoppoints').find('.nested-fields').remove()
- $('#ITL_stoppoints').find('.nested-head').after(html)
-
- # VALIDATION
- selection = []
-
- totalItems = collection.length
-
- $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) ->
- v = $(e.target).val()
+ console.log("ERROR")
+ success: (data, textStatus, jqXHR) ->
+ console.log("SUCCESS")
- if ( $.inArray(v, selection) != -1 )
- selection.splice(selection.indexOf(v), 1)
- else
- selection.push(v)
-
- alertMsg1 = "<div class='alert alert-danger' style='margin-bottom:15px;'>
- <p class='small'>Un ITL doit comporter au moins deux arrêts</p>
- </div>"
- alertMsg2 = "<div class='alert alert-danger' style='margin-bottom:15px;'>
- <p class='small'>Un ITL ne peut recouvrir tous les arrêts d'un itinéraire</p>
- </div>"
-
- $(document).on 'click', "input[type='submit']", (e)->
- inputName = $('#routing_constraint_zone_name').val()
-
- $('.alert-danger').remove()
-
- if ( selection.length < 2 && inputName != "" )
- e.preventDefault()
- $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove()
- $('#ITL_stoppoints').prepend(alertMsg1)
-
- if ( selection.length == totalItems && inputName != "" )
- e.preventDefault()
- $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove()
- $('#ITL_stoppoints').prepend(alertMsg2)
-
-$ ->
- ITL_stoppoints()
+ $("#itl_form #routing_constraint_zone_route_id").on 'change', -> update_stop_points()
- $('#routing_constraint_zone_route_id').on 'change', ->
- $('.alert-danger').remove()
- ITL_stoppoints()
+ update_stop_points()
diff --git a/app/controllers/autocomplete_calendars_controller.rb b/app/controllers/autocomplete_calendars_controller.rb
index 2b85fcff3..533b5503a 100644
--- a/app/controllers/autocomplete_calendars_controller.rb
+++ b/app/controllers/autocomplete_calendars_controller.rb
@@ -2,6 +2,7 @@ class AutocompleteCalendarsController < ApplicationController
respond_to :json, :only => [:autocomplete]
def autocomplete
- @calendars = current_organisation.calendars.search(params[:q]).result.paginate(page: params[:page])
+ scope = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id)
+ @calendars = scope.search(params[:q]).result.paginate(page: params[:page])
end
end
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 1e2056aad..4b6448ce8 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -13,6 +13,15 @@ class LinesController < BreadcrumbController
def index
@hide_group_of_line = line_referential.group_of_lines.empty?
index! do |format|
+ @lines = ModelDecorator.decorate(
+ @lines,
+ with: LineDecorator,
+ context: {
+ line_referential: @line_referential,
+ current_organisation: current_organisation
+ }
+ )
+
format.html {
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index 6fb5348f0..1eb2ddf28 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -4,14 +4,33 @@ class RoutingConstraintZonesController < ChouetteController
defaults resource_class: Chouette::RoutingConstraintZone
respond_to :html, :xml, :json
- before_action :check_stoppoint_param, only: [:create, :update]
+ # before_action :check_stoppoint_param, only: [:create, :update]
belongs_to :referential do
belongs_to :line, parent_class: Chouette::Line
end
+ def show
+ show! do |format|
+ @routing_constraint_zone = @routing_constraint_zone.decorate(context: {
+ referential: current_referential,
+ line: parent.id
+ })
+ end
+ end
+
+ def new
+ new! do |format|
+ format.html
+ @route = @line.routes.find params[:route_id] if params[:route_id]
+ format.js
+ end
+ end
+
protected
+ alias_method :routing_constraint_zone, :resource
+
def collection
@q = current_referential.routing_constraint_zones.search(params[:q])
@@ -25,26 +44,6 @@ class RoutingConstraintZonesController < ChouetteController
end
end
- def resource
- @routing_constraint_zone ||= begin
- routing_constraint_zone = current_referential.routing_constraint_zones.find(params[:id])
- routing_constraint_zone = routing_constraint_zone.decorate(context: {
- referential: current_referential,
- line: parent.id
- })
- end
- end
-
- def build_resource
- @routing_constraint_zone ||= begin
- routing_constraint_zone = current_referential.routing_constraint_zones.new
- routing_constraint_zone = routing_constraint_zone.decorate(context: {
- referential: current_referential,
- line: parent.id
- })
- end
- end
-
private
def sort_column
(Chouette::RoutingConstraintZone.column_names).include?(params[:sort]) ? params[:sort] : 'name'
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index 3704f2885..6d2639981 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -49,8 +49,8 @@ class TimeTablesController < ChouetteController
calendar.dates.each_with_index do |date, i|
@time_table.dates << Chouette::TimeTableDate.new(date: date, position: i, in_out: true)
end
- calendar.date_ranges.each_with_index do |date_range, i|
- @time_table.periods << Chouette::TimeTablePeriod.new(period_start: date_range.begin, period_end: date_range.end, position: i)
+ calendar.periods.each_with_index do |period, i|
+ @time_table.periods << Chouette::TimeTablePeriod.new(period_start: period.begin, period_end: period.end, position: i)
end
end
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index d03841356..22a71863a 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -7,21 +7,13 @@ class WorkbenchesController < BreadcrumbController
def show
scope = resource.all_referentials
scope = ransack_associated_lines(scope)
- scope = ransack_periode(scope)
+ scope = ransack_period(scope)
scope = ransack_status(scope)
- # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
- # We clone params[:q] so we can delete fake ransack filter arguments before calling search method,
- # which will allow us to preserve params[:q] for sorting
- ransack_params = params[:q].merge(archived_at_not_null: nil, archived_at_null: nil).clone
- ransack_params.delete('associated_lines_id_eq')
-
- @q = scope.ransack(ransack_params)
- @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30)
- @wbench_refs = ModelDecorator.decorate(
- @wbench_refs,
- with: ReferentialDecorator
- )
+ @q_for_form = scope.ransack(params[:q])
+ @q_for_result = scope.ransack(ransack_params)
+ @wbench_refs = sort_result(@q_for_result.result).paginate(page: params[:page], per_page: 30)
+ @wbench_refs = ModelDecorator.decorate(@wbench_refs, with: ReferentialDecorator)
show! do
build_breadcrumb :show
@@ -55,29 +47,34 @@ class WorkbenchesController < BreadcrumbController
end
def query_params
- if params[:q].present?
- params[:q].delete_if { |query, value| value.blank? }
- else
- params[:q] = { "archived_at_not_null"=>"1", "archived_at_null"=>"1" }
- end
+ params[:q] ||= {}
+ params[:q].delete_if { |query, value| value.blank? }
end
# Fake ransack filter
def ransack_associated_lines scope
- if params[:q] && params[:q]['associated_lines_id_eq']
+ if params[:q]['associated_lines_id_eq']
scope = scope.include_metadatas_lines([params[:q]['associated_lines_id_eq']])
end
scope
end
# Fake ransack filter
- def ransack_periode scope
- return scope unless params[:q] && params[:q]['validity_period']
- periode = params[:q]['validity_period']
- return scope if periode['end_lteq(1i)'].blank? || periode['begin_gteq(1i)'].blank?
-
- begin_range = Date.civil(periode["begin_gteq(1i)"].to_i, periode["begin_gteq(2i)"].to_i, periode["begin_gteq(3i)"].to_i)
- end_range = Date.civil(periode["end_lteq(1i)"].to_i, periode["end_lteq(2i)"].to_i, periode["end_lteq(3i)"].to_i)
+ def ransack_period scope
+ period = params[:q]['validity_period']
+ return scope unless period
+
+ begin
+ if period['begin_gteq'].kind_of?(Array)
+ begin_range = Date.new(*period['begin_gteq'].map(&:to_i))
+ end_range = Date.new(*period['end_lteq'].map(&:to_i))
+ else
+ begin_range = Date.new(period["begin_gteq(1i)"].to_i, period["begin_gteq(2i)"].to_i, period["begin_gteq(3i)"].to_i)
+ end_range = Date.new(period["end_lteq(1i)"].to_i, period["end_lteq(2i)"].to_i, period["end_lteq(3i)"].to_i)
+ end
+ rescue Exception => e
+ return scope
+ end
if begin_range > end_range
flash.now[:error] = t('referentials.errors.validity_period')
@@ -89,29 +86,28 @@ class WorkbenchesController < BreadcrumbController
scope
end
- # Fake (again) ransack filter
+ # Fake ransack filter
def ransack_status scope
- return scope unless params[:q]
-
- archived_at_not_null = params[:q]['archived_at_not_null'] == '1'
- archived_at_null = params[:q]['archived_at_null'] == '1'
-
- if !archived_at_not_null and !archived_at_null
- return scope.none
- end
+ archived = !params[:q]['archived_at_not_null'].to_i.zero?
+ unarchived = !params[:q]['archived_at_null'].to_i.zero?
- if archived_at_not_null and archived_at_null
- return scope
- end
-
- if archived_at_null
- return scope.where(archived_at: nil)
- end
-
- if archived_at_not_null
- return scope.where("archived_at is not null")
- end
+ # Both status checked, means no filter
+ return scope unless archived || unarchived
+ return scope if archived && unarchived
+ scope = scope.where(archived_at: nil) if unarchived
+ scope = scope.where("archived_at is not null") if archived
scope
end
+
+ # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
+ # We clone params[:q] so we can delete fake ransack filter arguments before calling search method,
+ # which will allow us to preserve params[:q] for sorting
+ def ransack_params
+ copy_params = params[:q].clone
+ copy_params.delete('associated_lines_id_eq')
+ copy_params.delete('archived_at_not_null')
+ copy_params.delete('archived_at_null')
+ copy_params
+ end
end
diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb
index 683b66a52..4fb7a797d 100644
--- a/app/helpers/links_helper.rb
+++ b/app/helpers/links_helper.rb
@@ -1,5 +1,5 @@
module LinksHelper
def destroy_link_content(translation_key = 'actions.destroy')
- content_tag(:span, nil, class: 'fa fa-trash') + t(translation_key)
+ content_tag(:span, nil, class: 'fa fa-trash mr-xs') + t(translation_key)
end
end
diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb
index 3d43e9fc7..edcad76c3 100644
--- a/app/helpers/newapplication_helper.rb
+++ b/app/helpers/newapplication_helper.rb
@@ -16,7 +16,7 @@ module NewapplicationHelper
end
columns.map do |k, v|
- if ["ID Codif", "Oid", "OiD", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante", "Période englobante", "Nombre de courses associées", "Journées d'application", "Arrêts de l'itinéraire", "Arrêts inclus dans l'ITL"].include? k
+ if ["ID Codifligne", "Oid", "OiD", "ID", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante", "Période englobante", "Nombre de courses associées", "Journées d'application", "Arrêts de l'itinéraire", "Arrêts inclus dans l'ITL"].include? k
hcont << content_tag(:th, k)
else
hcont << content_tag(:th, sortable_columns(collection, k))
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index b93e9b22b..e1b8b406d 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -104,6 +104,10 @@ module TableBuilderHelper
end
def tbody(collection, columns, selectable, links)
+ # Certain controllers don't define a `#current_referential`. In these
+ # cases, avoid a `NoMethodError`.
+ referential = current_referential if respond_to?(:current_referential)
+
content_tag :tbody do
collection.map do |item|
@@ -122,7 +126,10 @@ module TableBuilderHelper
if column_is_linkable?(column)
# Build a link to the `item`
- polymorph_url = URL.polymorphic_url_parts(item)
+ polymorph_url = URL.polymorphic_url_parts(
+ item,
+ referential
+ )
bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir')
else
bcont << content_tag(:td, value)
diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb
index abb907678..39cffd2cd 100644
--- a/app/helpers/table_builder_helper/custom_links.rb
+++ b/app/helpers/table_builder_helper/custom_links.rb
@@ -31,7 +31,10 @@ module TableBuilderHelper
polymorph_url << action
end
- polymorph_url += URL.polymorphic_url_parts(@obj)
+ polymorph_url += URL.polymorphic_url_parts(
+ @obj,
+ @user_context.context[:referential]
+ )
end
def method_for_action(action)
diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb
index f60864ac1..894e5ddf8 100644
--- a/app/helpers/table_builder_helper/url.rb
+++ b/app/helpers/table_builder_helper/url.rb
@@ -1,12 +1,11 @@
module TableBuilderHelper
- # Depends on `current_referential`, defined in object controllers
class URL
- def self.polymorphic_url_parts(item)
+ def self.polymorphic_url_parts(item, referential)
polymorph_url = []
unless item.is_a?(Calendar) || item.is_a?(Referential)
- if current_referential
- polymorph_url << current_referential
+ if referential
+ polymorph_url << referential
polymorph_url << item.line if item.respond_to? :line
polymorph_url << item.route.line if item.is_a?(Chouette::RoutingConstraintZone)
polymorph_url << item if item.respond_to? :line_referential
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index 70fea9619..fb575515a 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -28,7 +28,7 @@ class Calendar < ActiveRecord::Base
self.dates.each do |d|
tt.dates << Chouette::TimeTableDate.new(date: d, in_out: true)
end
- self.date_ranges.each do |p|
+ self.periods.each do |p|
tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end)
end
end
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb
index a146dcff1..868d8121e 100644
--- a/app/models/chouette/journey_pattern.rb
+++ b/app/models/chouette/journey_pattern.rb
@@ -27,7 +27,7 @@ class Chouette::JourneyPattern < Chouette::TridentActiveRecord
jp = find_by(objectid: item['object_id']) || state_create_instance(route, item)
next if item['deletable'] && jp.persisted? && jp.destroy
# Update attributes and stop_points associations
- jp.update_attributes(state_permited_attributes(item))
+ jp.update_attributes(state_permited_attributes(item)) unless item['new_record']
jp.state_stop_points_update(item) if !jp.errors.any? && jp.persisted?
item['errors'] = jp.errors if jp.errors.any?
end
@@ -53,6 +53,13 @@ class Chouette::JourneyPattern < Chouette::TridentActiveRecord
def self.state_create_instance route, item
# Flag new record, so we can unset object_id if transaction rollback
jp = route.journey_patterns.create(state_permited_attributes(item))
+
+ # FIXME
+ # DefaultAttributesSupport will trigger some weird validation on after save
+ # wich will call to valid?, wich will populate errors
+ # In this case, we mark jp to be valid if persisted? return true
+ jp.errors.clear if jp.persisted?
+
item['object_id'] = jp.objectid
item['new_record'] = true
jp
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index cb1d0c5da..d907d797e 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -520,18 +520,15 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
self.convert_continuous_dates_to_periods
end
-
+ # remove days from another calendar
def disjoin!(another_tt)
transaction do
- # remove days from another calendar
- days_to_exclude = self.intersects(another_tt.effective_days)
- days = self.effective_days - days_to_exclude
+ days = self.included_days_in_dates_and_periods - another_tt.included_days_in_dates_and_periods
self.dates.clear
self.periods.clear
- days.each {|d| self.dates << Chouette::TimeTableDate.new( :date =>d, :in_out => true)}
-
- self.dates.to_a.sort! { |a,b| a.date <=> b.date}
- self.periods.to_a.sort! { |a,b| a.period_start <=> b.period_start}
+ days.sort.each do |d|
+ self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true)
+ end
self.save!
end
self.convert_continuous_dates_to_periods
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 3a5851310..71c339780 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -23,15 +23,14 @@ module Chouette
validates_presence_of :route
validates_presence_of :journey_pattern
+ validates :vehicle_journey_at_stops, :vjas_departure_time_must_be_before_next_stop_arrival_time,
+ vehicle_journey_at_stops_are_in_increasing_time_order: true
+ validates_presence_of :number
has_many :vehicle_journey_at_stops, -> { includes(:stop_point).order("stop_points.position") }, :dependent => :destroy
has_and_belongs_to_many :time_tables, :class_name => 'Chouette::TimeTable', :foreign_key => "vehicle_journey_id", :association_foreign_key => "time_table_id"
has_many :stop_points, -> { order("stop_points.position") }, :through => :vehicle_journey_at_stops
- validates :vehicle_journey_at_stops, :vjas_departure_time_must_be_before_next_stop_arrival_time,
- vehicle_journey_at_stops_are_in_increasing_time_order: true
- validates_presence_of :number
-
before_validation :set_default_values,
:calculate_vehicle_journey_at_stop_day_offset
diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb
index e39928a17..75fedc732 100644
--- a/app/models/clean_up.rb
+++ b/app/models/clean_up.rb
@@ -6,8 +6,8 @@ class CleanUp < ActiveRecord::Base
enumerize :date_type, in: %i(between before after)
- validates :begin_date, presence: true
- validates :date_type, presence: true
+ validates_presence_of :begin_date, message: :presence
+ validates_presence_of :date_type, message: :presence
after_commit :perform_cleanup, :on => :create
def perform_cleanup
@@ -16,10 +16,13 @@ class CleanUp < ActiveRecord::Base
def clean
{}.tap do |result|
- result['time_table'] = send("destroy_time_tables_#{self.date_type}").try(:count)
+ processed = send("destroy_time_tables_#{self.date_type}")
+ if processed
+ result['time_table'] = processed[:time_tables].try(:count)
+ result['vehicle_journey'] = processed[:vehicle_journeys].try(:count)
+ end
result['time_table_date'] = send("destroy_time_tables_dates_#{self.date_type}").try(:count)
result['time_table_period'] = send("destroy_time_tables_periods_#{self.date_type}").try(:count)
- result['vehicle_journey'] = destroy_vehicle_journey_without_time_table.try(:count)
self.overlapping_periods.each do |period|
exclude_dates_in_overlapping_period(period)
end
@@ -27,7 +30,7 @@ class CleanUp < ActiveRecord::Base
end
def destroy_time_tables_between
- time_tables = Chouette::TimeTable.where('end_date <= ? AND start_date >= ?', self.end_date, self.begin_date)
+ time_tables = Chouette::TimeTable.where('end_date < ? AND start_date > ?', self.end_date, self.begin_date)
self.destroy_time_tables(time_tables)
end
@@ -50,7 +53,7 @@ class CleanUp < ActiveRecord::Base
end
def destroy_time_tables_dates_between
- Chouette::TimeTableDate.in_dates.where('date >= ? AND date <= ?', self.begin_date, self.end_date).destroy_all
+ Chouette::TimeTableDate.in_dates.where('date > ? AND date < ?', self.begin_date, self.end_date).destroy_all
end
def destroy_time_tables_periods_before
@@ -62,7 +65,7 @@ class CleanUp < ActiveRecord::Base
end
def destroy_time_tables_periods_between
- Chouette::TimeTablePeriod.where('period_start >= ? AND period_end <= ?', self.begin_date, self.end_date).destroy_all
+ Chouette::TimeTablePeriod.where('period_start > ? AND period_end < ?', self.begin_date, self.end_date).destroy_all
end
def overlapping_periods
@@ -106,13 +109,16 @@ class CleanUp < ActiveRecord::Base
end
def destroy_time_tables(time_tables)
+ results = { :time_tables => [], :vehicle_journeys => [] }
# Delete vehicle_journey time_table association
time_tables.each do |time_table|
time_table.vehicle_journeys.each do |vj|
vj.time_tables.delete(time_table)
+ results[:vehicle_journeys] << vj.destroy if vj.time_tables.empty?
end
end
- time_tables.destroy_all
+ results[:time_tables] = time_tables.destroy_all
+ results
end
aasm column: :status do
diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim
index d7849005b..4ce5de57f 100644
--- a/app/views/calendars/show.html.slim
+++ b/app/views/calendars/show.html.slim
@@ -25,4 +25,4 @@
Calendar.human_attribute_name(:shared) => t("#{@calendar.shared}"),
'Organisation' => @calendar.organisation.name,
Calendar.human_attribute_name(:dates) => @calendar.dates.collect{|d| l(d, format: :short)}.join(', ').html_safe,
- Calendar.human_attribute_name(:date_ranges) => @calendar.date_ranges.collect{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end - (d.exclude_end? ? 1.day : 0), format: :short))}.join('<br>').html_safe }
+ Calendar.human_attribute_name(:date_ranges) => @calendar.periods.map{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end, format: :short))}.join('<br>').html_safe }
diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim
index efdb81d9c..c72b61c00 100644
--- a/app/views/layouts/navigation/_main_nav_left.html.slim
+++ b/app/views/layouts/navigation/_main_nav_left.html.slim
@@ -35,8 +35,8 @@
span Jeux de données
= link_to '#', class: 'list-group-item' do
span Import
- = link_to '#', class: 'list-group-item' do
- span Modèle de calendrier
+ = link_to calendars_path, class: 'list-group-item' do
+ span Modèles de calendrier
= link_to '#', class: 'list-group-item' do
span Rapport de contrôle
= link_to '#', class: 'list-group-item' do
diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim
index a0188f562..0e34b2e4c 100644
--- a/app/views/lines/_filters.html.slim
+++ b/app/views/lines/_filters.html.slim
@@ -8,19 +8,19 @@
.ffg-row
.form-group.togglable
- = f.label @lines.human_attribute_name(:network), required: false, class: 'control-label'
+ = f.label Chouette::Line.human_attribute_name(:network), required: false, class: 'control-label'
= f.input :network_id_eq_any, collection: @line_referential.networks.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
- = f.label @lines.human_attribute_name(:company), required: false, class: 'control-label'
+ = f.label Chouette::Line.human_attribute_name(:company), required: false, class: 'control-label'
= f.input :company_id_eq_any, collection: @line_referential.companies.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
- = f.label @lines.human_attribute_name(:transport_mode), required: false, class: 'control-label'
+ = f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label'
= f.input :transport_mode_eq_any, collection: sorted_transport_mode, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.line.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
- = f.label @lines.human_attribute_name(:transport_submode), required: false, class: 'control-label'
+ = f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label'
= f.input :transport_submode_eq_any, collection: sorted_transport_submode, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.line.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.actions
diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim
index d7b6be5c8..630d63068 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -16,18 +16,44 @@
- if @lines.any?
.row
.col-lg-12
- = table_builder @lines,
- { 'Oid' => Proc.new { |n| n.objectid.local_id },
- :number => 'number',
- :name => 'name',
- :deactivated => Proc.new{|n| n.deactivated? ? t('false') : t('true')},
- 'networks.name' => Proc.new { |n| n.try(:network).try(:name) },
- 'companies.name' => Proc.new { |n| n.try(:company).try(:name) },
- :transport_mode => Proc.new { |n| n.transport_mode.nil? ? '-' : t("enumerize.line.transport_mode.#{n.try(:transport_mode)}") },
- :transport_submode => Proc.new { |n| n.transport_submode.nil? ? '-' : t("enumerize.line.transport_submode.#{n.try(:transport_submode)}") } },
- [:show, :delete],
- [],
- 'table has-filter has-search'
+ = table_builder_2 @lines,
+ [ \
+ TableBuilderHelper::Column.new( \
+ name: 'ID Codifligne', \
+ attribute: Proc.new { |n| n.objectid.local_id }, \
+ sortable: false \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :number, \
+ attribute: 'number' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :name, \
+ attribute: 'name' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :deactivated, \
+ attribute: Proc.new{|n| n.deactivated? ? t('false') : t('true')} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: 'networks.name', \
+ attribute: Proc.new { |n| n.try(:network).try(:name) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: 'companies.name', \
+ attribute: Proc.new { |n| n.try(:company).try(:name) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :transport_mode, \
+ attribute: Proc.new { |n| n.transport_mode.nil? ? '-' : t("enumerize.line.transport_mode.#{n.try(:transport_mode)}") } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :transport_submode, \
+ attribute: Proc.new { |n| n.transport_submode.nil? ? '-' : t("enumerize.line.transport_submode.#{n.try(:transport_submode)}") } \
+ ) \
+ ],
+ links: [:show],
+ cls: 'table has-filter has-search'
= new_pagination @lines, 'pull-right'
diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim
index 7a033fb5f..85d1d416d 100644
--- a/app/views/referential_companies/index.html.slim
+++ b/app/views/referential_companies/index.html.slim
@@ -1,7 +1,7 @@
/ PageHeader
= pageheader 'map-marker',
t('companies.index.title'),
- 'Lorem ipsum dolor sit amet',
+ '',
'',
(policy(Chouette::Company).create? ? link_to(t('companies.actions.new'), new_referential_company_path(@referential), class: 'btn btn-default') : '')
@@ -23,7 +23,7 @@
.row
.col-lg-12
= table_builder @companies,
- { 'ID Codif' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ { 'ID Codifligne' => Proc.new { |n| n.try(:objectid).try(:local_id) },
:name => 'name', :phone => 'phone', :email => 'email', :url => 'url' },
[:show, :edit, :delete],
[],
diff --git a/app/views/referential_companies/show.html.slim b/app/views/referential_companies/show.html.slim
index ae89c1444..177ce2d69 100644
--- a/app/views/referential_companies/show.html.slim
+++ b/app/views/referential_companies/show.html.slim
@@ -22,7 +22,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { 'ID Codif' => @company.try(:objectid).try(:local_id),
+ { t('id_codif') => @company.try(:objectid).try(:local_id),
Chouette::Company.human_attribute_name(:phone) => @company.phone,
Chouette::Company.human_attribute_name(:email) => @company.email,
Chouette::Company.human_attribute_name(:url) => @company.url }
diff --git a/app/views/referential_lines/_filters.html.slim b/app/views/referential_lines/_filters.html.slim
index 93d449507..379d6234f 100644
--- a/app/views/referential_lines/_filters.html.slim
+++ b/app/views/referential_lines/_filters.html.slim
@@ -1,7 +1,7 @@
= search_form_for @q, url: referential_line_path(@referential, @line), class: 'form form-filter' do |f|
.ffg-row
.input-group.search_bar
- = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'itinéraire ou un OiD..."
+ = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'itinéraire ou un ID..."
span.input-group-btn
button.btn.btn-default#search-btn type='submit'
span.fa.fa-search
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index db99381d3..0bb6d9032 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -29,7 +29,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { 'ID Codif' => @line.objectid.local_id,
+ { t('id_codif') => @line.objectid.local_id,
'Activé' => (@line.deactivated? ? t('false') : t('true')),
@line.human_attribute_name(:network) => (@line.network.nil? ? t('lines.index.unset') : link_to(@line.network.name, [@referential, @line.network]) ),
@line.human_attribute_name(:company) => (@line.company.nil? ? t('lines.index.unset') : link_to(@line.company.name, [@referential, @line.company]) ),
@@ -52,7 +52,7 @@
.row
.col-lg-12
= table_builder @routes,
- { 'OiD' => Proc.new { |n| n.objectid.local_id },
+ { 'ID' => Proc.new { |n| n.objectid.local_id },
:name => 'name',
:published_name => 'published_name',
:wayback => 'wayback_text',
diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim
index 38ffb836a..d6c52d352 100644
--- a/app/views/referential_networks/index.html.slim
+++ b/app/views/referential_networks/index.html.slim
@@ -23,11 +23,11 @@
.row
.col-lg-12
= table_builder @networks,
- { 'ID Codif' => Proc.new { |n| n.try(:objectid).try(:local_id) }, :name => 'name' },
+ { 'ID Codifligne' => Proc.new { |n| n.try(:objectid).try(:local_id) }, :name => 'name' },
[:show, :edit, :delete],
[],
'table has-search'
-
+
= new_pagination @networks, 'pull-right'
- unless @networks.any?
diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim
index 3a195b342..59bdd0dee 100644
--- a/app/views/referential_networks/show.html.slim
+++ b/app/views/referential_networks/show.html.slim
@@ -22,4 +22,4 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { 'ID Codif' => @network.try(:objectid).try(:local_id) }
+ { t('id_codif') => @network.try(:objectid).try(:local_id) }
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 8308cf770..17ba8ad88 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -39,7 +39,7 @@
.col-lg-12
/ ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes]
= table_builder @reflines,
- { 'ID Codif' => Proc.new { |n| n.objectid.local_id },
+ { 'ID Codifligne' => Proc.new { |n| n.objectid.local_id },
:number => 'number',
:name => 'name',
:deactivated => Proc.new{ |n| n.deactivated? ? t('false') : t('true') },
@@ -70,7 +70,7 @@
= f.input :date_type, as: :radio_buttons, label: false
= f.input :begin_date, as: :date, label: t('titles.clean_up.begin_date'),:wrapper_html => { class: 'date smart_date', title: t('titles.clean_up.begin_date') }
- = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper hidden smert_date', title: t('titles.clean_up.end_date') }
+ = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper smart_date', title: t('titles.clean_up.end_date'), id: "end_date" }
.modal-footer
button.btn.btn-link type='button' data-dismiss='modal' Annuler
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index 92a5080ae..eee19d85a 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -1,7 +1,7 @@
/ PageHeader
= pageheader 'map-marker',
@route.name,
- 'Lorem ipsum dolor sit amet',
+ '',
t('last_update', time: l(@route.updated_at, format: :short)),
(policy(@route).edit? ? link_to(t('actions.edit'), edit_referential_line_route_path(@referential, @line, @route), class: 'btn btn-default') : '') do
@@ -21,7 +21,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { 'OiD' => @route.try(:objectid).try(:local_id),
+ { t('id_codif') => @route.try(:objectid).try(:local_id),
t('activerecord.attributes.route.published_name') => (@route.published_name ? @route.published_name : '-'),
@route.human_attribute_name(:wayback) => (@route.wayback ? @route.wayback_text : '-' ),
@route.human_attribute_name(:opposite_route) => (@route.opposite_route ? @route.opposite_route.name : '-') }
diff --git a/app/views/routing_constraint_zones/_filters.html.slim b/app/views/routing_constraint_zones/_filters.html.slim
index 07d351b1f..433dde4ab 100644
--- a/app/views/routing_constraint_zones/_filters.html.slim
+++ b/app/views/routing_constraint_zones/_filters.html.slim
@@ -1,7 +1,7 @@
= search_form_for @q, url: referential_line_routing_constraint_zones_path(@referential, @line), class: 'form form-filter' do |f|
.ffg-row
.input-group.search_bar
- = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'ITL ou un OiD..."
+ = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'ITL ou un ID..."
span.input-group-btn
button.btn.btn-default#search-btn type='submit'
span.fa.fa-search
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
deleted file mode 100644
index 5e5f44269..000000000
--- a/app/views/routing_constraint_zones/_form.html.slim
+++ /dev/null
@@ -1,25 +0,0 @@
-= simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
-
- .row
- .col-lg-12
- = form.input :name
- = form.input :route_id, collection: @line.routes, include_blank: false
-
- .separator
-
- #ITL_stoppoints
- .subform
- .nested-head
- .wrapper
- div
- .form-group
- label.control-label Arrêt
- div
- .form-group
- label.control-label Commune
- div
-
- = hidden_field_tag 'stop_point_ids', @routing_constraint_zone.stop_point_ids.to_s, id: 'stop_point_ids'
-
-
- = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
diff --git a/app/views/routing_constraint_zones/_stop_points.html.slim b/app/views/routing_constraint_zones/_stop_points.html.slim
new file mode 100644
index 000000000..10c1d4900
--- /dev/null
+++ b/app/views/routing_constraint_zones/_stop_points.html.slim
@@ -0,0 +1,13 @@
+- stop_points.each do |stop_point|
+ .wrapper
+ div
+ = link_to referential_stop_area_path(@referential, stop_point.stop_area.id), class: 'navlink', title: "Voir l'arrêt" do
+ span = stop_point.stop_area.name
+
+ div
+ span
+ = "#{stop_point.stop_area.city_name} (#{stop_point.stop_area.zip_code})"
+ div
+ span.has_radio
+ = check_box_tag( "routing_constraint_zone[stop_point_ids][]", "#{stop_point.id}", @routing_constraint_zone.stop_point_ids && @routing_constraint_zone.stop_point_ids.include?(stop_point.id) )
+ span.radio-label
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
index 589083927..4fe2786a3 100644
--- a/app/views/routing_constraint_zones/edit.html.slim
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -6,7 +6,34 @@
/ PageContent
.page_content
- .container-fluid
- .row
- .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
- == render 'form'
+ .container-fluid
+ .row
+ .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
+ = simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
+
+ .row
+ .col-lg-12
+ = form.input :name
+ = form.association :route, collection: @line.routes, disabled: true
+
+ .separator
+
+ - @routing_constraint_zone.errors[:stop_point_ids].each do |error_message|
+ .alert.alert-danger = error_message
+
+ #ITL_stoppoints
+ .subform
+ .nested-head
+ .wrapper
+ div
+ .form-group
+ label.control-label Arrêt
+ div
+ .form-group
+ label.control-label Commune
+ div
+
+ .nested-fields
+ = render( partial: 'routing_constraint_zones/stop_points', object: @routing_constraint_zone.route.stop_points)
+
+ = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim
index 248efedb4..596ea9e91 100644
--- a/app/views/routing_constraint_zones/index.html.slim
+++ b/app/views/routing_constraint_zones/index.html.slim
@@ -17,7 +17,7 @@
.row
.col-lg-12
= table_builder @routing_constraint_zones,
- { 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ { 'ID' => Proc.new { |n| n.try(:objectid).try(:local_id) },
:name => 'name', :stop_points_count => 'stop_points_count',
:route => 'route_name' },
[:show, :edit, :delete],
diff --git a/app/views/routing_constraint_zones/new.html.slim b/app/views/routing_constraint_zones/new.html.slim
index f6ae62825..ab7143a76 100644
--- a/app/views/routing_constraint_zones/new.html.slim
+++ b/app/views/routing_constraint_zones/new.html.slim
@@ -7,4 +7,29 @@
.container-fluid
.row
.col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
- == render 'form'
+ = simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
+
+ .row
+ .col-lg-12
+ = form.input :name
+ = form.input :route_id, collection: @line.routes, include_blank: false, input_html: {data: {url: new_referential_line_routing_constraint_zone_path(@referential, @line) }}
+
+ .separator
+
+ - @routing_constraint_zone.errors[:stop_point_ids].each do |error_message|
+ .alert.alert-danger = error_message
+
+ #ITL_stoppoints
+ .subform
+ .nested-head
+ .wrapper
+ div
+ .form-group
+ label.control-label Arrêt
+ div
+ .form-group
+ label.control-label Commune
+ div
+ .nested-fields#stop_points
+
+ = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
diff --git a/app/views/routing_constraint_zones/new.js.erb b/app/views/routing_constraint_zones/new.js.erb
new file mode 100644
index 000000000..406845a4d
--- /dev/null
+++ b/app/views/routing_constraint_zones/new.js.erb
@@ -0,0 +1 @@
+$("#stop_points").html("<%= escape_javascript(render partial: 'routing_constraint_zones/stop_points', object: @route.stop_points) %>");
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index 1dad4f561..3decc086f 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -28,7 +28,7 @@
.col-lg-12
= table_builder @routing_constraint_zone.route.stop_points,
{ "Arrêts de l'itinéraire" => 'name',
- "Arrêts inclus dans l'ITL" => Proc.new{ |rsp| (@routing_constraint_zone.stop_points.collect{|c| c.name}.include? rsp.name) ? 'Oui' : 'Non' } },
+ "Arrêts inclus dans l'ITL" => Proc.new{ |rsp| (@routing_constraint_zone.stop_point_ids.include? rsp.id) ? 'Oui' : 'Non' } },
[],
[],
'table has-stoppoints'
diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim
index 27c9372ac..338e7e878 100644
--- a/app/views/stop_areas/index.html.slim
+++ b/app/views/stop_areas/index.html.slim
@@ -1,7 +1,7 @@
/ PageHeader
= pageheader 'map-marker',
t('stop_areas.index.title'),
- 'Lorem ipsum dolor sit amet',
+ '',
'',
(policy(Chouette::StopArea).create? ? link_to(t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary') : '')
@@ -16,7 +16,6 @@
- if @stop_areas.any?
.row
.col-lg-12
- p = t('activerecord.attributes.stop_point.deleted_at')
= table_builder @stop_areas,
{ 'ID Reflex' => Proc.new { |n| n.try(:user_objectid) }, :name => 'name', :registration_number => 'registration_number', :deleted_at => Proc.new{|s| s.deleted_at ? t('false') : t('true')},
:zip_code => 'zip_code', :city_name => 'city_name', :area_type => Proc.new{|s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}"))} },
diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim
index bdf7b61a5..0427554ef 100644
--- a/app/views/stop_areas/show.html.slim
+++ b/app/views/stop_areas/show.html.slim
@@ -22,7 +22,7 @@
= definition_list t('metadatas'),
{ @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"),
@stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number,
- 'Code Reflex' => @stop_area.user_objectid,
+ t('id_reflex') => @stop_area.user_objectid,
'Coordonnées' => geo_data(@stop_area, @stop_area_referential),
@stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code,
@stop_area.human_attribute_name(:city_name) => @stop_area.city_name,
diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim
index 402b09b98..a0b9e4380 100644
--- a/app/views/time_tables/index.html.slim
+++ b/app/views/time_tables/index.html.slim
@@ -15,7 +15,7 @@
.row
.col-lg-12
= table_builder @time_tables,
- { 'OiD' => Proc.new { |n| n.objectid.local_id }, :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment',
+ { 'ID' => Proc.new { |n| n.objectid.local_id }, :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment',
"Période englobante" => Proc.new{ |tt| tt.bounding_dates.empty? ? '-' : t('bounding_dates', debut: l(tt.bounding_dates.min), end: l(tt.bounding_dates.max)) },
"Nombre de courses associées" => Proc.new{ |tt| tt.vehicle_journeys.count },
"Journées d'application" => Proc.new{ |tt| (%w(monday tuesday wednesday thursday friday saturday sunday).collect{|d| tt.send(d) ? t("calendars.days.#{d}") : '' }).reject{|a| a.empty?}.join(', ').html_safe },
diff --git a/app/views/workbenches/_filters.html.slim b/app/views/workbenches/_filters.html.slim
index 4eaf910c0..d7ac79577 100644
--- a/app/views/workbenches/_filters.html.slim
+++ b/app/views/workbenches/_filters.html.slim
@@ -1,4 +1,4 @@
-= search_form_for @q, url: workbench_path(@workbench.id), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f|
+= search_form_for @q_for_form, url: workbench_path(@workbench.id), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f|
.ffg-row
.input-group.search_bar
= f.search_field :name_cont, class: 'form-control', placeholder: 'Indiquez un nom de référentiel...'
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index 37c396b46..bb8b71ab2 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -7,7 +7,7 @@
/ Below is secundary actions & optional contents (filters, ...)
.row.mb-sm
.col-lg-12.text-right
- = link_to Import.model_name.human.pluralize.capitalize, workbench_imports_path(@workbench), class: 'btn btn-primary'
+ = link_to t('actions.import'), workbench_imports_path(@workbench), class: 'btn btn-primary'
- if policy(Referential).create?
= link_to t('actions.add'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary'
@@ -43,6 +43,7 @@
), \
TableBuilderHelper::Column.new( \
key: :lines, \
+ name: 'Nb lignes', \
attribute: Proc.new {|w| w.lines.count} \
), \
TableBuilderHelper::Column.new( \
diff --git a/bin/bundle b/bin/bundle
deleted file mode 100755
index 66e9889e8..000000000
--- a/bin/bundle
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
-load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
deleted file mode 100755
index f2b0313dd..000000000
--- a/bin/rails
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env ruby
-begin
- load File.expand_path('../spring', __FILE__)
-rescue LoadError => e
- raise unless e.message.include?('spring')
-end
-APP_PATH = File.expand_path('../../config/application', __FILE__)
-require_relative '../config/boot'
-require 'rails/commands'
diff --git a/bin/rake b/bin/rake
deleted file mode 100755
index d87d5f578..000000000
--- a/bin/rake
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env ruby
-begin
- load File.expand_path('../spring', __FILE__)
-rescue LoadError => e
- raise unless e.message.include?('spring')
-end
-require_relative '../config/boot'
-require 'rake'
-Rake.application.run
diff --git a/bin/spring b/bin/spring
deleted file mode 100755
index fb2ec2ebb..000000000
--- a/bin/spring
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env ruby
-
-# This file loads spring without using Bundler, in order to be fast.
-# It gets overwritten when you run the `spring binstub` command.
-
-unless defined?(Spring)
- require 'rubygems'
- require 'bundler'
-
- lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
- spring = lockfile.specs.detect { |spec| spec.name == "spring" }
- if spring
- Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
- gem 'spring', spring.version
- require 'spring/binstub'
- end
-end
diff --git a/config/deploy.rb b/config/deploy.rb
index 0445ec480..4ab888e92 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -51,7 +51,7 @@ namespace :deploy do
end
task :bundle_link do
- run "ln -fs #{bundle_cmd} #{release_path}/bin/bundle"
+ run "mkdir -p #{release_path}/bin && ln -fs #{bundle_cmd} #{release_path}/bin/bundle"
end
after "bundle:install", "deploy:bundle_link"
diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml
index fe4d3d4e5..cffd04fcf 100644
--- a/config/locales/actions.en.yml
+++ b/config/locales/actions.en.yml
@@ -15,6 +15,7 @@ en:
sync: 'Synchronize'
combine: 'Combine'
actualize: 'Actualize'
+ import: 'Import'
or: "or"
cancel: "Cancel"
search_hint: "Type in a search term"
diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml
index ae0537ebb..86e72088a 100644
--- a/config/locales/actions.fr.yml
+++ b/config/locales/actions.fr.yml
@@ -5,8 +5,8 @@ fr:
delete: 'Supprimer'
search: "Chercher"
submit: "Valider"
- add: 'Ajouter'
- new: 'Ajouter'
+ add: 'Créer'
+ new: 'Créer'
show: 'Consulter'
archive: 'Conserver'
unarchive: 'Déconserver'
@@ -16,6 +16,7 @@ fr:
sync: 'Synchroniser'
combine: 'Combiner'
actualize: 'Actualiser'
+ import: 'Importer'
or: "ou"
cancel: "Annuler"
search_hint: "Entrez un texte à rechercher"
diff --git a/config/locales/clean_ups.en.yml b/config/locales/clean_ups.en.yml
index 148362c35..588eb55d5 100644
--- a/config/locales/clean_ups.en.yml
+++ b/config/locales/clean_ups.en.yml
@@ -22,3 +22,14 @@ en:
clean_up:
begin_date: "Begin date of clean up"
end_date: "End date of clean up"
+ activerecord:
+ errors:
+ models:
+ clean_up:
+ attributes:
+ date_type:
+ presence: "A clean up must have a date type"
+ begin_date:
+ presence: "A clean up must have a begin date"
+ end_date:
+ presence: "A clean up must have a end date"
diff --git a/config/locales/clean_ups.fr.yml b/config/locales/clean_ups.fr.yml
index cb0ce3f1a..001c2b1cb 100644
--- a/config/locales/clean_ups.fr.yml
+++ b/config/locales/clean_ups.fr.yml
@@ -14,11 +14,21 @@ fr:
end_date: "Fin date limite : "
titles:
clean_up:
- begin_date: "Début date de la purge"
- end_date: "Fin date de la purge"
-
+ begin_date: "Date de début de la purge"
+ end_date: "Date de fin de la purge"
formtastic:
titles:
clean_up:
- begin_date: "Début date de la purge"
- end_date: "Fin date de la purge"
+ begin_date: "Date de début de la purge"
+ end_date: "Date de fin de la purge"
+ activerecord:
+ errors:
+ models:
+ clean_up:
+ attributes:
+ date_type:
+ presence: "Une purge doit avoir un type de renseigné"
+ begin_date:
+ presence: "Une purge doit avoir une date de début"
+ end_date:
+ presence: "Une purge doit avoir une date de fin"
diff --git a/config/locales/companies.en.yml b/config/locales/companies.en.yml
index ac11a896a..301f4d68d 100644
--- a/config/locales/companies.en.yml
+++ b/config/locales/companies.en.yml
@@ -15,7 +15,7 @@ en:
index:
title: "Companies"
name: "Search by name..."
- name_or_objectid: "Search by name or by objectid..."
+ name_or_objectid: "Search by name or by Codifligne ID..."
advanced_search: "Advanced search"
activerecord:
models:
diff --git a/config/locales/companies.fr.yml b/config/locales/companies.fr.yml
index e582736c9..58fcc2ed7 100644
--- a/config/locales/companies.fr.yml
+++ b/config/locales/companies.fr.yml
@@ -15,7 +15,7 @@ fr:
index:
title: "Transporteurs"
name: "Recherche par nom..."
- name_or_objectid: "Recherche par nom ou objectid..."
+ name_or_objectid: "Recherche par nom ou ID Codifligne..."
advanced_search: "Recherche avancée"
activerecord:
models:
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3f6a68f8d..0a6002175 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -20,3 +20,7 @@ en:
validity_range: '%{debut} > %{end}'
bounding_dates: '%{debut} > %{end}'
metadatas: 'Informations'
+
+ id_codif: 'Codifligne ID'
+ id_reflex: 'Reflex ID'
+ objectid: 'ID'
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 49d1c5bb7..782844ba4 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -20,3 +20,6 @@ fr:
validity_range: '%{debut} > %{end}'
bounding_dates: '%{debut} > %{end}'
metadatas: 'Informations'
+
+ id_codif: 'ID Codifligne'
+ id_reflex: 'ID Reflex'
diff --git a/config/locales/networks.en.yml b/config/locales/networks.en.yml
index a5962e2a6..86be535e4 100644
--- a/config/locales/networks.en.yml
+++ b/config/locales/networks.en.yml
@@ -15,7 +15,7 @@ en:
index:
title: "Networks"
name: "Search by name..."
- name_or_objectid: "Search by name or by objectid..."
+ name_or_objectid: "Search by name or by Codifligne ID..."
advanced_search: "Advanced search"
activerecord:
models:
diff --git a/config/locales/networks.fr.yml b/config/locales/networks.fr.yml
index 99fd2ac95..30d061968 100644
--- a/config/locales/networks.fr.yml
+++ b/config/locales/networks.fr.yml
@@ -15,7 +15,7 @@ fr:
index:
title: "Réseaux"
name: "Recherche par nom..."
- name_or_objectid: "Recherche par nom ou objectid..."
+ name_or_objectid: "Recherche par nom ou ID Codifligne..."
advanced_search: "Recherche avancée"
activerecord:
models:
diff --git a/config/locales/routing_constraint_zones.fr.yml b/config/locales/routing_constraint_zones.fr.yml
index 4faff6606..1199bcf3c 100644
--- a/config/locales/routing_constraint_zones.fr.yml
+++ b/config/locales/routing_constraint_zones.fr.yml
@@ -24,12 +24,12 @@ fr:
routing_constraint_zones:
search_no_results: "Aucune ITL ne correspond à votre recherche"
actions:
- destroy_confirm: Etes vous sûr de supprimer cette zone de contrainte ?
+ destroy_confirm: Etes vous sûr de supprimer cette ITL ?
new:
- title: Ajouter un ITL
+ title: Créer une ITL
edit:
- title: "Editer la zone de contrainte %{routing_constraint_zone}"
+ title: "Editer l'ITL : %{routing_constraint_zone}"
show:
title: "Zone de contrainte %{routing_constraint_zone}"
index:
- title: "Interdictions de traffic local"
+ title: "Interdictions de trafic local"
diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml
index 60ab3fa3d..3e49cdf7c 100644
--- a/config/locales/stop_areas.fr.yml
+++ b/config/locales/stop_areas.fr.yml
@@ -90,7 +90,7 @@ fr:
published_name: "Nom public"
deleted: "Supprimé"
deleted_at: "Activé"
- comment: "Description"
+ comment: "Commentaire"
stop_area_type: "Type d'arrêt"
area_type: "Type d'arrêt"
nearest_topic_name: "Point d'intérêt le plus proche"
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
index dd5bf1c2e..5348ad96b 100644
--- a/spec/factories/referentials.rb
+++ b/spec/factories/referentials.rb
@@ -8,5 +8,6 @@ FactoryGirl.define do
association :line_referential
association :stop_area_referential
time_zone "Europe/Paris"
+ ready { true }
end
end
diff --git a/spec/features/workbenches_permissions_spec.rb b/spec/features/workbenches_permissions_spec.rb
index 962ffdedc..d58293538 100644
--- a/spec/features/workbenches_permissions_spec.rb
+++ b/spec/features/workbenches_permissions_spec.rb
@@ -18,20 +18,20 @@ describe 'Workbenches', type: :feature do
context 'on show view' do
let( :path ){ workbench_path(workbench) }
- context 'if present → ' do
+ context 'if present → ' do
let( :permission ){ true }
it 'shows the corresponding button' do
expected_href = new_referential_path(workbench_id: workbench)
- expect( page ).to have_link('Ajouter', href: expected_href)
+ expect( page ).to have_link('Créer', href: expected_href)
end
end
- context 'if absent → ' do
+ context 'if absent → ' do
let( :permission ){ false }
it 'does not show the corresponding button' do
- expect( page ).not_to have_link('Ajouter')
+ expect( page ).not_to have_link('Créer')
end
end
# let!(:ready_referential) { create :referential, workbench: workbench, metadatas: referential_metadatas, ready: true, organisation: @user.organisation }
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index 953eb2bf5..9a40a8376 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -3,50 +3,190 @@
describe 'Workbenches', type: :feature do
login_user
- #let!(:organisations) { Array.new(2) { create :organisation } }
- #let!(:referentials) { Array.new(2) { create :referential, ready: true } }
- let(:line_referential) { create :line_referential }
- let(:workbenches) { Array.new(2) { create :workbench, line_referential: line_referential, organisation: @user.organisation } }
- let(:workbench) { workbenches.first }
- let!(:line) { create :line, line_referential: line_referential }
+ let(:line_ref) { create :line_referential }
+ let(:line) { create :line, line_referential: line_ref }
+ let(:ref_metadata) { create(:referential_metadata, lines: [line]) }
- let(:referential_metadatas) { Array.new(2) { |i| create :referential_metadata, lines: [line] } }
+ let!(:workbench) { create(:workbench, line_referential: line_ref, organisation: @user.organisation) }
+ let!(:referential) { create :referential, workbench: workbench, metadatas: [ref_metadata], organisation: @user.organisation }
describe 'show' do
+ context 'ready' do
+ it 'should show ready referentials' do
+ visit workbench_path(workbench)
+ expect(page).to have_content(referential.name)
+ end
- let!(:ready_referential) { create :referential, workbench: workbench, metadatas: referential_metadatas, ready: true, organisation: @user.organisation }
- let!(:unready_referential) { create :referential, workbench: workbench }
+ it 'should not show unready referentials' do
+ referential.update_attribute(:ready, false)
+ visit workbench_path(workbench)
+ expect(page).to_not have_content(referential.name)
+ end
+ end
- before(:each) { visit workbench_path(workbench) }
+ context 'filtering' do
+ let(:another_organisation) { create :organisation }
+ let(:another_line) { create :line, line_referential: line_ref }
+ let(:another_ref_metadata) { create(:referential_metadata, lines: [another_line]) }
+ let!(:other_referential) { create :referential, workbench: workbench, metadatas: [another_ref_metadata], organisation: another_organisation}
- it 'shows ready referentials belonging to that workbench by default' do
- expect(page).to have_content(ready_referential.name)
- expect(page).not_to have_content(unready_referential.name)
- end
+ before(:each) do
+ visit workbench_path(workbench)
+ end
+
+ context 'without any filter' do
+ it 'should have results' do
+ click_button 'Filtrer'
+ expect(page).to have_content(referential.name)
+ expect(page).to have_content(other_referential.name)
+ end
+ end
+
+ context 'filter by organisation' do
+ it 'should be possible to filter by organisation' do
+ find("#q_organisation_name_eq_any_#{@user.organisation.name.parameterize.underscore}").set(true)
+ click_button 'Filtrer'
+
+ expect(page).to have_content(referential.name)
+ expect(page).not_to have_content(other_referential.name)
+ end
+
+ it 'should be possible to filter by multiple organisation' do
+ find("#q_organisation_name_eq_any_#{@user.organisation.name.parameterize.underscore}").set(true)
+ find("#q_organisation_name_eq_any_#{another_organisation.name.parameterize.underscore}").set(true)
+ click_button 'Filtrer'
+
+ expect(page).to have_content(referential.name)
+ expect(page).to have_content(other_referential.name)
+ end
+
+ it 'should keep filter value on submit' do
+ box = "#q_organisation_name_eq_any_#{another_organisation.name.parameterize.underscore}"
+ find(box).set(true)
+ click_button 'Filtrer'
+ expect(find(box)).to be_checked
+ end
+ end
+
+ context 'filter by status' do
+ it 'should display archived referentials' do
+ other_referential.update_attribute(:archived_at, Date.today)
+ find("#q_archived_at_not_null").set(true)
+
+ click_button 'Filtrer'
+ expect(page).to have_content(other_referential.name)
+ expect(page).to_not have_content(referential.name)
+ end
+
+ it 'should display both archived and unarchived referentials' do
+ other_referential.update_attribute(:archived_at, Date.today)
+ find("#q_archived_at_not_null").set(true)
+ find("#q_archived_at_null").set(true)
+
+ click_button 'Filtrer'
+ expect(page).to have_content(referential.name)
+ expect(page).to have_content(other_referential.name)
+ end
+
+ it 'should display unarchived referentials' do
+ other_referential.update_attribute(:archived_at, Date.today)
+ find("#q_archived_at_null").set(true)
+
+ click_button 'Filtrer'
+ expect(page).to have_content(referential.name)
+ expect(page).to_not have_content(other_referential.name)
+ end
- context 'user has the permission to create referentials' do
- it 'shows the link for a new referetnial' do
- expect(page).to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbenches.first))
+ it 'should keep filter value on submit' do
+ find("#q_archived_at_null").set(true)
+ click_button 'Filtrer'
+ expect(find("#q_archived_at_null")).to be_checked
+ end
+ end
+
+ context 'filter by validity period' do
+ def fill_validity_field date, field
+ select date.year, :from => "q[validity_period][#{field}(1i)]"
+ select I18n.t("date.month_names")[date.month], :from => "q[validity_period][#{field}(2i)]"
+ select date.day, :from => "q[validity_period][#{field}(3i)]"
+ end
+
+ it 'should show results for referential in range' do
+ dates = referential.validity_period.to_a
+ fill_validity_field dates[0], 'begin_gteq'
+ fill_validity_field dates[1], 'end_lteq'
+ click_button 'Filtrer'
+
+ expect(page).to have_content(referential.name)
+ expect(page).to_not have_content(other_referential.name)
+ end
+
+ it 'should keep filtering on sort' do
+ dates = referential.validity_period.to_a
+ fill_validity_field dates[0], 'begin_gteq'
+ fill_validity_field dates[1], 'end_lteq'
+ click_button 'Filtrer'
+
+ find('a[href*="&sort=validity_period"]').click
+
+ expect(page).to have_content(referential.name)
+ expect(page).to_not have_content(other_referential.name)
+ end
+
+ it 'should not show results for out off range' do
+ fill_validity_field(Date.today - 2.year, 'begin_gteq')
+ fill_validity_field(Date.today - 1.year, 'end_lteq')
+ click_button 'Filtrer'
+
+ expect(page).to_not have_content(referential.name)
+ expect(page).to_not have_content(other_referential.name)
+ end
+
+ it 'should keep value on submit' do
+ dates = referential.validity_period.to_a
+ ['begin_gteq', 'end_lteq'].each_with_index do |field, index|
+ fill_validity_field dates[index], field
+ end
+ click_button 'Filtrer'
+
+ ['begin_gteq', 'end_lteq'].each_with_index do |field, index|
+ expect(find("#q_validity_period_#{field}_3i").value).to eq dates[index].day.to_s
+ expect(find("#q_validity_period_#{field}_2i").value).to eq dates[index].month.to_s
+ expect(find("#q_validity_period_#{field}_1i").value).to eq dates[index].year.to_s
+ end
+ end
end
end
- context 'user does not have the permission to create referentials' do
- it 'does not show the clone link for referetnial' do
- @user.update_attribute(:permissions, [])
- visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbenches.first))
+ context 'permissions' do
+ before(:each) do
+ visit workbench_path(workbench)
+ end
+
+ context 'user has the permission to create referentials' do
+ it 'shows the link for a new referetnial' do
+ expect(page).to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ end
+ end
+
+ context 'user does not have the permission to create referentials' do
+ it 'does not show the clone link for referential' do
+ @user.update_attribute(:permissions, [])
+ visit referential_path(referential)
+ expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ end
end
end
end
describe 'create new Referential' do
it "create a new Referential with a specifed line and period" do
- visit workbench_path(workbench)
+ referential.destroy
+ visit workbench_path(workbench)
click_link I18n.t('actions.add')
-
- fill_in "referential[name]", with: "Referential to test creation" # Nom du JDD
- select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]' # Lignes
+ fill_in "referential[name]", with: "Referential to test creation"
+ select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]'
click_button "Valider"
expect(page).to have_css("h1", text: "Referential to test creation")
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 8f4d98c88..d90c14204 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -81,7 +81,7 @@ describe TableBuilderHelper, type: :helper do
<li><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li>
<li><a href="/referentials/new?from=#{referential.id}">Dupliquer</a></li>
<li><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li>
- <li class="delete-action"><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" rel="nofollow" data-method="delete" href="/referentials/#{referential.id}"><span class="fa fa-trash"></span>Supprimer</a></li>
+ <li class="delete-action"><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" rel="nofollow" data-method="delete" href="/referentials/#{referential.id}"><span class="fa fa-trash mr-xs"></span>Supprimer</a></li>
</ul>
</div>
</td>
@@ -176,7 +176,7 @@ describe TableBuilderHelper, type: :helper do
referential: referential
)
allow(helper).to receive(:current_user).and_return(user_context)
- allow(TableBuilderHelper::URL).to receive(:current_referential)
+ allow(helper).to receive(:current_referential)
.and_return(referential)
companies = [company]
@@ -284,7 +284,7 @@ describe TableBuilderHelper, type: :helper do
referential: referential
)
allow(helper).to receive(:current_user).and_return(user_context)
- allow(TableBuilderHelper::URL).to receive(:current_referential)
+ allow(helper).to receive(:current_referential)
.and_return(referential)
companies = [company]
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index cf7e4aa27..f5020ebf8 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -8,13 +8,13 @@ RSpec.describe Calendar, :type => :model do
it { is_expected.to validate_uniqueness_of(:short_name) }
describe '#to_time_table' do
- let(:calendar) { create(:calendar, date_ranges: [Date.today..(Date.today + 1.month)]) }
+ let(:calendar) { create(:calendar, date_ranges: [Date.today...(Date.today + 1.month)]) }
it 'should convert calendar to an instance of Chouette::TimeTable' do
time_table = calendar.convert_to_time_table
expect(time_table).to be_an_instance_of(Chouette::TimeTable)
- expect(time_table.periods[0].period_start).to eq(calendar.date_ranges[0].begin)
- expect(time_table.periods[0].period_end).to eq(calendar.date_ranges[0].end)
+ expect(time_table.periods[0].period_start).to eq(calendar.periods[0].begin)
+ expect(time_table.periods[0].period_end).to eq(calendar.periods[0].end)
expect(time_table.dates.map(&:date)).to match_array(calendar.dates)
end
end
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index aaf9a694f..6601ed5f4 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -20,6 +20,11 @@ describe Chouette::JourneyPattern, :type => :model do
expect(journey_pattern).to_not be_valid
expect(journey_pattern.errors).to have_key(:stop_points)
end
+
+ it 'should only validate on update' do
+ jp = build(:journey_pattern_common)
+ expect(jp).to be_valid
+ end
end
describe "state_update" do
diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb
index 536de873a..bd74a2d4c 100644
--- a/spec/models/chouette/time_table_spec.rb
+++ b/spec/models/chouette/time_table_spec.rb
@@ -7,6 +7,10 @@ describe Chouette::TimeTable, :type => :model do
it { is_expected.to validate_presence_of :comment }
it { is_expected.to validate_uniqueness_of :objectid }
+ def create_time_table_periode time_table, start_date, end_date
+ create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date)
+ end
+
describe "#merge! with time_table" do
let(:another_tt) { create(:time_table) }
let(:another_tt_periods_to_range) { another_tt.periods.map{|p| p.period_start..p.period_end } }
@@ -72,6 +76,58 @@ describe Chouette::TimeTable, :type => :model do
end
end
+ describe "#disjoin!" do
+ let(:another_tt) { create(:time_table) }
+
+ context 'dates' do
+ before do
+ subject.periods.clear
+ another_tt.periods.clear
+ end
+
+ it 'should remove common dates' do
+ subject.disjoin!(another_tt)
+ expect(subject.reload.dates).to be_empty
+ end
+
+ it 'should remove common dates with mixed none common dates' do
+ another_tt.dates.clear
+ another_tt.dates << create(:time_table_date, time_table: another_tt, date: subject.dates[0].date)
+
+ subject.disjoin!(another_tt)
+ expect(subject.reload.dates.map(&:date)).to_not include(another_tt.dates[0].date)
+ end
+ end
+
+ context 'periods' do
+ let(:another_tt_periods_to_range) { another_tt.periods.map{|p| p.period_start..p.period_end } }
+ # Clear dates as we are testing periods
+ before do
+ subject.dates.clear
+ another_tt.dates.clear
+ end
+
+ it 'should remove common dates in periods' do
+ subject.disjoin!(another_tt)
+ expect(subject_periods_to_range).to_not include(*another_tt_periods_to_range)
+ end
+
+ it 'should build new period without common dates in periods' do
+ subject.periods.clear
+ another_tt.periods.clear
+
+ subject.periods << create_time_table_periode(subject, Date.today, Date.today + 10.day)
+ another_tt.periods << create_time_table_periode(another_tt, Date.tomorrow, Date.today + 3.day)
+
+ subject.disjoin!(another_tt)
+ expected_range = Date.tomorrow..Date.today + 3.day
+
+ expect(subject_periods_to_range).to_not include(expected_range)
+ expect(subject.periods.count).to eq 1
+ end
+ end
+ end
+
describe '#intersect! with time_table' do
let(:another_tt) { create(:time_table) }
@@ -105,10 +161,6 @@ describe Chouette::TimeTable, :type => :model do
another_tt.dates.clear
end
- def create_time_table_periode time_table, start_date, end_date
- create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date)
- end
-
it 'should keep common dates in periods' do
subject.intersect!(another_tt)
expect(subject_periods_to_range).to include(*another_tt_periods_to_range)
@@ -1117,294 +1169,6 @@ end
end
end
- describe "#disjoin!" do
- context "timetables have periods with common day_types " do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,6))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,20))
- subject.int_day_types = 4|16|32|128
- another_tt = create(:time_table , :int_day_types => (4|16|64|128) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,6), :period_end => Date.new(2014,8,12))
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,15), :period_end => Date.new(2014,8,2))
- subject.disjoin! another_tt
- subject.reload
- end
- it "should have 0 periods" do
- expect(subject.periods.size).to eq(0)
- end
- it "should have only dates " do
- expect(subject.dates.size).to eq(11)
- expect(subject.dates[0].date).to eq(Date.new(2014,6,30))
- expect(subject.dates[1].date).to eq(Date.new(2014,7,2))
- expect(subject.dates[2].date).to eq(Date.new(2014,7,3))
- expect(subject.dates[3].date).to eq(Date.new(2014,7,5))
- expect(subject.dates[4].date).to eq(Date.new(2014,7,7))
- expect(subject.dates[5].date).to eq(Date.new(2014,7,9))
- expect(subject.dates[6].date).to eq(Date.new(2014,7,10))
- expect(subject.dates[7].date).to eq(Date.new(2014,7,12))
- expect(subject.dates[8].date).to eq(Date.new(2014,7,14))
- expect(subject.dates[9].date).to eq(Date.new(2014,7,17))
- expect(subject.dates[10].date).to eq(Date.new(2014,8,4))
- end
- end
- context "timetables have periods or dates " do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,17), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,18), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,19), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,20), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,8,6), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,8,7), :in_out => true)
- subject.int_day_types = 0
- another_tt = create(:time_table , :int_day_types => (4|16|64|128) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,6), :period_end => Date.new(2014,8,12))
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,17), :period_end => Date.new(2014,7,25))
- subject.disjoin! another_tt
- subject.reload
- end
- it "should have 0 period" do
- expect(subject.periods.size).to eq(0)
- end
- it "should not modify day_types" do
- expect(subject.int_day_types).to eq(0)
- end
- it "should have date reduced for period" do
- expect(subject.dates.size).to eq(4)
- expect(subject.dates[0].date).to eq(Date.new(2014,7,16))
- expect(subject.dates[1].date).to eq(Date.new(2014,7,17))
- expect(subject.dates[2].date).to eq(Date.new(2014,7,20))
- expect(subject.dates[3].date).to eq(Date.new(2014,8,7))
- end
- end
- context "disjoined timetable have all periods in removed ones " do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,20))
- subject.int_day_types = 4|16|32|128
- another_tt = create(:time_table , :int_day_types => (4|16|64|128) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,31), :period_end => Date.new(2014,8,12))
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,20))
- subject.disjoin! another_tt
- subject.reload
- end
- it "should have 0 result periods" do
- expect(subject.periods.size).to eq(0)
- end
- it "should have dates for period reduced" do
- expect(subject.dates.size).to eq(4)
- expect(subject.dates[0].date).to eq(Date.new(2014,7,3))
- expect(subject.dates[1].date).to eq(Date.new(2014,7,10))
- expect(subject.dates[2].date).to eq(Date.new(2014,7,17))
- expect(subject.dates[3].date).to eq(Date.new(2014,8,7))
- end
- end
-
- context "timetable with dates against timetable with dates and periods" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,17), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,18), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,19), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,20), :in_out => true)
- subject.int_day_types = 0
- another_tt = create(:time_table , :int_day_types => (4|16|64|128) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,31), :period_end => Date.new(2014,8,12))
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,17), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,18), :in_out => true)
- subject.disjoin! another_tt
- subject.reload
- end
- it "should have 0 result periods" do
- expect(subject.periods.size).to eq(0)
- end
- it "should have 3 dates left" do
- expect(subject.dates.size).to eq(3)
- expect(subject.dates[0].date).to eq(Date.new(2014,7,16))
- expect(subject.dates[1].date).to eq(Date.new(2014,7,19))
- expect(subject.dates[2].date).to eq(Date.new(2014,7,20))
- end
- end
-
- context "timetable with dates against timetable with dates and periods all covered" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,1), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,2), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,5), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,6), :in_out => true)
- subject.int_day_types = 512
- another_tt = create(:time_table , :int_day_types => (32|64|512) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,11))
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,1), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,2), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,5), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,6), :in_out => true)
- subject.disjoin! another_tt
- subject.reload
- end
-
- it "should have 0 result periods" do
- expect(subject.periods.size).to eq(0)
- end
-
- it "should have 0 dates left" do
- expect(subject.dates.size).to eq(0)
- end
- end
-
- context "with only periods : disjoined timetable have no empty period" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,10), :period_end => Date.new(2014,8,31))
- subject.int_day_types = 4|8
- another_tt = create(:time_table , :int_day_types => (4|8) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,4), :period_end => Date.new(2014,8,7))
- subject.disjoin! another_tt
- subject.reload
- end
-
- it "should have 0 result periods" do
- expect(subject.periods.size).to eq(0)
- end
-
- it "should have 6 dates " do
- expect(subject.dates.size).to eq(6)
- expect(subject.dates[0].date).to eq(Date.new(2014,8,11))
- expect(subject.dates[1].date).to eq(Date.new(2014,8,12))
- expect(subject.dates[2].date).to eq(Date.new(2014,8,18))
- expect(subject.dates[3].date).to eq(Date.new(2014,8,19))
- expect(subject.dates[4].date).to eq(Date.new(2014,8,25))
- expect(subject.dates[5].date).to eq(Date.new(2014,8,26))
- end
- end
-
- context "with only periods : disjoined timetable have no one day period" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,6))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,10), :period_end => Date.new(2014,8,31))
- subject.int_day_types = 4|8|16
- another_tt = create(:time_table , :int_day_types => (4|8) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,4), :period_end => Date.new(2014,8,5))
- subject.disjoin! another_tt
- subject.reload
- end
-
- it "should have 3 result periods" do
- expect(subject.periods.size).to eq(3)
- [
- ['2014-08-11', '2014-08-13'],
- ['2014-08-18', '2014-08-20'],
- ['2014-08-25', '2014-08-27']
- ].each_with_index do |period, index|
- expect(subject.periods[index].period_start.to_s).to eq(period[0])
- expect(subject.periods[index].period_end.to_s).to eq(period[1])
- end
- end
-
- it "should not modify day_types" do
- expect(subject.int_day_types).to eq(4|8|16)
- end
-
- it "should have 1 dates " do
- expect(subject.dates.size).to eq(1)
- expect(subject.dates.first.date.to_s).to eq('2014-08-06')
- end
- end
-
- context "with periods against dates: disjoined timetable have no unused excluded date" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8))
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,10), :period_end => Date.new(2014,8,31))
- subject.int_day_types = 4|8|16
- another_tt = create(:time_table , :int_day_types => (0) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,8,4), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,8,5), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,8,7), :in_out => true)
- subject.disjoin! another_tt
- subject.reload
- end
-
- it "should have same 3 result periods" do
- expect(subject.periods.size).to eq(3)
- [
- ['2014-08-11', '2014-08-13'],
- ['2014-08-18', '2014-08-20'],
- ['2014-08-25', '2014-08-27']
- ].each_with_index do |period, index|
- expect(subject.periods[index].period_start.to_s).to eq(period[0])
- expect(subject.periods[index].period_end.to_s).to eq(period[1])
- end
- end
-
- it "should not modify day_types" do
- expect(subject.int_day_types).to eq(4|8|16)
- end
-
- it "should have only 1 dates " do
- expect(subject.dates.size).to eq(1)
- expect(subject.dates.first.date.to_s).to eq('2014-08-06')
- end
- end
-
-
- context "with same definition : dsjointed timetable should be empty" do
- before do
- subject.periods.clear
- subject.dates.clear
- subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2015,6,1), :period_end => Date.new(2015,6,30))
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2015,6,16), :in_out => true)
- subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2015,6,22), :in_out => false)
- subject.int_day_types = 4|8|16|32|64|128|256
- another_tt = create(:time_table , :int_day_types => ( 4|8|16|32|64|128|256) )
- another_tt.periods.clear
- another_tt.dates.clear
- another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2015,6,1), :period_end => Date.new(2015,6,30))
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2015,6,16), :in_out => true)
- another_tt.dates << Chouette::TimeTableDate.new( :date => Date.new(2015,6,22), :in_out => false)
- subject.disjoin! another_tt
- subject.reload
- end
- it "should have same 0 result periods" do
- expect(subject.periods.size).to eq(0)
- end
- it "should have 0 dates " do
- expect(subject.dates.size).to eq(0)
- end
- end
- end
-
describe "#duplicate" do
it 'should also copy tags' do
subject.tag_list.add('tag1', 'tag2')
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index ee88ca773..01440be0e 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -2,18 +2,17 @@ require 'rails_helper'
RSpec.describe CleanUp, :type => :model do
- it { should validate_presence_of(:begin_date) }
- it { should validate_presence_of(:date_type) }
+ it { should validate_presence_of(:date_type).with_message(:presence) }
+ it { should validate_presence_of(:begin_date).with_message(:presence) }
it { should belong_to(:referential) }
context '#exclude_dates_in_overlapping_period with :before date_type' do
let(:time_table) { create(:time_table) }
let(:period) { time_table.periods[0] }
- let(:cleaner) { create(:clean_up, date_type: :before) }
+ let(:cleaner) { create(:clean_up, date_type: :before, begin_date: period.period_end) }
it 'should add exclude date into period for overlapping period' do
days_in_period = (period.period_start..period.period_end).count
- cleaner.begin_date = period.period_end
expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
time_table.dates.where(in_out: false).count
@@ -31,11 +30,10 @@ RSpec.describe CleanUp, :type => :model do
context '#exclude_dates_in_overlapping_period with :after date_type' do
let(:time_table) { create(:time_table) }
let(:period) { time_table.periods[0] }
- let(:cleaner) { create(:clean_up, date_type: :after) }
+ let(:cleaner) { create(:clean_up, date_type: :after, begin_date: period.period_start + 1.day) }
it 'should add exclude date into period for overlapping period' do
days_in_period = (period.period_start..period.period_end).count
- cleaner.begin_date = period.period_start + 1.day
expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
time_table.dates.where(in_out: false).count
}.by(days_in_period - 2)
@@ -72,11 +70,11 @@ RSpec.describe CleanUp, :type => :model do
end
context '#overlapping_periods' do
- let(:cleaner) { create(:clean_up, date_type: :before, end_date: nil) }
let(:time_table) { create(:time_table) }
+ let(:period) { time_table.periods[0] }
+ let(:cleaner) { create(:clean_up, date_type: :before, begin_date: period.period_start) }
it 'should detect overlapping periods' do
- cleaner.begin_date = time_table.periods[0].period_start
expect(cleaner.overlapping_periods).to include(time_table.periods[0])
end
@@ -128,7 +126,7 @@ RSpec.describe CleanUp, :type => :model do
it 'should destroy record' do
expect{ cleaner.destroy_time_tables_dates_between }.to change {
Chouette::TimeTableDate.count
- }.by(-time_table.dates.count)
+ }.by(-time_table.dates.count + 2)
end
it 'should not destroy record not in range' do
@@ -155,7 +153,7 @@ RSpec.describe CleanUp, :type => :model do
context '#destroy_time_tables_between' do
let!(:time_table) { create(:time_table ) }
- let(:cleaner) { create(:clean_up, date_type: :after, begin_date: time_table.start_date, end_date: time_table.end_date) }
+ let(:cleaner) { create(:clean_up, date_type: :between, begin_date: time_table.start_date - 1.day, end_date: time_table.end_date + 1.day) }
it 'should destroy time_tables with validity period in purge range' do
expect{ cleaner.destroy_time_tables_between }.to change {
@@ -200,9 +198,17 @@ RSpec.describe CleanUp, :type => :model do
end
it 'should destroy time_table vehicle_journey association' do
+ vj = create(:vehicle_journey, time_tables: [time_table, create(:time_table)])
+ cleaner.destroy_time_tables(Chouette::TimeTable.where(id: time_table.id))
+
+ expect(vj.reload.time_tables.map(&:id)).to_not include(time_table.id)
+ end
+
+ it 'should also destroy associated vehicle_journey if it belongs to any other time_table' do
vj = create(:vehicle_journey, time_tables: [time_table])
- cleaner.destroy_time_tables(Chouette::TimeTable.all)
- expect(vj.reload.time_tables).to be_empty
+ expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
+ Chouette::VehicleJourney.count
+ }.by(-1)
end
end
@@ -232,7 +238,7 @@ RSpec.describe CleanUp, :type => :model do
}.by(-1)
end
- it 'should not destroy time_tables with end_date > purge begin date' do
+ it 'should not destroy time_tables with end_date > purge begin_date' do
cleaner.begin_date = Date.today
expect{ cleaner.destroy_time_tables_before }.to_not change {
Chouette::TimeTable.count
diff --git a/spec/policies/application_policy_spec.rb b/spec/policies/application_policy_spec.rb
index a7234461e..3ec177209 100644
--- a/spec/policies/application_policy_spec.rb
+++ b/spec/policies/application_policy_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe ApplicationPolicy, type: :policy do
end
it "allows a user with a different organisation" do
- user.update_attribute :organisation, referential.organisation
+ user.organisation = referential.organisation
expect_it.to permit(user_context, referential)
end
end
diff --git a/spec/policies/boiv_policy_spec.rb b/spec/policies/boiv_policy_spec.rb
index 514534adc..6787ab2ac 100644
--- a/spec/policies/boiv_policy_spec.rb
+++ b/spec/policies/boiv_policy_spec.rb
@@ -1,5 +1,7 @@
RSpec.describe BoivPolicy, type: :policy do
+ let( :record ){ nil }
+
permissions :index? do
it_behaves_like 'permitted policy and same organisation', 'boiv:read-offer'
end
diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb
index ead5918aa..e720b2bc7 100644
--- a/spec/policies/line_policy_spec.rb
+++ b/spec/policies/line_policy_spec.rb
@@ -1,5 +1,8 @@
RSpec.describe LinePolicy, type: :policy do
+ let( :record ){ build_stubbed :line }
+
+
%w{create destroy edit}.each do | permission |
footnote_permission = "#{permission}_footnote"
permissions "#{footnote_permission}?".to_sym do
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
index baf14c9fc..cc949ff45 100644
--- a/spec/policies/route_policy_spec.rb
+++ b/spec/policies/route_policy_spec.rb
@@ -1,5 +1,7 @@
RSpec.describe RoutePolicy, type: :policy do
+ let( :record ){ build_stubbed :route }
+
permissions :create? do
it_behaves_like 'permitted policy', 'routes.create', archived: true
end
diff --git a/spec/policies/routing_constraint_zone_policy_spec.rb b/spec/policies/routing_constraint_zone_policy_spec.rb
index 4b0f2cafe..2508b49f9 100644
--- a/spec/policies/routing_constraint_zone_policy_spec.rb
+++ b/spec/policies/routing_constraint_zone_policy_spec.rb
@@ -1,5 +1,8 @@
RSpec.describe RoutingConstraintZonePolicy, type: :policy do
+ let( :record ){ build_stubbed :routing_constraint_zone }
+
+
permissions :create? do
it_behaves_like 'permitted policy', 'routing_constraint_zones.create', archived: true
end
diff --git a/spec/policies/time_table_policy_spec.rb b/spec/policies/time_table_policy_spec.rb
index 1283a9fcf..90e6600ea 100644
--- a/spec/policies/time_table_policy_spec.rb
+++ b/spec/policies/time_table_policy_spec.rb
@@ -1,5 +1,8 @@
RSpec.describe TimeTablePolicy, type: :policy do
+ let( :record ){ build_stubbed :time_table }
+
+
permissions :duplicate? do
it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
end
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index 56433b2ee..02fea2944 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -24,8 +24,8 @@ module Support
into.module_eval do
subject { described_class }
let( :user_context ) { create_user_context(user: user, referential: referential) }
- let( :referentail ) { create :referential }
- let( :user ) { create :user }
+ let( :referential ) { build_stubbed :referential }
+ let( :user ) { build_stubbed :user }
end
end
def with_user_permission(permission, &blk)
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 4d14c46da..33ed1ffae 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -3,11 +3,11 @@ RSpec.shared_examples 'permitted policy and same organisation' do
context 'permission absent → ' do
it "denies a user with a different organisation" do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
it 'and also a user with the same organisation' do
- user.update_attribute :organisation, referential.organisation
- expect_it.not_to permit(user_context, referential)
+ user.organisation = referential.organisation
+ expect_it.not_to permit(user_context, record)
end
end
@@ -17,19 +17,19 @@ RSpec.shared_examples 'permitted policy and same organisation' do
end
it 'denies a user with a different organisation' do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
it 'but allows it for a user with the same organisation' do
- user.update_attribute :organisation, referential.organisation
- expect_it.to permit(user_context, referential)
+ user.organisation = referential.organisation
+ expect_it.to permit(user_context, record)
end
if archived
it 'removes the permission for archived referentials' do
- user.update_attribute :organisation, referential.organisation
- referential.update_attribute :archived_at, 42.seconds.ago
- expect_it.not_to permit(user_context, referential)
+ user.organisation = referential.organisation
+ referential.archived_at = 42.seconds.ago
+ expect_it.not_to permit(user_context, record)
end
end
end
@@ -39,7 +39,7 @@ RSpec.shared_examples 'permitted policy' do
| permission, archived: false|
context 'permission absent → ' do
it "denies a user with a different organisation" do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
end
context 'permission present → ' do
@@ -47,13 +47,13 @@ RSpec.shared_examples 'permitted policy' do
add_permissions(permission, for_user: user)
end
it 'allows a user with a different organisation' do
- expect_it.to permit(user_context, referential)
+ expect_it.to permit(user_context, record)
end
if archived
it 'removes the permission for archived referentials' do
- referential.update_attribute :archived_at, 42.seconds.ago
- expect_it.not_to permit(user_context, referential)
+ referential.archived_at = 42.seconds.ago
+ expect_it.not_to permit(user_context, record)
end
end
end