Skip to content

Commit

Permalink
Merge pull request #1039 from sparc-request/jtm_fixing_status_bug
Browse files Browse the repository at this point in the history
Jtm fixing status bug
  • Loading branch information
Stuart-Johnson committed Aug 10, 2017
2 parents b33fd71 + 5d18553 commit 25b0c05
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Organization < ApplicationRecord
audited
acts_as_taggable

after_create :build_default_statuses

belongs_to :parent, :class_name => 'Organization'
has_many :submission_emails, :dependent => :destroy
has_many :associated_surveys, as: :surveyable, dependent: :destroy
Expand Down Expand Up @@ -357,7 +359,7 @@ def setup_available_statuses
def get_available_statuses
tmp_available_statuses = self.available_statuses.reject{|status| status.new_record?}
statuses = []
if tmp_available_statuses.empty?
if tmp_available_statuses.empty? || tmp_available_statuses.collect(&:status) == DEFAULT_STATUSES
self.parents.each do |parent|
if !parent.available_statuses.empty?
statuses = AVAILABLE_STATUSES.select{|k,v| parent.available_statuses.map(&:status).include? k}
Expand Down Expand Up @@ -410,4 +412,10 @@ def self.authorized_child_organizations(org_ids)
orgs | authorized_child_organizations(orgs.pluck(:id))
end
end

def build_default_statuses
DEFAULT_STATUSES.each do |status|
AvailableStatus.find_or_create_by(organization_id: self.id, status: status)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
= f.fields_for :available_statuses, @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |as|
%tr
%th= as.label :status, "#{AvailableStatus::TYPES[as.object.status].gsub('CTRC', 'Nexus')}:"
%td= as.check_box "_destroy", {class: 'available-status', :checked => !as.object.new_record? || DEFAULT_STATUSES.include?(as.object.status), :disabled => ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status]), data: { status: as.object.status }}, false, true
%td= as.check_box "_destroy", {class: 'available-status', checked: !as.object.new_record?, disabled: ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status]), data: { status: as.object.status }}, false, true
= as.hidden_field :status, :value => as.object.status
%td
%legend= t(:organization_form)[:selected_statuses]
Expand Down
8 changes: 4 additions & 4 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,16 @@

describe "get available statuses" do

it "should set the status to the parent's status if there is one" do
expect(core.get_available_statuses).to eq({"draft"=>"Draft", "submitted"=>"Submitted"})
it "should set inherit the parent's status if there is one" do
expect(core.get_available_statuses).to include({"administrative_review"=>"Administrative Review"})
end

it "should set the status to the default if there are no parent statuses" do
expect(provider.get_available_statuses).to include("draft" => "Draft", "submitted" => "Submitted", "complete" => "Complete", "in_process" => "In Process", "awaiting_pi_approval" => "Awaiting Requester Response", "on_hold" => "On Hold")
end

it "should not get the parent's status if it already has a status" do
expect(program.get_available_statuses).to eq({"draft"=>"Draft", "submitted"=>"Submitted"})
it "should not get the parent's status if it already has a non-default status" do
expect(program.get_available_statuses).to include({"administrative_review"=>"Administrative Review"})
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/support/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def build_per_patient_per_visit_services
let!(:clinical_provider) { create(:clinical_provider, organization_id: program.id, identity_id: jug2.id) }
let!(:available_status) { create(:available_status, organization_id: program.id, status: 'submitted')}
let!(:available_status2) { create(:available_status, organization_id: program.id, status: 'draft')}
let!(:available_status3) { create(:available_status, organization_id: program.id, status: 'administrative_review')}
let!(:subsidy) { Subsidy.auditing_enabled = false; create(:subsidy_without_validations, percent_subsidy: 0.45, sub_service_request_id: sub_service_request.id)}
let!(:subsidy_map) { create(:subsidy_map, organization_id: program.id) }
end
Expand Down

0 comments on commit 25b0c05

Please sign in to comment.