summaryrefslogtreecommitdiff
path: root/spec/migrations/update_invalid_member_states_spec.rb
blob: 802634230a9b666364c844cab10056f479ab28c8 (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
# frozen_string_literal: true

require 'spec_helper'

require_migration!

RSpec.describe UpdateInvalidMemberStates do
  let(:members) { table(:members) }
  let(:groups) { table(:namespaces) }
  let(:projects) { table(:projects) }
  let(:users) { table(:users) }

  before do
    user = users.create!(first_name: 'Test', last_name: 'User', email: 'test@user.com', projects_limit: 1)
    group = groups.create!(name: 'gitlab', path: 'gitlab-org')
    project = projects.create!(namespace_id: group.id)

    members.create!(state: 2, source_id: group.id, source_type: 'Group', type: 'GroupMember', user_id: user.id, access_level: 50, notification_level: 0)
    members.create!(state: 2, source_id: project.id, source_type: 'Project', type: 'ProjectMember', user_id: user.id, access_level: 50, notification_level: 0)
    members.create!(state: 1, source_id: group.id, source_type: 'Group', type: 'GroupMember', user_id: user.id, access_level: 50, notification_level: 0)
    members.create!(state: 0, source_id: group.id, source_type: 'Group', type: 'GroupMember', user_id: user.id, access_level: 50, notification_level: 0)
  end

  it 'updates matching member record states' do
    expect { migrate! }
      .to change { members.where(state: 0).count }.from(1).to(3)
      .and change { members.where(state: 2).count }.from(2).to(0)
      .and change { members.where(state: 1).count }.by(0)
  end
end