diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-19 16:11:23 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-09-19 16:26:20 +0200 |
commit | 3914af2f7129fc03ccddda0957bde43d5a26b0eb (patch) | |
tree | 8a7128be234c64f34fcc58623296b88c5c0e5a10 | |
parent | 6ab74da9c687a13c1692f8ccb05af72be3a73695 (diff) | |
download | gitlab-ce-3914af2f7129fc03ccddda0957bde43d5a26b0eb.tar.gz |
Use set in some API specsrc/use-set-in-api-specs
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | spec/requests/api/access_requests_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/award_emoji_spec.rb | 14 | ||||
-rw-r--r-- | spec/requests/api/boards_spec.rb | 33 | ||||
-rw-r--r-- | spec/requests/api/branches_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/broadcast_messages_spec.rb | 11 | ||||
-rw-r--r-- | spec/requests/api/v3/award_emoji_spec.rb | 14 | ||||
-rw-r--r-- | spec/requests/api/v3/boards_spec.rb | 25 | ||||
-rw-r--r-- | spec/requests/api/v3/branches_spec.rb | 10 | ||||
-rw-r--r-- | spec/requests/api/v3/broadcast_messages_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/v3/builds_spec.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/v3/issues_spec.rb | 19 |
11 files changed, 87 insertions, 81 deletions
diff --git a/spec/requests/api/access_requests_spec.rb b/spec/requests/api/access_requests_spec.rb index 6bd17697c33..50d0f72f6bc 100644 --- a/spec/requests/api/access_requests_spec.rb +++ b/spec/requests/api/access_requests_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' describe API::AccessRequests do - let(:master) { create(:user) } - let(:developer) { create(:user) } - let(:access_requester) { create(:user) } - let(:stranger) { create(:user) } + set(:master) { create(:user) } + set(:developer) { create(:user) } + set(:access_requester) { create(:user) } + set(:stranger) { create(:user) } - let(:project) do + set(:project) do create(:project, :public, :access_requestable, creator_id: master.id, namespace: master.namespace) do |project| project.team << [developer, :developer] project.team << [master, :master] @@ -14,7 +14,7 @@ describe API::AccessRequests do end end - let(:group) do + set(:group) do create(:group, :public, :access_requestable) do |group| group.add_developer(developer) group.add_owner(master) diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 593068b8cd7..7a0765c1fae 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe API::AwardEmoji do - let(:user) { create(:user) } - let!(:project) { create(:project) } - let(:issue) { create(:issue, project: project) } - let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } - let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } - let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } - let!(:note) { create(:note, project: project, noteable: issue) } + set(:user) { create(:user) } + set(:project) { create(:project) } + set(:issue) { create(:issue, project: project) } + set(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } + let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } + set(:note) { create(:note, project: project, noteable: issue) } before do project.team << [user, :master] diff --git a/spec/requests/api/boards_spec.rb b/spec/requests/api/boards_spec.rb index f698d5dddb3..fcfa4ddfbfe 100644 --- a/spec/requests/api/boards_spec.rb +++ b/spec/requests/api/boards_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper' describe API::Boards do - let(:user) { create(:user) } - let(:user2) { create(:user) } - let(:non_member) { create(:user) } - let(:guest) { create(:user) } - let(:admin) { create(:user, :admin) } - let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } - - let!(:dev_label) do + set(:user) { create(:user) } + set(:user2) { create(:user) } + set(:non_member) { create(:user) } + set(:guest) { create(:user) } + set(:admin) { create(:user, :admin) } + set(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } + + set(:dev_label) do create(:label, title: 'Development', color: '#FFAABB', project: project) end - let!(:test_label) do + set(:test_label) do create(:label, title: 'Testing', color: '#FFAACC', project: project) end - let!(:ux_label) do + set(:ux_label) do create(:label, title: 'UX', color: '#FF0000', project: project) end - let!(:dev_list) do + set(:dev_list) do create(:list, label: dev_label, position: 1) end - let!(:test_list) do + set(:test_list) do create(:list, label: test_label, position: 2) end - let!(:board) do + set(:board) do create(:board, project: project, lists: [dev_list, test_list]) end @@ -187,8 +187,11 @@ describe API::Boards do end context "when the user is project owner" do - let(:owner) { create(:user) } - let(:project) { create(:project, namespace: owner.namespace) } + set(:owner) { create(:user) } + + before do + project.update(namespace: owner.namespace) + end it "deletes the list if an admin requests it" do delete api("#{base_url}/#{dev_list.id}", owner) diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index cc794fad3a7..16b12446ed4 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe API::Branches do - let(:user) { create(:user) } - let(:guest) { create(:user).tap { |u| project.add_guest(u) } } + set(:user) { create(:user) } let(:project) { create(:project, :repository, creator: user, path: 'my.project') } + let(:guest) { create(:user).tap { |u| project.add_guest(u) } } let(:branch_name) { 'feature' } let(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let(:branch_with_dot) { project.repository.find_branch('ends-with.json') } @@ -40,7 +40,9 @@ describe API::Branches do end context 'when unauthenticated', 'and project is public' do - let(:project) { create(:project, :public, :repository) } + before do + project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + end it_behaves_like 'repository branches' end @@ -118,7 +120,9 @@ describe API::Branches do end context 'when unauthenticated', 'and project is public' do - let(:project) { create(:project, :public, :repository) } + before do + project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + end it_behaves_like 'repository branch' end diff --git a/spec/requests/api/broadcast_messages_spec.rb b/spec/requests/api/broadcast_messages_spec.rb index b043a333d33..eacc575d97f 100644 --- a/spec/requests/api/broadcast_messages_spec.rb +++ b/spec/requests/api/broadcast_messages_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' describe API::BroadcastMessages do - let(:user) { create(:user) } - let(:admin) { create(:admin) } + set(:user) { create(:user) } + set(:admin) { create(:admin) } + set(:message) { create(:broadcast_message) } describe 'GET /broadcast_messages' do it 'returns a 401 for anonymous users' do @@ -31,8 +32,6 @@ describe API::BroadcastMessages do end describe 'GET /broadcast_messages/:id' do - let!(:message) { create(:broadcast_message) } - it 'returns a 401 for anonymous users' do get api("/broadcast_messages/#{message.id}") @@ -103,8 +102,6 @@ describe API::BroadcastMessages do end describe 'PUT /broadcast_messages/:id' do - let!(:message) { create(:broadcast_message) } - it 'returns a 401 for anonymous users' do put api("/broadcast_messages/#{message.id}"), attributes_for(:broadcast_message) @@ -155,8 +152,6 @@ describe API::BroadcastMessages do end describe 'DELETE /broadcast_messages/:id' do - let!(:message) { create(:broadcast_message) } - it 'returns a 401 for anonymous users' do delete api("/broadcast_messages/#{message.id}"), attributes_for(:broadcast_message) diff --git a/spec/requests/api/v3/award_emoji_spec.rb b/spec/requests/api/v3/award_emoji_spec.rb index 681e8e04295..36d793f505d 100644 --- a/spec/requests/api/v3/award_emoji_spec.rb +++ b/spec/requests/api/v3/award_emoji_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe API::V3::AwardEmoji do - let(:user) { create(:user) } - let!(:project) { create(:project) } - let(:issue) { create(:issue, project: project) } - let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } - let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } - let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } - let!(:note) { create(:note, project: project, noteable: issue) } + set(:user) { create(:user) } + set(:project) { create(:project) } + set(:issue) { create(:issue, project: project) } + set(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } + let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } + set(:note) { create(:note, project: project, noteable: issue) } before { project.team << [user, :master] } diff --git a/spec/requests/api/v3/boards_spec.rb b/spec/requests/api/v3/boards_spec.rb index b86aab2ec70..ea2627142bf 100644 --- a/spec/requests/api/v3/boards_spec.rb +++ b/spec/requests/api/v3/boards_spec.rb @@ -1,28 +1,28 @@ require 'spec_helper' describe API::V3::Boards do - let(:user) { create(:user) } - let(:guest) { create(:user) } - let(:non_member) { create(:user) } - let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } + set(:user) { create(:user) } + set(:guest) { create(:user) } + set(:non_member) { create(:user) } + set(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } - let!(:dev_label) do + set(:dev_label) do create(:label, title: 'Development', color: '#FFAABB', project: project) end - let!(:test_label) do + set(:test_label) do create(:label, title: 'Testing', color: '#FFAACC', project: project) end - let!(:dev_list) do + set(:dev_list) do create(:list, label: dev_label, position: 1) end - let!(:test_list) do + set(:test_list) do create(:list, label: test_label, position: 2) end - let!(:board) do + set(:board) do create(:board, project: project, lists: [dev_list, test_list]) end @@ -98,8 +98,11 @@ describe API::V3::Boards do end context "when the user is project owner" do - let(:owner) { create(:user) } - let(:project) { create(:project, namespace: owner.namespace) } + set(:owner) { create(:user) } + + before do + project.update(namespace: owner.namespace) + end it "deletes the list if an admin requests it" do delete v3_api("#{base_url}/#{dev_list.id}", owner) diff --git a/spec/requests/api/v3/branches_spec.rb b/spec/requests/api/v3/branches_spec.rb index c88f7788697..9cd11a67712 100644 --- a/spec/requests/api/v3/branches_spec.rb +++ b/spec/requests/api/v3/branches_spec.rb @@ -2,11 +2,11 @@ require 'spec_helper' require 'mime/types' describe API::V3::Branches do - let(:user) { create(:user) } - let(:user2) { create(:user) } - let!(:project) { create(:project, :repository, creator: user) } - let!(:master) { create(:project_member, :master, user: user, project: project) } - let!(:guest) { create(:project_member, :guest, user: user2, project: project) } + set(:user) { create(:user) } + set(:user2) { create(:user) } + set(:project) { create(:project, :repository, creator: user) } + set(:master) { create(:project_member, :master, user: user, project: project) } + set(:guest) { create(:project_member, :guest, user: user2, project: project) } let!(:branch_name) { 'feature' } let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let!(:branch_with_dot) { CreateBranchService.new(project, user).execute("with.1.2.3", "master") } diff --git a/spec/requests/api/v3/broadcast_messages_spec.rb b/spec/requests/api/v3/broadcast_messages_spec.rb index 948cd78c177..d04b1c72004 100644 --- a/spec/requests/api/v3/broadcast_messages_spec.rb +++ b/spec/requests/api/v3/broadcast_messages_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' describe API::V3::BroadcastMessages do - let(:user) { create(:user) } - let(:admin) { create(:admin) } + set(:user) { create(:user) } + set(:admin) { create(:admin) } describe 'DELETE /broadcast_messages/:id' do - let!(:message) { create(:broadcast_message) } + set(:message) { create(:broadcast_message) } it 'returns a 401 for anonymous users' do delete v3_api("/broadcast_messages/#{message.id}"), diff --git a/spec/requests/api/v3/builds_spec.rb b/spec/requests/api/v3/builds_spec.rb index dc95599546c..0a2ff1058e3 100644 --- a/spec/requests/api/v3/builds_spec.rb +++ b/spec/requests/api/v3/builds_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe API::V3::Builds do - let(:user) { create(:user) } + set(:user) { create(:user) } let(:api_user) { user } - let!(:project) { create(:project, :repository, creator: user, public_builds: false) } - let!(:developer) { create(:project_member, :developer, user: user, project: project) } - let(:reporter) { create(:project_member, :reporter, project: project) } - let(:guest) { create(:project_member, :guest, project: project) } - let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } + set(:project) { create(:project, :repository, creator: user, public_builds: false) } + set(:developer) { create(:project_member, :developer, user: user, project: project) } + set(:reporter) { create(:project_member, :reporter, project: project) } + set(:guest) { create(:project_member, :guest, project: project) } + set(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } let!(:build) { create(:ci_build, pipeline: pipeline) } describe 'GET /projects/:id/builds ' do diff --git a/spec/requests/api/v3/issues_spec.rb b/spec/requests/api/v3/issues_spec.rb index 9a0e6647ebf..86768d7397a 100644 --- a/spec/requests/api/v3/issues_spec.rb +++ b/spec/requests/api/v3/issues_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe API::V3::Issues, :mailer do - let(:user) { create(:user) } - let(:user2) { create(:user) } - let(:non_member) { create(:user) } - let(:guest) { create(:user) } - let(:author) { create(:author) } - let(:assignee) { create(:assignee) } - let(:admin) { create(:user, :admin) } + set(:user) { create(:user) } + set(:user2) { create(:user) } + set(:non_member) { create(:user) } + set(:guest) { create(:user) } + set(:author) { create(:author) } + set(:assignee) { create(:assignee) } + set(:admin) { create(:user, :admin) } let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } let!(:closed_issue) do create :closed_issue, @@ -822,7 +822,8 @@ describe API::V3::Issues, :mailer do end context 'resolving issues in a merge request' do - let(:discussion) { create(:diff_note_on_merge_request).to_discussion } + set(:diff_note_on_merge_request) { create(:diff_note_on_merge_request) } + let(:discussion) { diff_note_on_merge_request.to_discussion } let(:merge_request) { discussion.noteable } let(:project) { merge_request.source_project } before do @@ -1169,7 +1170,7 @@ describe API::V3::Issues, :mailer do end context "when the user is project owner" do - let(:owner) { create(:user) } + set(:owner) { create(:user) } let(:project) { create(:project, namespace: owner.namespace) } it "deletes the issue if an admin requests it" do |