docbrown/spec/requests/moderations_spec.rb
Abraham Williams 9cb40e546b Enables Rails cops (#2186)
* Enable Rails cops

* Fix Rails/DynamicFindBy

* Fix Rails/HttpStatus

* Fix Rails/Blank

* Fix Rails/RequestReferer

* Fix Rails/ActiveRecordAliases

* Fix Rails/FindBy

* Fix Rails/Presence

* Fix Rails/Delegate

* Fix Rails/Validation

* Fix Rails/PluralizationGrammar

* Fix Rails/Present

* Fix Rails/Output

* Fix Rails/Blank

* Fix Rails/FilePath

* Fix Rails/InverseOf

* Fix Rails/LexicallyScopedActionFilter

* Add Rails/OutputSafety to TODO

* Add Rails/HasManyOrHasOneDependent to TODO

* Add Rails/SkipsModelValidations to TODO
2019-03-25 09:25:55 -04:00

60 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.shared_examples "an elevated privilege required request" do |path|
context "when not logged-in" do
it "does not grant acesss", proper_status: true do
get path
expect(response).to have_http_status(:not_found)
end
it "raises Pundit::NotAuthorizedError internally" do
expect { get path }.to raise_error(Pundit::NotAuthorizedError)
end
end
context "when user is not trusted" do
before { sign_in create(:user) }
it "does not grant acesss", proper_status: true do
get path
expect(response).to have_http_status(:not_found)
end
it "internally raise Pundit::NotAuthorized internally" do
expect { get path }.to raise_error(Pundit::NotAuthorizedError)
end
end
end
RSpec.describe "Moderations", type: :request do
let(:user) { create(:user, :trusted) }
let(:article) { create(:article) }
let(:comment) { create(:comment, commentable: article) }
it_behaves_like "an elevated privilege required request", "/username/random-article/mod"
it_behaves_like "an elevated privilege required request", "/username/comment/1/mod"
context "when user is trusted" do
before { sign_in user }
it "grant access to comment moderation" do
get comment.path + "/mod"
expect(response).to have_http_status(:ok)
end
it "grant access to article moderation" do
get article.path + "/mod"
expect(response).to have_http_status(:ok)
end
it "grants access to /mod index" do
get "/mod"
expect(response).to have_http_status(:ok)
end
it "grants access to /mod index with articles" do
create(:article, published: true)
get "/mod"
expect(response.body).to include("Experience Level Target")
end
end
end