Commit 73faf3c7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Rename approve->approval. Add approval count to project

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 99ae2c02
class Approve < ActiveRecord::Base
class Approval < ActiveRecord::Base
belongs_to :user
belongs_to :merge_request
end
......@@ -35,7 +35,7 @@ class MergeRequest < ActiveRecord::Base
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
has_one :merge_request_diff, dependent: :destroy
has_many :approves, class_name: 'Approve', dependent: :destroy
has_many :approvals, dependent: :destroy
after_create :create_merge_request_diff
after_update :update_merge_request_diff
......@@ -409,4 +409,18 @@ class MergeRequest < ActiveRecord::Base
locked_at.nil? || locked_at < (Time.now - 1.day)
end
def approvals_left
approvals_required - approvals.count
end
def approvals_required
target_project.approvals_before_merge
end
def requires_approve?
return false if approvals_required.zero?
approvals_required > approvals.count
end
end
......@@ -130,7 +130,7 @@ class User < ActiveRecord::Base
has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue"
has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: :destroy
has_many :approves, class_name: 'Approve', dependent: :destroy
has_many :approvals, dependent: :destroy
#
......
class CreateApproves < ActiveRecord::Migration
def change
create_table :approves do |t|
create_table :approvals do |t|
t.integer :merge_request_id, null: false
t.integer :user_id, null: false
......
class AddProjectMergeApproves < ActiveRecord::Migration
def change
add_column :projects, :approvals_before_merge, :integer, null: false, default: 0
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150609113337) do
ActiveRecord::Schema.define(version: 20150609125332) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -49,7 +49,7 @@ ActiveRecord::Schema.define(version: 20150609113337) do
t.string "after_sign_out_path"
end
create_table "approves", force: true do |t|
create_table "approvals", force: true do |t|
t.integer "merge_request_id", null: false
t.integer "user_id", null: false
t.datetime "created_at"
......@@ -440,6 +440,7 @@ ActiveRecord::Schema.define(version: 20150609113337) do
t.string "import_type"
t.string "import_source"
t.boolean "merge_requests_rebase_default", default: true
t.integer "approvals_before_merge", default: 0, null: false
end
add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :approve do
factory :approval do
merge_request
user
end
......
require 'spec_helper'
describe Approve do
subject { create(:approve) }
describe Approval do
subject { create(:approval) }
it { should be_valid }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment