mirror of
https://github.com/tildeverse/lobsters
synced 2024-06-20 23:47:04 +00:00
Add tests for categories
This commit is contained in:
parent
693caf55b4
commit
ef927af10a
|
@ -1,5 +1,46 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Category, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Category do
|
||||
context 'validations' do
|
||||
it 'allows a valid category to be created' do
|
||||
category = Category.create(
|
||||
category: Faker::Lorem.word,
|
||||
)
|
||||
expect(category).to be_valid
|
||||
end
|
||||
|
||||
it 'does not allow a category to be saved without a name' do
|
||||
expect(Category.create).not_to be_valid
|
||||
end
|
||||
|
||||
it 'does not allow an empty category to be saved' do
|
||||
expect(Category.create(category: '')).not_to be_valid
|
||||
end
|
||||
|
||||
it 'does not allow a category with a name too long to be saved' do
|
||||
expect(Category.create(category: 'A' * 26)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'logs modification in moderation log' do
|
||||
let(:edit_user) { create :user }
|
||||
|
||||
it 'logs on create' do
|
||||
expect { Category.create(category: 'new_category', edit_user_id: edit_user.id) }
|
||||
.to change { Moderation.count }.by(1)
|
||||
mod = Moderation.last
|
||||
expect(mod.action).to include 'new_category'
|
||||
expect(mod.action).to start_with 'Created new category'
|
||||
expect(mod.moderator_user_id).to be edit_user.id
|
||||
end
|
||||
|
||||
it 'logs on update' do
|
||||
expect { Category.first.update(category: 'new_category_name', edit_user_id: edit_user.id) }
|
||||
.to change { Moderation.count }.by(1)
|
||||
mod = Moderation.last
|
||||
expect(mod.action).to include 'new_category_name'
|
||||
expect(mod.action).to start_with 'Updating'
|
||||
expect(mod.moderator_user_id).to be edit_user.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user