Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def destroy
private

def find_noteable
params.each do |name, value|
return Regexp.last_match(1).classify.constantize.find(value) if name =~ /(.+)_id$/
end
nil
Patient.with_practice(current_user.practice_id).find(params[:patient_id])
end

def note_params
Expand Down
18 changes: 18 additions & 0 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ class NotesControllerTest < ActionController::TestCase
end
end

test 'should not create a note for a patient in another practice' do
assert_no_difference 'Note.count' do
assert_raises(ActiveRecord::RecordNotFound) do
post :create, params: { patient_id: patients(:three).id, note: { notes: 'Cross-practice note' }, format: :js }
end
end
end

test 'should not destroy a note for a patient in another practice' do
foreign_note = Note.create!(notes: 'Private note', user: users(:user_in_yet_another_practice), noteable: patients(:three))

assert_no_difference 'Note.count' do
assert_raises(ActiveRecord::RecordNotFound) do
delete :destroy, params: { patient_id: patients(:three).id, id: foreign_note.id, format: :js }
end
end
end

test 'requires authentication' do
@controller.session['user'] = nil

Expand Down
Loading