File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ FactoryBot . define do
2+ factory :book do
3+ title { Faker ::Book . title }
4+ author { Faker ::Book . author }
5+ description { Faker ::Lorem . paragraph }
6+ association :recommender , factory : :user
7+ end
8+ end
Original file line number Diff line number Diff line change 1+ require 'rails_helper'
2+
3+ describe Book , type : :model do
4+ let ( :book ) { create ( :book ) }
5+
6+ it 'is expected to have a valid factory' do
7+ expect ( book . valid? ) . to eq true
8+ end
9+
10+ context 'Associations' do
11+ it { should belong_to ( :recommender ) . class_name ( 'User' ) }
12+ end
13+
14+ context 'Validations' do
15+ it { should validate_presence_of ( :recommender ) }
16+ it { should validate_presence_of ( :title ) }
17+ it { should validate_presence_of ( :author ) }
18+ it { should validate_presence_of ( :description ) }
19+
20+ it 'is invalid without a title' do
21+ book . title = nil
22+ expect ( book . valid? ) . to eq false
23+ end
24+
25+ it 'is invalid without a recommender' do
26+ book . recommender = nil
27+ expect ( book . valid? ) . to eq false
28+ end
29+
30+ it "is not valid with a empty title" do
31+ book . title = ''
32+ expect ( book ) . to_not be_valid
33+ end
34+ end
35+ end
You can’t perform that action at this time.
0 commit comments