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

Jtm fixing status bug #1039

Merged
merged 5 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
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| status.status} == DEFAULT_STATUSES.collect{|k, v| k}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be shorter to do tmp_available_statuses.map(&:status) == DEFAULT_STATUSES.keys

Copy link
Contributor

@wtholt wtholt Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#collect and #map are the same thing (https://stackoverflow.com/questions/5254732/difference-between-map-and-collect-in-ruby). I also think DEFAULT_STATUSES is an array.

So I think you could do

 tmp_available_statuses.collect(&:status) == DEFAULT_STATUSES

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Will! Works like a charm. I'll push the changes up.

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", {:checked => !as.object.new_record? || DEFAULT_STATUSES.include?(as.object.status), :disabled => ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status])}, false, true
%td= as.check_box "_destroy", {:checked => !as.object.new_record?, :disabled => ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[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