Note we're excluding a few files: * Configuration files that weren't generated by us * Migration files that weren't generated by us * The Gemfile, since it includes an important comment that must be on the same line as the gem declaration * The Budget::Stats class, since the heading statistics are a mess and having shorter lines would require a lot of refactoring
47 lines
1.6 KiB
Ruby
47 lines
1.6 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Moderation::UsersController do
|
|
before { sign_in create(:moderator).user }
|
|
let(:user) { create(:user, email: "user@consul.dev") }
|
|
|
|
describe "PUT hide" do
|
|
it "keeps query parameters while using protected redirects" do
|
|
user = create(:user, email: "user@consul.dev")
|
|
|
|
get :hide, params: { id: user, name_or_email: "user@consul.dev", host: "evil.dev" }
|
|
|
|
expect(response).to redirect_to "/moderation/users?name_or_email=user%40consul.dev"
|
|
end
|
|
end
|
|
|
|
describe "PUT block" do
|
|
it "keeps query parameters while using protected redirects" do
|
|
user = create(:user, email: "user@consul.dev")
|
|
|
|
get :block, params: { id: user, search: "user@consul.dev", host: "evil.dev" }
|
|
|
|
expect(response).to redirect_to "/moderation/users?search=user%40consul.dev"
|
|
end
|
|
|
|
it "redirects to the index of the section where it was called with a notice" do
|
|
proposal = create(:proposal, author: user)
|
|
request.env["HTTP_REFERER"] = proposal_path(proposal)
|
|
|
|
put :block, params: { id: user }
|
|
|
|
expect(response).to redirect_to proposals_path
|
|
expect(flash[:notice]).to eq "The user has been blocked. " \
|
|
"All contents authored by this user have been hidden."
|
|
end
|
|
|
|
it "redirects to the index with a nested resource" do
|
|
investment = create(:budget_investment, author: user)
|
|
request.env["HTTP_REFERER"] = budget_investment_path(investment.budget, investment)
|
|
|
|
put :block, params: { id: user }
|
|
|
|
expect(response).to redirect_to budget_investments_path(investment.budget)
|
|
end
|
|
end
|
|
end
|