summaryrefslogtreecommitdiff
path: root/spec/migrations/remove_duplicate_mr_events_spec.rb
blob: 2509ac6afd6094b9f3a63a6642b69f5083a634f1 (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
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170815060945_remove_duplicate_mr_events.rb')

describe RemoveDuplicateMrEvents, :delete do
  let(:migration) { described_class.new }

  describe '#up' do
    let(:user) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
    let(:merge_requests) { create_list(:merge_request, 2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
    let(:issue) { create(:issue) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
    let!(:events) do
      [
        create(:event, :created, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs
        create(:event, :created, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs
        create(:event, :updated, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs
        create(:event, :created, author: user, target: merge_requests.second), # rubocop:disable RSpec/FactoriesInMigrationSpecs
        create(:event, :created, author: user, target: issue), # rubocop:disable RSpec/FactoriesInMigrationSpecs
        create(:event, :created, author: user, target: issue) # rubocop:disable RSpec/FactoriesInMigrationSpecs
      ]
    end

    it 'removes duplicated merge request create records' do
      expect { migration.up }.to change { Event.count }.from(6).to(5)
    end
  end
end