2023-01-18 21:11:27 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe PostPolicy do
|
|
|
|
|
subject { PostPolicy.new(user, record) }
|
|
|
|
|
|
|
|
|
|
let(:record) { FactoryBot.create(:post) }
|
|
|
|
|
|
|
|
|
|
context 'being a user' do
|
|
|
|
|
context 'not being the post author' do
|
|
|
|
|
let(:user) { FactoryBot.build_stubbed(:user) }
|
|
|
|
|
|
|
|
|
|
it { should_not permit(:update) }
|
|
|
|
|
it { should_not permit(:destroy) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'being the post author' do
|
|
|
|
|
let(:user) { FactoryBot.build(:user, id: record.user_id) }
|
|
|
|
|
|
|
|
|
|
it { should permit(:update) }
|
|
|
|
|
it { should permit(:destroy) }
|
|
|
|
|
|
|
|
|
|
it 'permits "title" and "description" attributes' do
|
|
|
|
|
expect(subject.permitted_attributes_for_update).to eq([:title, :description])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'being a moderator' do
|
|
|
|
|
let(:user) { FactoryBot.build_stubbed(:moderator) }
|
|
|
|
|
|
|
|
|
|
it { should permit(:update) }
|
|
|
|
|
it { should permit(:destroy) }
|
|
|
|
|
|
2024-07-12 20:38:46 +02:00
|
|
|
it 'permits "title", "description", "board_id", "post_status_id" and "approval_status" attributes' do
|
|
|
|
|
permitted_attributes = [:title, :description, :board_id, :post_status_id, :approval_status]
|
2023-01-18 21:11:27 +01:00
|
|
|
expect(subject.permitted_attributes_for_update).to eq(permitted_attributes)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'being a admin' do
|
|
|
|
|
let(:user) { FactoryBot.build_stubbed(:admin) }
|
|
|
|
|
|
|
|
|
|
it { should permit(:update) }
|
|
|
|
|
it { should permit(:destroy) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'being a owner' do
|
|
|
|
|
let(:user) { FactoryBot.build_stubbed(:owner) }
|
|
|
|
|
|
|
|
|
|
it { should permit(:update) }
|
|
|
|
|
it { should permit(:destroy) }
|
|
|
|
|
end
|
|
|
|
|
end
|