mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-29 06:26:07 +10:00
ProjectGroupLink model with migration and specs
This commit is contained in:
@@ -67,6 +67,9 @@ class Project < ActiveRecord::Base
|
||||
has_many :deploy_keys_projects, dependent: :destroy
|
||||
has_many :deploy_keys, through: :deploy_keys_projects
|
||||
|
||||
has_many :project_group_links_path, dependent: :destroy
|
||||
has_many :invited_groups, through: :project_group_links, source: 'group'
|
||||
|
||||
delegate :name, to: :owner, allow_nil: true, prefix: true
|
||||
delegate :members, to: :team, prefix: true
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#-------------------------------------------------------------------
|
||||
#
|
||||
# The GitLab Enterprise Edition (EE) license
|
||||
#
|
||||
# Copyright (c) 2013 GitLab.com
|
||||
#
|
||||
# All Rights Reserved. No part of this software may be reproduced without
|
||||
# prior permission of GitLab.com. By using this software you agree to be
|
||||
# bound by the GitLab Enterprise Support Subscription Terms.
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
class ProjectGroupLink < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :group
|
||||
|
||||
validates :project_id, presence: true
|
||||
validates :group_id, presence: true
|
||||
validates :group_id, uniqueness: { scope: [:project_id], message: "already shared with this group" }
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class CreateProjectGroupLinks < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :project_group_links do |t|
|
||||
t.integer :project_id, null: false
|
||||
t.integer :group_id, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
+8
-1
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130624162710) do
|
||||
ActiveRecord::Schema.define(:version => 20130711063759) do
|
||||
|
||||
create_table "deploy_keys_projects", :force => true do |t|
|
||||
t.integer "deploy_key_id", :null => false
|
||||
@@ -157,6 +157,13 @@ ActiveRecord::Schema.define(:version => 20130624162710) do
|
||||
add_index "notes", ["project_id", "noteable_type"], :name => "index_notes_on_project_id_and_noteable_type"
|
||||
add_index "notes", ["project_id"], :name => "index_notes_on_project_id"
|
||||
|
||||
create_table "project_group_links", :force => true do |t|
|
||||
t.integer "project_id", :null => false
|
||||
t.integer "group_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "path"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :project_group_link do
|
||||
project
|
||||
group
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ProjectGroupLink do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:group) }
|
||||
it { should belong_to(:project) }
|
||||
end
|
||||
|
||||
describe "Mass assignment" do
|
||||
it { should_not allow_mass_assignment_of(:group_id) }
|
||||
it { should_not allow_mass_assignment_of(:project_id) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
let!(:project_group_link) { create(:project_group_link) }
|
||||
|
||||
it { should validate_presence_of(:project_id) }
|
||||
it { should validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) }
|
||||
it { should validate_presence_of(:group_id) }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user