Commit 587e16a4e3d171cfcf477388ca1e5c8c95c8c018
Exists in
spb-stable
and in
3 other branches
Merge pull request #6560 from tsigo/visibility-traits
Visibility traits for Project Factory
Showing
11 changed files
with
54 additions
and
54 deletions
Show diff stats
features/steps/project/redirects.rb
... | ... | @@ -4,7 +4,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps |
4 | 4 | include SharedProject |
5 | 5 | |
6 | 6 | step 'public project "Community"' do |
7 | - create :project, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | |
7 | + create :project, :public, name: 'Community' | |
8 | 8 | end |
9 | 9 | |
10 | 10 | step 'private project "Enterprise"' do | ... | ... |
features/steps/public/projects.rb
... | ... | @@ -4,7 +4,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
4 | 4 | include SharedProject |
5 | 5 | |
6 | 6 | step 'public empty project "Empty Public Project"' do |
7 | - create :empty_project, name: 'Empty Public Project', visibility_level: Gitlab::VisibilityLevel::PUBLIC | |
7 | + create :empty_project, :public, name: 'Empty Public Project' | |
8 | 8 | end |
9 | 9 | |
10 | 10 | step 'I should see project "Empty Public Project"' do | ... | ... |
features/steps/shared/project.rb
... | ... | @@ -79,7 +79,7 @@ module SharedProject |
79 | 79 | end |
80 | 80 | |
81 | 81 | step 'internal project "Internal"' do |
82 | - create :project, name: 'Internal', visibility_level: Gitlab::VisibilityLevel::INTERNAL | |
82 | + create :project, :internal, name: 'Internal' | |
83 | 83 | end |
84 | 84 | |
85 | 85 | step 'I should see project "Internal"' do |
... | ... | @@ -91,7 +91,7 @@ module SharedProject |
91 | 91 | end |
92 | 92 | |
93 | 93 | step 'public project "Community"' do |
94 | - create :project, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | |
94 | + create :project, :public, name: 'Community' | |
95 | 95 | end |
96 | 96 | |
97 | 97 | step 'I should see project "Community"' do |
... | ... | @@ -112,14 +112,14 @@ module SharedProject |
112 | 112 | step '"John Doe" is authorized to internal project "Internal"' do |
113 | 113 | user = user_exists("John Doe", username: "john_doe") |
114 | 114 | project = Project.find_by(name: "Internal") |
115 | - project ||= create :project, name: 'Internal', visibility_level: Gitlab::VisibilityLevel::INTERNAL | |
115 | + project ||= create :project, :internal, name: 'Internal' | |
116 | 116 | project.team << [user, :master] |
117 | 117 | end |
118 | 118 | |
119 | 119 | step '"John Doe" is authorized to public project "Community"' do |
120 | 120 | user = user_exists("John Doe", username: "john_doe") |
121 | 121 | project = Project.find_by(name: "Community") |
122 | - project ||= create :project, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | |
122 | + project ||= create :project, :public, name: 'Community' | |
123 | 123 | project.team << [user, :master] |
124 | 124 | end |
125 | 125 | end | ... | ... |
spec/factories.rb
... | ... | @@ -32,6 +32,18 @@ FactoryGirl.define do |
32 | 32 | path { name.downcase.gsub(/\s/, '_') } |
33 | 33 | namespace |
34 | 34 | creator |
35 | + | |
36 | + trait :public do | |
37 | + visibility_level Gitlab::VisibilityLevel::PUBLIC | |
38 | + end | |
39 | + | |
40 | + trait :internal do | |
41 | + visibility_level Gitlab::VisibilityLevel::INTERNAL | |
42 | + end | |
43 | + | |
44 | + trait :private do | |
45 | + visibility_level Gitlab::VisibilityLevel::PRIVATE | |
46 | + end | |
35 | 47 | end |
36 | 48 | |
37 | 49 | # Generates a test repository from the repository stored under `spec/seed_project.tar.gz`. | ... | ... |
spec/features/security/group/internal_group_access_spec.rb
... | ... | @@ -16,7 +16,7 @@ describe "Group with internal project access" do |
16 | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | 17 | group.add_user(guest, Gitlab::Access::GUEST) |
18 | 18 | |
19 | - create(:project, group: group, visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
19 | + create(:project, :internal, group: group) | |
20 | 20 | end |
21 | 21 | |
22 | 22 | describe "GET /groups/:path" do | ... | ... |
spec/features/security/group/mixed_group_access_spec.rb
... | ... | @@ -16,8 +16,8 @@ describe "Group access" do |
16 | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | 17 | group.add_user(guest, Gitlab::Access::GUEST) |
18 | 18 | |
19 | - create(:project, path: "internal_project", group: group, visibility_level: Gitlab::VisibilityLevel::INTERNAL) | |
20 | - create(:project, path: "public_project", group: group, visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
19 | + create(:project, :internal, path: "internal_project", group: group) | |
20 | + create(:project, :public, path: "public_project", group: group) | |
21 | 21 | end |
22 | 22 | |
23 | 23 | describe "GET /groups/:path" do | ... | ... |
spec/features/security/group/public_group_access_spec.rb
... | ... | @@ -16,7 +16,7 @@ describe "Group with public project access" do |
16 | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | 17 | group.add_user(guest, Gitlab::Access::GUEST) |
18 | 18 | |
19 | - create(:project, group: group, visibility_level: Gitlab::VisibilityLevel::PUBLIC) | |
19 | + create(:project, :public, group: group) | |
20 | 20 | end |
21 | 21 | |
22 | 22 | describe "GET /groups/:path" do | ... | ... |
spec/features/security/project/internal_access_spec.rb
1 | 1 | require 'spec_helper' |
2 | 2 | |
3 | 3 | describe "Internal Project Access" do |
4 | - let(:project) { create(:project) } | |
4 | + let(:project) { create(:project, :internal) } | |
5 | 5 | |
6 | 6 | let(:master) { create(:user) } |
7 | 7 | let(:guest) { create(:user) } |
8 | 8 | let(:reporter) { create(:user) } |
9 | 9 | |
10 | 10 | before do |
11 | - # internal project | |
12 | - project.visibility_level = Gitlab::VisibilityLevel::INTERNAL | |
13 | - project.save! | |
14 | - | |
15 | 11 | # full access |
16 | 12 | project.team << [master, :master] |
17 | 13 | |
18 | 14 | # readonly |
19 | 15 | project.team << [reporter, :reporter] |
20 | - | |
21 | 16 | end |
22 | 17 | |
23 | 18 | describe "Project should be internal" do | ... | ... |
spec/finders/projects_finder_spec.rb
... | ... | @@ -4,10 +4,10 @@ describe ProjectsFinder do |
4 | 4 | let(:user) { create :user } |
5 | 5 | let(:group) { create :group } |
6 | 6 | |
7 | - let(:project1) { create(:empty_project, group: group, visibility_level: Project::PUBLIC) } | |
8 | - let(:project2) { create(:empty_project, group: group, visibility_level: Project::INTERNAL) } | |
9 | - let(:project3) { create(:empty_project, group: group, visibility_level: Project::PRIVATE) } | |
10 | - let(:project4) { create(:empty_project, group: group, visibility_level: Project::PRIVATE) } | |
7 | + let(:project1) { create(:empty_project, :public, group: group) } | |
8 | + let(:project2) { create(:empty_project, :internal, group: group) } | |
9 | + let(:project3) { create(:empty_project, :private, group: group) } | |
10 | + let(:project4) { create(:empty_project, :private, group: group) } | |
11 | 11 | |
12 | 12 | context 'non authenticated' do |
13 | 13 | subject { ProjectsFinder.new.execute(nil, group: group) } | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -133,7 +133,7 @@ describe API::API do |
133 | 133 | end |
134 | 134 | |
135 | 135 | it "should set a project as public" do |
136 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::PUBLIC }) | |
136 | + project = attributes_for(:project, :public) | |
137 | 137 | post api("/projects", user), project |
138 | 138 | json_response['public'].should be_true |
139 | 139 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC |
... | ... | @@ -147,21 +147,21 @@ describe API::API do |
147 | 147 | end |
148 | 148 | |
149 | 149 | it "should set a project as internal" do |
150 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::INTERNAL }) | |
150 | + project = attributes_for(:project, :internal) | |
151 | 151 | post api("/projects", user), project |
152 | 152 | json_response['public'].should be_false |
153 | 153 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
154 | 154 | end |
155 | 155 | |
156 | 156 | it "should set a project as internal overriding :public" do |
157 | - project = attributes_for(:project, { public: true, visibility_level: Gitlab::VisibilityLevel::INTERNAL }) | |
157 | + project = attributes_for(:project, :internal, { public: true }) | |
158 | 158 | post api("/projects", user), project |
159 | 159 | json_response['public'].should be_false |
160 | 160 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
161 | 161 | end |
162 | 162 | |
163 | 163 | it "should set a project as private" do |
164 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::PRIVATE }) | |
164 | + project = attributes_for(:project, :private) | |
165 | 165 | post api("/projects", user), project |
166 | 166 | json_response['public'].should be_false |
167 | 167 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE |
... | ... | @@ -215,7 +215,7 @@ describe API::API do |
215 | 215 | end |
216 | 216 | |
217 | 217 | it "should set a project as public" do |
218 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::PUBLIC }) | |
218 | + project = attributes_for(:project, :public) | |
219 | 219 | post api("/projects/user/#{user.id}", admin), project |
220 | 220 | json_response['public'].should be_true |
221 | 221 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC |
... | ... | @@ -229,21 +229,21 @@ describe API::API do |
229 | 229 | end |
230 | 230 | |
231 | 231 | it "should set a project as internal" do |
232 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::INTERNAL }) | |
232 | + project = attributes_for(:project, :internal) | |
233 | 233 | post api("/projects/user/#{user.id}", admin), project |
234 | 234 | json_response['public'].should be_false |
235 | 235 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
236 | 236 | end |
237 | 237 | |
238 | 238 | it "should set a project as internal overriding :public" do |
239 | - project = attributes_for(:project, { public: true, visibility_level: Gitlab::VisibilityLevel::INTERNAL }) | |
239 | + project = attributes_for(:project, :internal, { public: true }) | |
240 | 240 | post api("/projects/user/#{user.id}", admin), project |
241 | 241 | json_response['public'].should be_false |
242 | 242 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
243 | 243 | end |
244 | 244 | |
245 | 245 | it "should set a project as private" do |
246 | - project = attributes_for(:project, { visibility_level: Gitlab::VisibilityLevel::PRIVATE }) | |
246 | + project = attributes_for(:project, :private) | |
247 | 247 | post api("/projects/user/#{user.id}", admin), project |
248 | 248 | json_response['public'].should be_false |
249 | 249 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE |
... | ... | @@ -490,10 +490,10 @@ describe API::API do |
490 | 490 | |
491 | 491 | describe :fork_admin do |
492 | 492 | let(:project_fork_target) { create(:project) } |
493 | - let(:project_fork_source) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
493 | + let(:project_fork_source) { create(:project, :public) } | |
494 | 494 | |
495 | 495 | describe "POST /projects/:id/fork/:forked_from_id" do |
496 | - let(:new_project_fork_source) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
496 | + let(:new_project_fork_source) { create(:project, :public) } | |
497 | 497 | |
498 | 498 | it "shouldn't available for non admin users" do |
499 | 499 | post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) |
... | ... | @@ -562,10 +562,10 @@ describe API::API do |
562 | 562 | let!(:post) { create(:empty_project, name: "#{query}_post", creator_id: user.id, namespace: user.namespace) } |
563 | 563 | let!(:pre_post) { create(:empty_project, name: "pre_#{query}_post", creator_id: user.id, namespace: user.namespace) } |
564 | 564 | let!(:unfound) { create(:empty_project, name: 'unfound', creator_id: user.id, namespace: user.namespace) } |
565 | - let!(:internal) { create(:empty_project, name: "internal #{query}", visibility_level: Gitlab::VisibilityLevel::INTERNAL) } | |
566 | - let!(:unfound_internal) { create(:empty_project, name: 'unfound internal', visibility_level: Gitlab::VisibilityLevel::INTERNAL) } | |
567 | - let!(:public) { create(:empty_project, name: "public #{query}", visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
568 | - let!(:unfound_public) { create(:empty_project, name: 'unfound public', visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
565 | + let!(:internal) { create(:empty_project, :internal, name: "internal #{query}") } | |
566 | + let!(:unfound_internal) { create(:empty_project, :internal, name: 'unfound internal') } | |
567 | + let!(:public) { create(:empty_project, :public, name: "public #{query}") } | |
568 | + let!(:unfound_public) { create(:empty_project, :public, name: 'unfound public') } | |
569 | 569 | |
570 | 570 | context "when unauthenticated" do |
571 | 571 | it "should return authentication error" do | ... | ... |
spec/services/search_service_spec.rb
1 | 1 | require 'spec_helper' |
2 | 2 | |
3 | 3 | describe 'Search::GlobalService' do |
4 | - let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } | |
5 | 4 | let(:user) { create(:user, namespace: found_namespace) } |
6 | - let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
5 | + let(:public_user) { create(:user, namespace: public_namespace) } | |
6 | + let(:internal_user) { create(:user, namespace: internal_namespace) } | |
7 | 7 | |
8 | + let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } | |
8 | 9 | let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') } |
9 | - let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } | |
10 | + let(:internal_namespace) { create(:namespace, name: 'searchable internal namespace', path: 'something_internal') } | |
11 | + let(:public_namespace) { create(:namespace, name: 'searchable public namespace', path: 'something_public') } | |
10 | 12 | |
11 | - let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') } | |
12 | - let(:internal_user) { create(:user, namespace: internal_namespace) } | |
13 | - let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } | |
14 | - | |
15 | - let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') } | |
16 | - let(:public_user) { create(:user, namespace: public_namespace) } | |
17 | - let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } | |
13 | + let!(:found_project) { create(:project, :private, name: 'searchable_project', creator_id: user.id, namespace: found_namespace) } | |
14 | + let!(:unfound_project) { create(:project, :private, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace) } | |
15 | + let!(:internal_project) { create(:project, :internal, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace) } | |
16 | + let!(:public_project) { create(:project, :public, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace) } | |
18 | 17 | |
19 | 18 | describe '#execute' do |
20 | 19 | context 'unauthenticated' do |
21 | 20 | it 'should return public projects only' do |
22 | 21 | context = Search::GlobalService.new(nil, search: "searchable") |
23 | 22 | results = context.execute |
24 | - results[:projects].should have(1).items | |
25 | - results[:projects].should include(public_project) | |
23 | + results[:projects].should match_array [public_project] | |
26 | 24 | end |
27 | 25 | end |
28 | 26 | |
... | ... | @@ -30,24 +28,19 @@ describe 'Search::GlobalService' do |
30 | 28 | it 'should return public, internal and private projects' do |
31 | 29 | context = Search::GlobalService.new(user, search: "searchable") |
32 | 30 | results = context.execute |
33 | - results[:projects].should have(3).items | |
34 | - results[:projects].should include(public_project) | |
35 | - results[:projects].should include(found_project) | |
36 | - results[:projects].should include(internal_project) | |
31 | + results[:projects].should match_array [public_project, found_project, internal_project] | |
37 | 32 | end |
38 | 33 | |
39 | 34 | it 'should return only public & internal projects' do |
40 | 35 | context = Search::GlobalService.new(internal_user, search: "searchable") |
41 | 36 | results = context.execute |
42 | - results[:projects].should have(2).items | |
43 | - results[:projects].should include(internal_project) | |
44 | - results[:projects].should include(public_project) | |
37 | + results[:projects].should match_array [internal_project, public_project] | |
45 | 38 | end |
46 | 39 | |
47 | 40 | it 'namespace name should be searchable' do |
48 | 41 | context = Search::GlobalService.new(user, search: "searchable namespace") |
49 | 42 | results = context.execute |
50 | - results[:projects].should == [found_project] | |
43 | + results[:projects].should match_array [found_project] | |
51 | 44 | end |
52 | 45 | end |
53 | 46 | end | ... | ... |