blob: 7532721a38b87c0d8f6f35035d461654339cd939 (
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
|
require "rails_helper"
RSpec.describe User do
subject { build(:user, password: "password") }
describe "#validations" do
it "validates the presence of a username" do
subject.username = nil
expect(subject).to_not be_valid
expect(subject.errors[:username]).to_not be_empty
subject.username = ""
expect(subject).to_not be_valid
expect(subject.errors[:username]).to_not be_empty
end
it "is valid" do
expect(subject).to be_valid
end
end
describe "#authenticate" do
context "when the password is correct" do
it "returns true" do
expect(subject.authenticate("password")).to be_truthy
end
end
context "when the password is incorrect" do
it "returns false" do
expect(subject.authenticate("wrong")).to be_falsey
end
end
end
end
|