|
1 | 1 | require 'rails_helper'
|
2 | 2 |
|
3 | 3 | RSpec.describe User, type: :model do
|
4 |
| - subject { |
5 |
| - described_class.new(email: "john@doe.com", |
6 |
| - name: 'John', |
7 |
| - password: "john_password", |
8 |
| - ) |
9 |
| - } |
| 4 | + user = FactoryBot.create(:user) |
10 | 5 |
|
11 | 6 | describe "Validations" do
|
12 | 7 | it "should be valid" do
|
13 |
| - expect(subject).to be_valid |
| 8 | + expect(user).to be_valid |
14 | 9 | end
|
15 | 10 |
|
16 | 11 | it "should not be valid without an email" do
|
17 |
| - subject.email = nil |
18 |
| - expect(subject).to_not be_valid |
| 12 | + user.email = nil |
| 13 | + expect(user).to_not be_valid |
19 | 14 | end
|
20 | 15 |
|
21 | 16 | it "should not be valid without a name" do
|
22 |
| - subject.name = nil |
23 |
| - expect(subject).to_not be_valid |
| 17 | + user.name = nil |
| 18 | + expect(user).to_not be_valid |
24 | 19 | end
|
25 | 20 |
|
26 | 21 | it "name should be less than 32 characters" do
|
27 |
| - subject.name = "this is a very very very long name" |
28 |
| - expect(subject).to_not be_valid |
| 22 | + user.name = "this is a very very very long name" |
| 23 | + expect(user).to_not be_valid |
29 | 24 | end
|
30 | 25 |
|
31 | 26 | it "should not be valid without a password" do
|
32 |
| - subject.password = nil |
33 |
| - expect(subject).to_not be_valid |
| 27 | + user.password = nil |
| 28 | + expect(user).to_not be_valid |
34 | 29 | end
|
35 | 30 |
|
36 |
| - it "password must be at least 6 characters" do |
37 |
| - subject.password = '12' |
38 |
| - expect(subject).to_not be_valid |
| 31 | + it "password must have at least 6 characters" do |
| 32 | + user.password = '12' |
| 33 | + expect(user).to_not be_valid |
39 | 34 | end
|
40 | 35 | end
|
41 | 36 | end
|
0 commit comments