creddit/spec/models/post_spec.rb

57 lines
1.1 KiB
Ruby
Raw Normal View History

2015-07-14 16:29:22 -04:00
require 'rails_helper'
describe Post, type: :model do
let(:post) { build(:post) }
it { should belong_to(:user) }
it { should belong_to(:subcreddit) }
2015-07-20 15:12:26 -04:00
it { should delegate_method(:username).to(:user).with_prefix }
2015-07-14 16:29:22 -04:00
context 'with valid data' do
it 'should be valid' do
expect(post).to be_valid
end
it 'should allow blank content' do
post.content = ''
expect(post).to be_valid
end
it 'should allow a blank link' do
post.link = ''
expect(post).to be_valid
end
end
context 'with invalid data' do
it 'should not allow a blank title' do
post.title = ''
expect(post).to be_invalid
end
it 'should not allow a long title' do
post.title = 'a' * 301
expect(post).to be_invalid
end
it 'should not allow long content' do
post.content = 'a' * 15001
expect(post).to be_invalid
end
end
context '#to_param' do
it 'generates the correct param' do
post.save
expect(post.to_param).to eq("#{post.id}-#{post.title.parameterize}")
end
end
end