move timeline test data to shared context

This commit is contained in:
Georg Gadinger 2023-02-20 21:47:46 +01:00 committed by Andreas Nedbal
parent 920187bc88
commit 1791ea2d1a
4 changed files with 130 additions and 299 deletions

View File

@ -92,112 +92,8 @@ describe Answer, type: :model do
end end
end end
describe ".public_timeline" do describe ".public_timeline", timeline_test_data: true do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:user1) { FactoryBot.create(:user) }
let(:user2) { FactoryBot.create(:user) }
let(:blocked_user) { FactoryBot.create(:user) }
let(:muted_user) { FactoryBot.create(:user) }
let!(:answer_to_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a true anonymous coward",
question: FactoryBot.create(
:question,
author_is_anonymous: true
)
)
end
let!(:answer_to_normal_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a normal user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: false
)
)
end
let!(:answer_to_normal_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a cowardly user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: true
)
)
end
let!(:answer_from_blocked_user) do
FactoryBot.create(
:answer,
user: blocked_user,
content: "answer from a blocked user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_blocked_user) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_blocked_user_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user who's a coward",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: true
)
)
end
let!(:answer_from_muted_user) do
FactoryBot.create(
:answer,
user: muted_user,
content: "answer from a muted user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_muted_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_muted_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user who's a coward",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: true
)
)
end
subject { Answer.public_timeline } subject { Answer.public_timeline }

View File

@ -64,112 +64,8 @@ RSpec.describe(List, type: :model) do
end end
end end
describe "#timeline" do describe "#timeline", timeline_test_data: true do
let(:list) { List.create(user:, display_name: "test list") } let(:list) { List.create(user:, display_name: "test list") }
let(:user1) { FactoryBot.create(:user) }
let(:user2) { FactoryBot.create(:user) }
let(:blocked_user) { FactoryBot.create(:user) }
let(:muted_user) { FactoryBot.create(:user) }
let!(:answer_to_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a true anonymous coward",
question: FactoryBot.create(
:question,
author_is_anonymous: true
)
)
end
let!(:answer_to_normal_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a normal user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: false
)
)
end
let!(:answer_to_normal_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a cowardly user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: true
)
)
end
let!(:answer_from_blocked_user) do
FactoryBot.create(
:answer,
user: blocked_user,
content: "answer from a blocked user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_blocked_user) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_blocked_user_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user who's a coward",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: true
)
)
end
let!(:answer_from_muted_user) do
FactoryBot.create(
:answer,
user: muted_user,
content: "answer from a muted user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_muted_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_muted_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user who's a coward",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: true
)
)
end
before do before do
list.add_member user1 list.add_member user1

View File

@ -212,95 +212,7 @@ RSpec.describe User, type: :model do
end end
end end
context "user follows users with answers to questions from blocked or muted users" do context "user follows users with answers to questions from blocked or muted users", timeline_test_data: true do
let(:blocked_user) { FactoryBot.create(:user) }
let(:muted_user) { FactoryBot.create(:user) }
let(:user1) { FactoryBot.create(:user) }
let(:user2) { FactoryBot.create(:user) }
let!(:answer_to_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a true anonymous coward",
question: FactoryBot.create(
:question,
author_is_anonymous: true
)
)
end
let!(:answer_to_normal_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a normal user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: false
)
)
end
let!(:answer_to_normal_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a cowardly user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: true
)
)
end
let!(:answer_to_blocked_user) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_blocked_user_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user who's a coward",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: true
)
)
end
let!(:answer_to_muted_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_muted_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user who's a coward",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: true
)
)
end
before do before do
me.follow user1 me.follow user1
me.follow user2 me.follow user2
@ -314,6 +226,8 @@ RSpec.describe User, type: :model do
expect(subject).to include(answer_to_muted_user_anonymous) expect(subject).to include(answer_to_muted_user_anonymous)
expect(subject).to include(answer_to_blocked_user) expect(subject).to include(answer_to_blocked_user)
expect(subject).to include(answer_to_muted_user) expect(subject).to include(answer_to_muted_user)
expect(subject).not_to include(answer_from_blocked_user)
expect(subject).not_to include(answer_from_muted_user)
end end
context "when blocking and muting some users" do context "when blocking and muting some users" do
@ -330,6 +244,8 @@ RSpec.describe User, type: :model do
expect(subject).to include(answer_to_muted_user_anonymous) expect(subject).to include(answer_to_muted_user_anonymous)
expect(subject).not_to include(answer_to_blocked_user) expect(subject).not_to include(answer_to_blocked_user)
expect(subject).not_to include(answer_to_muted_user) expect(subject).not_to include(answer_to_muted_user)
expect(subject).not_to include(answer_from_blocked_user)
expect(subject).not_to include(answer_from_muted_user)
end end
end end
end end

View File

@ -0,0 +1,123 @@
# frozen_string_literal: true
RSpec.shared_context "Timeline test data" do
let(:user1) { FactoryBot.create(:user) }
let(:user2) { FactoryBot.create(:user) }
let(:blocked_user) { FactoryBot.create(:user) }
let(:muted_user) { FactoryBot.create(:user) }
let!(:answer_to_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a true anonymous coward",
question: FactoryBot.create(
:question,
author_is_anonymous: true
)
)
end
let!(:answer_to_normal_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a normal user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: false
)
)
end
let!(:answer_to_normal_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a cowardly user",
question: FactoryBot.create(
:question,
user: user1,
author_is_anonymous: true
)
)
end
let!(:answer_from_blocked_user) do
FactoryBot.create(
:answer,
user: blocked_user,
content: "answer from a blocked user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_blocked_user) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_blocked_user_anonymous) do
FactoryBot.create(
:answer,
user: user1,
content: "answer to a blocked user who's a coward",
question: FactoryBot.create(
:question,
user: blocked_user,
author_is_anonymous: true
)
)
end
let!(:answer_from_muted_user) do
FactoryBot.create(
:answer,
user: muted_user,
content: "answer from a muted user",
question: FactoryBot.create(:question)
)
end
let!(:answer_to_muted_user) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: false
)
)
end
let!(:answer_to_muted_user_anonymous) do
FactoryBot.create(
:answer,
user: user2,
content: "answer to a muted user who's a coward",
question: FactoryBot.create(
:question,
user: muted_user,
author_is_anonymous: true
)
)
end
end
RSpec.configure do |config|
config.include_context "Timeline test data", timeline_test_data: true
end