Commit 1ba28aae authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Implement UsersProject project_access validation

parent 640018ba
......@@ -28,6 +28,7 @@ class UsersProject < ActiveRecord::Base
validates :user, presence: true
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
delegate :name, :email, to: :user, prefix: true
......
......@@ -45,6 +45,7 @@ FactoryGirl.define do
factory :users_project do
user
project
project_access { UsersProject::MASTER }
end
factory :issue do
......
......@@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) }
before do
project.users << user
project.add_access(user, :admin)
end
it "should link using a simple name" do
......@@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end
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}"
......
......@@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user)
project = create(:project)
with_resque do
project.users << user
project.add_access(user, :admin)
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
......@@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do
user = create(:user)
project = create(:project)
project.users << user
project.add_access(user, :admin)
with_resque do
project.users_projects.clear
end
......
......@@ -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_presence_of(:project) }
it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) }
end
describe "Delegate methods" do
......
......@@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do
u = create(:user, name: "fred")
project.users << u
project.add_access(u, :admin)
u
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