Implement UsersProject project_access validation

This commit is contained in:
Dmitriy Zaporozhets 2012-12-22 19:52:28 +02:00
parent 640018ba55
commit 1ba28aaef8
6 changed files with 8 additions and 5 deletions

View file

@ -28,6 +28,7 @@ class UsersProject < ActiveRecord::Base
validates :user, presence: true validates :user, presence: true
validates :user_id, uniqueness: { :scope => [:project_id], message: "already exists in project" } validates :user_id, uniqueness: { :scope => [:project_id], message: "already exists in project" }
validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true
validates :project, presence: true validates :project, presence: true
delegate :name, :email, to: :user, prefix: true delegate :name, :email, to: :user, prefix: true

View file

@ -45,6 +45,7 @@ FactoryGirl.define do
factory :users_project do factory :users_project do
user user
project project
project_access { UsersProject::MASTER }
end end
factory :issue do factory :issue do

View file

@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) } let(:expected) { project_team_member_path(project, member) }
before do before do
project.users << user project.add_access(user, :admin)
end end
it "should link using a simple name" do it "should link using a simple name" do
@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end end
it "should handle references in lists" do it "should handle references in lists" do
project.users << user project.add_access(user, :admin)
actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}" actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"

View file

@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user) user = create(:user)
project = create(:project) project = create(:project)
with_resque do with_resque do
project.users << user project.add_access(user, :admin)
end end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end end
@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do it "project_destroy hook" do
user = create(:user) user = create(:user)
project = create(:project) project = create(:project)
project.users << user project.add_access(user, :admin)
with_resque do with_resque do
project.users_projects.clear project.users_projects.clear
end end

View file

@ -29,6 +29,7 @@ describe UsersProject do
it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) } it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) }
it { should validate_presence_of(:project) } it { should validate_presence_of(:project) }
it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) }
end end
describe "Delegate methods" do describe "Delegate methods" do

View file

@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) } let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do let(:fred) do
u = create(:user, name: "fred") u = create(:user, name: "fred")
project.users << u project.add_access(u, :admin)
u u
end end