docbrown/spec/requests/admin/privileged_reactions_spec.rb
Ridhwana 3a4da2dd5a
RFC 50: Remove hardcoded paths and use path_helpers instead (in the specs) (#13549)
* feat: update the paths in the spec files

* feat: update hardcoded paths with path helpers

* chore: update hardcoded paths to path helpers

* chore: hardcode describe blocks

* chore: oops

* feat: update some more hardcoded to use link_to's

* fix broken tests

* chore: admin_articles path

* chore: oops remove rails helper

* feat: add starting /

* chore: more pre slashes

* chore: add pre slashes

* chore: some small typos

* fix: oops
2021-04-28 21:32:51 +02:00

55 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/moderations/privileged_reactions", type: :request do
context "when the user is not an admin" do
let(:user) { create(:user) }
before do
sign_in user
end
it "blocks the request" do
expect do
get admin_privileged_reactions_path
end.to raise_error(Pundit::NotAuthorizedError)
end
end
context "when the user is a single resource admin" do
let(:single_resource_admin) { create(:user, :single_resource_admin, resource: ModeratorAction) }
it "renders with status 200" do
sign_in single_resource_admin
get admin_moderator_actions_path
expect(response.status).to eq 200
end
end
context "when the user is an admin" do
let(:admin) { create(:user, :admin) }
let(:moderator) { create(:user, :trusted) }
let!(:user_reaction) { create(:vomit_reaction, :user, user: moderator) }
let!(:comment_reaction) { create(:vomit_reaction, :comment, user: moderator) }
let!(:article_reaction) { create(:vomit_reaction, user: moderator) }
before do
sign_in admin
end
it "does not block the request" do
expect do
get admin_privileged_reactions_path
end.not_to raise_error
end
describe "GETS /admin/moderations/privileged_reactions" do
it "renders to appropriate page" do
get admin_privileged_reactions_path
expect(response.body).to include(CGI.escapeHTML(moderator.username))
.and include(CGI.escapeHTML(user_reaction.reactable.username))
.and include(CGI.escapeHTML(comment_reaction.reactable.user.username))
.and include(CGI.escapeHTML(article_reaction.reactable.title))
end
end
end
end