Skip to content

Commit

Permalink
Merge pull request #300 from sparc-request/jw_admin_epic
Browse files Browse the repository at this point in the history
fixed validation on inactive studies
  • Loading branch information
jwiel86 committed Feb 23, 2016
2 parents 2333968 + 99d000a commit ca0169a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Protocol < ActiveRecord::Base
validates :sponsor_name, :presence => true, :if => :is_study?
validates_associated :human_subjects_info, :message => "must contain 8 numerical digits", :if => :validate_nct
validates :selected_for_epic, inclusion: [true, false], :if => :is_study?
validate :validate_study_type_answers, if: [:is_study?, :selected_for_epic]
validate :validate_study_type_answers, if: [:is_study?, :selected_for_epic?, "StudyTypeQuestionGroup.active.pluck(:id).first == study_type_question_group_id"]
end

validation_group :user_details do
Expand Down
63 changes: 63 additions & 0 deletions spec/features/portal/admin/admin_edit_inactive_study.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'rails_helper'
RSpec.describe 'editing a study', js: true do
let_there_be_lane
let_there_be_j
fake_login_for_each_test

build_service_request()
build_arms()
build_one_time_fee_services()
build_per_patient_per_visit_services()
build_study_type_question_groups()
build_study_type_questions()

let!(:answer1) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_higher_level_of_privacy.id, answer: 1)}
let!(:answer2) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_certificate_of_conf.id, answer: 0)}
let!(:answer3) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_access_study_info.id, answer: 0)}
let!(:answer4) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_epic_inbasket.id, answer: 0)}
let!(:answer5) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_research_active.id, answer: 1)}
let!(:answer6) { StudyTypeAnswer.create(protocol_id: study.id, study_type_question_id: stq_restrict_sending.id, answer: 1)}

let!(:study) {

protocol = build(:study)
protocol.update_attributes(funding_status: "funded", funding_source: "federal", indirect_cost_rate: 50.0, start_date: Time.now, end_date: Time.now + 2.month, selected_for_epic: false, study_type_question_group_id: StudyTypeQuestionGroup.active.pluck(:id).first)
protocol.save validate: false
identity = Identity.find_by_ldap_uid('jug2')
create(
:project_role,
protocol_id: protocol.id,
identity_id: identity.id,
project_rights: "approve",
role: "primary-pi")
identity2 = Identity.find_by_ldap_uid('jpl6@musc.edu')
create(
:project_role,
protocol_id: protocol.id,
identity_id: identity2.id,
project_rights: "approve",
role: "business-grants-manager")
service_request.update_attribute(:protocol_id, protocol.id)
protocol.reload
protocol
}

before :each do
add_visits
study.update_attributes(potential_funding_start_date: (Time.now + 1.day))
study.update_attributes(funding_start_date: nil)
study.human_subjects_info.update_attributes(irb_expiration_date: nil)
study.update_attributes(selected_for_epic: true)
study.update_attributes(study_type_question_group_id: StudyTypeQuestionGroup.inactive.pluck(:id).first)
visit portal_admin_sub_service_request_path sub_service_request.id
click_on('Project/Study Information')
wait_for_javascript_to_finish
end

context 'epic box' do
it 'should not throw an error when saved' do
click_button 'Save'
expect(page).to_not have_content("Study type questions must be selected")
end
end
end
3 changes: 2 additions & 1 deletion spec/features/portal/admin/admin_edit_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
end
end

context "switching from project to study" do
# virgin project: a project that has never been a study (selected_for_epic= nil)
context "switching from virgin project to study" do
before :each do
project.update_attribute(:selected_for_epic, nil)
select 'Study', from: 'protocol_type'
Expand Down

0 comments on commit ca0169a

Please sign in to comment.