Skip to content

Commit

Permalink
Add a way to edit existing volunteer notes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhian-cs committed Apr 6, 2022
1 parent 72e4620 commit 89a940e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
25 changes: 22 additions & 3 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
class NotesController < ApplicationController
before_action :find_note, only: %i[edit update]
before_action :find_volunteer

def create
volunteer = Volunteer.find(params[:volunteer_id])
volunteer.notes.create(note_params)
redirect_to edit_volunteer_path(volunteer)
@volunteer.notes.create(note_params)
redirect_to edit_volunteer_path(@volunteer)
end

def edit
end

def update
@note.update(note_params)

redirect_to edit_volunteer_path(@volunteer)
end

private

def find_note
@note = Note.find(params[:id])
end

def find_volunteer
@volunteer = Volunteer.find(params[:volunteer_id])
end

def note_params
params.require(:note).permit(:content).merge({creator_id: current_user.id})
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/notes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= form_with(model: @note, local: true, url: volunteer_note_path(@volunteer, @note)) do |form| %>
<h3>Update Volunteer Note</h3>

<div class="form-group">
<%= form.text_area :content,
rows: 5,
placeholder: t("volunteers.edit.notes_placeholder"),
class: "form-control"
%>
</div>

<%= form.submit t("notes.update"), class: "btn btn-primary", id: "note-submit" %>
<% end %>
3 changes: 3 additions & 0 deletions config/locales/views.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ en:
send_reminder: Send Reminder
supervisor_checkbox_text: Send CC to Supervisor
tooltip: Remind volunteer to input case contacts

notes:
update: Update Note
mileage_rates:
index:
mileage_rates: Mileage Rates
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
patch :reminder
get :impersonate
end
resources :notes, only: %i[create]
resources :notes, only: %i[create edit update]
end
resources :case_assignments, only: %i[create destroy] do
member do
Expand Down
28 changes: 28 additions & 0 deletions spec/requests/notes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "rails_helper"

RSpec.describe "/volunteers/notes", type: :request do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id) }
let(:note) { volunteer.notes.create(creator: admin, content: "Good job.") }

describe "PATCH /update" do
subject(:request) { patch volunteer_note_path(volunteer, note), params: params }

context "when logged in as an admin" do
before do
sign_in admin
request
end

context "with valid params" do
let(:params) { {note: {content: "Very nice!"}} }

it "returns success response" do
expect(response).to redirect_to(edit_volunteer_path(volunteer))
expect(note.reload.content).to eq "Very nice!"
end
end
end
end
end
29 changes: 29 additions & 0 deletions spec/system/volunteers/notes/edit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "rails_helper"

RSpec.describe "volunteers/notes/edit", type: :system do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id) }
let(:note) { volunteer.notes.create(creator: admin, content: "Good job.") }

context "when logged in as an admin" do
before do
sign_in admin
visit edit_volunteer_note_path(volunteer, note)
end

scenario "editing an existing note" do
expect(page).to have_text("Good job.")

fill_in("note[content]", with: "Great job!")

click_on("Update Note")

expect(page.current_path).to eq edit_volunteer_path(volunteer)

expect(page).to have_text("Great job!")

expect(note.reload.content).to eq "Great job!"
end
end
end

0 comments on commit 89a940e

Please sign in to comment.