Add GroupLabel model

This commit is contained in:
Douglas Barbosa Alexandre 2016-09-19 12:04:38 -03:00
parent d927336403
commit d820c090ec
7 changed files with 44 additions and 0 deletions

View file

@ -19,6 +19,7 @@ class Group < Namespace
has_many :project_group_links, dependent: :destroy
has_many :shared_projects, through: :project_group_links, source: :project
has_many :notification_settings, dependent: :destroy, as: :source
has_many :labels, class_name: 'GroupLabel'
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
validate :visibility_level_allowed_by_projects

View file

@ -0,0 +1,5 @@
class GroupLabel < Label
belongs_to :group
validates :group, presence: true
end

View file

@ -0,0 +1,9 @@
class AddTypeToLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :labels, :type, :string
end
end

View file

@ -0,0 +1,13 @@
class AddGroupIdToLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def change
add_column :labels, :group_id, :integer
add_foreign_key :labels, :namespaces, column: :group_id, on_delete: :cascade
add_concurrent_index :labels, :group_id
end
end

View file

@ -529,8 +529,11 @@ ActiveRecord::Schema.define(version: 20161017095000) do
t.string "description"
t.integer "priority"
t.text "description_html"
t.string "type"
t.integer "group_id"
end
add_index "labels", ["group_id"], name: "index_labels_on_group_id", using: :btree
add_index "labels", ["priority"], name: "index_labels_on_priority", using: :btree
add_index "labels", ["project_id"], name: "index_labels_on_project_id", using: :btree
add_index "labels", ["title"], name: "index_labels_on_title", using: :btree
@ -1213,6 +1216,7 @@ ActiveRecord::Schema.define(version: 20161017095000) do
add_foreign_key "boards", "projects"
add_foreign_key "issue_metrics", "issues", on_delete: :cascade
add_foreign_key "labels", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "lists", "boards"
add_foreign_key "lists", "labels"
add_foreign_key "merge_request_metrics", "merge_requests", on_delete: :cascade

View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe GroupLabel, models: true do
describe 'relationships' do
it { is_expected.to belong_to(:group) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:group) }
end
end

View file

@ -12,6 +12,7 @@ describe Group, models: true do
it { is_expected.to have_many(:project_group_links).dependent(:destroy) }
it { is_expected.to have_many(:shared_projects).through(:project_group_links) }
it { is_expected.to have_many(:notification_settings).dependent(:destroy) }
it { is_expected.to have_many(:labels).class_name('GroupLabel') }
describe '#members & #requesters' do
let(:requester) { create(:user) }