2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-03 16:20:13 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SuperAdmins::ReleaseNotesController, type: :controller do
|
|
|
|
let(:super_admin) { create(:super_admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in super_admin if super_admin.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "acl" do
|
|
|
|
context 'when user is not signed as super admin' do
|
|
|
|
let(:super_admin) { nil }
|
|
|
|
let!(:release_note) { create(:release_note, published: false) }
|
|
|
|
|
|
|
|
it 'is not allowed to post' do
|
|
|
|
expect { post :create, params: { release_note: { released_on: Date.current, published: "0", body: "bam" } } }.not_to change(ReleaseNote, :count)
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(flash[:alert]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not allowed to put' do
|
|
|
|
expect {
|
|
|
|
put :update, params: {
|
|
|
|
id: release_note.id,
|
|
|
|
release_note: {
|
|
|
|
released_on: Date.current,
|
|
|
|
published: "1",
|
|
|
|
categories: release_note.categories,
|
|
|
|
body: "hacked body"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.not_to change { release_note.reload.body }
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(flash[:alert]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not allowed to index' do
|
|
|
|
get :index
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(flash[:alert]).to be_present
|
|
|
|
end
|
2023-10-26 14:36:03 +02:00
|
|
|
|
|
|
|
it 'is not allowed to destroy' do
|
|
|
|
delete :destroy, params: { id: release_note.id }
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
expect(flash[:alert]).to be_present
|
|
|
|
expect(release_note.reload).to be_persisted
|
|
|
|
end
|
2023-10-03 16:20:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed as super admin' do
|
2023-10-26 14:36:03 +02:00
|
|
|
let(:release_note) { create(:release_note, published: false) }
|
|
|
|
|
2023-10-03 16:20:13 +02:00
|
|
|
it 'is allowed to post' do
|
|
|
|
expect { post :create, params: { release_note: { categories: ['api'], released_on: Date.current, published: "0", body: "bam" } } }.to change(ReleaseNote, :count).by(1)
|
|
|
|
expect(flash[:notice]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is allowed to put' do
|
|
|
|
put :update, params: {
|
|
|
|
id: release_note.id,
|
|
|
|
release_note: {
|
|
|
|
released_on: Date.current,
|
|
|
|
published: "1",
|
|
|
|
categories: release_note.categories,
|
|
|
|
body: "new body"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
release_note.reload
|
|
|
|
expect(release_note.body.to_plain_text).to eq("new body")
|
|
|
|
expect(release_note.published).to be_truthy
|
|
|
|
end
|
2023-10-26 14:36:03 +02:00
|
|
|
|
|
|
|
it 'is allowed to destroy' do
|
|
|
|
delete :destroy, params: { id: release_note.id }
|
|
|
|
expect(flash[:notice]).to be_present
|
|
|
|
expect { release_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2023-10-03 16:20:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|