From 70f6e581b60340ff42508ff937d6f15979d449bc Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 10 Mar 2024 20:30:47 +0100 Subject: [PATCH] Add specs to check for upper maximum question length --- .../question/create_followers_spec.rb | 8 +++++++ spec/lib/use_case/question/create_spec.rb | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/spec/lib/use_case/question/create_followers_spec.rb b/spec/lib/use_case/question/create_followers_spec.rb index b5511459..00331cbb 100644 --- a/spec/lib/use_case/question/create_followers_spec.rb +++ b/spec/lib/use_case/question/create_followers_spec.rb @@ -36,5 +36,13 @@ describe UseCase::Question::CreateFollowers do it "increments the asked count" do expect { subject }.to change { source_user.reload.asked_count }.by(1) end + + context "content is over 32768 characters long" do + let(:content) { "a" * 32769 } + + it "raises an error" do + expect { subject }.to raise_error(Errors::QuestionTooLong) + end + end end end diff --git a/spec/lib/use_case/question/create_spec.rb b/spec/lib/use_case/question/create_spec.rb index a31e9073..a5ee2bd9 100644 --- a/spec/lib/use_case/question/create_spec.rb +++ b/spec/lib/use_case/question/create_spec.rb @@ -75,6 +75,27 @@ describe UseCase::Question::Create do it_behaves_like "creates the question" end end + + context "content is over 32768 characters long" do + let(:content) { "a" * 32769 } + + context "recipient does not allow long questions" do + it "raises an error" do + expect { subject }.to raise_error(Errors::QuestionTooLong) + end + end + + context "recipient allows long questions" do + before do + target_user.profile.allow_long_questions = true + target_user.profile.save + end + + it "raises an error" do + expect { subject }.to raise_error(Errors::QuestionTooLong) + end + end + end end shared_examples "filters questions" do