Ensure that we have only one list per label per board
This commit is contained in:
parent
c08a14c3c2
commit
c14ac83575
|
@ -6,6 +6,7 @@ class List < ActiveRecord::Base
|
|||
|
||||
validates :board, :list_type, presence: true
|
||||
validates :label, :position, presence: true, if: :label?
|
||||
validates :label_id, uniqueness: { scope: :board_id }, if: :label?
|
||||
validates :position, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :label?
|
||||
|
||||
delegate :name, to: :label, allow_nil: true, prefix: true
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class AddUniqueIndexToListsLabelId < ActiveRecord::Migration
|
||||
include Gitlab::Database::MigrationHelpers
|
||||
|
||||
DOWNTIME = false
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_concurrent_index :lists, [:board_id, :label_id], unique: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :lists, column: [:board_id, :label_id] if index_exists?(:lists, [:board_id, :label_id], unique: true)
|
||||
end
|
||||
end
|
|
@ -550,6 +550,7 @@ ActiveRecord::Schema.define(version: 20160810142633) do
|
|||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "lists", ["board_id", "label_id"], name: "index_lists_on_board_id_and_label_id", unique: true, using: :btree
|
||||
add_index "lists", ["board_id"], name: "index_lists_on_board_id", using: :btree
|
||||
add_index "lists", ["label_id"], name: "index_lists_on_label_id", using: :btree
|
||||
|
||||
|
|
|
@ -17,6 +17,12 @@ describe List do
|
|||
it { is_expected.to validate_presence_of(:position) }
|
||||
it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) }
|
||||
|
||||
it 'validates uniqueness of label scoped to board_id' do
|
||||
create(:list)
|
||||
|
||||
expect(subject).to validate_uniqueness_of(:label_id).scoped_to(:board_id)
|
||||
end
|
||||
|
||||
context 'when list_type is set to backlog' do
|
||||
subject { described_class.new(list_type: :backlog) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue