From 246923a335dac8163d2085dc6cd7576dbb809828 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 21 Jul 2016 16:09:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=AC=A1=E6=95=B0=E8=A1=A8=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=B3=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/commit.rb | 10 ++++++++++ db/migrate/20160721075236_create_commits.rb | 14 ++++++++++++++ spec/factories/commits.rb | 11 +++++++++++ spec/models/commit_spec.rb | 5 +++++ 4 files changed, 40 insertions(+) create mode 100644 app/models/commit.rb create mode 100644 db/migrate/20160721075236_create_commits.rb create mode 100644 spec/factories/commits.rb create mode 100644 spec/models/commit_spec.rb diff --git a/app/models/commit.rb b/app/models/commit.rb new file mode 100644 index 000000000..246b8be0c --- /dev/null +++ b/app/models/commit.rb @@ -0,0 +1,10 @@ +class Commit < ActiveRecord::Base + attr_accessible :comments, :committed_on, :committer, :project_id, :repository_id, :version + has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy + after_create :act_as_forge_activity + + # 项目中提交动态 + def act_as_forge_activity + self.forge_acts << ForgeActivity.new(:user_id => 2, :project_id => self.project_id) + end +end diff --git a/db/migrate/20160721075236_create_commits.rb b/db/migrate/20160721075236_create_commits.rb new file mode 100644 index 000000000..5482c10c5 --- /dev/null +++ b/db/migrate/20160721075236_create_commits.rb @@ -0,0 +1,14 @@ +class CreateCommits < ActiveRecord::Migration + def change + create_table :commits do |t| + t.integer :repository_id + t.string :version + t.string :committer + t.text :comments + t.date :committed_on + t.integer :project_id + + t.timestamps + end + end +end diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb new file mode 100644 index 000000000..c520e8b64 --- /dev/null +++ b/spec/factories/commits.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :commit do + repository_id 1 +version "MyString" +committer "MyString" +comments "MyText" +committed_on "2016-07-21" +project_id 1 + end + +end diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb new file mode 100644 index 000000000..546996270 --- /dev/null +++ b/spec/models/commit_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Commit, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end