Skip to content

Commit

Permalink
Merge pull request #831 from sparc-request/jw_epic_ques_spec_refactor
Browse files Browse the repository at this point in the history
Jw epic ques spec refactor
  • Loading branch information
jleonardw9 committed Jan 2, 2017
2 parents b7ee489 + 131f939 commit dc17e63
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 1,074 deletions.
1 change: 1 addition & 0 deletions app/helpers/dashboard/protocols_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def break_before_parenthetical(s)
s
end
end

def consolidated_request_buttons_display(protocol)
if !protocol.has_first_draft_service_request? && protocol.service_requests.present?
raw(
Expand Down
10 changes: 0 additions & 10 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ def is_epic?
USE_EPIC
end

# virgin project: a project that has never been a study
def virgin_project?
selected_for_epic.nil?
end

def is_project?
self.type == 'Project'
end
Expand All @@ -273,11 +268,6 @@ def activate
update_attribute(:study_type_question_group_id, StudyTypeQuestionGroup.active.pluck(:id).first)
end

def display_answers
answers = StudyTypeQuestion.joins(:study_type_question_group).where(study_type_question_groups: { version: version_type })
answers.map{ |ans| ans.study_type_answers.find_by_protocol_id(id) }
end

def email_about_change_in_authorized_user(modified_role, action)
# Alert authorized users of deleted authorized user
# Send emails if SEND_AUTHORIZED_USER_EMAILS is set to true and if there are any non-draft SSRs
Expand Down
5 changes: 5 additions & 0 deletions app/models/study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def determine_study_type_note
StudyTypeFinder.new(self).determine_study_type_note
end

def display_answers
answers = StudyTypeQuestion.joins(:study_type_question_group).where(study_type_question_groups: { version: version_type })
answers.map{ |ans| ans.study_type_answers.find_by_protocol_id(id) }
end

def populate_for_edit
super
self.build_research_types_info unless self.research_types_info
Expand Down
45 changes: 45 additions & 0 deletions spec/models/protocol/activate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

require 'date'
require 'rails_helper'

RSpec.describe 'Protocol' do
let_there_be_lane
let_there_be_j
build_service_request_with_study()
build_service_request_with_project()
build_study_type_question_groups()
build_study_type_questions()
build_study_type_answers()

describe "#activate" do
context "protocol is not active" do
before :each do
study.update_attributes(study_type_question_group_id: StudyTypeQuestionGroup.where(active:false).pluck(:id).first)
end

it "should activate protocol" do
study.activate
expect(study.study_type_question_group_id).to eq StudyTypeQuestionGroup.where(active:true).pluck(:id).first
end
end
end
end

0 comments on commit dc17e63

Please sign in to comment.