-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathcopy_solved_topic_custom_field_spec.rb
42 lines (35 loc) · 1.32 KB
/
copy_solved_topic_custom_field_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
require_relative "../../db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics"
RSpec.describe CopySolvedTopicCustomFieldToDiscourseSolvedSolvedTopics, type: :migration do
let(:migration) { described_class.new }
describe "handling duplicates" do
it "ensures only unique topic_id and answer_post_id are inserted" do
topic = Fabricate(:topic)
topic1 = Fabricate(:topic)
post1 = Fabricate(:post, topic: topic)
TopicCustomField.create!(
topic_id: topic.id,
name: "accepted_answer_post_id",
value: post1.id.to_s,
)
# explicit duplicate
TopicCustomField.create!(
topic_id: topic1.id,
name: "accepted_answer_post_id",
value: post1.id.to_s,
)
second_topic = Fabricate(:topic)
post2 = Fabricate(:post, topic: second_topic)
TopicCustomField.create!(
topic_id: second_topic.id,
name: "accepted_answer_post_id",
value: post2.id.to_s,
)
migration.up
expected_count = DiscourseSolved::SolvedTopic.count
expect(expected_count).to eq(2)
expect(DiscourseSolved::SolvedTopic.where(topic_id: topic.id).count).to eq(1)
expect(DiscourseSolved::SolvedTopic.where(answer_post_id: post1.id).count).to eq(1)
end
end
end