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