Skip to content

Commit 688695d

Browse files
committed
Implement a ChangeUserPassword command
1 parent 3c1f0c6 commit 688695d

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ChangeUserPassword
2+
def initialize(repository = User)
3+
@repo = repository
4+
end
5+
6+
def change_user_password(new_password)
7+
user = @repo.first
8+
user.password = new_password
9+
user.save
10+
user
11+
end
12+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require "spec_helper"
2+
3+
app_require "commands/users/change_user_password"
4+
5+
describe ChangeUserPassword do
6+
let(:repo) do
7+
double("repo")
8+
end
9+
10+
let(:user) do
11+
double("user", id: 1, password_digest: BCrypt::Password.create(old_password))
12+
end
13+
14+
let(:old_password){ "old-pw" }
15+
let(:new_password){ "new-pw" }
16+
17+
describe "#change_user_password" do
18+
it "changes the password of the user" do
19+
command = ChangeUserPassword.new(repo)
20+
21+
repo.should_receive(:first){ user }
22+
user.should_receive(:password=).with(new_password)
23+
user.should_receive(:save)
24+
25+
command.change_user_password(new_password)
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)