Commit 1897fb00b8d804cffa40da074f83575489beddb0
1 parent
65d63470
Exists in
spb-stable
and in
3 other branches
Make use of project factory traits
Showing
10 changed files
with
42 additions
and
54 deletions
Show diff stats
features/steps/project/redirects.rb
@@ -4,7 +4,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps | @@ -4,7 +4,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps | ||
4 | include SharedProject | 4 | include SharedProject |
5 | 5 | ||
6 | step 'public project "Community"' do | 6 | step 'public project "Community"' do |
7 | - create :project, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | 7 | + create :project, :public, name: 'Community' |
8 | end | 8 | end |
9 | 9 | ||
10 | step 'private project "Enterprise"' do | 10 | step 'private project "Enterprise"' do |
features/steps/public/projects.rb
@@ -4,7 +4,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps | @@ -4,7 +4,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps | ||
4 | include SharedProject | 4 | include SharedProject |
5 | 5 | ||
6 | step 'public empty project "Empty Public Project"' do | 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 | end | 8 | end |
9 | 9 | ||
10 | step 'I should see project "Empty Public Project"' do | 10 | step 'I should see project "Empty Public Project"' do |
features/steps/shared/project.rb
@@ -79,7 +79,7 @@ module SharedProject | @@ -79,7 +79,7 @@ module SharedProject | ||
79 | end | 79 | end |
80 | 80 | ||
81 | step 'internal project "Internal"' do | 81 | step 'internal project "Internal"' do |
82 | - create :project, name: 'Internal', visibility_level: Gitlab::VisibilityLevel::INTERNAL | 82 | + create :project, :internal, name: 'Internal' |
83 | end | 83 | end |
84 | 84 | ||
85 | step 'I should see project "Internal"' do | 85 | step 'I should see project "Internal"' do |
@@ -91,7 +91,7 @@ module SharedProject | @@ -91,7 +91,7 @@ module SharedProject | ||
91 | end | 91 | end |
92 | 92 | ||
93 | step 'public project "Community"' do | 93 | step 'public project "Community"' do |
94 | - create :project, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | 94 | + create :project, :public, name: 'Community' |
95 | end | 95 | end |
96 | 96 | ||
97 | step 'I should see project "Community"' do | 97 | step 'I should see project "Community"' do |
@@ -112,14 +112,14 @@ module SharedProject | @@ -112,14 +112,14 @@ module SharedProject | ||
112 | step '"John Doe" is authorized to internal project "Internal"' do | 112 | step '"John Doe" is authorized to internal project "Internal"' do |
113 | user = user_exists("John Doe", username: "john_doe") | 113 | user = user_exists("John Doe", username: "john_doe") |
114 | project = Project.find_by(name: "Internal") | 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 | project.team << [user, :master] | 116 | project.team << [user, :master] |
117 | end | 117 | end |
118 | 118 | ||
119 | step '"John Doe" is authorized to public project "Community"' do | 119 | step '"John Doe" is authorized to public project "Community"' do |
120 | user = user_exists("John Doe", username: "john_doe") | 120 | user = user_exists("John Doe", username: "john_doe") |
121 | project = Project.find_by(name: "Community") | 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 | project.team << [user, :master] | 123 | project.team << [user, :master] |
124 | end | 124 | end |
125 | end | 125 | end |
spec/features/security/group/internal_group_access_spec.rb
@@ -16,7 +16,7 @@ describe "Group with internal project access" do | @@ -16,7 +16,7 @@ describe "Group with internal project access" do | ||
16 | group.add_user(reporter, Gitlab::Access::REPORTER) | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | group.add_user(guest, Gitlab::Access::GUEST) | 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 | end | 20 | end |
21 | 21 | ||
22 | describe "GET /groups/:path" do | 22 | describe "GET /groups/:path" do |
spec/features/security/group/mixed_group_access_spec.rb
@@ -16,8 +16,8 @@ describe "Group access" do | @@ -16,8 +16,8 @@ describe "Group access" do | ||
16 | group.add_user(reporter, Gitlab::Access::REPORTER) | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | group.add_user(guest, Gitlab::Access::GUEST) | 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 | end | 21 | end |
22 | 22 | ||
23 | describe "GET /groups/:path" do | 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,7 +16,7 @@ describe "Group with public project access" do | ||
16 | group.add_user(reporter, Gitlab::Access::REPORTER) | 16 | group.add_user(reporter, Gitlab::Access::REPORTER) |
17 | group.add_user(guest, Gitlab::Access::GUEST) | 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 | end | 20 | end |
21 | 21 | ||
22 | describe "GET /groups/:path" do | 22 | describe "GET /groups/:path" do |
spec/features/security/project/internal_access_spec.rb
1 | require 'spec_helper' | 1 | require 'spec_helper' |
2 | 2 | ||
3 | describe "Internal Project Access" do | 3 | describe "Internal Project Access" do |
4 | - let(:project) { create(:project) } | 4 | + let(:project) { create(:project, :internal) } |
5 | 5 | ||
6 | let(:master) { create(:user) } | 6 | let(:master) { create(:user) } |
7 | let(:guest) { create(:user) } | 7 | let(:guest) { create(:user) } |
8 | let(:reporter) { create(:user) } | 8 | let(:reporter) { create(:user) } |
9 | 9 | ||
10 | before do | 10 | before do |
11 | - # internal project | ||
12 | - project.visibility_level = Gitlab::VisibilityLevel::INTERNAL | ||
13 | - project.save! | ||
14 | - | ||
15 | # full access | 11 | # full access |
16 | project.team << [master, :master] | 12 | project.team << [master, :master] |
17 | 13 | ||
18 | # readonly | 14 | # readonly |
19 | project.team << [reporter, :reporter] | 15 | project.team << [reporter, :reporter] |
20 | - | ||
21 | end | 16 | end |
22 | 17 | ||
23 | describe "Project should be internal" do | 18 | describe "Project should be internal" do |
spec/finders/projects_finder_spec.rb
@@ -4,10 +4,10 @@ describe ProjectsFinder do | @@ -4,10 +4,10 @@ describe ProjectsFinder do | ||
4 | let(:user) { create :user } | 4 | let(:user) { create :user } |
5 | let(:group) { create :group } | 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 | context 'non authenticated' do | 12 | context 'non authenticated' do |
13 | subject { ProjectsFinder.new.execute(nil, group: group) } | 13 | subject { ProjectsFinder.new.execute(nil, group: group) } |
spec/requests/api/projects_spec.rb
@@ -133,7 +133,7 @@ describe API::API do | @@ -133,7 +133,7 @@ describe API::API do | ||
133 | end | 133 | end |
134 | 134 | ||
135 | it "should set a project as public" do | 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 | post api("/projects", user), project | 137 | post api("/projects", user), project |
138 | json_response['public'].should be_true | 138 | json_response['public'].should be_true |
139 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC | 139 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC |
@@ -147,21 +147,21 @@ describe API::API do | @@ -147,21 +147,21 @@ describe API::API do | ||
147 | end | 147 | end |
148 | 148 | ||
149 | it "should set a project as internal" do | 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 | post api("/projects", user), project | 151 | post api("/projects", user), project |
152 | json_response['public'].should be_false | 152 | json_response['public'].should be_false |
153 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL | 153 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
154 | end | 154 | end |
155 | 155 | ||
156 | it "should set a project as internal overriding :public" do | 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 | post api("/projects", user), project | 158 | post api("/projects", user), project |
159 | json_response['public'].should be_false | 159 | json_response['public'].should be_false |
160 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL | 160 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
161 | end | 161 | end |
162 | 162 | ||
163 | it "should set a project as private" do | 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 | post api("/projects", user), project | 165 | post api("/projects", user), project |
166 | json_response['public'].should be_false | 166 | json_response['public'].should be_false |
167 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE | 167 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE |
@@ -215,7 +215,7 @@ describe API::API do | @@ -215,7 +215,7 @@ describe API::API do | ||
215 | end | 215 | end |
216 | 216 | ||
217 | it "should set a project as public" do | 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 | post api("/projects/user/#{user.id}", admin), project | 219 | post api("/projects/user/#{user.id}", admin), project |
220 | json_response['public'].should be_true | 220 | json_response['public'].should be_true |
221 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC | 221 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PUBLIC |
@@ -229,21 +229,21 @@ describe API::API do | @@ -229,21 +229,21 @@ describe API::API do | ||
229 | end | 229 | end |
230 | 230 | ||
231 | it "should set a project as internal" do | 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 | post api("/projects/user/#{user.id}", admin), project | 233 | post api("/projects/user/#{user.id}", admin), project |
234 | json_response['public'].should be_false | 234 | json_response['public'].should be_false |
235 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL | 235 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
236 | end | 236 | end |
237 | 237 | ||
238 | it "should set a project as internal overriding :public" do | 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 | post api("/projects/user/#{user.id}", admin), project | 240 | post api("/projects/user/#{user.id}", admin), project |
241 | json_response['public'].should be_false | 241 | json_response['public'].should be_false |
242 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL | 242 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::INTERNAL |
243 | end | 243 | end |
244 | 244 | ||
245 | it "should set a project as private" do | 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 | post api("/projects/user/#{user.id}", admin), project | 247 | post api("/projects/user/#{user.id}", admin), project |
248 | json_response['public'].should be_false | 248 | json_response['public'].should be_false |
249 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE | 249 | json_response['visibility_level'].should == Gitlab::VisibilityLevel::PRIVATE |
@@ -490,10 +490,10 @@ describe API::API do | @@ -490,10 +490,10 @@ describe API::API do | ||
490 | 490 | ||
491 | describe :fork_admin do | 491 | describe :fork_admin do |
492 | let(:project_fork_target) { create(:project) } | 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 | describe "POST /projects/:id/fork/:forked_from_id" do | 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 | it "shouldn't available for non admin users" do | 498 | it "shouldn't available for non admin users" do |
499 | post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) | 499 | post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) |
@@ -562,10 +562,10 @@ describe API::API do | @@ -562,10 +562,10 @@ describe API::API do | ||
562 | let!(:post) { create(:empty_project, name: "#{query}_post", creator_id: user.id, namespace: user.namespace) } | 562 | let!(:post) { create(:empty_project, name: "#{query}_post", creator_id: user.id, namespace: user.namespace) } |
563 | let!(:pre_post) { create(:empty_project, name: "pre_#{query}_post", creator_id: user.id, namespace: user.namespace) } | 563 | let!(:pre_post) { create(:empty_project, name: "pre_#{query}_post", creator_id: user.id, namespace: user.namespace) } |
564 | let!(:unfound) { create(:empty_project, name: 'unfound', creator_id: user.id, namespace: user.namespace) } | 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 | context "when unauthenticated" do | 570 | context "when unauthenticated" do |
571 | it "should return authentication error" do | 571 | it "should return authentication error" do |
spec/services/search_service_spec.rb
1 | require 'spec_helper' | 1 | require 'spec_helper' |
2 | 2 | ||
3 | describe 'Search::GlobalService' do | 3 | describe 'Search::GlobalService' do |
4 | - let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') } | ||
5 | let(:user) { create(:user, namespace: found_namespace) } | 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 | let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') } | 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 | describe '#execute' do | 18 | describe '#execute' do |
20 | context 'unauthenticated' do | 19 | context 'unauthenticated' do |
21 | it 'should return public projects only' do | 20 | it 'should return public projects only' do |
22 | context = Search::GlobalService.new(nil, search: "searchable") | 21 | context = Search::GlobalService.new(nil, search: "searchable") |
23 | results = context.execute | 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 | end | 24 | end |
27 | end | 25 | end |
28 | 26 | ||
@@ -30,24 +28,19 @@ describe 'Search::GlobalService' do | @@ -30,24 +28,19 @@ describe 'Search::GlobalService' do | ||
30 | it 'should return public, internal and private projects' do | 28 | it 'should return public, internal and private projects' do |
31 | context = Search::GlobalService.new(user, search: "searchable") | 29 | context = Search::GlobalService.new(user, search: "searchable") |
32 | results = context.execute | 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 | end | 32 | end |
38 | 33 | ||
39 | it 'should return only public & internal projects' do | 34 | it 'should return only public & internal projects' do |
40 | context = Search::GlobalService.new(internal_user, search: "searchable") | 35 | context = Search::GlobalService.new(internal_user, search: "searchable") |
41 | results = context.execute | 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 | end | 38 | end |
46 | 39 | ||
47 | it 'namespace name should be searchable' do | 40 | it 'namespace name should be searchable' do |
48 | context = Search::GlobalService.new(user, search: "searchable namespace") | 41 | context = Search::GlobalService.new(user, search: "searchable namespace") |
49 | results = context.execute | 42 | results = context.execute |
50 | - results[:projects].should == [found_project] | 43 | + results[:projects].should match_array [found_project] |
51 | end | 44 | end |
52 | end | 45 | end |
53 | end | 46 | end |