Skip to content

Commit

Permalink
Merge pull request #1800 from sparc-request/kg-single_service_landing
Browse files Browse the repository at this point in the history
KG - Single Service Landing Page Redirect if Service Inactive
  • Loading branch information
Stuart-Johnson committed Apr 3, 2019
2 parents cd281f2 + 5deaaa2 commit 64476c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
19 changes: 12 additions & 7 deletions app/controllers/service_requests_controller.rb
Expand Up @@ -32,6 +32,7 @@ class ServiceRequestsController < ApplicationController
before_action :authorize_identity, except: [:approve_changes, :get_help, :feedback, :show]
before_action :authenticate_identity!, except: [:catalog, :add_service, :remove_service, :get_help, :feedback]
before_action :find_locked_org_ids, only: [:catalog]
before_action :find_service, only: [:catalog]

def show
@protocol = @service_request.protocol
Expand Down Expand Up @@ -59,13 +60,6 @@ def navigate
def catalog
@institutions = Institution.all

if params[:service_id]
@service = Service.find(params[:service_id])
@provider = @service.provider
@program = @service.program
@core = @service.core
end

setup_catalog_calendar
setup_catalog_news_feed
end
Expand Down Expand Up @@ -413,4 +407,15 @@ def should_queue_epic?(protocol)
return true
end
end

def find_service
if params[:service_id]
@service = Service.find(params[:service_id])
@provider = @service.provider
@program = @service.program
@core = @service.core

redirect_to catalog_service_request_path unless @service.is_available?
end
end
end
35 changes: 25 additions & 10 deletions spec/controllers/service_requests/get_catalog_spec.rb
Expand Up @@ -59,11 +59,6 @@
stub_config('use_google_calendar', true)

it 'should assign @events' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)

session[:srid] = sr.id

get :catalog, xhr: true

expect(assigns(:events)).to be
Expand All @@ -74,17 +69,37 @@
stub_config('use_news_feed', true)

it 'should assign @news' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)

session[:srid] = sr.id

get :catalog, xhr: true

expect(assigns(:news)).to be
end
end

context 'params[:service_id] is present' do
it 'should assign @service' do
service = create(:service)
allow_any_instance_of(Service).to receive(:provider).and_return(nil)
allow_any_instance_of(Service).to receive(:program).and_return(nil)
allow_any_instance_of(Service).to receive(:core).and_return(nil)

get :catalog, params: { service_id: service.id }, xhr: true

expect(assigns(:service)).to eq(service)
end

context 'service is inactive' do
it 'should redirect' do
service = create(:service, is_available: false)
allow_any_instance_of(Service).to receive(:provider).and_return(nil)
allow_any_instance_of(Service).to receive(:program).and_return(nil)
allow_any_instance_of(Service).to receive(:core).and_return(nil)

get :catalog, params: { service_id: service.id }, xhr: true

expect(controller).to redirect_to(catalog_service_request_path)
end
end
end
it 'should render template' do
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
Expand Down

0 comments on commit 64476c0

Please sign in to comment.