Add traits for ProjectFeatures to Project factory
https://gitlab.com/gitlab-org/gitlab-ce/issues/24007
This commit is contained in:
parent
4d11903dcf
commit
3deb66ea56
25 changed files with 62 additions and 78 deletions
|
@ -2,7 +2,6 @@ require 'spec_helper'
|
|||
|
||||
describe SearchController do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:empty_project, :public) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
@ -22,7 +21,7 @@ describe SearchController do
|
|||
before { sign_out(user) }
|
||||
|
||||
it "doesn't expose comments on issues" do
|
||||
project = create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :issues_private)
|
||||
note = create(:note_on_issue, project: project)
|
||||
|
||||
get :show, project_id: project.id, scope: 'notes', search: note.note
|
||||
|
@ -31,17 +30,8 @@ describe SearchController do
|
|||
end
|
||||
end
|
||||
|
||||
it "doesn't expose comments on issues" do
|
||||
project = create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE)
|
||||
note = create(:note_on_issue, project: project)
|
||||
|
||||
get :show, project_id: project.id, scope: 'notes', search: note.note
|
||||
|
||||
expect(assigns[:search_objects].count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't expose comments on merge_requests" do
|
||||
project = create(:empty_project, :public, merge_requests_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :merge_requests_private)
|
||||
note = create(:note_on_merge_request, project: project)
|
||||
|
||||
get :show, project_id: project.id, scope: 'notes', search: note.note
|
||||
|
@ -50,7 +40,7 @@ describe SearchController do
|
|||
end
|
||||
|
||||
it "doesn't expose comments on snippets" do
|
||||
project = create(:empty_project, :public, snippets_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :snippets_private)
|
||||
note = create(:note_on_project_snippet, project: project)
|
||||
|
||||
get :show, project_id: project.id, scope: 'notes', search: note.note
|
||||
|
|
|
@ -56,6 +56,25 @@ FactoryGirl.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait(:wiki_enabled) { wiki_access_level ProjectFeature::ENABLED }
|
||||
trait(:wiki_disabled) { wiki_access_level ProjectFeature::DISABLED }
|
||||
trait(:wiki_private) { wiki_access_level ProjectFeature::PRIVATE }
|
||||
trait(:builds_enabled) { builds_access_level ProjectFeature::ENABLED }
|
||||
trait(:builds_disabled) { builds_access_level ProjectFeature::DISABLED }
|
||||
trait(:builds_private) { builds_access_level ProjectFeature::PRIVATE }
|
||||
trait(:snippets_enabled) { snippets_access_level ProjectFeature::ENABLED }
|
||||
trait(:snippets_disabled) { snippets_access_level ProjectFeature::DISABLED }
|
||||
trait(:snippets_private) { snippets_access_level ProjectFeature::PRIVATE }
|
||||
trait(:issues_disabled) { issues_access_level ProjectFeature::DISABLED }
|
||||
trait(:issues_enabled) { issues_access_level ProjectFeature::ENABLED }
|
||||
trait(:issues_private) { issues_access_level ProjectFeature::PRIVATE }
|
||||
trait(:merge_requests_enabled) { merge_requests_access_level ProjectFeature::ENABLED }
|
||||
trait(:merge_requests_disabled) { merge_requests_access_level ProjectFeature::DISABLED }
|
||||
trait(:merge_requests_private) { merge_requests_access_level ProjectFeature::PRIVATE }
|
||||
trait(:repository_enabled) { repository_access_level ProjectFeature::ENABLED }
|
||||
trait(:repository_disabled) { repository_access_level ProjectFeature::DISABLED }
|
||||
trait(:repository_private) { repository_access_level ProjectFeature::PRIVATE }
|
||||
|
||||
# Nest Project Feature attributes
|
||||
transient do
|
||||
wiki_access_level ProjectFeature::ENABLED
|
||||
|
|
|
@ -7,7 +7,7 @@ feature 'Group merge requests page', feature: true do
|
|||
include_examples 'project features apply to issuables', MergeRequest
|
||||
|
||||
context 'archived issuable' do
|
||||
let(:project_archived) { create(:project, :archived, group: group, merge_requests_access_level: ProjectFeature::ENABLED) }
|
||||
let(:project_archived) { create(:project, :archived, :merge_requests_enabled, group: group) }
|
||||
let(:issuable_archived) { create(:merge_request, source_project: project_archived, target_project: project_archived, title: 'issuable of an archived project') }
|
||||
let(:access_level) { ProjectFeature::ENABLED }
|
||||
let(:user) { user_in_group }
|
||||
|
|
|
@ -12,13 +12,8 @@ feature 'Project settings > Merge Requests', feature: true, js: true do
|
|||
end
|
||||
|
||||
context 'when Merge Request and Pipelines are initially enabled' do
|
||||
before do
|
||||
project.project_feature.update_attribute('merge_requests_access_level', ProjectFeature::ENABLED)
|
||||
end
|
||||
|
||||
context 'when Pipelines are initially enabled' do
|
||||
before do
|
||||
project.project_feature.update_attribute('builds_access_level', ProjectFeature::ENABLED)
|
||||
visit edit_project_path(project)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'spec_helper'
|
|||
|
||||
describe 'Projects > Wiki > User views wiki in project page', feature: true do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:empty_project) }
|
||||
|
||||
before do
|
||||
project.team << [user, :master]
|
||||
|
@ -10,12 +9,11 @@ describe 'Projects > Wiki > User views wiki in project page', feature: true do
|
|||
end
|
||||
|
||||
context 'when repository is disabled for project' do
|
||||
before do
|
||||
project.project_feature.update!(
|
||||
repository_access_level: ProjectFeature::DISABLED,
|
||||
merge_requests_access_level: ProjectFeature::DISABLED,
|
||||
builds_access_level: ProjectFeature::DISABLED
|
||||
)
|
||||
let(:project) do
|
||||
create(:empty_project,
|
||||
:repository_disabled,
|
||||
:merge_requests_disabled,
|
||||
:builds_disabled)
|
||||
end
|
||||
|
||||
context 'when wiki homepage contains a link' do
|
||||
|
|
|
@ -224,7 +224,7 @@ describe IssuesFinder do
|
|||
let(:scope) { nil }
|
||||
|
||||
it "doesn't return team-only issues to non team members" do
|
||||
project = create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :issues_private)
|
||||
issue = create(:issue, project: project)
|
||||
|
||||
expect(issues).not_to include(issue)
|
||||
|
|
|
@ -9,8 +9,6 @@ describe NotesFinder do
|
|||
end
|
||||
|
||||
describe '#execute' do
|
||||
it 'finds notes on snippets when project is public and user isnt a member'
|
||||
|
||||
it 'finds notes on merge requests' do
|
||||
create(:note_on_merge_request, project: project)
|
||||
|
||||
|
@ -45,9 +43,11 @@ describe NotesFinder do
|
|||
|
||||
context 'on restricted projects' do
|
||||
let(:project) do
|
||||
create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE,
|
||||
snippets_access_level: ProjectFeature::PRIVATE,
|
||||
merge_requests_access_level: ProjectFeature::PRIVATE)
|
||||
create(:empty_project,
|
||||
:public,
|
||||
:issues_private,
|
||||
:snippets_private,
|
||||
:merge_requests_private)
|
||||
end
|
||||
|
||||
it 'publicly excludes notes on merge requests' do
|
||||
|
|
|
@ -203,7 +203,6 @@ describe ProjectsHelper do
|
|||
|
||||
context "when project moves from public to private" do
|
||||
before do
|
||||
project.project_feature.update_attributes(issues_access_level: ProjectFeature::ENABLED)
|
||||
project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ describe Gitlab::ContributionsCalendar do
|
|||
end
|
||||
|
||||
let(:feature_project) do
|
||||
create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE) do |project|
|
||||
create(:empty_project, :public, :issues_private) do |project|
|
||||
create(:project_member, user: contributor, project: project).project
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,8 +94,6 @@ describe Gitlab::GitAccess, lib: true do
|
|||
|
||||
context 'when repository is enabled' do
|
||||
it 'give access to download code' do
|
||||
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::ENABLED)
|
||||
|
||||
expect(subject.allowed?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,8 +36,6 @@ describe Gitlab::GitAccessWiki, lib: true do
|
|||
|
||||
context 'when wiki feature is enabled' do
|
||||
it 'give access to download wiki code' do
|
||||
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::ENABLED)
|
||||
|
||||
expect(subject.allowed?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -202,7 +202,7 @@ describe Gitlab::GithubImport::Importer, lib: true do
|
|||
end
|
||||
end
|
||||
|
||||
let(:project) { create(:project, import_url: "#{repo_root}/octocat/Hello-World.git", wiki_access_level: ProjectFeature::DISABLED) }
|
||||
let(:project) { create(:project, :wiki_disabled, import_url: "#{repo_root}/octocat/Hello-World.git") }
|
||||
let(:credentials) { { user: 'joe' } }
|
||||
|
||||
context 'when importing a GitHub project' do
|
||||
|
|
|
@ -6,7 +6,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
|
|||
let(:user) { create(:user) }
|
||||
let(:namespace) { create(:namespace, owner: user) }
|
||||
let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: "", project_path: 'path') }
|
||||
let!(:project) { create(:empty_project, name: 'project', path: 'project', builds_access_level: ProjectFeature::DISABLED, issues_access_level: ProjectFeature::DISABLED) }
|
||||
let!(:project) { create(:empty_project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') }
|
||||
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
|
||||
let(:restored_project_json) { project_tree_restorer.restore }
|
||||
|
||||
|
@ -121,13 +121,13 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
|
|||
end
|
||||
|
||||
context 'with group' do
|
||||
let!(:project) do
|
||||
let!(:project) do
|
||||
create(:empty_project,
|
||||
name: 'project',
|
||||
path: 'project',
|
||||
builds_access_level: ProjectFeature::DISABLED,
|
||||
issues_access_level: ProjectFeature::DISABLED,
|
||||
group: create(:group))
|
||||
:builds_disabled,
|
||||
:issues_disabled,
|
||||
name: 'project',
|
||||
path: 'project',
|
||||
group: create(:group))
|
||||
end
|
||||
|
||||
it 'has group labels' do
|
||||
|
|
|
@ -152,6 +152,9 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
|
|||
project = create(:project,
|
||||
:public,
|
||||
:repository,
|
||||
:issues_disabled,
|
||||
:wiki_enabled,
|
||||
:builds_private,
|
||||
issues: [issue],
|
||||
snippets: [snippet],
|
||||
releases: [release],
|
||||
|
@ -185,10 +188,6 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
|
|||
create(:event, :created, target: milestone, project: project, author: user)
|
||||
create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker')
|
||||
|
||||
project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
|
||||
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::ENABLED)
|
||||
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::PRIVATE)
|
||||
|
||||
project
|
||||
end
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
|
|||
end
|
||||
|
||||
it "doesn't list issue notes when access is restricted" do
|
||||
project = create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :issues_private)
|
||||
note = create(:note_on_issue, project: project)
|
||||
|
||||
results = described_class.new(user, project, note.note)
|
||||
|
@ -172,7 +172,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
|
|||
end
|
||||
|
||||
it "doesn't list merge_request notes when access is restricted" do
|
||||
project = create(:empty_project, :public, merge_requests_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:empty_project, :public, :merge_requests_private)
|
||||
note = create(:note_on_merge_request, project: project)
|
||||
|
||||
results = described_class.new(user, project, note.note)
|
||||
|
|
|
@ -247,7 +247,7 @@ describe Ability, lib: true do
|
|||
end
|
||||
|
||||
describe '.project_disabled_features_rules' do
|
||||
let(:project) { create(:empty_project, wiki_access_level: ProjectFeature::DISABLED) }
|
||||
let(:project) { create(:empty_project, :wiki_disabled) }
|
||||
|
||||
subject { described_class.allowed(project.owner, project) }
|
||||
|
||||
|
|
|
@ -37,8 +37,6 @@ describe Guest, lib: true do
|
|||
|
||||
context 'when repository is enabled' do
|
||||
it 'allows to pull the repo' do
|
||||
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::ENABLED)
|
||||
|
||||
expect(Guest.can?(:download_code, public_project)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,7 +57,6 @@ describe ProjectFeature do
|
|||
context 'when feature is enabled for everyone' do
|
||||
it "returns true" do
|
||||
features.each do |feature|
|
||||
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::ENABLED)
|
||||
expect(project.feature_available?(:issues, user)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
@ -104,7 +103,6 @@ describe ProjectFeature do
|
|||
|
||||
it "returns true when feature is enabled for everyone" do
|
||||
features.each do |feature|
|
||||
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::ENABLED)
|
||||
expect(project.public_send("#{feature}_enabled?")).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -632,7 +632,7 @@ describe Project, models: true do
|
|||
end
|
||||
|
||||
describe '#has_wiki?' do
|
||||
let(:no_wiki_project) { create(:empty_project, wiki_access_level: ProjectFeature::DISABLED, has_external_wiki: false) }
|
||||
let(:no_wiki_project) { create(:empty_project, :wiki_disabled, has_external_wiki: false) }
|
||||
let(:wiki_enabled_project) { create(:empty_project) }
|
||||
let(:external_wiki_project) { create(:empty_project, has_external_wiki: true) }
|
||||
|
||||
|
|
|
@ -1232,7 +1232,7 @@ describe User, models: true do
|
|||
end
|
||||
|
||||
it 'does not include projects for which issues are disabled' do
|
||||
project = create(:empty_project, issues_access_level: ProjectFeature::DISABLED)
|
||||
project = create(:empty_project, :issues_disabled)
|
||||
|
||||
expect(user.projects_where_can_admin_issues.to_a).to be_empty
|
||||
expect(user.can?(:admin_issue, project)).to eq(false)
|
||||
|
|
|
@ -425,7 +425,7 @@ describe API::Issues, api: true do
|
|||
end
|
||||
|
||||
it 'returns no issues when user has access to project but not issues' do
|
||||
restricted_project = create(:empty_project, :public, issues_access_level: ProjectFeature::PRIVATE)
|
||||
restricted_project = create(:empty_project, :public, :issues_private)
|
||||
create(:issue, project: restricted_project)
|
||||
|
||||
get api("/projects/#{restricted_project.id}/issues", non_member)
|
||||
|
|
|
@ -57,7 +57,7 @@ describe 'Git HTTP requests', lib: true do
|
|||
end
|
||||
|
||||
context 'but the repo is disabled' do
|
||||
let(:project) { create(:project, repository_access_level: ProjectFeature::DISABLED, wiki_access_level: ProjectFeature::ENABLED) }
|
||||
let(:project) { create(:project, :repository_disabled, :wiki_enabled) }
|
||||
let(:wiki) { ProjectWiki.new(project) }
|
||||
let(:path) { "/#{wiki.repository.path_with_namespace}.git" }
|
||||
|
||||
|
@ -141,7 +141,7 @@ describe 'Git HTTP requests', lib: true do
|
|||
context 'when the repo is public' do
|
||||
context 'but the repo is disabled' do
|
||||
it 'does not allow to clone the repo' do
|
||||
project = create(:project, :public, repository_access_level: ProjectFeature::DISABLED)
|
||||
project = create(:project, :public, :repository_disabled)
|
||||
|
||||
download("#{project.path_with_namespace}.git", {}) do |response|
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
|
@ -151,7 +151,7 @@ describe 'Git HTTP requests', lib: true do
|
|||
|
||||
context 'but the repo is enabled' do
|
||||
it 'allows to clone the repo' do
|
||||
project = create(:project, :public, repository_access_level: ProjectFeature::ENABLED)
|
||||
project = create(:project, :public, :repository_enabled)
|
||||
|
||||
download("#{project.path_with_namespace}.git", {}) do |response|
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
@ -161,7 +161,7 @@ describe 'Git HTTP requests', lib: true do
|
|||
|
||||
context 'but only project members are allowed' do
|
||||
it 'does not allow to clone the repo' do
|
||||
project = create(:project, :public, repository_access_level: ProjectFeature::PRIVATE)
|
||||
project = create(:project, :public, :repository_private)
|
||||
|
||||
download("#{project.path_with_namespace}.git", {}) do |response|
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
|
@ -360,10 +360,6 @@ describe 'Git HTTP requests', lib: true do
|
|||
let(:project) { build.project }
|
||||
let(:other_project) { create(:empty_project) }
|
||||
|
||||
before do
|
||||
project.project_feature.update_attributes(builds_access_level: ProjectFeature::ENABLED)
|
||||
end
|
||||
|
||||
context 'when build created by system is authenticated' do
|
||||
it "downloads get status 200" do
|
||||
clone_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: build.token
|
||||
|
|
|
@ -90,10 +90,6 @@ describe Projects::CreateService, '#execute', services: true do
|
|||
end
|
||||
|
||||
context 'global builds_enabled true does enable CI by default' do
|
||||
before do
|
||||
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::ENABLED)
|
||||
end
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,8 +31,8 @@ shared_examples 'issuable create service' do
|
|||
|
||||
context "when issuable feature is private" do
|
||||
before do
|
||||
project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE)
|
||||
project.project_feature.update(merge_requests_access_level: ProjectFeature::PRIVATE)
|
||||
project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE,
|
||||
merge_requests_access_level: ProjectFeature::PRIVATE)
|
||||
end
|
||||
|
||||
levels = [Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC]
|
||||
|
|
|
@ -5,7 +5,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
|
|||
subject { described_class.new }
|
||||
|
||||
it 'passes when the project has no push events' do
|
||||
project = create(:project_empty_repo, wiki_access_level: ProjectFeature::DISABLED)
|
||||
project = create(:project_empty_repo, :wiki_disabled)
|
||||
project.events.destroy_all
|
||||
break_repo(project)
|
||||
|
||||
|
@ -25,7 +25,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
|
|||
end
|
||||
|
||||
it 'fails if the wiki repository is broken' do
|
||||
project = create(:project_empty_repo, wiki_access_level: ProjectFeature::ENABLED)
|
||||
project = create(:project_empty_repo, :wiki_enabled)
|
||||
project.create_wiki
|
||||
|
||||
# Test sanity: everything should be fine before the wiki repo is broken
|
||||
|
@ -39,7 +39,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
|
|||
end
|
||||
|
||||
it 'skips wikis when disabled' do
|
||||
project = create(:project_empty_repo, wiki_access_level: ProjectFeature::DISABLED)
|
||||
project = create(:project_empty_repo, :wiki_disabled)
|
||||
# Make sure the test would fail if the wiki repo was checked
|
||||
break_wiki(project)
|
||||
|
||||
|
@ -49,7 +49,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
|
|||
end
|
||||
|
||||
it 'creates missing wikis' do
|
||||
project = create(:project_empty_repo, wiki_access_level: ProjectFeature::ENABLED)
|
||||
project = create(:project_empty_repo, :wiki_enabled)
|
||||
FileUtils.rm_rf(wiki_path(project))
|
||||
|
||||
subject.perform(project.id)
|
||||
|
|
Loading…
Reference in a new issue