BigW Consortium Gitlab

remove_empty_fork_networks_spec.rb 1.15 KB
Newer Older
1 2 3 4 5
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20171114104051_remove_empty_fork_networks.rb')

describe RemoveEmptyForkNetworks, :migration do
  let!(:fork_networks) { table(:fork_networks) }
6 7
  let!(:projects) { table(:projects) }
  let!(:fork_network_members) { table(:fork_network_members) }
8

9 10 11
  let(:deleted_project) { projects.create! }
  let!(:empty_network) { fork_networks.create!(id: 1, root_project_id: deleted_project.id) }
  let!(:other_network) { fork_networks.create!(id: 2, root_project_id: projects.create.id) }
12 13

  before do
14 15 16 17 18
    fork_network_members.create(fork_network_id: empty_network.id,
                                project_id: empty_network.root_project_id)
    fork_network_members.create(fork_network_id: other_network.id,
                                project_id: other_network.root_project_id)

19 20 21 22 23 24 25 26 27 28 29 30 31
    deleted_project.destroy!
  end

  it 'deletes only the fork network without members' do
    expect(fork_networks.count).to eq(2)

    migrate!

    expect(fork_networks.find_by(id: empty_network.id)).to be_nil
    expect(fork_networks.find_by(id: other_network.id)).not_to be_nil
    expect(fork_networks.count).to eq(1)
  end
end