From e793bffd18b331f2db2bb567c479fdbf02c66aec Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 22 Aug 2017 16:01:56 +0200 Subject: API - workbench imports controller --- app/controllers/api/v1/imports_controller.rb | 4 ++++ app/views/api/v1/imports/index.rabl | 3 +++ app/views/api/v1/imports/show.rabl | 6 ++++++ config/routes.rb | 4 +++- spec/controllers/api/v1/imports_controller_spec.rb | 25 ++++++++++++++++++++++ spec/support/shared_context.rb | 2 +- 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/imports_controller.rb create mode 100644 app/views/api/v1/imports/index.rabl create mode 100644 app/views/api/v1/imports/show.rabl create mode 100644 spec/controllers/api/v1/imports_controller_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..ac2ec4516 --- /dev/null +++ b/app/controllers/api/v1/imports_controller.rb @@ -0,0 +1,4 @@ +class Api::V1::ImportsController < Api::V1::IbooController + defaults :resource_class => Api::V1::ApiKey + belongs_to :workbench +end diff --git a/app/views/api/v1/imports/index.rabl b/app/views/api/v1/imports/index.rabl new file mode 100644 index 000000000..e8cfd101e --- /dev/null +++ b/app/views/api/v1/imports/index.rabl @@ -0,0 +1,3 @@ +collection @imports + +extends "api/v1/imports/show" diff --git a/app/views/api/v1/imports/show.rabl b/app/views/api/v1/imports/show.rabl new file mode 100644 index 000000000..180894cb8 --- /dev/null +++ b/app/views/api/v1/imports/show.rabl @@ -0,0 +1,6 @@ +object @import + +attributes :id, :name, :status +node :referential_ids do |i| + i.workbench.referentials.map(&:id) +end diff --git a/config/routes.rb b/config/routes.rb index 43aec62ea..3572f50e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,7 +32,9 @@ ChouetteIhm::Application.routes.draw do namespace :api do namespace :v1 do - resources :workbenches, only: [:index, :show] + resources :workbenches, only: [:index, :show] do + resources :imports + end resources :access_links, only: [:index, :show] resources :access_points, only: [:index, :show] resources :connection_links, only: [:index, :show] diff --git a/spec/controllers/api/v1/imports_controller_spec.rb b/spec/controllers/api/v1/imports_controller_spec.rb new file mode 100644 index 000000000..52fbf8e9b --- /dev/null +++ b/spec/controllers/api/v1/imports_controller_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe Api::V1::ImportsController, type: :controller do + let(:workbench) { create :workbench, organisation: organisation } + + context 'unauthenticated' do + describe 'GET #index' do + it 'should not be successful' do + get :index, workbench_id: workbench.id + expect(response).not_to be_success + end + end + end + + context 'authenticated' do + include_context 'iboo authenticated api user' + + describe 'GET #index' do + it 'should be successful' do + get :index, workbench_id: workbench.id + expect(response).to be_success + end + end + end +end diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb index 1282518c1..e7416f2f1 100644 --- a/spec/support/shared_context.rb +++ b/spec/support/shared_context.rb @@ -1,5 +1,5 @@ shared_context 'iboo authenticated api user' do - let(:api_key) { create(:api_key) } + let(:api_key) { create(:api_key, organisation: organisation) } before do request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(api_key.organisation.code, api_key.token) -- cgit v1.2.3