Use just one action to hide users
Other than removing a redundant action, we're fixing two bugs when blocking an author using the links in the public views: * We were always redirecting to the debates index, even if we blocked the author of a proposal or an investment * We weren't showing any kind of success message
This commit is contained in:
@@ -2,14 +2,32 @@ require "rails_helper"
|
||||
|
||||
describe Moderation::UsersController do
|
||||
before { sign_in create(:moderator).user }
|
||||
let(:user) { create(:user, email: "user@consul.dev") }
|
||||
|
||||
describe "PUT hide_in_moderation_screen" do
|
||||
describe "PUT hide" do
|
||||
it "keeps query parameters while using protected redirects" do
|
||||
user = create(:user, email: "user@consul.dev")
|
||||
|
||||
get :hide_in_moderation_screen, params: { id: user, search: "user@consul.dev", host: "evil.dev" }
|
||||
get :hide, 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 :hide, params: { id: user }
|
||||
|
||||
expect(response).to redirect_to proposals_path
|
||||
expect(flash[:notice]).to eq "User blocked. All of this user's debates and comments 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 :hide, params: { id: user }
|
||||
|
||||
expect(response).to redirect_to budget_investments_path(investment.budget)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user