From 92d5918b91ac3254f97c4d93d1ef423d3e9c3b09 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:36:24 +0100 Subject: [PATCH] Add tests for social graph hiding setting --- spec/controllers/user_controller_spec.rb | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 11599f0a..b66b50b8 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -9,6 +9,32 @@ describe UserController, type: :controller do otp_secret_key: "EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3" end + 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 + describe "#show" do subject { get :show, params: { username: user.screen_name } } @@ -35,6 +61,8 @@ describe UserController, type: :controller do expect(response).to render_template("user/show_follow") end end + + include_examples "social graph hidden" end describe "#followings" do @@ -49,6 +77,8 @@ describe UserController, type: :controller do expect(response).to render_template("user/show_follow") end end + + include_examples "social graph hidden" end describe "#questions" do