Unverified Commit 03654a6a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Label and LabelLink models for implementing own GitLab labels


Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 535feb08
class Label < ActiveRecord::Base
belongs_to :project
has_many :label_links, dependent: :destroy
validates :color, format: { with: /\A\#[0-9A-Fa-f]{3}{1,2}+\Z/ }, allow_blank: true
validates :project, presence: true
end
class LabelLink < ActiveRecord::Base
belongs_to :target, polymorphic: true
belongs_to :label
validates :target, presence: true
validates :label, presence: true
end
class CreateLabels < ActiveRecord::Migration
def change
create_table :labels do |t|
t.string :title
t.string :color
t.integer :project_id
t.timestamps
end
end
end
class CreateLabelLinks < ActiveRecord::Migration
def change
create_table :label_links do |t|
t.integer :label_id
t.integer :target_id
t.string :target_type
t.timestamps
end
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140625115202) do
ActiveRecord::Schema.define(version: 20140729140420) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -109,6 +109,22 @@
add_index "keys", ["user_id"], name: "index_keys_on_user_id", using: :btree
create_table "label_links", force: true do |t|
t.integer "label_id"
t.integer "target_id"
t.string "target_type"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "labels", force: true do |t|
t.string "title"
t.string "color"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "merge_request_diffs", force: true do |t|
t.string "state"
t.text "st_commits"
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :label_link do
label
target factory: :issue
end
end
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :label do
title "Bug"
color "#990000"
project
end
end
require 'spec_helper'
describe LabelLink do
let(:label) { create(:label_link) }
it { label.should be_valid }
it { should belong_to(:label) }
it { should belong_to(:target) }
end
require 'spec_helper'
describe Label do
let(:label) { create(:label) }
it { label.should be_valid }
it { should belong_to(:project) }
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