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

clean_up_noteable_id_for_notes_on_commits_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 531c1dbb76aae2a204d1a956f6e224f45a9e3948 (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
# frozen_string_literal: true

require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190313092516_clean_up_noteable_id_for_notes_on_commits.rb')

RSpec.describe CleanUpNoteableIdForNotesOnCommits do
  let(:notes) { table(:notes) }

  before do
    notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')
    notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')
    notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')

    notes.create!(noteable_type: 'Issue', noteable_id: 1, note: 'Test')
    notes.create!(noteable_type: 'MergeRequest', noteable_id: 1, note: 'Test')
    notes.create!(noteable_type: 'Snippet', noteable_id: 1, note: 'Test')
  end

  it 'clears noteable_id for notes on commits' do
    expect { migrate! }.to change { dirty_notes_on_commits.count }.from(3).to(0)
  end

  it 'does not clear noteable_id for other notes' do
    expect { migrate! }.not_to change { other_notes.count }
  end

  def dirty_notes_on_commits
    notes.where(noteable_type: 'Commit').where('noteable_id IS NOT NULL')
  end

  def other_notes
    notes.where("noteable_type != 'Commit' AND noteable_id IS NOT NULL")
  end
end