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

SAW - changed funding sources constant call to query #959

Merged
merged 5 commits into from
Jul 14, 2017
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
4 changes: 2 additions & 2 deletions app/helpers/dashboard/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def pretty_program_core(ssr)

def display_funding_source(project)
if project.funding_status == 'funded'
(FUNDING_SOURCES.invert)[project.funding_source]
PermissibleValue.get_value('funding_source', project.funding_source)
elsif project.funding_status == 'pending_funding'
(POTENTIAL_FUNDING_SOURCES.invert)[project.potential_funding_source]
PermissibleValue.get_value('potential_funding_source', project.potential_funding_source)
else
''
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/permissible_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ def self.get_value(category, key)
def self.get_value_list(category)
PermissibleValue.where(category: category).pluck(:value)
end
end

# Get a hash of PermissibleValue values as the keys and keys as values
def self.get_value_key_hash(category)
Hash[PermissibleValue.where(category: category).pluck(:value, :key)]
end
end
8 changes: 4 additions & 4 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@ def epic_title
def display_funding_source_value
if funding_status == "funded"
if funding_source == "internal"
"#{FUNDING_SOURCES.key funding_source}: #{funding_source_other}"
"#{PermissibleValue.get_value('funding_source', funding_source)}: #{funding_source_other}"
else
"#{FUNDING_SOURCES.key funding_source}"
"#{PermissibleValue.get_value('funding_source', funding_source)}"
end
elsif funding_status == "pending_funding"
if potential_funding_source == "internal"
"#{POTENTIAL_FUNDING_SOURCES.key potential_funding_source}: #{potential_funding_source_other}"
"#{PermissibleValue.get_value('potential_funding_source', potential_funding_source)}: #{potential_funding_source_other}"
else
"#{POTENTIAL_FUNDING_SOURCES.key potential_funding_source}"
"#{PermissibleValue.get_value('potential_funding_source', potential_funding_source)}"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
%ul.excluded_funding_sources
- entity.subsidy_map.excluded_funding_sources.each do |excluded_funding_source|
%li
= FUNDING_SOURCES.reverse_hash_to_strings[excluded_funding_source.funding_source]
= PermissibleValue.get_value('funding_source', excluded_funding_source.funding_source)
%span.ui-icon.ui-icon-close.remove_funding_source{:funding_source_id => excluded_funding_source.id}
= select_tag 'funding_source', options_for_select( FUNDING_SOURCES.each{ |a| [a[0], a[1]]}), :prompt => '--- Select ---', :class => 'new_excluded_funding_source', :style => 'width:325px;'
= select_tag 'funding_source', options_for_select(PermissibleValue.get_value_key_hash('funding_source')), :prompt => '--- Select ---', :class => 'new_excluded_funding_source', :style => 'width:325px;'
%a.add_new_excluded_funding_source.btn{:org_id => entity.id, :org_type => entity.class}
= t("cm_shared.labels.exclude_button")
%br
Expand Down
4 changes: 2 additions & 2 deletions app/views/dashboard/protocols/form/_project_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(FUNDING_SOURCES, protocol.funding_source),
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -72,7 +72,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(POTENTIAL_FUNDING_SOURCES, protocol.potential_funding_source),
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(FUNDING_SOURCES, protocol.funding_source),
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -89,7 +89,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(POTENTIAL_FUNDING_SOURCES, protocol.potential_funding_source),
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
4 changes: 2 additions & 2 deletions app/views/protocols/form/_project_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(FUNDING_SOURCES, protocol.funding_source),
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -72,7 +72,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(POTENTIAL_FUNDING_SOURCES, protocol.potential_funding_source),
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
title: t(:protocols)[:tooltips][:funding_source]
.col-lg-10
= form.select :funding_source,
options_for_select(FUNDING_SOURCES, protocol.funding_source),
options_for_select(PermissibleValue.get_value_key_hash('funding_source'), protocol.funding_source),
{ include_blank: t(:protocols)[:prompts][:source] },
class: 'selectpicker'

Expand All @@ -85,7 +85,7 @@
title: t(:protocols)[:tooltips][:potential_funding_source]
.col-lg-10
= form.select :potential_funding_source,
options_for_select(POTENTIAL_FUNDING_SOURCES, protocol.potential_funding_source),
options_for_select(PermissibleValue.get_value_key_hash('potential_funding_source'), protocol.potential_funding_source),
{ include_blank: t(:protocols)[:prompts][:potential_source] },
class: 'selectpicker'

Expand Down
5 changes: 5 additions & 0 deletions spec/features/happy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def click_add_service_for(service)
question_2 = create(:question, question_type: 'textarea', content: '2) Please leave your feedback and/or suggestions for future improvement.', section: section)


###############
# "Constants" #
###############
create(:permissible_value, category: 'funding_source', key: 'federal', value: 'Federal')


######################
# Visit catalog page #
Expand Down
2 changes: 1 addition & 1 deletion spec/features/protocol/user_creates_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@sr = create(:service_request_without_validations, status: 'first_draft')
ssr = create(:sub_service_request_without_validations, service_request: @sr, organization: program, status: 'first_draft')
create(:line_item, service_request: @sr, sub_service_request: ssr, service: service)

create(:permissible_value, category: 'funding_source', key: 'federal', value: 'Federal')
end

context 'and clicks \'New Project\'' do
Expand Down
1 change: 1 addition & 0 deletions spec/features/protocol/user_creates_study_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@sr = create(:service_request_without_validations, status: 'first_draft')
ssr = create(:sub_service_request_without_validations, service_request: @sr, organization: program, status: 'first_draft')
create(:line_item, service_request: @sr, sub_service_request: ssr, service: service)
create(:permissible_value, category: 'funding_source', key: 'federal', value: 'Federal')

StudyTypeQuestionGroup.create(active: true)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/features/protocol/user_edits_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
@sr = create(:service_request_without_validations, status: 'first_draft', protocol: @protocol)
ssr = create(:sub_service_request_without_validations, service_request: @sr, organization: program, status: 'first_draft')
create(:line_item, service_request: @sr, sub_service_request: ssr, service: service)

create(:permissible_value, category: 'funding_source', key: 'federal', value: 'Federal')

StudyTypeQuestionGroup.create(active: 1)
end

Expand Down
7 changes: 7 additions & 0 deletions spec/views/dashboard/protocols/_summary.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def render_summary_for protocol

let_there_be_lane

before :each do
create(:permissible_value, category: 'funding_source', key: 'college', value: 'College Department')
create(:permissible_value, category: 'funding_source', key: 'federal', value: 'Federal')
create(:permissible_value, category: 'potential_funding_source', key: 'college', value: 'College Department')
create(:permissible_value, category: 'potential_funding_source', key: 'federal', value: 'Federal')
end

context 'Protocol is a Study' do
it 'should be titled "Study Summary"' do
protocol = build(:protocol_federally_funded,
Expand Down