* Create DiscussionLocks
* Fix specs
* Update nullify_blank_notes_and_reason
* Update before_validation call
* Updated DiscussionLockPolicy for clarity
* Move permitted_attributes to a constant
* Update route
* Apply suggestions from code review for frontend
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
* Add title tags
* Wrap unlock confirm in main element
* Wrap flash messages up in div
* Actually fix title tags
* Hide comment reply button when discussion is locked
* Add E2E tests
* Try to fix E2E tests
* Cypress...you work locally but not in CI...why!?
* PR feedback
* Update E2E tests
* More E2E updates 😭
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
51 lines
1.7 KiB
Ruby
51 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe DiscussionLockPolicy do
|
|
subject { described_class.new(locking_user, discussion_lock) }
|
|
|
|
let!(:locking_user) { create(:user) }
|
|
let(:article) { build_stubbed(:article, user: locking_user) }
|
|
let(:discussion_lock) { build_stubbed(:discussion_lock, locking_user: locking_user, article: article) }
|
|
let(:valid_attributes) { %i[article_id notes reason] }
|
|
|
|
context "when user is not signed-in" do
|
|
let(:locking_user) { nil }
|
|
|
|
it { within_block_is_expected.to raise_error(Pundit::NotAuthorizedError) }
|
|
end
|
|
|
|
context "when user is not the author" do
|
|
let(:user) { build_stubbed(:user) }
|
|
let(:discussion_lock) { build_stubbed(:discussion_lock, locking_user: user, article: article) }
|
|
|
|
it { is_expected.to forbid_actions(%i[create destroy]) }
|
|
end
|
|
|
|
context "when user is the author" do
|
|
let(:article) { build_stubbed(:article, user: locking_user) }
|
|
|
|
it { is_expected.to permit_actions(%i[create destroy]) }
|
|
it { is_expected.to permit_mass_assignment_of(valid_attributes) }
|
|
end
|
|
|
|
context "when user is suspended" do
|
|
let(:user) { build_stubbed(:user, :suspended) }
|
|
let(:discussion_lock) { build_stubbed(:discussion_lock, locking_user: user, article: article) }
|
|
|
|
it { is_expected.to forbid_actions(%i[create destroy]) }
|
|
end
|
|
|
|
context "when user is an admin" do
|
|
let(:locking_user) { build(:user, :admin) }
|
|
|
|
it { is_expected.to permit_actions(%i[create destroy]) }
|
|
it { is_expected.to permit_mass_assignment_of(valid_attributes) }
|
|
end
|
|
|
|
context "when user is a super_admin" do
|
|
let(:locking_user) { build(:user, :super_admin) }
|
|
|
|
it { is_expected.to permit_actions(%i[create destroy]) }
|
|
it { is_expected.to permit_mass_assignment_of(valid_attributes) }
|
|
end
|
|
end
|