main
 1require "rails_helper"
 2
 3RSpec.describe User do
 4  subject { build(:user, password: "password") }
 5
 6  describe "#validations" do
 7    it "validates the presence of a username" do
 8      subject.username = nil
 9      expect(subject).to_not be_valid
10      expect(subject.errors[:username]).to_not be_empty
11
12      subject.username = ""
13      expect(subject).to_not be_valid
14      expect(subject.errors[:username]).to_not be_empty
15    end
16
17    it "is valid" do
18      expect(subject).to be_valid
19    end
20  end
21
22  describe "#authenticate" do
23    context "when the password is correct" do
24      it "returns true" do
25        expect(subject.authenticate("password")).to be_truthy
26      end
27    end
28
29    context "when the password is incorrect" do
30      it "returns false" do
31        expect(subject.authenticate("wrong")).to be_falsey
32      end
33    end
34  end
35end