-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add specs on form/account controllers
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters