Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - Service Request Resubmission Epic Queue Push Logic Change #2301

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/service_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def confirmation
@protocol = @service_request.protocol
@service_request.previous_submitted_at = @service_request.submitted_at

if Setting.get_value("use_epic") && @service_request.should_push_to_epic? && @protocol.selected_for_epic?
if @service_request.should_push_to_epic?
# Send a notification to Lane et al to create users in Epic. Once
# that has been done, one of them will click a link which calls
# approve_epic_rights.
Expand Down
4 changes: 0 additions & 4 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ def indirect_costs_for_one_time_fee
end
end

def should_push_to_epic?
return self.service.send_to_epic
end

### audit reporting methods ###

def audit_field_value_mapping
Expand Down
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def rmid_server_status
end

def should_push_to_epic?
service_requests.any?(&:should_push_to_epic?)
self.service_requests.any?(&:should_push_to_epic?)
end

def has_nexus_services?
Expand Down
10 changes: 8 additions & 2 deletions app/models/service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,14 @@ def eligible_for_subsidy?
self.sub_service_requests.any?(&:eligible_for_subsidy?)
end

def should_push_to_epic?
return self.line_items.any? { |li| li.should_push_to_epic? }
def should_push_to_epic?(ssrids=nil)
# https://www.pivotaltracker.com/story/show/156705787
Setting.get_value("use_epic") && self.protocol.selected_for_epic? &&
if self.previously_submitted?
self.line_items.joins(:sub_service_request, :service).where(services: { send_to_epic: true }, sub_service_requests: { id: (ssrids.present? ? ssrids : self.sub_service_requests.ids), status: 'draft' }).any?
else
self.services.where(send_to_epic: true).any?
end
end

def has_ctrc_clinical_services?
Expand Down
4 changes: 0 additions & 4 deletions app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ def generate_approvals(current_user)
end
end

def should_push_to_epic?
return self.line_items.any? { |li| li.should_push_to_epic? }
end

def update_org_tree
my_tree = nil
if organization.type == "Core"
Expand Down
109 changes: 109 additions & 0 deletions spec/models/service_request/should_push_to_epic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~
require 'rails_helper'

RSpec.describe ServiceRequest, type: :model do
let!(:organization) { create(:organization) }
let!(:service_epic) { create(:service, organization: organization, send_to_epic: true) }
let!(:service_no_epic) { create(:service, organization: organization, send_to_epic: false) }

describe '#should_push_to_epic?' do
context 'epic is enabled' do
stub_config('use_epic', true)

context 'protocol is selected for epic' do
let!(:protocol) { create(:study_federally_funded, primary_pi: create(:identity), selected_for_epic: true) }

context 'new ServiceRequest' do
let!(:sr) { create(:service_request, protocol: protocol, submitted_at: nil) }
let!(:ssr) { create(:sub_service_request, service_request: sr, organization: organization) }

context 'services are selected for epic' do
let!(:li) { create(:line_item, service_request: sr, sub_service_request: ssr, service: service_epic) }

it 'should return true' do
expect(sr.should_push_to_epic?).to eq(true)
end
end

context 'services are not selected for epic' do
let!(:li) { create(:line_item, service_request: sr, sub_service_request: ssr, service: service_no_epic) }

it 'should return false' do
expect(sr.should_push_to_epic?).to eq(false)
end
end
end

context 'ServiceRequest is previously submitted' do
let!(:sr) { create(:service_request, :submitted, protocol: protocol) }

context 'Draft SSR to be resubmitted' do
let!(:ssr) { create(:sub_service_request, service_request: sr, organization: organization, status: 'draft', submitted_at: DateTime.now) }

context 'services are selected for epic' do
let!(:li) { create(:line_item, service_request: sr, sub_service_request: ssr, service: service_epic) }

it 'should return true' do
expect(sr.should_push_to_epic?).to eq(true)
end
end

context 'services are not selected for epic' do
let!(:li) { create(:line_item, service_request: sr, sub_service_request: ssr, service: service_no_epic) }

it 'should return false' do
expect(sr.should_push_to_epic?).to eq(false)
end
end
end

context 'No draft SSRs to be resubmitted' do
let!(:ssr) { create(:sub_service_request, :submitted, service_request: sr, organization: organization) }
let!(:li) { create(:line_item, service_request: sr, sub_service_request: ssr, service: service_epic) }

it 'should return false' do
expect(sr.should_push_to_epic?).to eq(false)
end
end
end

context 'protocol is not selected for epic' do
let!(:protocol) { create(:study_federally_funded, primary_pi: create(:identity), selected_for_epic: false) }
let!(:sr) { create(:service_request, protocol: protocol) }

it 'should return false' do
expect(sr.should_push_to_epic?).to eq(false)
end
end
end
end

context 'epic is disabled' do
stub_config('use_epic', false)

let!(:sr) { create(:service_request_without_validations) }

it 'should return false' do
expect(sr.should_push_to_epic?).to eq(false)
end
end
end
end
49 changes: 36 additions & 13 deletions spec/support/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,35 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

def populate_settings_before_suite
Setting.auditing_enabled = false
SettingsPopulator.new().populate

Setting.find_by_key("use_epic").update_attribute(:value, true)
Setting.find_by_key("use_ldap").update_attribute(:value, false)
Setting.find_by_key("use_funding_module").update_attribute(:value, true)
Setting.find_by_key("suppress_ldap_for_user_search").update_attribute(:value, true)
Setting.find_by_key("ldap_auth_username").update_attribute(:value, nil)
Setting.find_by_key("ldap_auth_password").update_attribute(:value, nil)
Setting.find_by_key("ldap_filter").update_attribute(:value, nil)

load File.expand_path("../../../app/lib/directory.rb", __FILE__)
@settings_populated ||= false

# Don't re-run settings population
unless @settings_populated
Setting.auditing_enabled = false
SettingsPopulator.new().populate

Setting.find_by_key("use_epic").update_attribute(:value, true)
Setting.find_by_key("use_ldap").update_attribute(:value, false)
Setting.find_by_key("use_funding_module").update_attribute(:value, true)
Setting.find_by_key("suppress_ldap_for_user_search").update_attribute(:value, true)
Setting.find_by_key("ldap_auth_username").update_attribute(:value, nil)
Setting.find_by_key("ldap_auth_password").update_attribute(:value, nil)
Setting.find_by_key("ldap_filter").update_attribute(:value, nil)

load File.expand_path("../../../app/lib/directory.rb", __FILE__)

@settings_populated = true
end
end

def stub_config(key, value)
setting = Setting.find_by_key(key)
unless setting = Setting.find_by_key(key)
# Scenario: The specs are run such that a stub_config is called before
# a test causes there to be no Settings yet. before :suite doesn't work
populate_settings_before_suite
setting = Setting.find_by_key(key)
end

default_value = setting.value

before :each do
Expand All @@ -47,7 +60,17 @@ def stub_config(key, value)
end

RSpec.configure do |config|
config.before :all do
populate_settings_before_suite
end

config.before :each do
# This sometimes triggers a failure because of missing settings depending on
# the order that specs are run. This method wastes processing during the suite
# so let's stub it
allow_any_instance_of(Identity).to receive(:send_admin_mail).and_return(true)

# Cache settings for slight efficiency boost during tests
Setting.preload_values
end
end