summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-19 12:04:38 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:57:14 -0200
commitd820c090ec85f8118e4cea75bd63d800e812ea25 (patch)
tree63ab9b40c13f1a44add19cad9d40f4c58f7f31c8
parentd927336403a92d340d7e5b2d2328c5a0e029d666 (diff)
downloadgitlab-ce-d820c090ec85f8118e4cea75bd63d800e812ea25.tar.gz
Add GroupLabel model
-rw-r--r--app/models/group.rb1
-rw-r--r--app/models/group_label.rb5
-rw-r--r--db/migrate/20160919144305_add_type_to_labels.rb9
-rw-r--r--db/migrate/20160919145149_add_group_id_to_labels.rb13
-rw-r--r--db/schema.rb4
-rw-r--r--spec/models/group_label_spec.rb11
-rw-r--r--spec/models/group_spec.rb1
7 files changed, 44 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index a2f88cca828..00a595d2705 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -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
diff --git a/app/models/group_label.rb b/app/models/group_label.rb
new file mode 100644
index 00000000000..a854d075820
--- /dev/null
+++ b/app/models/group_label.rb
@@ -0,0 +1,5 @@
+class GroupLabel < Label
+ belongs_to :group
+
+ validates :group, presence: true
+end
diff --git a/db/migrate/20160919144305_add_type_to_labels.rb b/db/migrate/20160919144305_add_type_to_labels.rb
new file mode 100644
index 00000000000..43aac7846d3
--- /dev/null
+++ b/db/migrate/20160919144305_add_type_to_labels.rb
@@ -0,0 +1,9 @@
+class AddTypeToLabels < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def change
+ add_column :labels, :type, :string
+ end
+end
diff --git a/db/migrate/20160919145149_add_group_id_to_labels.rb b/db/migrate/20160919145149_add_group_id_to_labels.rb
new file mode 100644
index 00000000000..05e21af0584
--- /dev/null
+++ b/db/migrate/20160919145149_add_group_id_to_labels.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 5ce855fe08f..37f0be0e834 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/spec/models/group_label_spec.rb b/spec/models/group_label_spec.rb
new file mode 100644
index 00000000000..a82d23bcc0b
--- /dev/null
+++ b/spec/models/group_label_spec.rb
@@ -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
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 0b3ef9b98fd..ac862055ebc 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -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) }