diff options
| author | Luc Donnet | 2017-12-06 16:47:10 +0100 |
|---|---|---|
| committer | Luc Donnet | 2017-12-06 16:47:10 +0100 |
| commit | b85fd26e9b399b488aaf76d417e63e2a75e98689 (patch) | |
| tree | 5a5099b81e5617c64bb248e71f2c4492d7700138 | |
| parent | 1c8cf43eb38b20dfb37508c8c731ae7bdaa320a6 (diff) | |
| parent | af709926b6fac4fce22345a34fdf57de5b4d6cbf (diff) | |
| download | chouette-core-b85fd26e9b399b488aaf76d417e63e2a75e98689.tar.bz2 | |
Merge branch 'master' into staging
32 files changed, 437 insertions, 109 deletions
@@ -1,4 +1,3 @@ -# coding: utf-8 source 'https://rubygems.org' # Use https for github diff --git a/app/controllers/api/v1/internals/application_controller.rb b/app/controllers/api/v1/internals/application_controller.rb new file mode 100644 index 000000000..ab9daf4f7 --- /dev/null +++ b/app/controllers/api/v1/internals/application_controller.rb @@ -0,0 +1,29 @@ +module Api + module V1 + module Internals + class ApplicationController < ActionController::Base + respond_to :json + layout false + before_action :require_token + + def require_token + authenticate_token || render_unauthorized("Access denied") + end + + protected + + def render_unauthorized(message) + errors = { errors: [ { detail: message } ] } + render json: errors, status: :unauthorized + end + + private + def authenticate_token + authenticate_with_http_token do |token| + return true if Rails.application.secrets.api_token == token + end + end + end + end + end +end diff --git a/app/controllers/api/v1/internals/compliance_check_sets_controller.rb b/app/controllers/api/v1/internals/compliance_check_sets_controller.rb new file mode 100644 index 000000000..ccf1bcd2f --- /dev/null +++ b/app/controllers/api/v1/internals/compliance_check_sets_controller.rb @@ -0,0 +1,55 @@ +module Api + module V1 + module Internals + class ComplianceCheckSetsController < Api::V1::Internals::ApplicationController + include ControlFlow + + def validated + find_compliance_check_set + + if @compliance_check_set.update_status + render :validated + else + render json: { + status: "error", + messages: @compliance_check_set.errors.full_messages + } + end + end + + def notify_parent + find_compliance_check_set + check_parent + + if @compliance_check_set.notify_parent + render json: { + status: "ok", + message:"#{@compliance_check_set.parent_type} (id: #{@compliance_check_set.parent_id}) successfully notified at #{l(@compliance_check_set.notified_parent_at)}" + } + else + render json: {status: "error", message: @compliance_check_set.errors.full_messages } + end + end + + private + + def check_parent + unless @compliance_check_set.parent + render json: {status: "error", message: I18n.t('compliance_check_sets.errors.no_parent') } + finish_action! + end + end + + def find_compliance_check_set + @compliance_check_set = ComplianceCheckSet.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render json: { + status: "error", + message: "Record not found" + } + finish_action! + end + end + end + end +end diff --git a/app/controllers/api/v1/internals/netex_imports_controller.rb b/app/controllers/api/v1/internals/netex_imports_controller.rb new file mode 100644 index 000000000..c8e33f7b8 --- /dev/null +++ b/app/controllers/api/v1/internals/netex_imports_controller.rb @@ -0,0 +1,104 @@ +module Api + module V1 + module Internals + class NetexImportsController < Api::V1::Internals::ApplicationController + include ControlFlow + + def create + respond_to do | format | + format.json(&method(:create_models)) + end + end + + def notify_parent + find_netex_import + if @netex_import.notify_parent + render json: { + status: "ok", + message:"#{@netex_import.parent_type} (id: #{@netex_import.parent_id}) successfully notified at #{l(@netex_import.notified_parent_at)}" + } + else + render json: {status: "error", message: @netex_import.errors.full_messages } + end + end + + private + + def find_netex_import + @netex_import = NetexImport.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render json: { + status: "error", + message: "Record not found" + } + finish_action! + end + + def find_workbench + @workbench = Workbench.find(netex_import_params['workbench_id']) + rescue ActiveRecord::RecordNotFound + render json: {errors: {'workbench_id' => 'missing'}}, status: 406 + finish_action! + end + + def create_models + find_workbench + create_referential + create_netex_import + end + + def create_netex_import + attributes = netex_import_params.merge creator: "Webservice" + + attributes = attributes.merge referential_id: @new_referential.id + + @netex_import = NetexImport.new attributes + @netex_import.save! + + unless @netex_import.referential + Rails.logger.info "Can't create referential for import #{@netex_import.id}: #{@new_referential.inspect} #{@new_referential.metadatas.inspect} #{@new_referential.errors.full_messages}" + @netex_import.messages.create criticity: :error, message_key: "referential_creation" + end + rescue ActiveRecord::RecordInvalid + render json: {errors: @netex_import.errors}, status: 406 + finish_action! + end + + def create_referential + @new_referential = + Referential.new( + name: netex_import_params['name'], + organisation_id: @workbench.organisation_id, + workbench_id: @workbench.id, + metadatas: [metadata] + ) + @new_referential.save + end + + def metadata + metadata = ReferentialMetadata.new + + if netex_import_params['file'] + netex_file = STIF::NetexFile.new(netex_import_params['file'].to_io) + frame = netex_file.frames.first + + if frame + metadata.periodes = frame.periods + + line_objectids = frame.line_refs.map { |ref| "STIF:CODIFLIGNE:Line:#{ref}" } + metadata.line_ids = @workbench.lines.where(objectid: line_objectids).pluck(:id) + end + end + + metadata + end + + def netex_import_params + params + .require('netex_import') + .permit(:file, :name, :workbench_id, :parent_id, :parent_type) + end + end + end + end +end 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/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb index 03b920030..600c69126 100644 --- a/app/controllers/compliance_check_sets_controller.rb +++ b/app/controllers/compliance_check_sets_controller.rb @@ -12,7 +12,7 @@ class ComplianceCheckSetsController < ChouetteController @q_for_form = scope.ransack(params[:q]) format.html { @compliance_check_sets = ModelDecorator.decorate( - @q_for_form.result, + @q_for_form.result.order(created_at: :desc), with: ComplianceCheckSetDecorator ) } diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 5e23a1795..46d34efda 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -77,10 +77,10 @@ class ImportsController < ChouetteController end def sort_column - parent.imports.column_names.include?(params[:sort]) ? params[:sort] : 'name' + parent.imports.column_names.include?(params[:sort]) ? params[:sort] : 'created_at' end def sort_direction - %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' + %w[asc desc].include?(params[:direction]) ? params[:direction] : 'desc' end def decorate_imports(imports) 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/compliance_check_set.rb b/app/models/compliance_check_set.rb index d734e5f5a..020100f4a 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -19,6 +19,13 @@ class ComplianceCheckSet < ActiveRecord::Base where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end) end + def notify_parent + if parent + # parent.child_change + update(notified_parent_at: DateTime.now) + end + end + def update_status statuses = compliance_check_resources.map do |resource| case resource.status 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/netex_import.rb b/app/models/netex_import.rb index a7a5bb9b8..b21af3408 100644 --- a/app/models/netex_import.rb +++ b/app/models/netex_import.rb @@ -27,7 +27,9 @@ class NetexImport < Import end def call_boiv_iev + Rails.logger.error("Begin IEV call for import") Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}")) + Rails.logger.error("End IEV call for import") rescue Exception => e logger.error "IEV server error : #{e.message}" logger.error e.backtrace.inspect diff --git a/app/models/referential.rb b/app/models/referential.rb index ee74bd9f5..29efaa609 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 @@ -286,6 +288,7 @@ class Referential < ActiveRecord::Base def create_schema unless created_from Apartment::Tenant.create slug + Rails.logger.error( "Schema migrations count for Referential #{slug} " + Referential.connection.select_value("select count(*) from #{slug}.schema_migrations;").to_s ) end 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/breadcrumbs.rb b/config/breadcrumbs.rb index 14c3d5470..970f933f0 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -81,6 +81,11 @@ crumb :import do |workbench, import| parent :imports, workbench end +crumb :import_resources do |import, import_resources| + link I18n.t('import_resources.index.title'), workbench_import_import_resources_path(import.workbench, import) + parent :import, import.workbench, import +end + crumb :organisation do |organisation| link breadcrumb_name(organisation), organisation_path(organisation) end diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml index 87d9abef0..49323c91f 100644 --- a/config/locales/compliance_check_sets.en.yml +++ b/config/locales/compliance_check_sets.en.yml @@ -22,6 +22,8 @@ en: table_state: "%{lines_status} lines imported on %{lines_in_compliance_check_set} in the archive" table_explanation: "These controls apply to all imported data and condition the construction of your organization's offer." metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" + errors: + no_parent: "The compliance check set doesn't have any parent" activerecord: attributes: compliance_check_set: diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml index 84db8b934..0382f2937 100644 --- a/config/locales/compliance_check_sets.fr.yml +++ b/config/locales/compliance_check_sets.fr.yml @@ -18,6 +18,8 @@ fr: table_state: "%{lines_status} lignes importées sur %{lines_in_compliance_check_set} présentes dans l'archive" table_explanation: Ces contrôles s’appliquent pour toutes les données importées et conditionnent la construction de l’offre de votre organisation metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" + errors: + no_parent: "Le jeux de contrôle n'a pas de parent" activerecord: attributes: compliance_check_set: 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/config/routes.rb b/config/routes.rb index 8ea8168bf..65fa62557 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,9 +64,10 @@ ChouetteIhm::Application.routes.draw do resources :stop_areas, only: [:index, :show] resources :time_tables, only: [:index, :show] resources :vehicle_journeys, only: :show - patch 'compliance_check_sets/:id', - to: 'compliance_check_sets#validated', - as: 'compliance_check_set' + namespace :internals do + get 'compliance_check_sets/:id/notify_parent', to: 'compliance_check_sets#notify_parent' + get 'netex_imports/:id/notify_parent', to: 'netex_imports#notify_parent' + end end end diff --git a/config/secrets.yml b/config/secrets.yml index 2f9d5abe6..0de3fd6ef 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,6 +13,7 @@ development: secret_key_base: e901adb90fc1fff22f7237d138ef232a5425b67e81ccb3ce7003aab2c002d35a7c3d593c0fca3dcb21e8c911a8260c984a830d1d61776ad3005eb373abebc695 api_endpoint: "http://localhost:8080/chouette_iev/" + api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8= google_analytic_tracker: "UA-AAAAAAAA" # geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa" newrelic_licence_key: "" @@ -21,6 +22,7 @@ development: test: secret_key_base: 54f61aab23322611dd0bbf73b7f034db34281f7f4b3c4992eaaff20ecc9673bbd467beaa6fcb48379ca69b80bc5662deac4e33ca144f2482146123d3e966016a api_endpoint: "http://localhost:8080/chouette_iev/" + api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8= google_analytic_tracker: "UA-AAAAAAAA" # geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa" osrm_endpoint: "http://router.project-osrm.org" @@ -30,6 +32,7 @@ test: production: secret_key_base: 54f61aab23322611dd0bbf73b7f034db34281f7f4b3c4992eaaff20ecc9673bbd467beaa6fcb48379ca69b80bc5662deac4e33ca144f2482146123d3e966016a api_endpoint: "http://localhost:8080/chouette_iev/" + api_token: VFHir2GWWjuRNZnHHnQD5Hn+ubRMQ1kNLnu7oCLf+4KR8+PmYqb1EzKZmmuRfVP/yxS0aQ3NklfNbbgUatTtly5540oo4L6ePdbYkwDzrBXF9xgYekOlTCwIGSl430mluv3wcXNEbrRLu2CevIBULtiRZriAEYVOpp9G+lQI+t8= google_analytic_tracker: "UA-AAAAAAAA" # geoportail_api_key: "aaaaaaaaaaaaaaaaaaaaaa" newrelic_licence_key: "" diff --git a/db/migrate/20171130131328_add_notify_parent_at_to_compliance_check_sets.rb b/db/migrate/20171130131328_add_notify_parent_at_to_compliance_check_sets.rb new file mode 100644 index 000000000..3bf6b8aa1 --- /dev/null +++ b/db/migrate/20171130131328_add_notify_parent_at_to_compliance_check_sets.rb @@ -0,0 +1,5 @@ +class AddNotifyParentAtToComplianceCheckSets < ActiveRecord::Migration + def change + add_column :compliance_check_sets, :notified_parent_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 4650d8812..4a04dac26 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171128112629) do +ActiveRecord::Schema.define(version: 20171130180144) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -195,6 +195,7 @@ ActiveRecord::Schema.define(version: 20171128112629) do t.string "name" t.datetime "started_at" t.datetime "ended_at" + t.datetime "notified_parent_at" end add_index "compliance_check_sets", ["compliance_control_set_id"], name: "index_compliance_check_sets_on_compliance_control_set_id", using: :btree @@ -279,22 +280,6 @@ ActiveRecord::Schema.define(version: 20171128112629) do add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree - create_table "delayed_jobs", id: :bigserial, force: :cascade do |t| - t.integer "priority", default: 0 - t.integer "attempts", default: 0 - t.text "handler" - t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" - t.string "locked_by", limit: 255 - t.string "queue", limit: 255 - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree - create_table "exports", id: :bigserial, force: :cascade do |t| t.integer "referential_id", limit: 8 t.string "status" @@ -414,7 +399,7 @@ ActiveRecord::Schema.define(version: 20171128112629) do t.datetime "started_at" t.datetime "ended_at" t.string "token_download" - t.string "type", limit: 255 + t.string "type" t.integer "parent_id", limit: 8 t.string "parent_type" t.datetime "notified_parent_at" @@ -557,11 +542,6 @@ ActiveRecord::Schema.define(version: 20171128112629) do add_index "networks", ["objectid"], name: "networks_objectid_key", unique: true, using: :btree add_index "networks", ["registration_number"], name: "networks_registration_number_key", using: :btree - create_table "object_id_factories", id: :bigserial, force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "organisations", id: :bigserial, force: :cascade do |t| t.string "name" t.datetime "created_at" @@ -728,7 +708,7 @@ ActiveRecord::Schema.define(version: 20171128112629) do create_table "stop_areas", id: :bigserial, force: :cascade do |t| t.integer "parent_id", limit: 8 - t.string "objectid", null: false + t.string "objectid", null: false t.integer "object_version", limit: 8 t.string "name" t.string "comment" @@ -736,8 +716,8 @@ ActiveRecord::Schema.define(version: 20171128112629) do t.string "registration_number" t.string "nearest_topic_name" t.integer "fare_code" - t.decimal "longitude", precision: 19, scale: 16 - t.decimal "latitude", precision: 19, scale: 16 + t.decimal "longitude", precision: 19, scale: 16 + t.decimal "latitude", precision: 19, scale: 16 t.string "long_lat_type" t.string "country_code" t.string "street_name" @@ -755,7 +735,7 @@ ActiveRecord::Schema.define(version: 20171128112629) do t.datetime "deleted_at" t.datetime "created_at" t.datetime "updated_at" - t.string "stif_type", limit: 255 + t.string "stif_type" end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -825,17 +805,17 @@ ActiveRecord::Schema.define(version: 20171128112629) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color", limit: 255 + t.string "color" t.integer "created_from_id", limit: 8 t.string "checksum" t.text "checksum_source" @@ -990,9 +970,7 @@ ActiveRecord::Schema.define(version: 20171128112629) do add_foreign_key "compliance_controls", "compliance_control_blocks" add_foreign_key "compliance_controls", "compliance_control_sets" add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade - add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify - add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "vehicle_journeys", on_delete: :nullify add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", on_delete: :cascade add_foreign_key "journey_patterns", "stop_points", column: "arrival_stop_point_id", name: "arrival_point_fkey", on_delete: :nullify diff --git a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb deleted file mode 100644 index 1c3784807..000000000 --- a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -RSpec.describe Api::V1::ComplianceCheckSetsController, type: :controller do - include_context 'iboo authenticated api user' - - describe "POST #validate" do - let(:check_set) { create(:compliance_check_set) } - - it "calls #update_status on the ComplianceCheckSet" do - expect_any_instance_of(ComplianceCheckSet).to receive(:update_status) - - patch :validated, id: check_set.id - end - - context "responds with" do - render_views - - it "object JSON on #update_status true" do - allow_any_instance_of( - ComplianceCheckSet - ).to receive(:update_status).and_return(true) - - patch :validated, id: check_set.id - - expect(JSON.parse(response.body)['id']).to eq(check_set.id) - end - - it "error JSON on #update_status false" do - allow_any_instance_of( - ComplianceCheckSet - ).to receive(:update_status).and_return(false) - - patch :validated, id: check_set.id - - expect(response.body).to include('error') - end - end - end -end diff --git a/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb new file mode 100644 index 000000000..e73790384 --- /dev/null +++ b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +RSpec.describe Api::V1::Internals::ComplianceCheckSetsController, type: :controller do + let(:check_set_1) { create :compliance_check_set } + let(:check_set_2) { create :compliance_check_set } + + describe "GET #notify_parent" do + context 'unauthenticated' do + include_context 'iboo wrong authorisation internal api' + + it 'should not be successful' do + get :notify_parent, id: check_set_1.id, format: :json + expect(response).to have_http_status 401 + end + end + + context 'authenticated' do + include_context 'iboo authenticated internal api' + + describe "with existing record" do + + before(:each) do + get :notify_parent, id: check_set_2.id, format: :json + end + + it 'should be successful' do + expect(response).to have_http_status 200 + end + + describe "that has a parent" do + xit "calls #notify_parent on the import" do + expect(check_set_2.reload.notified_parent_at).not_to be_nil + end + end + + describe "that does not have a parent" do + xit "should not be successful" do + expect(response.body).to include("error") + end + end + + end + + describe "with non existing record" do + it "should throw an error" do + get :notify_parent, id: 47, format: :json + expect(response.body).to include("error") + end + end + end + end +end diff --git a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb new file mode 100644 index 000000000..ccdc258f4 --- /dev/null +++ b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb @@ -0,0 +1,42 @@ +RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do + let(:import_1) { create :netex_import } + let(:import_2) { create :netex_import } + + describe "GET #notify_parent" do + context 'unauthenticated' do + include_context 'iboo wrong authorisation internal api' + + it 'should not be successful' do + get :notify_parent, id: import_1.id, format: :json + expect(response).to have_http_status 401 + end + end + + context 'authenticated' do + include_context 'iboo authenticated internal api' + + describe "with existing record" do + + before(:each) do + get :notify_parent, id: import_2.id, format: :json + end + + it 'should be successful' do + expect(response).to have_http_status 200 + end + + it "calls #notify_parent on the import" do + expect(import_2.reload.notified_parent_at).not_to be_nil + end + end + + describe "with non existing record" do + it "should throw an error" do + get :notify_parent, id: 47, format: :json + expect(response.body).to include("error") + end + end + end + end +end + diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb deleted file mode 100644 index 3ddb1dad1..000000000 --- a/spec/controllers/compliance_check_sets_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails_helper' - -RSpec.describe ComplianceCheckSetsController, type: :controller do - login_user - - let(:compliance_check_set) { create :compliance_check_set } - - describe "GET executed" do - it 'should be successful' do - get :executed, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id - expect(response).to be_success - end - end - - describe "GET index" do - it 'should be successful' do - get :index, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id - expect(response).to be_success - end - end - -end 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 diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb index e9b0025a2..5e472eb85 100644 --- a/spec/support/shared_context.rb +++ b/spec/support/shared_context.rb @@ -13,3 +13,19 @@ shared_context 'iboo wrong authorisation api user' do request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('fake code', api_key.token) end end + +shared_context 'iboo authenticated internal api' do + let(:api_key) { Rails.application.secrets.api_token } + + before do + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key) + end +end + +shared_context 'iboo wrong authorisation internal api' do + let(:api_key) { "false_api_token" } + + before do + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key) + end +end |
