aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--app/controllers/api/v1/netex_imports_controller.rb6
-rw-r--r--app/controllers/time_table_combinations_controller.rb1
-rw-r--r--app/models/chouette/access_point.rb1
-rw-r--r--app/models/concerns/objectid_formatter_support.rb4
-rw-r--r--app/models/referential.rb8
-rw-r--r--app/services/http_service.rb1
-rw-r--r--app/views/time_table_combinations/new.html.slim1
-rw-r--r--app/views/time_tables/edit.html.slim1
-rw-r--r--config/locales/time_table_combinations.en.yml2
-rw-r--r--config/locales/time_table_combinations.fr.yml2
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb68
-rw-r--r--spec/support/random.rb9
13 files changed, 94 insertions, 11 deletions
diff --git a/Gemfile b/Gemfile
index 3c625a530..21f534c8b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,3 @@
-# coding: utf-8
source 'https://rubygems.org'
# Use https for github
diff --git a/app/controllers/api/v1/netex_imports_controller.rb b/app/controllers/api/v1/netex_imports_controller.rb
index 8e8c48986..d86c1fcd8 100644
--- a/app/controllers/api/v1/netex_imports_controller.rb
+++ b/app/controllers/api/v1/netex_imports_controller.rb
@@ -1,9 +1,11 @@
module Api
module V1
- class NetexImportsController < ChouetteController
+ class NetexImportsController < ActionController::Base
include ControlFlow
- skip_before_action :authenticate
+
+ respond_to :json, :xml
+ layout false
def create
respond_to do | format |
diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb
index 26cd425b3..317bc5518 100644
--- a/app/controllers/time_table_combinations_controller.rb
+++ b/app/controllers/time_table_combinations_controller.rb
@@ -1,5 +1,6 @@
class TimeTableCombinationsController < ChouetteController
include ReferentialSupport
+ defaults :resource_class => TimeTableCombination
belongs_to :referential do
belongs_to :time_table, :parent_class => Chouette::TimeTable
end
diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb
index 7428db1ea..b6f78f239 100644
--- a/app/models/chouette/access_point.rb
+++ b/app/models/chouette/access_point.rb
@@ -10,7 +10,6 @@ module Chouette
include Geokit::Mappable
include ProjectionFields
- include ObjectidSupport
has_many :access_links, :dependent => :destroy
belongs_to :stop_area
diff --git a/app/models/concerns/objectid_formatter_support.rb b/app/models/concerns/objectid_formatter_support.rb
index 34a51740f..edc7704b4 100644
--- a/app/models/concerns/objectid_formatter_support.rb
+++ b/app/models/concerns/objectid_formatter_support.rb
@@ -3,9 +3,9 @@ module ObjectidFormatterSupport
included do
extend Enumerize
- enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex'
+ enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne)
validates_presence_of :objectid_format
-
+
def objectid_formatter
objectid_formatter_class.new
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index ee74bd9f5..ca20c639f 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -127,10 +127,11 @@ class Referential < ActiveRecord::Base
Chouette::RoutingConstraintZone.all
end
- after_initialize :define_default_attributes
+ before_validation :define_default_attributes
def define_default_attributes
self.time_zone ||= Time.zone.name
+ self.objectid_format ||= workbench.objectid_format if workbench
end
def switch
@@ -140,8 +141,8 @@ class Referential < ActiveRecord::Base
end
def self.new_from(from, functional_scope)
- Referential.new(
- name: I18n.t("activerecord.copy", :name => from.name),
+ Referential.new(
+ name: I18n.t("activerecord.copy", name: from.name),
slug: "#{from.slug}_clone",
prefix: from.prefix,
time_zone: from.time_zone,
@@ -149,6 +150,7 @@ class Referential < ActiveRecord::Base
line_referential: from.line_referential,
stop_area_referential: from.stop_area_referential,
created_from: from,
+ objectid_format: from.objectid_format,
metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) }
)
end
diff --git a/app/services/http_service.rb b/app/services/http_service.rb
index db4441395..c0cc1c59b 100644
--- a/app/services/http_service.rb
+++ b/app/services/http_service.rb
@@ -26,7 +26,6 @@ module HTTPService extend self
# params: { netex_import: {referential_id: 13, workbench_id: 1}},
# upload: {file: [StringIO.new('howdy'), 'application/zip', 'greeting']})
def post_resource(host:, path:, token: nil, params: {}, upload: nil)
- token = token || params
Faraday.new(url: host) do |c|
c.headers['Authorization'] = "Token token=#{token.inspect}" if token
c.request :multipart
diff --git a/app/views/time_table_combinations/new.html.slim b/app/views/time_table_combinations/new.html.slim
index f18553081..7d2551311 100644
--- a/app/views/time_table_combinations/new.html.slim
+++ b/app/views/time_table_combinations/new.html.slim
@@ -1,4 +1,3 @@
-
.page_content
.container-fluid
.row
diff --git a/app/views/time_tables/edit.html.slim b/app/views/time_tables/edit.html.slim
index 6ad572906..e1c566ff4 100644
--- a/app/views/time_tables/edit.html.slim
+++ b/app/views/time_tables/edit.html.slim
@@ -1,5 +1,6 @@
- breadcrumb :time_table, @referential, @time_table
- page_header_content_for @time_table
+- content_for :page_header_title, t('time_tables.show.title', name: @time_table.comment), flush: true
.page_content
.container-fluid
diff --git a/config/locales/time_table_combinations.en.yml b/config/locales/time_table_combinations.en.yml
index 142270d13..6eae7b317 100644
--- a/config/locales/time_table_combinations.en.yml
+++ b/config/locales/time_table_combinations.en.yml
@@ -1,5 +1,7 @@
en:
time_table_combinations:
+ new:
+ title: Combine a calendar
success: "operation applied on timetable"
failure: "operation failed on timetable"
combined_type:
diff --git a/config/locales/time_table_combinations.fr.yml b/config/locales/time_table_combinations.fr.yml
index 5a23cf029..0430a382e 100644
--- a/config/locales/time_table_combinations.fr.yml
+++ b/config/locales/time_table_combinations.fr.yml
@@ -1,5 +1,7 @@
fr:
time_table_combinations:
+ new:
+ title: Combiner un calendrier
success: "opération appliquée sur le calendrier"
failure: "opération échouée"
combined_type:
diff --git a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
new file mode 100644
index 000000000..b3ee68be3
--- /dev/null
+++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
@@ -0,0 +1,68 @@
+RSpec.describe Referential do
+
+ let( :legal_formats ){ described_class.objectid_format.values }
+
+
+ describe 'default attributes' do
+
+ context 'referential w/o an objectid_format' do
+ let( :referential ){ described_class.new }
+ let( :workbench ){ build_stubbed :workbench, objectid_format: random_element(legal_formats) }
+
+ it "but a workbench will take the format of the workbench" do
+ referential.workbench = workbench
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to eq(workbench.objectid_format)
+ end
+
+ it 'and w/o a workbench will take the default objectid_format' do
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to be_nil
+ end
+ end
+
+
+ context 'referential with an objectid_format' do
+ let( :distinct_formats ){ distinct_random_elements(legal_formats, count: 2) }
+
+ let( :referential ){ build_stubbed :referential, objectid_format: distinct_formats.first}
+ let( :workbench ){ build_stubbed :workbench, objectid_format: distinct_formats.second }
+
+ it "and a workbench will not take the format of the workbench" do
+ referential.workbench = workbench
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+
+ it 'and w/o a workbench will not take the default objectid_format' do
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+ end
+
+ end
+
+
+
+ describe 'self.new_from' do
+
+ let( :source ){ build :referential }
+ let( :functional_scope ){ double('functional scope') }
+
+ it 'copies objectid_format from source' do
+ expect( described_class )
+ .to receive(:new)
+ .with(name: I18n.t("activerecord.copy", name: source.name),
+ slug: "#{source.slug}_clone",
+ prefix: source.prefix,
+ time_zone: source.time_zone,
+ bounds: source.bounds,
+ line_referential: source.line_referential,
+ stop_area_referential: source.stop_area_referential,
+ created_from: source,
+ objectid_format: source.objectid_format,
+ metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) })
+
+ described_class.new_from( source, functional_scope )
+ end
+
+ end
+end
diff --git a/spec/support/random.rb b/spec/support/random.rb
index 0ebc2ee5e..16d8b4df3 100644
--- a/spec/support/random.rb
+++ b/spec/support/random.rb
@@ -10,6 +10,15 @@ module Support
def random_element from
from[random_int(from.size)]
end
+
+ def random_elements( from, count: )
+ (1..count).map{ |_| random_element from }
+ end
+
+ def distinct_random_elements( from, count: )
+ f = from.dup
+ (1..count).map { |_| f.delete_at( random_int(f.size) ) }
+ end
def random_int max_plus_one=PRETTY_LARGE_INT
(random_number * max_plus_one).to_i