Add Post model

This commit is contained in:
riggraz
2019-08-24 16:51:25 +02:00
parent c66d350004
commit 0ceaa6acb5
5 changed files with 101 additions and 1 deletions

9
spec/factories/posts.rb Normal file
View File

@@ -0,0 +1,9 @@
FactoryBot.define do
factory :post do
title { "Post Title" }
description { "Post Description" }
board
user
post_status
end
end

55
spec/models/post_spec.rb Normal file
View File

@@ -0,0 +1,55 @@
require 'rails_helper'
RSpec.describe Post, type: :model do
let(:post) { FactoryBot.build(:post) }
it 'should be valid' do
expect(post).to be_valid
end
it 'has a non-null and non-empty title' do
nil_post = FactoryBot.build(:post, title: nil)
empty_post = FactoryBot.build(:post, title: "")
expect(nil_post).to be_invalid
expect(empty_post).to be_invalid
end
it 'has a title between 4 and 64 characters' do
too_short_post = FactoryBot.build(:post, title: "a" * 3)
short_post = FactoryBot.build(:post, title: "a" * 4)
long_post = FactoryBot.build(:post, title: "a" * 64)
too_long_post = FactoryBot.build(:post, title: "a" * 65)
expect(too_short_post).to be_invalid
expect(short_post).to be_valid
expect(long_post).to be_valid
expect(too_long_post).to be_invalid
end
it 'has a description that can be nil or empty' do
nil_description_post = FactoryBot.build(:post, description: nil)
empty_description_post = FactoryBot.build(:post, description: "")
expect(nil_description_post).to be_valid
expect(empty_description_post).to be_valid
end
it 'has a reference to a post status that can be nil' do
no_status_post = FactoryBot.build(:post, post_status_id: nil)
expect(no_status_post).to be_valid
end
it 'has a reference to a user than cannot be nil' do
no_user_post = FactoryBot.build(:post, user_id: nil)
expect(no_user_post).to be_invalid
end
it 'has a reference to a board than cannot be nil' do
no_board_post = FactoryBot.build(:post, board_id: nil)
expect(no_board_post).to be_invalid
end
end