Commit 3914af2f authored by Rémy Coutable's avatar Rémy Coutable

Use set in some API specs

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 6ab74da9
require 'spec_helper' require 'spec_helper'
describe API::AccessRequests do describe API::AccessRequests do
let(:master) { create(:user) } set(:master) { create(:user) }
let(:developer) { create(:user) } set(:developer) { create(:user) }
let(:access_requester) { create(:user) } set(:access_requester) { create(:user) }
let(:stranger) { 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| create(:project, :public, :access_requestable, creator_id: master.id, namespace: master.namespace) do |project|
project.team << [developer, :developer] project.team << [developer, :developer]
project.team << [master, :master] project.team << [master, :master]
...@@ -14,7 +14,7 @@ describe API::AccessRequests do ...@@ -14,7 +14,7 @@ describe API::AccessRequests do
end end
end end
let(:group) do set(:group) do
create(:group, :public, :access_requestable) do |group| create(:group, :public, :access_requestable) do |group|
group.add_developer(developer) group.add_developer(developer)
group.add_owner(master) group.add_owner(master)
......
require 'spec_helper' require 'spec_helper'
describe API::AwardEmoji do describe API::AwardEmoji do
let(:user) { create(:user) } set(:user) { create(:user) }
let!(:project) { create(:project) } set(:project) { create(:project) }
let(:issue) { create(:issue, project: project) } set(:issue) { create(:issue, project: project) }
let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } set(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) }
let!(:note) { create(:note, project: project, noteable: issue) } set(:note) { create(:note, project: project, noteable: issue) }
before do before do
project.team << [user, :master] project.team << [user, :master]
......
require 'spec_helper' require 'spec_helper'
describe API::Boards do describe API::Boards do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:user2) { create(:user) } set(:user2) { create(:user) }
let(:non_member) { create(:user) } set(:non_member) { create(:user) }
let(:guest) { create(:user) } set(:guest) { create(:user) }
let(:admin) { create(:user, :admin) } set(:admin) { create(:user, :admin) }
let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } 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) create(:label, title: 'Development', color: '#FFAABB', project: project)
end end
let!(:test_label) do set(:test_label) do
create(:label, title: 'Testing', color: '#FFAACC', project: project) create(:label, title: 'Testing', color: '#FFAACC', project: project)
end end
let!(:ux_label) do set(:ux_label) do
create(:label, title: 'UX', color: '#FF0000', project: project) create(:label, title: 'UX', color: '#FF0000', project: project)
end end
let!(:dev_list) do set(:dev_list) do
create(:list, label: dev_label, position: 1) create(:list, label: dev_label, position: 1)
end end
let!(:test_list) do set(:test_list) do
create(:list, label: test_label, position: 2) create(:list, label: test_label, position: 2)
end end
let!(:board) do set(:board) do
create(:board, project: project, lists: [dev_list, test_list]) create(:board, project: project, lists: [dev_list, test_list])
end end
...@@ -187,8 +187,11 @@ describe API::Boards do ...@@ -187,8 +187,11 @@ describe API::Boards do
end end
context "when the user is project owner" do context "when the user is project owner" do
let(:owner) { create(:user) } set(:owner) { create(:user) }
let(:project) { create(:project, namespace: owner.namespace) }
before do
project.update(namespace: owner.namespace)
end
it "deletes the list if an admin requests it" do it "deletes the list if an admin requests it" do
delete api("#{base_url}/#{dev_list.id}", owner) delete api("#{base_url}/#{dev_list.id}", owner)
......
require 'spec_helper' require 'spec_helper'
describe API::Branches do describe API::Branches do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:guest) { create(:user).tap { |u| project.add_guest(u) } }
let(:project) { create(:project, :repository, creator: user, path: 'my.project') } 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_name) { 'feature' }
let(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
let(:branch_with_dot) { project.repository.find_branch('ends-with.json') } let(:branch_with_dot) { project.repository.find_branch('ends-with.json') }
...@@ -40,7 +40,9 @@ describe API::Branches do ...@@ -40,7 +40,9 @@ describe API::Branches do
end end
context 'when unauthenticated', 'and project is public' do 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' it_behaves_like 'repository branches'
end end
...@@ -118,7 +120,9 @@ describe API::Branches do ...@@ -118,7 +120,9 @@ describe API::Branches do
end end
context 'when unauthenticated', 'and project is public' do 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' it_behaves_like 'repository branch'
end end
......
require 'spec_helper' require 'spec_helper'
describe API::BroadcastMessages do describe API::BroadcastMessages do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:admin) { create(:admin) } set(:admin) { create(:admin) }
set(:message) { create(:broadcast_message) }
describe 'GET /broadcast_messages' do describe 'GET /broadcast_messages' do
it 'returns a 401 for anonymous users' do it 'returns a 401 for anonymous users' do
...@@ -31,8 +32,6 @@ describe API::BroadcastMessages do ...@@ -31,8 +32,6 @@ describe API::BroadcastMessages do
end end
describe 'GET /broadcast_messages/:id' do describe 'GET /broadcast_messages/:id' do
let!(:message) { create(:broadcast_message) }
it 'returns a 401 for anonymous users' do it 'returns a 401 for anonymous users' do
get api("/broadcast_messages/#{message.id}") get api("/broadcast_messages/#{message.id}")
...@@ -103,8 +102,6 @@ describe API::BroadcastMessages do ...@@ -103,8 +102,6 @@ describe API::BroadcastMessages do
end end
describe 'PUT /broadcast_messages/:id' do describe 'PUT /broadcast_messages/:id' do
let!(:message) { create(:broadcast_message) }
it 'returns a 401 for anonymous users' do it 'returns a 401 for anonymous users' do
put api("/broadcast_messages/#{message.id}"), put api("/broadcast_messages/#{message.id}"),
attributes_for(:broadcast_message) attributes_for(:broadcast_message)
...@@ -155,8 +152,6 @@ describe API::BroadcastMessages do ...@@ -155,8 +152,6 @@ describe API::BroadcastMessages do
end end
describe 'DELETE /broadcast_messages/:id' do describe 'DELETE /broadcast_messages/:id' do
let!(:message) { create(:broadcast_message) }
it 'returns a 401 for anonymous users' do it 'returns a 401 for anonymous users' do
delete api("/broadcast_messages/#{message.id}"), delete api("/broadcast_messages/#{message.id}"),
attributes_for(:broadcast_message) attributes_for(:broadcast_message)
......
require 'spec_helper' require 'spec_helper'
describe API::V3::AwardEmoji do describe API::V3::AwardEmoji do
let(:user) { create(:user) } set(:user) { create(:user) }
let!(:project) { create(:project) } set(:project) { create(:project) }
let(:issue) { create(:issue, project: project) } set(:issue) { create(:issue, project: project) }
let!(:award_emoji) { create(:award_emoji, awardable: issue, user: user) } set(:award_emoji) { create(:award_emoji, awardable: issue, user: user) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) } let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request, user: user) }
let!(:note) { create(:note, project: project, noteable: issue) } set(:note) { create(:note, project: project, noteable: issue) }
before { project.team << [user, :master] } before { project.team << [user, :master] }
......
require 'spec_helper' require 'spec_helper'
describe API::V3::Boards do describe API::V3::Boards do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:guest) { create(:user) } set(:guest) { create(:user) }
let(:non_member) { create(:user) } set(:non_member) { create(:user) }
let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } 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) create(:label, title: 'Development', color: '#FFAABB', project: project)
end end
let!(:test_label) do set(:test_label) do
create(:label, title: 'Testing', color: '#FFAACC', project: project) create(:label, title: 'Testing', color: '#FFAACC', project: project)
end end
let!(:dev_list) do set(:dev_list) do
create(:list, label: dev_label, position: 1) create(:list, label: dev_label, position: 1)
end end
let!(:test_list) do set(:test_list) do
create(:list, label: test_label, position: 2) create(:list, label: test_label, position: 2)
end end
let!(:board) do set(:board) do
create(:board, project: project, lists: [dev_list, test_list]) create(:board, project: project, lists: [dev_list, test_list])
end end
...@@ -98,8 +98,11 @@ describe API::V3::Boards do ...@@ -98,8 +98,11 @@ describe API::V3::Boards do
end end
context "when the user is project owner" do context "when the user is project owner" do
let(:owner) { create(:user) } set(:owner) { create(:user) }
let(:project) { create(:project, namespace: owner.namespace) }
before do
project.update(namespace: owner.namespace)
end
it "deletes the list if an admin requests it" do it "deletes the list if an admin requests it" do
delete v3_api("#{base_url}/#{dev_list.id}", owner) delete v3_api("#{base_url}/#{dev_list.id}", owner)
......
...@@ -2,11 +2,11 @@ require 'spec_helper' ...@@ -2,11 +2,11 @@ require 'spec_helper'
require 'mime/types' require 'mime/types'
describe API::V3::Branches do describe API::V3::Branches do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:user2) { create(:user) } set(:user2) { create(:user) }
let!(:project) { create(:project, :repository, creator: user) } set(:project) { create(:project, :repository, creator: user) }
let!(:master) { create(:project_member, :master, user: user, project: project) } set(:master) { create(:project_member, :master, user: user, project: project) }
let!(:guest) { create(:project_member, :guest, user: user2, project: project) } set(:guest) { create(:project_member, :guest, user: user2, project: project) }
let!(:branch_name) { 'feature' } let!(:branch_name) { 'feature' }
let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
let!(:branch_with_dot) { CreateBranchService.new(project, user).execute("with.1.2.3", "master") } let!(:branch_with_dot) { CreateBranchService.new(project, user).execute("with.1.2.3", "master") }
......
require 'spec_helper' require 'spec_helper'
describe API::V3::BroadcastMessages do describe API::V3::BroadcastMessages do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:admin) { create(:admin) } set(:admin) { create(:admin) }
describe 'DELETE /broadcast_messages/:id' do describe 'DELETE /broadcast_messages/:id' do
let!(:message) { create(:broadcast_message) } set(:message) { create(:broadcast_message) }
it 'returns a 401 for anonymous users' do it 'returns a 401 for anonymous users' do
delete v3_api("/broadcast_messages/#{message.id}"), delete v3_api("/broadcast_messages/#{message.id}"),
......
require 'spec_helper' require 'spec_helper'
describe API::V3::Builds do describe API::V3::Builds do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:api_user) { user } let(:api_user) { user }
let!(:project) { create(:project, :repository, creator: user, public_builds: false) } set(:project) { create(:project, :repository, creator: user, public_builds: false) }
let!(:developer) { create(:project_member, :developer, user: user, project: project) } set(:developer) { create(:project_member, :developer, user: user, project: project) }
let(:reporter) { create(:project_member, :reporter, project: project) } set(:reporter) { create(:project_member, :reporter, project: project) }
let(:guest) { create(:project_member, :guest, project: project) } set(:guest) { create(:project_member, :guest, project: project) }
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } set(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) }
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
describe 'GET /projects/:id/builds ' do describe 'GET /projects/:id/builds ' do
......
require 'spec_helper' require 'spec_helper'
describe API::V3::Issues, :mailer do describe API::V3::Issues, :mailer do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:user2) { create(:user) } set(:user2) { create(:user) }
let(:non_member) { create(:user) } set(:non_member) { create(:user) }
let(:guest) { create(:user) } set(:guest) { create(:user) }
let(:author) { create(:author) } set(:author) { create(:author) }
let(:assignee) { create(:assignee) } set(:assignee) { create(:assignee) }
let(:admin) { create(:user, :admin) } set(:admin) { create(:user, :admin) }
let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) } let!(:project) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
let!(:closed_issue) do let!(:closed_issue) do
create :closed_issue, create :closed_issue,
...@@ -822,7 +822,8 @@ describe API::V3::Issues, :mailer do ...@@ -822,7 +822,8 @@ describe API::V3::Issues, :mailer do
end end
context 'resolving issues in a merge request' do 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(:merge_request) { discussion.noteable }
let(:project) { merge_request.source_project } let(:project) { merge_request.source_project }
before do before do
...@@ -1169,7 +1170,7 @@ describe API::V3::Issues, :mailer do ...@@ -1169,7 +1170,7 @@ describe API::V3::Issues, :mailer do
end end
context "when the user is project owner" do context "when the user is project owner" do
let(:owner) { create(:user) } set(:owner) { create(:user) }
let(:project) { create(:project, namespace: owner.namespace) } let(:project) { create(:project, namespace: owner.namespace) }
it "deletes the issue if an admin requests it" do it "deletes the issue if an admin requests it" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment