summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/label.rb7
-rw-r--r--app/models/label_link.rb7
-rw-r--r--db/migrate/20140729134820_create_labels.rb11
-rw-r--r--db/migrate/20140729140420_create_label_links.rb11
-rw-r--r--db/schema.rb18
-rw-r--r--spec/factories/label_links.rb8
-rw-r--r--spec/factories/labels.rb9
-rw-r--r--spec/models/label_link_spec.rb9
-rw-r--r--spec/models/label_spec.rb8
9 files changed, 87 insertions, 1 deletions
diff --git a/app/models/label.rb b/app/models/label.rb
new file mode 100644
index 00000000000..17f293b698f
--- /dev/null
+++ b/app/models/label.rb
@@ -0,0 +1,7 @@
+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
diff --git a/app/models/label_link.rb b/app/models/label_link.rb
new file mode 100644
index 00000000000..47bd6eaf35f
--- /dev/null
+++ b/app/models/label_link.rb
@@ -0,0 +1,7 @@
+class LabelLink < ActiveRecord::Base
+ belongs_to :target, polymorphic: true
+ belongs_to :label
+
+ validates :target, presence: true
+ validates :label, presence: true
+end
diff --git a/db/migrate/20140729134820_create_labels.rb b/db/migrate/20140729134820_create_labels.rb
new file mode 100644
index 00000000000..3a4b6a152dc
--- /dev/null
+++ b/db/migrate/20140729134820_create_labels.rb
@@ -0,0 +1,11 @@
+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
diff --git a/db/migrate/20140729140420_create_label_links.rb b/db/migrate/20140729140420_create_label_links.rb
new file mode 100644
index 00000000000..2bfc4ae2094
--- /dev/null
+++ b/db/migrate/20140729140420_create_label_links.rb
@@ -0,0 +1,11 @@
+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
diff --git a/db/schema.rb b/db/schema.rb
index e4dcdf5bea2..7ab7982feab 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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 @@ ActiveRecord::Schema.define(version: 20140625115202) do
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"
diff --git a/spec/factories/label_links.rb b/spec/factories/label_links.rb
new file mode 100644
index 00000000000..d6b6f8581f6
--- /dev/null
+++ b/spec/factories/label_links.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :label_link do
+ label
+ target factory: :issue
+ end
+end
diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb
new file mode 100644
index 00000000000..af9f3efa641
--- /dev/null
+++ b/spec/factories/labels.rb
@@ -0,0 +1,9 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :label do
+ title "Bug"
+ color "#990000"
+ project
+ end
+end
diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb
new file mode 100644
index 00000000000..078e61a7d62
--- /dev/null
+++ b/spec/models/label_link_spec.rb
@@ -0,0 +1,9 @@
+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
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
new file mode 100644
index 00000000000..5098af84cc3
--- /dev/null
+++ b/spec/models/label_spec.rb
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe Label do
+ let(:label) { create(:label) }
+ it { label.should be_valid }
+
+ it { should belong_to(:project) }
+end