From 781f3ae0b3dab188ba7bb960e46addb0995b45f2 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 14 Jul 2017 10:25:32 +0200 Subject: Fixes: #3555@1h - Import#parent_id & #parent_type migration generated - Import#belongs_to :parent, class_name: to_s specified - Import#belongs_to :parent, class_name: to_s implemented --- app/controllers/import_tasks_controller.rb | 1 - app/models/import.rb | 2 ++ ...0170715041954_add_parent_type_and_parent_id_to_imports.rb | 6 ++++++ db/schema.rb | 4 +++- spec/controllers/api/v1/netex_import_controller_spec.rb | 12 ++++++++++++ spec/models/import_spec.rb | 1 + 6 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170715041954_add_parent_type_and_parent_id_to_imports.rb create mode 100644 spec/controllers/api/v1/netex_import_controller_spec.rb diff --git a/app/controllers/import_tasks_controller.rb b/app/controllers/import_tasks_controller.rb index 0e3ed6445..cb377ec5a 100644 --- a/app/controllers/import_tasks_controller.rb +++ b/app/controllers/import_tasks_controller.rb @@ -1,4 +1,3 @@ -# coding: utf-8 class ImportTasksController < ChouetteController defaults :resource_class => ImportTask diff --git a/app/models/import.rb b/app/models/import.rb index d0736ab0b..535c676b1 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -3,6 +3,8 @@ class Import < ActiveRecord::Base belongs_to :workbench belongs_to :referential + belongs_to :parent, class_name: to_s + extend Enumerize enumerize :status, in: %i(new pending successful failed running aborted canceled) diff --git a/db/migrate/20170715041954_add_parent_type_and_parent_id_to_imports.rb b/db/migrate/20170715041954_add_parent_type_and_parent_id_to_imports.rb new file mode 100644 index 000000000..96c1c2a59 --- /dev/null +++ b/db/migrate/20170715041954_add_parent_type_and_parent_id_to_imports.rb @@ -0,0 +1,6 @@ +class AddParentTypeAndParentIdToImports < ActiveRecord::Migration + def change + add_column :imports, :parent_id, :bigint + add_column :imports, :parent_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index e64e5c04a..b56027f48 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: 20170607141317) do +ActiveRecord::Schema.define(version: 20170715041954) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -285,6 +285,8 @@ ActiveRecord::Schema.define(version: 20170607141317) do t.datetime "ended_at" t.string "token_download" t.string "type", limit: 255 + t.integer "parent_id", limit: 8 + t.string "parent_type" end add_index "imports", ["referential_id"], name: "index_imports_on_referential_id", using: :btree diff --git a/spec/controllers/api/v1/netex_import_controller_spec.rb b/spec/controllers/api/v1/netex_import_controller_spec.rb new file mode 100644 index 000000000..b6b90f7d1 --- /dev/null +++ b/spec/controllers/api/v1/netex_import_controller_spec.rb @@ -0,0 +1,12 @@ +RSpec.describe Api::V1::NetexImportController, type: :controller do + let( :netex_import ){ build_stubbed :netex_import } + + it_behaves_like "api key protected controller" do + let(:data){ netex_import } + end + + describe "POST #create" do + + end + +end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index a2855d086..34bfb0b23 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.describe Import, :type => :model do it { should belong_to(:referential) } it { should belong_to(:workbench) } + it { should belong_to(:parent).class_name(described_class.to_s) } it { should enumerize(:status).in(:new, :pending, :successful, :failed, :canceled, :running, :aborted ) } -- cgit v1.2.3 From 0a12bcfd146fef2fe173ebe65b364d28c90969a3 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 17 Jul 2017 12:11:43 +0200 Subject: Refs: #3506@1.5h sketching out specs [amend me] --- app/controllers/api/v1/imports_controller.rb | 10 +++++++ app/controllers/imports_controller.rb | 2 ++ config/environments/development.rb | 23 ++++++++------- config/routes.rb | 37 +++++++++++++------------ spec/models/api/v1/netex_import_spec.rb | 15 ++++++++++ spec/routing/api/v1/access_links_routes_spec.rb | 9 ++++++ spec/routing/api/v1/import_routes_spec.rb | 10 +++++++ spec/routing/group_of_lines_spec.rb | 4 +-- 8 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 app/controllers/api/v1/imports_controller.rb create mode 100644 spec/models/api/v1/netex_import_spec.rb create mode 100644 spec/routing/api/v1/access_links_routes_spec.rb create mode 100644 spec/routing/api/v1/import_routes_spec.rb diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb new file mode 100644 index 000000000..7dc3021d9 --- /dev/null +++ b/app/controllers/api/v1/imports_controller.rb @@ -0,0 +1,10 @@ +module Api + module V1 + class ImportsController < ChouetteController + + def create + + end + end + end +end diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 70c5c1a0d..01a46f064 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -23,6 +23,8 @@ class ImportsController < BreadcrumbController end def create + require 'pry' + binding.pry create! { workbench_import_path(parent, resource) } end diff --git a/config/environments/development.rb b/config/environments/development.rb index 59cb9eefa..35f697d04 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -61,17 +61,20 @@ Rails.application.configure do config.reflex_api_url = "https://pprod.reflex.stif.info/ws/reflex/V1/service=getData" config.codifligne_api_url = "https://pprod.codifligne.stif.info/rest/v1/lc/getlist" - # config.chouette_authentication_settings = { - # type: "database" - # } - config.chouette_authentication_settings = { - type: "cas", - cas_server: "http://stif-portail-dev.af83.priv/sessions" - } + if Rails.env.development? && ENV['NO_VPN'] + config.chouette_authentication_settings = { + type: "database" + } + else + config.chouette_authentication_settings = { + type: "cas", + cas_server: "http://stif-portail-dev.af83.priv/sessions" + } + end config.stif_portail_api = - { - key: "Ohphie1Voo6the5hohpi", - url: "http://stif-portail-dev.af83.priv" + { + key: "Ohphie1Voo6the5hohpi", + url: "http://stif-portail-dev.af83.priv" } # Ext. apps links diff --git a/config/routes.rb b/config/routes.rb index aa6713857..0bfde2e25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,25 +32,26 @@ ChouetteIhm::Application.routes.draw do namespace :api do namespace :v1 do - resources :time_tables, :only => [:index, :show] - resources :connection_links, :only => [:index, :show] - resources :companies, :only => [:index, :show] - resources :networks, :only => [:index, :show] - resources :stop_areas, :only => [:index, :show] - resources :group_of_lines, :only => [:index, :show] - resources :access_points, :only => [:index, :show] - resources :access_links, :only => [:index, :show] - resources :lines, :only => [:index, :show] do - resources :journey_patterns, :only => [:index, :show] - resources :routes, :only => [:index, :show] do - resources :vehicle_journeys, :only => [:index, :show] - resources :journey_patterns, :only => [:index, :show] - resources :stop_areas, :only => [:index, :show] + resources :access_links, only: [:index, :show] + resources :access_points, only: [:index, :show] + resources :connection_links, only: [:index, :show] + resources :companies, only: [:index, :show] + resources :group_of_lines, only: [:index, :show] + resources :imports, only: :create + resources :journey_patterns, only: :show + resources :lines, only: [:index, :show] do + resources :journey_patterns, only: [:index, :show] + resources :routes, only: [:index, :show] do + resources :vehicle_journeys, only: [:index, :show] + resources :journey_patterns, only: [:index, :show] + resources :stop_areas, only: [:index, :show] end end - resources :routes, :only => :show - resources :journey_patterns, :only => :show - resources :vehicle_journeys, :only => :show + resources :networks, only: [:index, :show] + resources :routes, only: :show + resources :stop_areas, only: [:index, :show] + resources :time_tables, only: [:index, :show] + resources :vehicle_journeys, only: :show end end @@ -180,7 +181,7 @@ ChouetteIhm::Application.routes.draw do resources :timebands resources :access_points do - resources :access_links + resources :access_links end resources :stop_areas, controller: "referential_stop_areas" do diff --git a/spec/models/api/v1/netex_import_spec.rb b/spec/models/api/v1/netex_import_spec.rb new file mode 100644 index 000000000..f1fddc4ba --- /dev/null +++ b/spec/models/api/v1/netex_import_spec.rb @@ -0,0 +1,15 @@ +RSpec.describe Api::V1::NetexImportController, type: :controller do + + context 'POST create' do + + let( :netex_import ){ build_stubbed(:netex_import) } + + it 'creates a NetexImport record' do + expect_any_instance_of( ImportController ).to receive(:create).with( + params: netex_import.attributes + ) + + end + end + +end diff --git a/spec/routing/api/v1/access_links_routes_spec.rb b/spec/routing/api/v1/access_links_routes_spec.rb new file mode 100644 index 000000000..9164d3f05 --- /dev/null +++ b/spec/routing/api/v1/access_links_routes_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe Api::V1::AccessLinksController, type: :controller do + + it 'routes to index' do + expect( get: '/api/v1/access_links' ).to route_to( + controller: 'api/v1/access_links', + action: 'index' + ) + end +end diff --git a/spec/routing/api/v1/import_routes_spec.rb b/spec/routing/api/v1/import_routes_spec.rb new file mode 100644 index 000000000..7acc0e82d --- /dev/null +++ b/spec/routing/api/v1/import_routes_spec.rb @@ -0,0 +1,10 @@ +RSpec.describe Api::V1::ImportsController do + describe "routing" do + it { + expect(post: '/api/v1/imports').to route_to( + controller: 'api/v1/imports', + action: 'create' + ) + } + end +end diff --git a/spec/routing/group_of_lines_spec.rb b/spec/routing/group_of_lines_spec.rb index 2a7262893..01ebeefe4 100644 --- a/spec/routing/group_of_lines_spec.rb +++ b/spec/routing/group_of_lines_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe GroupOfLinesController do +RSpec.describe GroupOfLinesController do describe "routing" do it "not recognize #routes" do expect(get( "/line_referentials/1/group_of_lines/2/routes")).not_to route_to( -- cgit v1.2.3