From 998fe24e49e3765a48e2f9a0a2a03430b56c6292 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 11 Aug 2015 16:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8Bforge=5Fmessages=E8=A1=A8=20?= =?UTF-8?q?=E5=BB=BA=E7=AB=8Buser=E3=80=81project=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/forge_message.rb | 20 +++++++++++++++++++ .../20150811083322_create_forge_messages.rb | 13 ++++++++++++ spec/factories/forge_messages.rb | 10 ++++++++++ spec/models/forge_message_spec.rb | 5 +++++ 4 files changed, 48 insertions(+) create mode 100644 app/models/forge_message.rb create mode 100644 db/migrate/20150811083322_create_forge_messages.rb create mode 100644 spec/factories/forge_messages.rb create mode 100644 spec/models/forge_message_spec.rb diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb new file mode 100644 index 000000000..1543fab58 --- /dev/null +++ b/app/models/forge_message.rb @@ -0,0 +1,20 @@ +class ForgeMessage < ActiveRecord::Base + # 公共表中活动类型,命名规则:TYPE_OF_{类名}_ACT + TYPE_OF_ISSUE_ACT = "Issue" + TYPE_OF_MESSAGE_ACT = "Message" + TYPE_OF_ATTACHMENT_ACT = "Attachment" + TYPE_OF_DOCUMENT_ACT = "Document" + TYPE_OF_JOURNAL_ACT = "Journal" + TYPE_OF_WIKI_ACT = "Wiki" + TYPE_OF_NEWS_ACT = "News" + + attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed + + belongs_to :forge_message ,:polymorphic => true + belongs_to :project + belongs_to :user + validates :user_id,presence: true + validates :project_id,presence: true + validates :forge_message_id,presence: true + validates :forge_message_type, presence: true +end diff --git a/db/migrate/20150811083322_create_forge_messages.rb b/db/migrate/20150811083322_create_forge_messages.rb new file mode 100644 index 000000000..f81b68712 --- /dev/null +++ b/db/migrate/20150811083322_create_forge_messages.rb @@ -0,0 +1,13 @@ +class CreateForgeMessages < ActiveRecord::Migration + def change + create_table :forge_messages do |t| + t.integer :user_id + t.integer :project_id + t.integer :forge_message_id + t.string :forge_message_type + t.integer :viewed + + t.timestamps + end + end +end diff --git a/spec/factories/forge_messages.rb b/spec/factories/forge_messages.rb new file mode 100644 index 000000000..05bc84cc1 --- /dev/null +++ b/spec/factories/forge_messages.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :forge_message do + user_id 1 +project_id 1 +forge_message_id 1 +forge_message_type "MyString" +viewed 1 + end + +end diff --git a/spec/models/forge_message_spec.rb b/spec/models/forge_message_spec.rb new file mode 100644 index 000000000..ce6cd7e26 --- /dev/null +++ b/spec/models/forge_message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ForgeMessage, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end