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

KG - Change SR Notes to Protocol Notes #849

Merged
merged 2 commits into from Jan 10, 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
2 changes: 2 additions & 0 deletions app/controllers/service_requests_controller.rb
Expand Up @@ -151,6 +151,8 @@ def service_subsidy
end

def document_management
@notable_type = 'Protocol'
@notable_id = @service_request.protocol_id
@has_subsidy = @service_request.sub_service_requests.map(&:has_subsidy?).any?
@eligible_for_subsidy = @service_request.sub_service_requests.map(&:eligible_for_subsidy?).any?

Expand Down
Expand Up @@ -22,10 +22,6 @@
%h4.panel-title.pull-left
= protocol_panel_header_line(service_request)
.pull-right
%button.btn.btn-sm.btn-success.notes.list{ data: {notable_type: "ServiceRequest", notable_id: service_request.id } }
= t(:models)[:note][:plural]
%span.badge{id: "servicerequest_#{service_request.id}_notes"}
= service_request.notes.count
- if permission_to_edit
%button.btn.btn-warning.btn-sm.edit-service-request{ class: permission_to_edit ? '' : 'disabled', type: 'button', data: { permission: permission_to_edit.to_s, url: modify_request_button_url(service_request) } }
= t(:dashboard)[:service_requests][:modify_request]
Expand Down
2 changes: 1 addition & 1 deletion app/views/service_requests/document_management.html.haml
Expand Up @@ -28,7 +28,7 @@
= form_tag navigate_service_request_path(@service_request), id: 'service-request-form' do
- if @sub_service_request
= hidden_field_tag :sub_service_request_id, @sub_service_request.id
= render 'service_requests/document_management/document_management_left', service_request: @service_request
= render 'service_requests/document_management/document_management_left', service_request: @service_request, notable_type: @notable_type, notable_id: @notable_id
= render 'service_requests/document_management/document_management_right', service_request: @service_request, sub_service_request: @sub_service_request, sub_service_requests: @sub_service_requests, line_items_count: @line_items_count
= render 'service_requests/navigation/footer', service_request: @service_request, css_class: @css_class, back: @back, forward: @forward
= render 'additional_details/submissions/submission_modal'
Expand Up @@ -19,7 +19,7 @@
-# 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.
.col-md-9.document-management-left
= render 'service_requests/document_management/documents', service_request: service_request
= render 'service_requests/document_management/notes', service_request: service_request
= render 'service_requests/document_management/notes', service_request: service_request, notable_type: notable_type, notable_id: notable_id
- if service_request.additional_detail_services.present?
.document-management-submissions
= render "additional_details/document_management_submissions", service_request: service_request
Expand Up @@ -23,4 +23,4 @@
= t(:proper)[:document_management][:notes_notice]
%small
= t(:proper)[:document_management][:notes_instructions]
= render 'notes/table', notable_type: 'ServiceRequest', notable_id: service_request.id, notes: service_request.notes, in_dashboard: false
= render 'notes/table', notable_type: notable_type, notable_id: notable_id, notes: service_request.notes, in_dashboard: false
4 changes: 2 additions & 2 deletions config/locales/proper.en.yml
Expand Up @@ -138,8 +138,8 @@ en:
document_management:
documents_notice: "Shared Documents"
documents_instructions: "Visible to Authorized Users and selected Service Providers"
notes_notice: "Service Request Notes"
notes_instructions: "Important notes for your Service Request"
notes_notice: "Notes"
notes_instructions: "Important notes for your Study/Project"

##########
# REVIEW #
Expand Down
@@ -0,0 +1,9 @@
class ChangeServiceRequestNotesToProtocol < ActiveRecord::Migration
def change
Note.includes(:notable).where(notable_type: 'ServiceRequest').each do |note|
if note.notable
note.update_attributes(notable_type: 'Protocol', notable_id: note.notable.protocol_id)
end
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161122130742) do
ActiveRecord::Schema.define(version: 20170103144243) do

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down
42 changes: 42 additions & 0 deletions spec/controllers/service_requests/get_document_management_spec.rb
Expand Up @@ -46,6 +46,48 @@
expect(before_filters.include?(:authenticate_identity!)).to eq(true)
end

