From f7c6f78925bc2222e96ef2511a30d46afd1332d7 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Thu, 13 Jun 2019 08:49:03 +0200 Subject: [PATCH] Add external_protocols#index action --- .../external_protocols_controller.rb | 17 +++++++++-- .../_list_of_protocol_cards.html.erb | 5 ++++ .../_protocol_card.html.erb | 3 ++ config/routes.rb | 9 ++++-- .../external_protocols_controller_spec.rb | 28 ++++++++++++++++++- 5 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 app/views/protocol_importers/_list_of_protocol_cards.html.erb create mode 100644 app/views/protocol_importers/_protocol_card.html.erb diff --git a/app/controllers/external_protocols_controller.rb b/app/controllers/external_protocols_controller.rb index e9f19f154..f9603c2cc 100644 --- a/app/controllers/external_protocols_controller.rb +++ b/app/controllers/external_protocols_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ExternalProtocolsController < ApplicationController before_action :load_vars before_action :check_import_permissions, only: [:create] @@ -5,15 +7,20 @@ class ExternalProtocolsController < ApplicationController # GET def index # list_protocols = SearchService.call(index_params) - succeed = false - list_protocols = [ + succeed = true + protocols = [ { name: 'Protocol1' }, { name: 'Protocol2' }, { name: 'Protocol3' } ] if succeed - render json: list_protocols + render json: { + html: render_to_string( + partial: 'protocol_importers/list_of_protocol_cards.html.erb', + locals: { protocols: protocols } + ) + } else render json: { errors: { protocol: 'error_placeholder' } @@ -70,6 +77,10 @@ class ExternalProtocolsController < ApplicationController params.permit(:protocol_source, :key, :page_id, :page_size, :order_field, :order_dir) end + def show_params + params.permit(:protocol_source, :protocol_id) + end + def new_params params.permit(:protocol_source, :protocol_client_id) end diff --git a/app/views/protocol_importers/_list_of_protocol_cards.html.erb b/app/views/protocol_importers/_list_of_protocol_cards.html.erb new file mode 100644 index 000000000..4164c5c72 --- /dev/null +++ b/app/views/protocol_importers/_list_of_protocol_cards.html.erb @@ -0,0 +1,5 @@ +<% protocols.each do |protocol| %> + <%= render partial: 'protocol_importers/protocol_card', + locals: { protocol: protocol } %> +
+<% end %> diff --git a/app/views/protocol_importers/_protocol_card.html.erb b/app/views/protocol_importers/_protocol_card.html.erb new file mode 100644 index 000000000..f7311f7da --- /dev/null +++ b/app/views/protocol_importers/_protocol_card.html.erb @@ -0,0 +1,3 @@ +
+

<%= protocol[:name] %>

+
diff --git a/config/routes.rb b/config/routes.rb index 49ab711c3..40f0c91c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -206,12 +206,15 @@ Rails.application.routes.draw do get 'atwho_my_modules', to: 'at_who#my_modules' get 'atwho_menu_items', to: 'at_who#menu_items' end + + # External protocols routes + get 'list_external_protocol', to: 'external_protocols#index' + get 'build_external_protocol', to: 'external_protocols#new' + post 'import_external_protocol', to: 'external_protocols#create' + match '*path', to: 'teams#routing_error', via: [:get, :post, :put, :patch] - - get 'build_external_protocol', to: 'external_protocols#new' - post 'import_external_protocol', to: 'external_protocols#create' end get 'projects/archive', to: 'projects#archive', as: 'projects_archive' diff --git a/spec/controllers/external_protocols_controller_spec.rb b/spec/controllers/external_protocols_controller_spec.rb index a4853d770..35625bc40 100644 --- a/spec/controllers/external_protocols_controller_spec.rb +++ b/spec/controllers/external_protocols_controller_spec.rb @@ -9,6 +9,33 @@ describe ExternalProtocolsController, type: :controller do let(:team) { create :team, created_by: user } let!(:user_team) { create :user_team, :admin, user: user, team: team } + describe 'GET index' do + let(:params) do + { + team_id: team.id, + key: 'search_string', + protocol_source: 'protocolsio/v3', + page_id: 1, + page_size: 10, + order_field: 'activity', + order_dir: 'desc' + } + end + + let(:action) { get :index, params: params } + + it 'returns JSON, 200 response when protocol parsing was valid' do + action + expect(response).to have_http_status(:success) + expect(response.content_type).to eq 'application/json' + end + + it 'contains html key in the response' do + action + expect(JSON.parse(response.body)).to have_key('html') + end + end + describe 'GET new' do let(:params) do { @@ -50,7 +77,6 @@ describe ExternalProtocolsController, type: :controller do expect(response).to have_http_status(:bad_request) expect(response.content_type).to eq 'application/json' end - end describe 'POST create' do