Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fix_promoted_epics_discussion_ids_spec.rb « background_migration « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 452fc962c7b7c0cc72e8f804d9c6e17f5f4ef681 (plain)
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
43
44
45
46
47
48
49
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::FixPromotedEpicsDiscussionIds, schema: 20190715193142 do
  let(:namespaces) { table(:namespaces) }
  let(:users) { table(:users) }
  let(:epics) { table(:epics) }
  let(:notes) { table(:notes) }

  let(:user) { users.create!(email: 'test@example.com', projects_limit: 100, username: 'test') }
  let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
  let(:epic1) { epics.create!(id: 1, author_id: user.id, iid: 1, group_id: namespace.id, title: 'Epic with discussion', title_html: 'Epic with discussion') }

  def create_note(discussion_id)
    notes.create!(note: 'note comment',
                  noteable_id: epic1.id,
                  noteable_type: 'Epic',
                  discussion_id: discussion_id)
  end

  def expect_valid_discussion_id(id)
    expect(id).to match(/\A\h{40}\z/)
  end

  describe '#perform with batch of discussion ids' do
    it 'updates discussion ids' do
      note1 = create_note('00000000')
      note2 = create_note('00000000')
      note3 = create_note('10000000')

      subject.perform(%w(00000000 10000000))

      expect_valid_discussion_id(note1.reload.discussion_id)
      expect_valid_discussion_id(note2.reload.discussion_id)
      expect_valid_discussion_id(note3.reload.discussion_id)
      expect(note1.discussion_id).to eq(note2.discussion_id)
      expect(note1.discussion_id).not_to eq(note3.discussion_id)
    end

    it 'skips notes with discussion id not in range' do
      note4 = create_note('20000000')

      subject.perform(%w(00000000 10000000))

      expect(note4.reload.discussion_id).to eq('20000000')
    end
  end
end