Commit 7519a312 authored by Stan Hu's avatar Stan Hu

Merge branch 'osw-pass-state-id-instead-state-to-background-migration' into 'master'

Adjust wrong column reference for ResetMergeStatus (background job)

See merge request gitlab-org/gitlab!33899
parents 9e1f2215 d8198701
---
title: Adjust wrong column reference for ResetMergeStatus (background job)
merge_request: 33899
author:
type: fixed
......@@ -7,7 +7,7 @@ module Gitlab
class ResetMergeStatus
def perform(from_id, to_id)
relation = MergeRequest.where(id: from_id..to_id,
state: 'opened',
state_id: 1, # opened
merge_status: 'can_be_merged')
relation.update_all(merge_status: 'unchecked')
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Gitlab::BackgroundMigration::ResetMergeStatus, schema: 20190528180441 do
describe Gitlab::BackgroundMigration::ResetMergeStatus do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') }
......@@ -23,24 +23,24 @@ describe Gitlab::BackgroundMigration::ResetMergeStatus, schema: 20190528180441 d
end
it 'correctly updates opened mergeable MRs to unchecked' do
create_merge_request(1, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(2, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(3, state: 'opened', merge_status: 'can_be_merged')
create_merge_request(4, state: 'merged', merge_status: 'can_be_merged')
create_merge_request(5, state: 'opened', merge_status: 'cannot_be_merged')
create_merge_request(1, state_id: MergeRequest.available_states[:opened], merge_status: 'can_be_merged')
create_merge_request(2, state_id: MergeRequest.available_states[:opened], merge_status: 'can_be_merged')
create_merge_request(3, state_id: MergeRequest.available_states[:opened], merge_status: 'can_be_merged')
create_merge_request(4, state_id: MergeRequest.available_states[:merged], merge_status: 'can_be_merged')
create_merge_request(5, state_id: MergeRequest.available_states[:opened], merge_status: 'cannot_be_merged')
subject.perform(1, 5)
expected_rows = [
{ id: 1, state: 'opened', merge_status: 'unchecked' },
{ id: 2, state: 'opened', merge_status: 'unchecked' },
{ id: 3, state: 'opened', merge_status: 'unchecked' },
{ id: 4, state: 'merged', merge_status: 'can_be_merged' },
{ id: 5, state: 'opened', merge_status: 'cannot_be_merged' }
{ id: 1, state_id: MergeRequest.available_states[:opened], merge_status: 'unchecked' },
{ id: 2, state_id: MergeRequest.available_states[:opened], merge_status: 'unchecked' },
{ id: 3, state_id: MergeRequest.available_states[:opened], merge_status: 'unchecked' },
{ id: 4, state_id: MergeRequest.available_states[:merged], merge_status: 'can_be_merged' },
{ id: 5, state_id: MergeRequest.available_states[:opened], merge_status: 'cannot_be_merged' }
]
rows = merge_requests.order(:id).map do |row|
row.attributes.slice('id', 'state', 'merge_status').symbolize_keys
row.attributes.slice('id', 'state_id', 'merge_status').symbolize_keys
end
expect(rows).to eq(expected_rows)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment