diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 6231088f..3d76a4df 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index a26a77dd..abc0d374 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -45,6 +45,7 @@ FactoryGirl.define do factory :users_project do user project + project_access { UsersProject::MASTER } end factory :issue do diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index f0b792fc..b792e0c8 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -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}" diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb index 9d03b56c..7ae483a4 100644 --- a/spec/models/system_hook_spec.rb +++ b/spec/models/system_hook_spec.rb @@ -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 diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb index 1f896324..a9a1857e 100644 --- a/spec/models/users_project_spec.rb +++ b/spec/models/users_project_spec.rb @@ -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 diff --git a/spec/requests/gitlab_flavored_markdown_spec.rb b/spec/requests/gitlab_flavored_markdown_spec.rb index 98319f81..7f61c6aa 100644 --- a/spec/requests/gitlab_flavored_markdown_spec.rb +++ b/spec/requests/gitlab_flavored_markdown_spec.rb @@ -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