[refs #194] Add issue tags

This commit is contained in:
Alexander Machehin 2012-02-21 00:41:40 +06:00
parent 5dcc4eabf8
commit 0ce76207af
6 changed files with 34 additions and 2 deletions

View File

@ -8,6 +8,7 @@ class Issue < ActiveRecord::Base
has_many :comments, :as => :commentable, :dependent => :destroy #, :finder_sql => proc { "comments.commentable_id = '#{self.id}' AND comments.commentable_type = '#{self.class.name}'"}
has_many :subscribes, :as => :subscribeable, :dependent => :destroy #, :finder_sql => proc { "subscribes.subscribeable_id = '#{self.id}' AND subscribes.subscribeable_type = '#{self.class.name}'"}
has_many :tags, :dependent => :destroy
validates :title, :body, :project_id, :presence => true

8
app/models/tag.rb Normal file
View File

@ -0,0 +1,8 @@
class Tag < ActiveRecord::Base
belongs_to :issue
validates :name, :color, :presence => true
validates :color, :format => { :with => /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, :message => I18n.t('layout.issues.invalid_labels')}
before_create {|t| t.project_id = t.issue.project_id}
end

View File

@ -33,10 +33,11 @@ en:
number: Number
description: Description
by: by
labels: Labels
invalid_labels: Invalid hex color code
flash:
issue:
saved: Task saved
save_error: Task saves error
destroyed: Task deleted

View File

@ -33,6 +33,8 @@ ru:
number: Номер
description: Описание
by:
labels: Метки
invalid_labels: Неверный hex код
flash:
issue:

View File

@ -0,0 +1,15 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name, :null => false
t.string :color, :null => false
t.integer :issue_id, :null => false
t.integer :project_id, :null => false
t.timestamps
end
add_index :tags, :issue_id
add_index :tags, :project_id
end
end

5
spec/models/tag_spec.rb Normal file
View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Tag do
pending "add some examples to (or delete) #{__FILE__}"
end