summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-12-11 13:25:27 +0000
committerSean McGivern <sean@gitlab.com>2017-12-11 14:09:55 +0000
commit818397f96ee81a2a21d5a01e56239507ea79c811 (patch)
tree8ae89d6224d4a2a7ed8909cb4c963bacfa85bc41
parentdd45a1748920a555d107eaf8bfd4219ed2d4f987 (diff)
downloadgitlab-ce-818397f96ee81a2a21d5a01e56239507ea79c811.tar.gz
Add spec for removing issues.assignee_id
This migration also needs to be a post-deployment migration, as it removes a column.
-rw-r--r--app/models/issue.rb3
-rw-r--r--db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb (renamed from db/migrate/20170523073948_remove_assignee_id_from_issue.rb)4
-rw-r--r--spec/migrations/remove_assignee_id_from_issue_spec.rb37
3 files changed, 43 insertions, 1 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 33db197e612..bbda848c39d 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -10,6 +10,9 @@ class Issue < ActiveRecord::Base
include RelativePositioning
include TimeTrackable
include ThrottledTouch
+ include IgnorableColumn
+
+ ignore_column :assignee_id
DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
diff --git a/db/migrate/20170523073948_remove_assignee_id_from_issue.rb b/db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb
index 91b04023fc2..006d17b4d62 100644
--- a/db/migrate/20170523073948_remove_assignee_id_from_issue.rb
+++ b/db/post_migrate/20170523073948_remove_assignee_id_from_issue.rb
@@ -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_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
diff --git a/spec/migrations/remove_assignee_id_from_issue_spec.rb b/spec/migrations/remove_assignee_id_from_issue_spec.rb
new file mode 100644
index 00000000000..2c6f992d3ae
--- /dev/null
+++ b/spec/migrations/remove_assignee_id_from_issue_spec.rb
@@ -0,0 +1,37 @@
+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