2020-05-21 13:25:43 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe UserController, type: :controller do
|
2022-08-20 08:08:56 -07:00
|
|
|
let(:user) do
|
|
|
|
FactoryBot.create :user,
|
|
|
|
otp_module: :disabled,
|
|
|
|
otp_secret_key: "EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3"
|
|
|
|
end
|
2020-05-21 13:25:43 -07:00
|
|
|
|
2022-11-15 12:36:24 -08:00
|
|
|
shared_examples_for "social graph hidden" do
|
|
|
|
context "user has social graph hidden" do
|
|
|
|
before(:each) do
|
|
|
|
user.update(privacy_hide_social_graph: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the followers template to the current user" do
|
|
|
|
sign_in user
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response).to render_template("user/show_follow")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to the user profile page if not logged in" do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(user_path(user))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to the user profile page if logged in as a different user" do
|
|
|
|
sign_in FactoryBot.create(:user)
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(user_path(user))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-31 04:59:08 -08:00
|
|
|
describe "#show" do
|
|
|
|
subject { get :show, params: { username: user.screen_name } }
|
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
before(:each) { sign_in user }
|
|
|
|
|
|
|
|
it "renders the user/show template" do
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response).to render_template("user/show")
|
|
|
|
end
|
|
|
|
end
|
2022-11-16 13:33:30 -08:00
|
|
|
|
|
|
|
context "user opts out of search indexing" do
|
|
|
|
render_views
|
|
|
|
|
2022-11-16 13:34:57 -08:00
|
|
|
before(:each) do
|
2022-11-16 13:33:30 -08:00
|
|
|
sign_in user
|
|
|
|
user.privacy_noindex = true
|
|
|
|
user.save
|
2022-11-16 13:34:57 -08:00
|
|
|
end
|
2022-11-16 13:33:30 -08:00
|
|
|
|
|
|
|
it "renders the answer/show template" do
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response.body).to include("<meta content='noindex' name='robots'>")
|
|
|
|
end
|
|
|
|
end
|
2021-12-31 04:59:08 -08:00
|
|
|
end
|
|
|
|
|
2021-12-31 06:35:29 -08:00
|
|
|
describe "#followers" do
|
|
|
|
subject { get :followers, params: { username: user.screen_name } }
|
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
before(:each) { sign_in user }
|
|
|
|
|
|
|
|
it "renders the user/show_follow template" do
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response).to render_template("user/show_follow")
|
|
|
|
end
|
|
|
|
end
|
2022-11-15 12:36:24 -08:00
|
|
|
|
|
|
|
include_examples "social graph hidden"
|
2021-12-31 06:35:29 -08:00
|
|
|
end
|
|
|
|
|
2022-01-08 12:40:57 -08:00
|
|
|
describe "#followings" do
|
|
|
|
subject { get :followings, params: { username: user.screen_name } }
|
2021-12-31 06:35:29 -08:00
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
before(:each) { sign_in user }
|
|
|
|
|
|
|
|
it "renders the user/show_follow template" do
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response).to render_template("user/show_follow")
|
|
|
|
end
|
|
|
|
end
|
2022-11-15 12:36:24 -08:00
|
|
|
|
|
|
|
include_examples "social graph hidden"
|
2021-12-31 06:35:29 -08:00
|
|
|
end
|
|
|
|
|
2021-12-31 06:56:15 -08:00
|
|
|
describe "#questions" do
|
2022-12-27 14:06:24 -08:00
|
|
|
let!(:question_anyone) { FactoryBot.create(:question, user:, direct: false, author_is_anonymous: false) }
|
|
|
|
let!(:question_direct) { FactoryBot.create(:question, user:, direct: true, author_is_anonymous: false) }
|
|
|
|
let!(:question_direct_anon) { FactoryBot.create(:question, user:, direct: true, author_is_anonymous: true) }
|
|
|
|
|
2021-12-31 06:56:15 -08:00
|
|
|
subject { get :questions, params: { username: user.screen_name } }
|
|
|
|
|
2022-08-20 08:07:37 -07:00
|
|
|
it "renders the user/questions template" do
|
|
|
|
subject
|
|
|
|
expect(assigns(:user)).to eq(user)
|
|
|
|
expect(response).to render_template("user/questions")
|
|
|
|
end
|
|
|
|
|
2022-08-20 08:14:51 -07:00
|
|
|
context "when the current user is the question author" do
|
2022-08-20 08:07:37 -07:00
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
2022-12-27 14:06:24 -08:00
|
|
|
it "contains all non-anon questions" do
|
2022-08-20 08:07:37 -07:00
|
|
|
subject
|
2022-12-27 14:06:24 -08:00
|
|
|
expect(assigns(:questions)).to include(question_anyone, question_direct)
|
|
|
|
expect(assigns(:questions)).not_to include(question_direct_anon)
|
|
|
|
expect(assigns(:questions).size).to eq(2)
|
2022-08-20 08:07:37 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-20 08:14:51 -07:00
|
|
|
context "when the current user is someone else" do
|
2022-08-20 08:07:37 -07:00
|
|
|
let(:another_user) { FactoryBot.create :user }
|
2021-12-31 06:56:15 -08:00
|
|
|
|
2022-08-20 08:07:37 -07:00
|
|
|
before do
|
|
|
|
sign_in another_user
|
|
|
|
end
|
|
|
|
|
2022-12-27 14:06:24 -08:00
|
|
|
it "contains all non-direct non-anon questions" do
|
2021-12-31 06:56:15 -08:00
|
|
|
subject
|
2022-12-27 14:06:24 -08:00
|
|
|
expect(assigns(:questions)).to include(question_anyone)
|
|
|
|
expect(assigns(:questions)).not_to include(question_direct, question_direct_anon)
|
|
|
|
expect(assigns(:questions).size).to eq(1)
|
2022-08-20 08:07:37 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-20 08:14:51 -07:00
|
|
|
context "when a moderator uses unmask" do
|
2022-08-20 08:07:37 -07:00
|
|
|
let(:another_user) { FactoryBot.create :user, roles: ["moderator"] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in another_user
|
|
|
|
allow_any_instance_of(UserHelper).to receive(:moderation_view?) { true }
|
|
|
|
end
|
|
|
|
|
2022-12-27 14:06:24 -08:00
|
|
|
it "contains all non-anon questions" do
|
2022-08-20 08:07:37 -07:00
|
|
|
subject
|
2022-12-27 14:06:24 -08:00
|
|
|
expect(assigns(:questions)).to include(question_anyone, question_direct)
|
|
|
|
expect(assigns(:questions)).not_to include(question_direct_anon)
|
|
|
|
expect(assigns(:questions).size).to eq(2)
|
2022-08-20 08:07:37 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-20 08:14:51 -07:00
|
|
|
context "when user is not signed in" do
|
2022-12-27 14:06:24 -08:00
|
|
|
it "contains all non-direct non-anon questions" do
|
2022-08-20 08:07:37 -07:00
|
|
|
subject
|
2022-12-27 14:06:24 -08:00
|
|
|
expect(assigns(:questions)).to include(question_anyone)
|
|
|
|
expect(assigns(:questions)).not_to include(question_direct, question_direct_anon)
|
|
|
|
expect(assigns(:questions).size).to eq(1)
|
2021-12-31 06:56:15 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-21 13:25:43 -07:00
|
|
|
end
|