From ac60bc4b8f7515ba5d7864b11ca3729a19e1befc Mon Sep 17 00:00:00 2001
From: Andreas Nedbal <git@pixelde.su>
Date: Sat, 25 Jun 2022 02:02:43 +0200
Subject: [PATCH] Add tests for `UserController#edit_blocks`

---
 spec/controllers/user_controller_spec.rb | 33 ++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 3b5b2ec3..4ac9bd22 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -295,4 +295,37 @@ describe UserController, type: :controller do
       end
     end
   end
+
+  describe "#edit_blocks" do
+    subject { get :edit_blocks }
+
+    context "user signed in" do
+      before(:each) { sign_in user }
+
+      it "shows the edit_blocks page" do
+        subject
+        expect(response).to have_rendered(:edit_blocks)
+      end
+
+      it "only contains blocks of the signed in user" do
+        other_user = create(:user)
+        other_user.block(user)
+
+        subject
+
+        expect(assigns(:blocks)).to eq(user.active_block_relationships)
+      end
+
+      it "only contains anonymous blocks of the signed in user" do
+        other_user = create(:user)
+        question = create(:question)
+        other_user.anonymous_blocks.create(identifier: "very-real-identifier", question_id: question.id)
+
+        subject
+
+        expect(assigns(:anonymous_blocks)).to eq(user.anonymous_blocks)
+      end
+
+    end
+  end
 end