Skip to content
Merged
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
43 changes: 19 additions & 24 deletions spec/requests/notes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require "rails_helper"

RSpec.describe "/volunteers/notes", type: :request do
RSpec.shared_examples "create" do
let(:organization) { create(:casa_org) }
let(:organization) { create(:casa_org) }

shared_examples "create" do
# Caller must define: let(:user)
context "when in the same organization" do
it "can create a note for volunteer" do
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
Expand Down Expand Up @@ -33,13 +34,12 @@
end
end

RSpec.shared_examples "edit" do
let(:organization) { create(:casa_org) }

shared_examples "edit" do
# Caller must define: let(:user)
context "when in the same organization" do
let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org: organization) }

it "is successful if note belongs for volunteer" do
it "is successful if note belongs to volunteer" do
note = create(:note, notable: volunteer)

sign_in user
Expand Down Expand Up @@ -73,9 +73,8 @@
end
end

RSpec.shared_examples "update" do
let(:organization) { create(:casa_org) }

shared_examples "update" do
# Caller must define: let(:user)
context "when in the same organization" do
it "updates note and redirects to edit volunteer page" do
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
Expand Down Expand Up @@ -104,9 +103,8 @@
end
end

RSpec.shared_examples "delete" do
let(:organization) { create(:casa_org) }

shared_examples "delete" do
# Caller must define: let(:user)
context "when in the same organization" do
it "can delete notes about a volunteer" do
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
Expand Down Expand Up @@ -138,7 +136,7 @@
end

describe "POST /create" do
context "when logged in as admin" do
context "when logged in as an admin" do
it_behaves_like "create" do
let(:user) { create(:casa_admin, casa_org: organization) }
end
Expand All @@ -150,37 +148,35 @@
end
end

context "when logged in as volunteer" do
context "when logged in as a volunteer" do
it "cannot create a note" do
organization = create(:casa_org)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)

sign_in volunteer
expect {
expect do
post volunteer_notes_path(volunteer), params: {note: {content: "Very nice!"}}
}.not_to change(Note, :count)
end.not_to change(Note, :count)
expect(response).to redirect_to root_path
end
end
end

describe "GET /edit" do
context "when logged in as admin" do
context "when logged in as an admin" do
it_behaves_like "edit" do
let(:user) { create(:casa_admin, casa_org: organization) }
end
end

context "when logged in as supervisor" do
context "when logged in as a supervisor" do
it_behaves_like "edit" do
let(:user) { create(:supervisor, casa_org: organization) }
end
end

context "when logged in as volunteer" do
context "when logged in as a volunteer" do
context "when note belongs to volunteer" do
it "redirects to root path" do
organization = create(:casa_org)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org: organization)
note = create(:note, notable: volunteer)

Expand Down Expand Up @@ -209,7 +205,6 @@
context "when logged in as a volunteer" do
context "when updating note belonging to volunteer" do
it "does not update note and redirects to root path" do
organization = create(:casa_org)
volunteer = create(:volunteer, casa_org: organization)
note = create(:note, notable: volunteer, content: "Good job.")

Expand Down Expand Up @@ -242,9 +237,9 @@
note = create(:note, notable: volunteer)

sign_in volunteer
expect {
expect do
delete volunteer_note_path(volunteer, note)
}.not_to change(Note, :count)
end.not_to change(Note, :count)
expect(response).to redirect_to root_path
end
end
Expand Down
Loading