Commit 1ba28aaef8a985f6e06b2a2673dcaf4723843241
1 parent
640018ba
Exists in
master
and in
4 other branches
Implement UsersProject project_access validation
Showing
6 changed files
with
8 additions
and
5 deletions
Show diff stats
app/models/users_project.rb
... | ... | @@ -28,6 +28,7 @@ class UsersProject < ActiveRecord::Base |
28 | 28 | |
29 | 29 | validates :user, presence: true |
30 | 30 | validates :user_id, uniqueness: { :scope => [:project_id], message: "already exists in project" } |
31 | + validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true | |
31 | 32 | validates :project, presence: true |
32 | 33 | |
33 | 34 | delegate :name, :email, to: :user, prefix: true | ... | ... |
spec/factories.rb
spec/helpers/gitlab_markdown_helper_spec.rb
... | ... | @@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do |
85 | 85 | let(:expected) { project_team_member_path(project, member) } |
86 | 86 | |
87 | 87 | before do |
88 | - project.users << user | |
88 | + project.add_access(user, :admin) | |
89 | 89 | end |
90 | 90 | |
91 | 91 | it "should link using a simple name" do |
... | ... | @@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do |
314 | 314 | end |
315 | 315 | |
316 | 316 | it "should handle references in lists" do |
317 | - project.users << user | |
317 | + project.add_access(user, :admin) | |
318 | 318 | |
319 | 319 | actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}" |
320 | 320 | ... | ... |
spec/models/system_hook_spec.rb
... | ... | @@ -56,7 +56,7 @@ describe SystemHook do |
56 | 56 | user = create(:user) |
57 | 57 | project = create(:project) |
58 | 58 | with_resque do |
59 | - project.users << user | |
59 | + project.add_access(user, :admin) | |
60 | 60 | end |
61 | 61 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
62 | 62 | end |
... | ... | @@ -64,7 +64,7 @@ describe SystemHook do |
64 | 64 | it "project_destroy hook" do |
65 | 65 | user = create(:user) |
66 | 66 | project = create(:project) |
67 | - project.users << user | |
67 | + project.add_access(user, :admin) | |
68 | 68 | with_resque do |
69 | 69 | project.users_projects.clear |
70 | 70 | end | ... | ... |
spec/models/users_project_spec.rb
... | ... | @@ -29,6 +29,7 @@ describe UsersProject do |
29 | 29 | it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) } |
30 | 30 | |
31 | 31 | it { should validate_presence_of(:project) } |
32 | + it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) } | |
32 | 33 | end |
33 | 34 | |
34 | 35 | describe "Delegate methods" do | ... | ... |
spec/requests/gitlab_flavored_markdown_spec.rb