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

issues_moved_to_id_foreign_key_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd2b08099f283ca4820581424860e74228c83ea4 (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
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20171106151218_issues_moved_to_id_foreign_key.rb')

# The schema version has to be far enough in advance to have the
# only_mirror_protected_branches column in the projects table to create a
# project via FactoryBot.
describe IssuesMovedToIdForeignKey, :migration, schema: 20171114150259 do
  let!(:issue_first) { create(:issue, moved_to_id: issue_second.id) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
  let!(:issue_second) { create(:issue, moved_to_id: issue_third.id) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
  let!(:issue_third) { create(:issue) } # rubocop:disable RSpec/FactoriesInMigrationSpecs

  subject { described_class.new }

  it 'removes the orphaned moved_to_id' do
    subject.down

    issue_third.update_attributes(moved_to_id: 100000)

    subject.up

    expect(issue_first.reload.moved_to_id).to eq(issue_second.id)
    expect(issue_second.reload.moved_to_id).to eq(issue_third.id)
    expect(issue_third.reload.moved_to_id).to be_nil
  end
end