blob: 85b13ed7dca0aecc6f0d991e9fc06778b39a1cc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
require "rails_helper"
describe My::PasswordsController do
describe "#update" do
context "when not logged in" do
let(:user) { create(:user) }
it "redirects you to the login page" do
put :update, params: { id: user.id }
expect(response).to redirect_to(login_path)
end
end
context "when logged in" do
let(:user) { create(:user) }
before { http_login(user) }
context "when the new password and the confirmation password does not match" do
before :each do
put :update, params: {
id: user.id,
user: {
password: "foobar",
password_confirmation: "barfoo"
}
}
end
it "displays an error on the page" do
error_message = I18n.t("my.passwords.passwords_do_not_match")
expect(flash[:error]).to eql(error_message)
end
it "renders the show template" do
expect(response).to render_template(:index)
end
end
context "when the password and confirmation match" do
let(:new_password) { "booyakasham" }
before :each do
put :update, params: {
id: user.id,
user: {
password: new_password,
password_confirmation: new_password
}
}
end
it "updates the users password" do
expect(user.reload.authenticate(new_password)).to be_truthy
end
end
end
end
describe "#index" do
context "when logged in" do
let(:user) { create(:user) }
before :each do
http_login(user)
get :index
end
context "when displaying a form to change the current password" do
it "loads the user" do
expect(assigns(:user)).to eql(user)
end
end
end
end
end
|