File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
spec/models/better_together Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'rails_helper'
4+
5+ RSpec . describe BetterTogether ::Post , type : :model do
6+ it_behaves_like 'an authorable model'
7+
8+ it 'has a valid factory' do
9+ expect ( build ( :better_together_post ) ) . to be_valid
10+ end
11+
12+ it 'validates presence of title and content' do
13+ post = build ( :better_together_post , title : nil , content : nil )
14+ expect ( post ) . not_to be_valid
15+ expect ( post . errors [ :title ] ) . to include ( "can't be blank" )
16+ expect ( post . errors [ :content ] ) . to include ( "can't be blank" )
17+ end
18+
19+ describe '#to_s' do
20+ it 'returns the title' do
21+ post = build ( :better_together_post , title : 'Example' )
22+ expect ( post . to_s ) . to eq 'Example'
23+ end
24+ end
25+
26+ describe 'after_create #add_creator_as_author' do
27+ it 'creates an authorship for the creator_id' do
28+ creator = create ( :better_together_person )
29+ post = build ( :better_together_post )
30+ # Ensure no prebuilt authorships from the factory
31+ post . authorships . clear
32+ post . creator_id = creator . id
33+ post . save!
34+
35+ expect ( post . authors . reload . map ( &:id ) ) . to include ( creator . id )
36+ end
37+ end
38+ end
You can’t perform that action at this time.
0 commit comments