Skip to content

Commit

Permalink
Write assessment tests for ac-6.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Jun 28, 2024
1 parent 03c0d42 commit d218819
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions spec/requests/documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
post documents_url, params: {document: valid_attributes}
expect(response).to redirect_to(document_url(Document.last))
end

it "logs the use of this privileged function", control_id: "ac-6.9", statement_id: "ac-6.9_smt", assessment_plan_uuid: "06eb2b97-7665-467b-88d5-027170dc6f63" do
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with(/\[PRIVILEGED\] Document\(\d+\) created by #{user.id}/)
post documents_url, params: {document: valid_attributes}
end
end

context "with invalid parameters" do
Expand All @@ -101,6 +107,7 @@

describe "PATCH /update" do
let(:user) { User.create! email: "admin@gsa.gov", password: SecureRandom.alphanumeric, admin: true }
let!(:document) { Document.create! valid_attributes }

context "with valid parameters" do
let(:new_attributes) {
Expand All @@ -110,18 +117,22 @@
}

it "updates the requested document" do
document = Document.create! valid_attributes
patch document_url(document), params: {document: new_attributes}
document.reload
expect(document.description).to eq "We updated the description!"
end

it "redirects to the document" do
document = Document.create! valid_attributes
patch document_url(document), params: {document: new_attributes}
document.reload
expect(response).to redirect_to(document_url(document))
end

it "logs the use of this privileged function", control_id: "ac-6.9", statement_id: "ac-6.9_smt", assessment_plan_uuid: "06eb2b97-7665-467b-88d5-027170dc6f63" do
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with("[PRIVILEGED] Document(#{document.id}) updated by #{user.id}")
patch document_url(document), params: {document: new_attributes}
end
end

context "with invalid parameters" do
Expand All @@ -135,18 +146,23 @@

describe "DELETE /destroy" do
let(:user) { User.create! email: "admin@gsa.gov", password: SecureRandom.alphanumeric, admin: true }
let!(:document) { Document.create! valid_attributes }

it "destroys the requested document" do
document = Document.create! valid_attributes
expect {
delete document_url(document)
}.to change(Document, :count).by(-1)
end

it "redirects to the documents list" do
document = Document.create! valid_attributes
delete document_url(document)
expect(response).to redirect_to(documents_url)
end

it "logs the use of this privileged function", control_id: "ac-6.9", statement_id: "ac-6.9_smt", assessment_plan_uuid: "06eb2b97-7665-467b-88d5-027170dc6f63" do
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with("[PRIVILEGED] Document(#{document.id}) destroyed by #{user.id}")
delete document_url(document)
end
end
end

0 comments on commit d218819

Please sign in to comment.