Commit 818397f9 authored by Sean McGivern's avatar Sean McGivern

Add spec for removing issues.assignee_id

This migration also needs to be a post-deployment migration, as it removes a
column.
parent dd45a174
...@@ -10,6 +10,9 @@ class Issue < ActiveRecord::Base ...@@ -10,6 +10,9 @@ class Issue < ActiveRecord::Base
include RelativePositioning include RelativePositioning
include TimeTrackable include TimeTrackable
include ThrottledTouch include ThrottledTouch
include IgnorableColumn
ignore_column :assignee_id
DueDateStruct = Struct.new(:title, :name).freeze DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
......
...@@ -41,6 +41,8 @@ class RemoveAssigneeIdFromIssue < ActiveRecord::Migration ...@@ -41,6 +41,8 @@ class RemoveAssigneeIdFromIssue < ActiveRecord::Migration
update_value = Arel.sql('(SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)') update_value = Arel.sql('(SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)')
update_column_in_batches(:issues, :assignee_id, update_value) # This is only used in the down step, so we can ignore the RuboCop warning
# about large tables, as this is very unlikely to be run on GitLab.com
update_column_in_batches(:issues, :assignee_id, update_value) # rubocop:disable Migration/UpdateLargeTable
end end
end end
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170523073948_remove_assignee_id_from_issue.rb')
describe RemoveAssigneeIdFromIssue, :migration do
let(:issues) { table(:issues) }
let(:issue_assignees) { table(:issue_assignees) }
let(:users) { table(:users) }
let!(:user_1) { users.create(email: 'email1@example.com') }
let!(:user_2) { users.create(email: 'email2@example.com') }
let!(:user_3) { users.create(email: 'email3@example.com') }
def create_issue(assignees:)
issues.create.tap do |issue|
assignees.each do |assignee|
issue_assignees.create(issue_id: issue.id, user_id: assignee.id)
end
end
end
let!(:issue_single_assignee) { create_issue(assignees: [user_1]) }
let!(:issue_no_assignee) { create_issue(assignees: []) }
let!(:issue_multiple_assignees) { create_issue(assignees: [user_2, user_3]) }
describe '#down' do
it 'sets the assignee_id to a random matching assignee from the assignees table' do
migrate!
disable_migrations_output { described_class.new.down }
expect(issue_single_assignee.reload.assignee_id).to eq(user_1.id)
expect(issue_no_assignee.reload.assignee_id).to be_nil
expect(issue_multiple_assignees.reload.assignee_id).to eq(user_2.id).or(user_3.id)
disable_migrations_output { described_class.new.up }
end
end
end
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