Skip to content

Commit

Permalink
Merge pull request sparc-request#195 from bmic-development/kg-refacto…
Browse files Browse the repository at this point in the history
…r_has_human_subject_info

KG - Refactor has_human_subjects_info? to reduce coupling
  • Loading branch information
Stuart-Johnson committed Apr 6, 2017
2 parents 1665d3e + b7daf64 commit 95842bb
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 113 deletions.
3 changes: 0 additions & 3 deletions app/assets/javascripts/protocol_form.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ $(document).ready ->

if $('.human-subjects:checkbox:checked').length > 0
$('.rm-id').addClass('required')
$('.has-human-subject-info').val('true')

$(document).on 'click', '.human-subjects', ->
if $('.rm-id').hasClass('required')
$('.rm-id').removeClass('required')
$('.has-human-subject-info').val('false')
else
$('.rm-id').addClass('required')
$('.has-human-subject-info').val('true')

$(document).on 'blur', '.research-master-field', ->
rmId = $('.research-master-field').val()
Expand Down
1 change: 0 additions & 1 deletion app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def protocol_params
:type,
:udak_project_number,
:research_master_id,
:has_human_subject_info,
research_types_info_attributes: [:human_subjects, :vertebrate_animals, :investigational_products, :ip_patents],
study_types_attributes: [:name, :new, :position, :_destroy],
vertebrate_animals_info_attributes: [:iacuc_number,
Expand Down
1 change: 0 additions & 1 deletion app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def protocol_params
:type,
:udak_project_number,
:research_master_id,
:has_human_subject_info,
{:study_phase_ids => []},
research_types_info_attributes: [:human_subjects, :vertebrate_animals, :investigational_products, :ip_patents],
study_types_attributes: [:name, :new, :position, :_destroy],
Expand Down
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Protocol < ApplicationRecord
end

def has_human_subject_info?
self.has_human_subject_info == true
self.research_types_info.try(:human_subjects) || false
end

validate :existing_rm_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
= link_to t(:protocols)[:studies][:information][:research_master_id], RESEARCH_MASTER_LINK, target: '_blank'
.col-lg-3
= form.text_field :research_master_id, class: 'form-control research-master-field', readonly: action_name == "edit" && admin
= form.hidden_field :has_human_subject_info, value: false, class: 'has-human-subject-info'
- if action_name == "edit" && admin
.btn.btn-warning.edit-rmid
= t(:actions)[:edit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
= link_to t(:protocols)[:studies][:information][:research_master_id], RESEARCH_MASTER_LINK, target: '_blank'
.col-lg-10
= form.text_field :research_master_id, class: 'form-control research-master-field'
= form.hidden_field :has_human_subject_info, value: false, class: 'has-human-subject-info'

.form-group.row
= form.label :short_title, t(:protocols)[:studies][:information][:short_title],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveHasHumanSubjectsInfoFromProtocol < ActiveRecord::Migration[5.0]
def change
remove_column :protocols, :has_human_subject_info
end
end
182 changes: 91 additions & 91 deletions db/schema.rb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions spec/api/v1/protocols/get_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id').
sort

Expand All @@ -82,7 +82,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id', 'arms', 'service_requests', 'project_roles', 'human_subjects_info').
sort

Expand Down
4 changes: 2 additions & 2 deletions spec/api/v1/protocols/get_protocols_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id').
sort

Expand All @@ -93,7 +93,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id', 'arms', 'service_requests', 'project_roles', 'human_subjects_info').
sort

Expand Down
4 changes: 2 additions & 2 deletions spec/api/v1/protocols/get_protocols_with_ids_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id').
sort
expect(parsed_body['protocols'].map(&:keys).flatten.uniq.sort).to eq(expected_attributes)
Expand All @@ -93,7 +93,7 @@
parsed_body = JSON.parse(response.body)
expected_attributes = build(:protocol).attributes.
keys.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id', 'has_human_subject_info'].include?(key) }.
reject { |key| ['study_phase', 'id', 'created_at', 'updated_at', 'deleted_at', 'research_master_id'].include?(key) }.
push('callback_url', 'sparc_id', 'arms', 'service_requests', 'project_roles', 'human_subjects_info').
sort

Expand Down
6 changes: 2 additions & 4 deletions spec/controllers/dashboard/protocols/put_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@
@protocol = create(:protocol_without_validations,
primary_pi: @logged_in_user,
funding_status: "funded",
funding_source: "foundation",
has_human_subject_info: true)
funding_source: "foundation")
organization = create(:organization)
service_request = create(:service_request_without_validations, protocol: @protocol)
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
Expand Down Expand Up @@ -166,8 +165,7 @@
@protocol = create(:protocol_without_validations,
primary_pi: @logged_in_user,
funding_status: "funded",
funding_source: "foundation",
has_human_subject_info: true)
funding_source: "foundation")
organization = create(:organization)
service_request = create(:service_request_without_validations, protocol: @protocol)
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft', protocol_id: @protocol.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
type: "Study",
primary_pi: jug2,
funding_status: "funded",
funding_source: "foundation",
has_human_subject_info: true)
funding_source: "foundation")
organization = create(:organization)
service_request = create(:service_request_without_validations, protocol: @protocol)
create(:sub_service_request_without_validations, organization: organization, service_request: service_request, status: 'draft')
Expand All @@ -59,8 +58,7 @@
type: "Study",
primary_pi: jug2,
funding_status: "funded",
funding_source: "foundation",
has_human_subject_info: true)
funding_source: "foundation")
stub_const("RESEARCH_MASTER_ENABLED", true)

visit edit_dashboard_protocol_path(@protocol)
Expand Down

0 comments on commit 95842bb

Please sign in to comment.