it 'should assign @notable_type' do
org = create(:organization)
create(:subsidy_map, organization: org, max_dollar_cap: 100, max_percentage: 100)
service = create(:service, organization: org)
protocol = create(:protocol_federally_funded, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
ssr = create(:sub_service_request_without_validations, service_request: sr, organization: org)
li = create(:line_item, service_request: sr, sub_service_request: ssr, service: service)
arm = create(:arm, protocol: protocol)
liv = create(:line_items_visit, arm: arm, line_item: li)
vg = create(:visit_group, arm: arm, day: 1)
create(:visit, visit_group: vg, line_items_visit: liv)
create(:subsidy, sub_service_request: ssr)

xhr :get, :document_management, {
id: sr.id
}

expect(assigns(:notable_type)).to eq('Protocol')
end

it 'should assign @notable_id' do
org = create(:organization)
create(:subsidy_map, organization: org, max_dollar_cap: 100, max_percentage: 100)
service = create(:service, organization: org)
protocol = create(:protocol_federally_funded, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
ssr = create(:sub_service_request_without_validations, service_request: sr, organization: org)
li = create(:line_item, service_request: sr, sub_service_request: ssr, service: service)
arm = create(:arm, protocol: protocol)
liv = create(:line_items_visit, arm: arm, line_item: li)
vg = create(:visit_group, arm: arm, day: 1)
create(:visit, visit_group: vg, line_items_visit: liv)
create(:subsidy, sub_service_request: ssr)

xhr :get, :document_management, {
id: sr.id
}

expect(assigns(:notable_id)).to eq(protocol.id)
end

it 'should assign @has_subsidy' do
org = create(:organization)
create(:subsidy_map, organization: org, max_dollar_cap: 100, max_percentage: 100)
Expand Down
68 changes: 0 additions & 68 deletions spec/features/dashboard/protocols/index/notes_modal_spec.rb

This file was deleted.

Expand Up @@ -40,36 +40,6 @@ def go_to_show_protocol(protocol_id)
page
end

describe 'displayed ServiceRequest' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: user) }

describe 'notes button' do
context 'when user presses Add Note button and saves a note' do
it 'should create a new Note and display it in modal' do
service_request = create(:service_request_without_validations,
protocol: protocol,
status: 'draft')
create(:sub_service_request,
service_request: service_request,
organization: create(:organization),
status: 'draft')

page = go_to_show_protocol(protocol.id)
page.service_requests.first.notes_button.click
page.index_notes_modal.instance_exec do
new_note_button.click
wait_for_message_area
message_area.set('my important note')
add_note_button.click
end

expect(page.index_notes_modal).to have_notes(text: 'my important note')
expect(Note.count).to eq 1
end
end
end
end

describe 'displayed SubServiceRequest' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: user) }
let!(:service_request) do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/document_management/user_adds_note_spec.rb
Expand Up @@ -45,7 +45,7 @@
click_button 'Add a Note'
wait_for_javascript_to_finish

expect(page).to have_selector('.modal-dialog', text: 'New Service Request Note', visible: true)
expect(page).to have_selector('.modal-dialog', text: 'New Protocol Note', visible: true)
end

context 'and fills out the form and submits' do
Expand All @@ -61,8 +61,8 @@
click_button 'Add'
wait_for_javascript_to_finish

expect(@sr.notes.count).to eq(1)
expect(@sr.notes.first.body).to eq('Noteworthy Notes')
expect(@protocol.notes.count).to eq(1)
expect(@protocol.notes.first.body).to eq('Noteworthy Notes')
end
end
end
Expand Down