docbrown/spec/requests/admin/privileged_reactions_spec.rb
Josh Puetz 1c566e0ec4
[deploy] Move /internal to `/admin (#9639)
* First draft - all the big changes

* Changing some more references to 'internal'

* Relocate internal request tests to admin

* Relocate internal system tests to admin

* Fix trailing space

* Test fix

* Move queries from internal to admin

* Docs updates

* Rename internal stimuls controllers to admin (plus docs)

* Rename admin layout

* Fix routing after rebase

* Fixes for latest added admin interfaces

* Serviceworker ignore paths
2020-08-07 10:36:26 -04:00

55 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/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"
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"
end.not_to raise_error
end
describe "GETS /admin/privileged_reactions" do
it "renders to appropriate page" do
get "/admin/privileged_reactions"
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