Skip to content

Commit

Permalink
add specs on form/account controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamfall authored and Lubosky committed Jun 14, 2024
1 parent 3e97baf commit 1b06306
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
60 changes: 60 additions & 0 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require "rails_helper"

describe AccountsController do
let(:old_password) { "^#ur9EkLm@1W+OaDvgTT" }
let(:new_password) { "^#ur9EkLm@1W+OaDvg" }

let(:user) { create(:user, :completed_profile, password: "^#ur9EkLm@1W+OaDvgTT", password_confirmation: "^#ur9EkLm@1W+OaDvgTT") }

before do
sign_in user
end

describe "PATCH #update_password_settings" do
context "with valid params" do
it "updates the password and redirects to the dashboard with a success message" do
patch :update_password_settings, params: {
user: {
current_password: old_password,
password: new_password,
password_confirmation: new_password,
},
}

user.reload
expect(user.valid_password?(new_password)).to be_truthy
expect(flash[:notice]).to eq("Your account details were successfully saved")
expect(response).to redirect_to(dashboard_path)
end
end

context "with invalid params" do
it "does not update the password and renders the password_settings template with an error message" do
patch :update_password_settings, params: {
user: {
current_password: "wrong_password",
password: new_password,
password_confirmation: new_password,
},
}

user.reload
expect(user.valid_password?(new_password)).to be_falsey
expect(flash[:alert]).to eq("Error updating your password")
expect(response).to render_template(:password_settings)
end

it "sets @active_step to 5" do
patch :update_password_settings, params: {
user: {
current_password: "wrong_password",
password: new_password,
password_confirmation: new_password,
},
}

expect(assigns(:active_step)).to eq(5)
end
end
end
end
24 changes: 24 additions & 0 deletions spec/controllers/form_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,28 @@
end
end
end

describe "#add_attachment" do
let(:file) { Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/cat.jpg"), "image/jpeg") }

it "adds attachment to the form answer" do
expect {
post :add_attachment, params: {
form: {
file: file,
},
id: form_answer.id,
question_key: "org_chart",
}
}.to change {
form_answer.reload.form_answer_attachments.count
}.by(1)

expect(response).to have_http_status(:created)

id = JSON.parse(response.body)["id"]
attachment = FormAnswerAttachment.find_by(id: id)
expect(attachment).to be_present
end
end
end

0 comments on commit 1b06306

Please sign in to comment.