Commit 1d268a89 authored by tiagonbotelho's avatar tiagonbotelho

adds second batch of tests changed to active tense

parent 519275c1
...@@ -167,7 +167,7 @@ describe Projects::ProjectMembersController do ...@@ -167,7 +167,7 @@ describe Projects::ProjectMembersController do
sign_in(user) sign_in(user)
end end
it 'does not remove himself from the project' do it 'cannot remove himself from the project' do
delete :leave, namespace_id: project.namespace, delete :leave, namespace_id: project.namespace,
project_id: project project_id: project
......
...@@ -9,7 +9,7 @@ describe 'factories' do ...@@ -9,7 +9,7 @@ describe 'factories' do
expect { entity }.not_to raise_error expect { entity }.not_to raise_error
end end
it 'should be valid', if: factory.build_class < ActiveRecord::Base do it 'is valid', if: factory.build_class < ActiveRecord::Base do
expect(entity).to be_valid expect(entity).to be_valid
end end
end end
......
...@@ -46,13 +46,13 @@ describe DiffHelper do ...@@ -46,13 +46,13 @@ describe DiffHelper do
expect(diff_options).to include(no_collapse: true) expect(diff_options).to include(no_collapse: true)
end end
it 'should return paths if action name diff_for_path and param old path' do it 'returns paths if action name diff_for_path and param old path' do
allow(controller).to receive(:params) { { old_path: 'lib/wadus.rb' } } allow(controller).to receive(:params) { { old_path: 'lib/wadus.rb' } }
allow(controller).to receive(:action_name) { 'diff_for_path' } allow(controller).to receive(:action_name) { 'diff_for_path' }
expect(diff_options[:paths]).to include('lib/wadus.rb') expect(diff_options[:paths]).to include('lib/wadus.rb')
end end
it 'should return paths if action name diff_for_path and param new path' do it 'returns paths if action name diff_for_path and param new path' do
allow(controller).to receive(:params) { { new_path: 'lib/wadus.rb' } } allow(controller).to receive(:params) { { new_path: 'lib/wadus.rb' } }
allow(controller).to receive(:action_name) { 'diff_for_path' } allow(controller).to receive(:action_name) { 'diff_for_path' }
expect(diff_options[:paths]).to include('lib/wadus.rb') expect(diff_options[:paths]).to include('lib/wadus.rb')
......
...@@ -5,7 +5,7 @@ describe DisableEmailInterceptor, lib: true do ...@@ -5,7 +5,7 @@ describe DisableEmailInterceptor, lib: true do
Mail.register_interceptor(DisableEmailInterceptor) Mail.register_interceptor(DisableEmailInterceptor)
end end
it 'should not send emails' do it 'does not send emails' do
allow(Gitlab.config.gitlab).to receive(:email_enabled).and_return(false) allow(Gitlab.config.gitlab).to receive(:email_enabled).and_return(false)
expect { deliver_mail }.not_to change(ActionMailer::Base.deliveries, :count) expect { deliver_mail }.not_to change(ActionMailer::Base.deliveries, :count)
end end
......
...@@ -25,7 +25,7 @@ describe ExtractsPath, lib: true do ...@@ -25,7 +25,7 @@ describe ExtractsPath, lib: true do
@project = create(:project) @project = create(:project)
end end
it "log tree path should have no escape sequences" do it "log tree path has no escape sequences" do
assign_ref_vars assign_ref_vars
expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb") expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb")
end end
...@@ -33,7 +33,7 @@ describe ExtractsPath, lib: true do ...@@ -33,7 +33,7 @@ describe ExtractsPath, lib: true do
context 'escaped sequences in ref' do context 'escaped sequences in ref' do
let(:ref) { "improve%2Fawesome" } let(:ref) { "improve%2Fawesome" }
it "id should have no escape sequences" do it "id has no escape sequences" do
assign_ref_vars assign_ref_vars
expect(@ref).to eq('improve/awesome') expect(@ref).to eq('improve/awesome')
expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb") expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb")
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
let(:html) { 'H<sub>2</sub>O' } let(:html) { 'H<sub>2</sub>O' }
context "without project" do context "without project" do
it "should convert the input using Asciidoctor and default options" do it "converts the input using Asciidoctor and default options" do
expected_asciidoc_opts = { expected_asciidoc_opts = {
safe: :secure, safe: :secure,
backend: :html5, backend: :html5,
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
context "with asciidoc_opts" do context "with asciidoc_opts" do
let(:asciidoc_opts) { { safe: :safe, attributes: ['foo'] } } let(:asciidoc_opts) { { safe: :safe, attributes: ['foo'] } }
it "should merge the options with default ones" do it "merges the options with default ones" do
expected_asciidoc_opts = { expected_asciidoc_opts = {
safe: :safe, safe: :safe,
backend: :html5, backend: :html5,
......
...@@ -51,24 +51,24 @@ describe Gitlab::Auth, lib: true do ...@@ -51,24 +51,24 @@ describe Gitlab::Auth, lib: true do
let(:username) { 'John' } # username isn't lowercase, test this let(:username) { 'John' } # username isn't lowercase, test this
let(:password) { 'my-secret' } let(:password) { 'my-secret' }
it "should find user by valid login/password" do it "finds user by valid login/password" do
expect( gl_auth.find_with_user_password(username, password) ).to eql user expect( gl_auth.find_with_user_password(username, password) ).to eql user
end end
it 'should find user by valid email/password with case-insensitive email' do it 'finds user by valid email/password with case-insensitive email' do
expect(gl_auth.find_with_user_password(user.email.upcase, password)).to eql user expect(gl_auth.find_with_user_password(user.email.upcase, password)).to eql user
end end
it 'should find user by valid username/password with case-insensitive username' do it 'finds user by valid username/password with case-insensitive username' do
expect(gl_auth.find_with_user_password(username.upcase, password)).to eql user expect(gl_auth.find_with_user_password(username.upcase, password)).to eql user
end end
it "should not find user with invalid password" do it "does not find user with invalid password" do
password = 'wrong' password = 'wrong'
expect( gl_auth.find_with_user_password(username, password) ).not_to eql user expect( gl_auth.find_with_user_password(username, password) ).not_to eql user
end end
it "should not find user with invalid login" do it "does not find user with invalid login" do
user = 'wrong' user = 'wrong'
expect( gl_auth.find_with_user_password(username, password) ).not_to eql user expect( gl_auth.find_with_user_password(username, password) ).not_to eql user
end end
......
...@@ -64,7 +64,7 @@ describe Gitlab::LDAP::Access, lib: true do ...@@ -64,7 +64,7 @@ describe Gitlab::LDAP::Access, lib: true do
user.ldap_block user.ldap_block
end end
it 'should unblock user in GitLab' do it 'unblocks user in GitLab' do
access.allowed? access.allowed?
expect(user).not_to be_blocked expect(user).not_to be_blocked
end end
......
...@@ -36,7 +36,7 @@ describe Gitlab::LDAP::User, lib: true do ...@@ -36,7 +36,7 @@ describe Gitlab::LDAP::User, lib: true do
expect(ldap_user.changed?).to be_truthy expect(ldap_user.changed?).to be_truthy
end end
it "dont marks existing ldap user as changed" do it "does not mark existing ldap user as changed" do
create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain', ldap_email: true) create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain', ldap_email: true)
expect(ldap_user.changed?).to be_falsey expect(ldap_user.changed?).to be_falsey
end end
......
...@@ -42,7 +42,7 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -42,7 +42,7 @@ describe Gitlab::OAuth::User, lib: true do
describe 'signup' do describe 'signup' do
shared_examples 'to verify compliance with allow_single_sign_on' do shared_examples 'to verify compliance with allow_single_sign_on' do
context 'provider is marked as external' do context 'provider is marked as external' do
it 'should mark user as external' do it 'marks user as external' do
stub_omniauth_config(allow_single_sign_on: ['twitter'], external_providers: ['twitter']) stub_omniauth_config(allow_single_sign_on: ['twitter'], external_providers: ['twitter'])
oauth_user.save oauth_user.save
expect(gl_user).to be_valid expect(gl_user).to be_valid
...@@ -51,7 +51,7 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -51,7 +51,7 @@ describe Gitlab::OAuth::User, lib: true do
end end
context 'provider was external, now has been removed' do context 'provider was external, now has been removed' do
it 'should not mark external user as internal' do it 'does not mark external user as internal' do
create(:omniauth_user, extern_uid: 'my-uid', provider: 'twitter', external: true) create(:omniauth_user, extern_uid: 'my-uid', provider: 'twitter', external: true)
stub_omniauth_config(allow_single_sign_on: ['twitter'], external_providers: ['facebook']) stub_omniauth_config(allow_single_sign_on: ['twitter'], external_providers: ['facebook'])
oauth_user.save oauth_user.save
...@@ -62,7 +62,7 @@ describe Gitlab::OAuth::User, lib: true do ...@@ -62,7 +62,7 @@ describe Gitlab::OAuth::User, lib: true do
context 'provider is not external' do context 'provider is not external' do
context 'when adding a new OAuth identity' do context 'when adding a new OAuth identity' do
it 'should not promote an external user to internal' do it 'does not promote an external user to internal' do
user = create(:user, email: 'john@mail.com', external: true) user = create(:user, email: 'john@mail.com', external: true)
user.identities.create(provider: provider, extern_uid: uid) user.identities.create(provider: provider, extern_uid: uid)
......
...@@ -33,7 +33,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -33,7 +33,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
let!(:security_issue_1) { create(:issue, :confidential, project: project, title: 'Security issue 1', author: author) } let!(:security_issue_1) { create(:issue, :confidential, project: project, title: 'Security issue 1', author: author) }
let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignee: assignee) } let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignee: assignee) }
it 'should not list project confidential issues for non project members' do it 'does not list project confidential issues for non project members' do
results = described_class.new(non_member, project, query) results = described_class.new(non_member, project, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -43,7 +43,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -43,7 +43,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
expect(results.issues_count).to eq 1 expect(results.issues_count).to eq 1
end end
it 'should not list project confidential issues for project members with guest role' do it 'does not list project confidential issues for project members with guest role' do
project.team << [member, :guest] project.team << [member, :guest]
results = described_class.new(member, project, query) results = described_class.new(member, project, query)
...@@ -55,7 +55,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -55,7 +55,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
expect(results.issues_count).to eq 1 expect(results.issues_count).to eq 1
end end
it 'should list project confidential issues for author' do it 'lists project confidential issues for author' do
results = described_class.new(author, project, query) results = described_class.new(author, project, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -65,7 +65,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -65,7 +65,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
expect(results.issues_count).to eq 2 expect(results.issues_count).to eq 2
end end
it 'should list project confidential issues for assignee' do it 'lists project confidential issues for assignee' do
results = described_class.new(assignee, project.id, query) results = described_class.new(assignee, project.id, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -75,7 +75,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -75,7 +75,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
expect(results.issues_count).to eq 2 expect(results.issues_count).to eq 2
end end
it 'should list project confidential issues for project members' do it 'lists project confidential issues for project members' do
project.team << [member, :developer] project.team << [member, :developer]
results = described_class.new(member, project, query) results = described_class.new(member, project, query)
...@@ -87,7 +87,7 @@ describe Gitlab::ProjectSearchResults, lib: true do ...@@ -87,7 +87,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
expect(results.issues_count).to eq 3 expect(results.issues_count).to eq 3
end end
it 'should list all project issues for admin' do it 'lists all project issues for admin' do
results = described_class.new(admin, project, query) results = described_class.new(admin, project, query)
issues = results.objects('issues') issues = results.objects('issues')
......
...@@ -67,7 +67,7 @@ describe Gitlab::Saml::User, lib: true do ...@@ -67,7 +67,7 @@ describe Gitlab::Saml::User, lib: true do
end end
context 'user was external, now should not be' do context 'user was external, now should not be' do
it 'should make user internal' do it 'makes user internal' do
existing_user.update_attribute('external', true) existing_user.update_attribute('external', true)
saml_user.save saml_user.save
expect(gl_user).to be_valid expect(gl_user).to be_valid
...@@ -94,14 +94,14 @@ describe Gitlab::Saml::User, lib: true do ...@@ -94,14 +94,14 @@ describe Gitlab::Saml::User, lib: true do
context 'with allow_single_sign_on default (["saml"])' do context 'with allow_single_sign_on default (["saml"])' do
before { stub_omniauth_config(allow_single_sign_on: ['saml']) } before { stub_omniauth_config(allow_single_sign_on: ['saml']) }
it 'should not throw an error' do it 'does not throw an error' do
expect{ saml_user.save }.not_to raise_error expect{ saml_user.save }.not_to raise_error
end end
end end
context 'with allow_single_sign_on disabled' do context 'with allow_single_sign_on disabled' do
before { stub_omniauth_config(allow_single_sign_on: false) } before { stub_omniauth_config(allow_single_sign_on: false) }
it 'should throw an error' do it 'throws an error' do
expect{ saml_user.save }.to raise_error StandardError expect{ saml_user.save }.to raise_error StandardError
end end
end end
...@@ -223,7 +223,7 @@ describe Gitlab::Saml::User, lib: true do ...@@ -223,7 +223,7 @@ describe Gitlab::Saml::User, lib: true do
context 'dont block on create' do context 'dont block on create' do
before { stub_omniauth_config(block_auto_created_users: false) } before { stub_omniauth_config(block_auto_created_users: false) }
it 'should not block the user' do it 'does not block the user' do
saml_user.save saml_user.save
expect(gl_user).to be_valid expect(gl_user).to be_valid
expect(gl_user).not_to be_blocked expect(gl_user).not_to be_blocked
...@@ -233,7 +233,7 @@ describe Gitlab::Saml::User, lib: true do ...@@ -233,7 +233,7 @@ describe Gitlab::Saml::User, lib: true do
context 'block on create' do context 'block on create' do
before { stub_omniauth_config(block_auto_created_users: true) } before { stub_omniauth_config(block_auto_created_users: true) }
it 'should block user' do it 'blocks user' do
saml_user.save saml_user.save
expect(gl_user).to be_valid expect(gl_user).to be_valid
expect(gl_user).to be_blocked expect(gl_user).to be_blocked
......
...@@ -73,7 +73,7 @@ describe Gitlab::SearchResults do ...@@ -73,7 +73,7 @@ describe Gitlab::SearchResults do
let!(:security_issue_4) { create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignee: assignee) } let!(:security_issue_4) { create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignee: assignee) }
let!(:security_issue_5) { create(:issue, :confidential, project: project_4, title: 'Security issue 5') } let!(:security_issue_5) { create(:issue, :confidential, project: project_4, title: 'Security issue 5') }
it 'should not list confidential issues for non project members' do it 'does not list confidential issues for non project members' do
results = described_class.new(non_member, limit_projects, query) results = described_class.new(non_member, limit_projects, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -86,7 +86,7 @@ describe Gitlab::SearchResults do ...@@ -86,7 +86,7 @@ describe Gitlab::SearchResults do
expect(results.issues_count).to eq 1 expect(results.issues_count).to eq 1
end end
it 'should not list confidential issues for project members with guest role' do it 'does not list confidential issues for project members with guest role' do
project_1.team << [member, :guest] project_1.team << [member, :guest]
project_2.team << [member, :guest] project_2.team << [member, :guest]
...@@ -102,7 +102,7 @@ describe Gitlab::SearchResults do ...@@ -102,7 +102,7 @@ describe Gitlab::SearchResults do
expect(results.issues_count).to eq 1 expect(results.issues_count).to eq 1
end end
it 'should list confidential issues for author' do it 'lists confidential issues for author' do
results = described_class.new(author, limit_projects, query) results = described_class.new(author, limit_projects, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -115,7 +115,7 @@ describe Gitlab::SearchResults do ...@@ -115,7 +115,7 @@ describe Gitlab::SearchResults do
expect(results.issues_count).to eq 3 expect(results.issues_count).to eq 3
end end
it 'should list confidential issues for assignee' do it 'lists confidential issues for assignee' do
results = described_class.new(assignee, limit_projects, query) results = described_class.new(assignee, limit_projects, query)
issues = results.objects('issues') issues = results.objects('issues')
...@@ -128,7 +128,7 @@ describe Gitlab::SearchResults do ...@@ -128,7 +128,7 @@ describe Gitlab::SearchResults do
expect(results.issues_count).to eq 3 expect(results.issues_count).to eq 3
end end
it 'should list confidential issues for project members' do it 'lists confidential issues for project members' do
project_1.team << [member, :developer] project_1.team << [member, :developer]
project_2.team << [member, :developer] project_2.team << [member, :developer]
...@@ -144,7 +144,7 @@ describe Gitlab::SearchResults do ...@@ -144,7 +144,7 @@ describe Gitlab::SearchResults do
expect(results.issues_count).to eq 4 expect(results.issues_count).to eq 4
end end
it 'should list all issues for admin' do it 'lists all issues for admin' do
results = described_class.new(admin, limit_projects, query) results = described_class.new(admin, limit_projects, query)
issues = results.objects('issues') issues = results.objects('issues')
......
...@@ -9,19 +9,19 @@ describe Gitlab::Upgrader, lib: true do ...@@ -9,19 +9,19 @@ describe Gitlab::Upgrader, lib: true do
end end
describe 'latest_version?' do describe 'latest_version?' do
it 'should be true if newest version' do it 'is true if newest version' do
allow(upgrader).to receive(:latest_version_raw).and_return(current_version) allow(upgrader).to receive(:latest_version_raw).and_return(current_version)
expect(upgrader.latest_version?).to be_truthy expect(upgrader.latest_version?).to be_truthy
end end
end end
describe 'latest_version_raw' do describe 'latest_version_raw' do
it 'should be latest version for GitLab 5' do it 'is the latest version for GitLab 5' do
allow(upgrader).to receive(:current_version_raw).and_return("5.3.0") allow(upgrader).to receive(:current_version_raw).and_return("5.3.0")
expect(upgrader.latest_version_raw).to eq("v5.4.2") expect(upgrader.latest_version_raw).to eq("v5.4.2")
end end
it 'should get the latest version from tags' do it 'gets the latest version from tags' do
allow(upgrader).to receive(:fetch_git_tags).and_return([ allow(upgrader).to receive(:fetch_git_tags).and_return([
'6f0733310546402c15d3ae6128a95052f6c8ea96 refs/tags/v7.1.1', '6f0733310546402c15d3ae6128a95052f6c8ea96 refs/tags/v7.1.1',
'facfec4b242ce151af224e20715d58e628aa5e74 refs/tags/v7.1.1^{}', 'facfec4b242ce151af224e20715d58e628aa5e74 refs/tags/v7.1.1^{}',
......
...@@ -48,7 +48,7 @@ describe Notify do ...@@ -48,7 +48,7 @@ describe Notify do
it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'a user cannot unsubscribe through footer link'
it 'should not contain the new user\'s password' do it 'does not contain the new user\'s password' do
is_expected.not_to have_body_text /password/ is_expected.not_to have_body_text /password/
end end
end end
......
...@@ -591,7 +591,7 @@ describe Notify do ...@@ -591,7 +591,7 @@ describe Notify do
is_expected.to have_body_text /#{note.note}/ is_expected.to have_body_text /#{note.note}/
end end
it 'not contains note author' do it 'does not contain note author' do
is_expected.not_to have_body_text /wrote\:/ is_expected.not_to have_body_text /wrote\:/
end end
......
...@@ -53,59 +53,59 @@ describe ApplicationSetting, models: true do ...@@ -53,59 +53,59 @@ describe ApplicationSetting, models: true do
end end
context 'restricted signup domains' do context 'restricted signup domains' do
it 'set single domain' do it 'sets single domain' do
setting.domain_whitelist_raw = 'example.com' setting.domain_whitelist_raw = 'example.com'
expect(setting.domain_whitelist).to eq(['example.com']) expect(setting.domain_whitelist).to eq(['example.com'])
end end
it 'set multiple domains with spaces' do it 'sets multiple domains with spaces' do
setting.domain_whitelist_raw = 'example.com *.example.com' setting.domain_whitelist_raw = 'example.com *.example.com'
expect(setting.domain_whitelist).to eq(['example.com', '*.example.com']) expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
end end
it 'set multiple domains with newlines and a space' do it 'sets multiple domains with newlines and a space' do
setting.domain_whitelist_raw = "example.com\n *.example.com" setting.domain_whitelist_raw = "example.com\n *.example.com"
expect(setting.domain_whitelist).to eq(['example.com', '*.example.com']) expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
end end
it 'set multiple domains with commas' do it 'sets multiple domains with commas' do
setting.domain_whitelist_raw = "example.com, *.example.com" setting.domain_whitelist_raw = "example.com, *.example.com"
expect(setting.domain_whitelist).to eq(['example.com', '*.example.com']) expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
end end
end end
context 'blacklisted signup domains' do context 'blacklisted signup domains' do
it 'set single domain' do it 'sets single domain' do
setting.domain_blacklist_raw = 'example.com' setting.domain_blacklist_raw = 'example.com'
expect(setting.domain_blacklist).to contain_exactly('example.com') expect(setting.domain_blacklist).to contain_exactly('example.com')
end end
it 'set multiple domains with spaces' do it 'sets multiple domains with spaces' do
setting.domain_blacklist_raw = 'example.com *.example.com' setting.domain_blacklist_raw = 'example.com *.example.com'
expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
end end
it 'set multiple domains with newlines and a space' do it 'sets multiple domains with newlines and a space' do
setting.domain_blacklist_raw = "example.com\n *.example.com" setting.domain_blacklist_raw = "example.com\n *.example.com"
expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
end end
it 'set multiple domains with commas' do it 'sets multiple domains with commas' do
setting.domain_blacklist_raw = "example.com, *.example.com" setting.domain_blacklist_raw = "example.com, *.example.com"
expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
end end
it 'set multiple domains with semicolon' do it 'sets multiple domains with semicolon' do
setting.domain_blacklist_raw = "example.com; *.example.com" setting.domain_blacklist_raw = "example.com; *.example.com"
expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com') expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
end end
it 'set multiple domains with mixture of everything' do it 'sets multiple domains with mixture of everything' do
setting.domain_blacklist_raw = "example.com; *.example.com\n test.com\sblock.com yes.com" setting.domain_blacklist_raw = "example.com; *.example.com\n test.com\sblock.com yes.com"
expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com', 'test.com', 'block.com', 'yes.com') expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com', 'test.com', 'block.com', 'yes.com')
end end
it 'set multiple domain with file' do it 'sets multiple domain with file' do
setting.domain_blacklist_file = File.open(Rails.root.join('spec/fixtures/', 'domain_blacklist.txt')) setting.domain_blacklist_file = File.open(Rails.root.join('spec/fixtures/', 'domain_blacklist.txt'))
expect(setting.domain_blacklist).to contain_exactly('example.com', 'test.com', 'foo.bar') expect(setting.domain_blacklist).to contain_exactly('example.com', 'test.com', 'foo.bar')
end end
......
...@@ -23,19 +23,19 @@ describe BroadcastMessage, models: true do ...@@ -23,19 +23,19 @@ describe BroadcastMessage, models: true do
end end
describe '.current' do describe '.current' do
it "should return last message if time match" do it "returns last message if time match" do
message = create(:broadcast_message) message = create(:broadcast_message)
expect(BroadcastMessage.current).to eq message expect(BroadcastMessage.current).to eq message
end end
it "should return nil if time not come" do it "returns nil if time not come" do
create(:broadcast_message, :future) create(:broadcast_message, :future)
expect(BroadcastMessage.current).to be_nil expect(BroadcastMessage.current).to be_nil
end end
it "should return nil if time has passed" do it "returns nil if time has passed" do
create(:broadcast_message, :expired) create(:broadcast_message, :expired)
expect(BroadcastMessage.current).to be_nil expect(BroadcastMessage.current).to be_nil
......
...@@ -32,7 +32,7 @@ describe Ci::Build, models: true do ...@@ -32,7 +32,7 @@ describe Ci::Build, models: true do
end end
let(:create_from_build) { Ci::Build.create_from build } let(:create_from_build) { Ci::Build.create_from build }
it 'there should be a pending task' do it 'exists a pending task' do
expect(Ci::Build.pending.count(:all)).to eq 0 expect(Ci::Build.pending.count(:all)).to eq 0
create_from_build create_from_build
expect(Ci::Build.pending.count(:all)).to be > 0 expect(Ci::Build.pending.count(:all)).to be > 0
...@@ -573,19 +573,19 @@ describe Ci::Build, models: true do ...@@ -573,19 +573,19 @@ describe Ci::Build, models: true do
let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') } let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') }
let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') } let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') }
it 'to have no dependents if this is first build' do it 'expects to have no dependents if this is first build' do
expect(build.depends_on_builds).to be_empty expect(build.depends_on_builds).to be_empty
end end
it 'to have one dependent if this is test' do it 'expects to have one dependent if this is test' do
expect(rspec_test.depends_on_builds.map(&:id)).to contain_exactly(build.id) expect(rspec_test.depends_on_builds.map(&:id)).to contain_exactly(build.id)
end end
it 'to have all builds from build and test stage if this is last' do it 'expects to have all builds from build and test stage if this is last' do
expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, rspec_test.id, rubocop_test.id) expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, rspec_test.id, rubocop_test.id)
end end
it 'to have retried builds instead the original ones' do it 'expects to have retried builds instead the original ones' do
retried_rspec = Ci::Build.retry(rspec_test) retried_rspec = Ci::Build.retry(rspec_test)
expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, retried_rspec.id, rubocop_test.id) expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, retried_rspec.id, rubocop_test.id)
end end
...@@ -655,23 +655,23 @@ describe Ci::Build, models: true do ...@@ -655,23 +655,23 @@ describe Ci::Build, models: true do
describe 'build erasable' do describe 'build erasable' do
shared_examples 'erasable' do shared_examples 'erasable' do
it 'should remove artifact file' do it 'removes artifact file' do
expect(build.artifacts_file.exists?).to be_falsy expect(build.artifacts_file.exists?).to be_falsy
end end
it 'should remove artifact metadata file' do it 'removes artifact metadata file' do
expect(build.artifacts_metadata.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy
end end
it 'should erase build trace in trace file' do it 'erases build trace in trace file' do
expect(build.trace).to be_empty expect(build.trace).to be_empty
end end
it 'should set erased to true' do it 'sets erased to true' do
expect(build.erased?).to be true expect(build.erased?).to be true
end end
it 'should set erase date' do it 'sets erase date' do
expect(build.erased_at).not_to be_falsy expect(build.erased_at).not_to be_falsy
end end
end end
...@@ -704,7 +704,7 @@ describe Ci::Build, models: true do ...@@ -704,7 +704,7 @@ describe Ci::Build, models: true do
include_examples 'erasable' include_examples 'erasable'
it 'should record user who erased a build' do it 'records user who erased a build' do
expect(build.erased_by).to eq user expect(build.erased_by).to eq user
end end
end end
...@@ -714,7 +714,7 @@ describe Ci::Build, models: true do ...@@ -714,7 +714,7 @@ describe Ci::Build, models: true do
include_examples 'erasable' include_examples 'erasable'
it 'should not set user who erased a build' do it 'does not set user who erased a build' do
expect(build.erased_by).to be_nil expect(build.erased_by).to be_nil
end end
end end
...@@ -750,7 +750,7 @@ describe Ci::Build, models: true do ...@@ -750,7 +750,7 @@ describe Ci::Build, models: true do
end end
describe '#erase' do describe '#erase' do
it 'should not raise error' do it 'does not raise error' do
expect { build.erase }.not_to raise_error expect { build.erase }.not_to raise_error
end end
end end
...@@ -900,7 +900,7 @@ describe Ci::Build, models: true do ...@@ -900,7 +900,7 @@ describe Ci::Build, models: true do
context 'when build is running' do context 'when build is running' do
before { build.run! } before { build.run! }
it 'should return false' do it 'returns false' do
expect(build.retryable?).to be false expect(build.retryable?).to be false
end end
end end
...@@ -908,7 +908,7 @@ describe Ci::Build, models: true do ...@@ -908,7 +908,7 @@ describe Ci::Build, models: true do
context 'when build is finished' do context 'when build is finished' do
before { build.success! } before { build.success! }
it 'should return true' do it 'returns true' do
expect(build.retryable?).to be true expect(build.retryable?).to be true
end end
end end
......
...@@ -427,7 +427,7 @@ describe Ci::Pipeline, models: true do ...@@ -427,7 +427,7 @@ describe Ci::Pipeline, models: true do
end end
describe '#update_state' do describe '#update_state' do
it 'execute update_state after touching object' do it 'executes update_state after touching object' do
expect(pipeline).to receive(:update_state).and_return(true) expect(pipeline).to receive(:update_state).and_return(true)
pipeline.touch pipeline.touch
end end
...@@ -435,7 +435,7 @@ describe Ci::Pipeline, models: true do ...@@ -435,7 +435,7 @@ describe Ci::Pipeline, models: true do
context 'dependent objects' do context 'dependent objects' do
let(:commit_status) { build :commit_status, pipeline: pipeline } let(:commit_status) { build :commit_status, pipeline: pipeline }
it 'execute update_state after saving dependent object' do it 'executes update_state after saving dependent object' do
expect(pipeline).to receive(:update_state).and_return(true) expect(pipeline).to receive(:update_state).and_return(true)
commit_status.save commit_status.save
end end
......
...@@ -4,12 +4,12 @@ describe Ci::Trigger, models: true do ...@@ -4,12 +4,12 @@ describe Ci::Trigger, models: true do
let(:project) { FactoryGirl.create :empty_project } let(:project) { FactoryGirl.create :empty_project }
describe 'before_validation' do describe 'before_validation' do
it 'should set an random token if none provided' do it 'sets an random token if none provided' do
trigger = FactoryGirl.create :ci_trigger_without_token, project: project trigger = FactoryGirl.create :ci_trigger_without_token, project: project
expect(trigger.token).not_to be_nil expect(trigger.token).not_to be_nil
end end
it 'should not set an random token if one provided' do it 'does not set an random token if one provided' do
trigger = FactoryGirl.create :ci_trigger, project: project trigger = FactoryGirl.create :ci_trigger, project: project
expect(trigger.token).to eq('token') expect(trigger.token).to eq('token')
end end
......
...@@ -133,7 +133,7 @@ describe CommitStatus, models: true do ...@@ -133,7 +133,7 @@ describe CommitStatus, models: true do
@commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'success' @commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'success'
end end
it 'return unique statuses' do it 'returns unique statuses' do
is_expected.to eq([@commit4, @commit5]) is_expected.to eq([@commit4, @commit5])
end end
end end
...@@ -149,7 +149,7 @@ describe CommitStatus, models: true do ...@@ -149,7 +149,7 @@ describe CommitStatus, models: true do
@commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'ee', ref: nil, status: 'canceled' @commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'ee', ref: nil, status: 'canceled'
end end
it 'return statuses that are running or pending' do it 'returns statuses that are running or pending' do
is_expected.to eq([@commit1, @commit2]) is_expected.to eq([@commit1, @commit2])
end end
end end
...@@ -160,7 +160,7 @@ describe CommitStatus, models: true do ...@@ -160,7 +160,7 @@ describe CommitStatus, models: true do
context 'when no before_sha is set for pipeline' do context 'when no before_sha is set for pipeline' do
before { pipeline.before_sha = nil } before { pipeline.before_sha = nil }
it 'return blank sha' do it 'returns blank sha' do
is_expected.to eq(Gitlab::Git::BLANK_SHA) is_expected.to eq(Gitlab::Git::BLANK_SHA)
end end
end end
...@@ -169,7 +169,7 @@ describe CommitStatus, models: true do ...@@ -169,7 +169,7 @@ describe CommitStatus, models: true do
let(:value) { '1234' } let(:value) { '1234' }
before { pipeline.before_sha = value } before { pipeline.before_sha = value }
it 'return the set value' do it 'returns the set value' do
is_expected.to eq(value) is_expected.to eq(value)
end end
end end
...@@ -186,7 +186,7 @@ describe CommitStatus, models: true do ...@@ -186,7 +186,7 @@ describe CommitStatus, models: true do
context 'stages list' do context 'stages list' do
subject { CommitStatus.where(pipeline: pipeline).stages } subject { CommitStatus.where(pipeline: pipeline).stages }
it 'return ordered list of stages' do it 'returns ordered list of stages' do
is_expected.to eq(%w(build test deploy)) is_expected.to eq(%w(build test deploy))
end end
end end
...@@ -194,7 +194,7 @@ describe CommitStatus, models: true do ...@@ -194,7 +194,7 @@ describe CommitStatus, models: true do
context 'stages with statuses' do context 'stages with statuses' do
subject { CommitStatus.where(pipeline: pipeline).latest.stages_status } subject { CommitStatus.where(pipeline: pipeline).latest.stages_status }
it 'return list of stages with statuses' do it 'returns list of stages with statuses' do
is_expected.to eq({ is_expected.to eq({
'build' => 'failed', 'build' => 'failed',
'test' => 'success', 'test' => 'success',
......
...@@ -26,53 +26,53 @@ describe Milestone, 'Milestoneish' do ...@@ -26,53 +26,53 @@ describe Milestone, 'Milestoneish' do
end end
describe '#closed_items_count' do describe '#closed_items_count' do
it 'should not count confidential issues for non project members' do it 'does not count confidential issues for non project members' do
expect(milestone.closed_items_count(non_member)).to eq 2 expect(milestone.closed_items_count(non_member)).to eq 2
end end
it 'should not count confidential issues for project members with guest role' do it 'does not count confidential issues for project members with guest role' do
expect(milestone.closed_items_count(guest)).to eq 2 expect(milestone.closed_items_count(guest)).to eq 2
end end
it 'should count confidential issues for author' do it 'counts confidential issues for author' do
expect(milestone.closed_items_count(author)).to eq 4 expect(milestone.closed_items_count(author)).to eq 4
end end
it 'should count confidential issues for assignee' do it 'counts confidential issues for assignee' do
expect(milestone.closed_items_count(assignee)).to eq 4 expect(milestone.closed_items_count(assignee)).to eq 4
end end
it 'should count confidential issues for project members' do it 'counts confidential issues for project members' do
expect(milestone.closed_items_count(member)).to eq 6 expect(milestone.closed_items_count(member)).to eq 6
end end
it 'should count all issues for admin' do it 'counts all issues for admin' do
expect(milestone.closed_items_count(admin)).to eq 6 expect(milestone.closed_items_count(admin)).to eq 6
end end
end end
describe '#total_items_count' do describe '#total_items_count' do
it 'should not count confidential issues for non project members' do it 'does not count confidential issues for non project members' do
expect(milestone.total_items_count(non_member)).to eq 4 expect(milestone.total_items_count(non_member)).to eq 4
end end
it 'should not count confidential issues for project members with guest role' do it 'does not count confidential issues for project members with guest role' do
expect(milestone.total_items_count(guest)).to eq 4 expect(milestone.total_items_count(guest)).to eq 4
end end
it 'should count confidential issues for author' do it 'counts confidential issues for author' do
expect(milestone.total_items_count(author)).to eq 7 expect(milestone.total_items_count(author)).to eq 7
end end
it 'should count confidential issues for assignee' do it 'counts confidential issues for assignee' do
expect(milestone.total_items_count(assignee)).to eq 7 expect(milestone.total_items_count(assignee)).to eq 7
end end
it 'should count confidential issues for project members' do it 'counts confidential issues for project members' do
expect(milestone.total_items_count(member)).to eq 10 expect(milestone.total_items_count(member)).to eq 10
end end
it 'should count all issues for admin' do it 'counts all issues for admin' do
expect(milestone.total_items_count(admin)).to eq 10 expect(milestone.total_items_count(admin)).to eq 10
end end
end end
...@@ -91,27 +91,27 @@ describe Milestone, 'Milestoneish' do ...@@ -91,27 +91,27 @@ describe Milestone, 'Milestoneish' do
end end
describe '#percent_complete' do describe '#percent_complete' do
it 'should not count confidential issues for non project members' do it 'does not count confidential issues for non project members' do
expect(milestone.percent_complete(non_member)).to eq 50 expect(milestone.percent_complete(non_member)).to eq 50
end end
it 'should not count confidential issues for project members with guest role' do it 'does not count confidential issues for project members with guest role' do
expect(milestone.percent_complete(guest)).to eq 50 expect(milestone.percent_complete(guest)).to eq 50
end end
it 'should count confidential issues for author' do it 'counts confidential issues for author' do
expect(milestone.percent_complete(author)).to eq 57 expect(milestone.percent_complete(author)).to eq 57
end end
it 'should count confidential issues for assignee' do it 'counts confidential issues for assignee' do
expect(milestone.percent_complete(assignee)).to eq 57 expect(milestone.percent_complete(assignee)).to eq 57
end end
it 'should count confidential issues for project members' do it 'counts confidential issues for project members' do
expect(milestone.percent_complete(member)).to eq 60 expect(milestone.percent_complete(member)).to eq 60
end end
it 'should count confidential issues for admin' do it 'counts confidential issues for admin' do
expect(milestone.percent_complete(admin)).to eq 60 expect(milestone.percent_complete(admin)).to eq 60
end end
end end
......
...@@ -41,7 +41,7 @@ describe ApplicationSetting, 'TokenAuthenticatable' do ...@@ -41,7 +41,7 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
describe 'ensured! token' do describe 'ensured! token' do
subject { described_class.new.send("ensure_#{token_field}!") } subject { described_class.new.send("ensure_#{token_field}!") }
it 'should persist new token' do it 'persists new token' do
expect(subject).to eq described_class.current[token_field] expect(subject).to eq described_class.current[token_field]
end end
end end
......
...@@ -9,11 +9,11 @@ describe ForkedProjectLink, "add link on fork" do ...@@ -9,11 +9,11 @@ describe ForkedProjectLink, "add link on fork" do
@project_to = fork_project(project_from, user) @project_to = fork_project(project_from, user)
end end
it "project_to should know it is forked" do it "project_to knows it is forked" do
expect(@project_to.forked?).to be_truthy expect(@project_to.forked?).to be_truthy
end end
it "project should know who it is forked from" do it "project knows who it is forked from" do
expect(@project_to.forked_from_project).to eq(project_from) expect(@project_to.forked_from_project).to eq(project_from)
end end
end end
...@@ -29,15 +29,15 @@ describe '#forked?' do ...@@ -29,15 +29,15 @@ describe '#forked?' do
forked_project_link.save! forked_project_link.save!
end end
it "project_to should know it is forked" do it "project_to knows it is forked" do
expect(project_to.forked?).to be_truthy expect(project_to.forked?).to be_truthy
end end
it "project_from should not be forked" do it "project_from is not forked" do
expect(project_from.forked?).to be_falsey expect(project_from.forked?).to be_falsey
end end
it "project_to.destroy should destroy fork_link" do it "project_to.destroy destroys fork_link" do
expect(forked_project_link).to receive(:destroy) expect(forked_project_link).to receive(:destroy)
project_to.destroy project_to.destroy
end end
......
...@@ -29,15 +29,15 @@ describe GlobalMilestone, models: true do ...@@ -29,15 +29,15 @@ describe GlobalMilestone, models: true do
@global_milestones = GlobalMilestone.build_collection(milestones) @global_milestones = GlobalMilestone.build_collection(milestones)
end end
it 'should have all project milestones' do it 'has all project milestones' do
expect(@global_milestones.count).to eq(2) expect(@global_milestones.count).to eq(2)
end end
it 'should have all project milestones titles' do it 'has all project milestones titles' do
expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123']) expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123'])
end end
it 'should have all project milestones' do it 'has all project milestones' do
expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6) expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
end end
end end
...@@ -54,11 +54,11 @@ describe GlobalMilestone, models: true do ...@@ -54,11 +54,11 @@ describe GlobalMilestone, models: true do
@global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones) @global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones)
end end
it 'should have exactly one group milestone' do it 'has exactly one group milestone' do
expect(@global_milestone.title).to eq('Milestone v1.2') expect(@global_milestone.title).to eq('Milestone v1.2')
end end
it 'should have all project milestones with the same title' do it 'has all project milestones with the same title' do
expect(@global_milestone.milestones.count).to eq(3) expect(@global_milestone.milestones.count).to eq(3)
end end
end end
...@@ -66,7 +66,7 @@ describe GlobalMilestone, models: true do ...@@ -66,7 +66,7 @@ describe GlobalMilestone, models: true do
describe '#safe_title' do describe '#safe_title' do
let(:milestone) { create(:milestone, title: "git / test", project: project1) } let(:milestone) { create(:milestone, title: "git / test", project: project1) }
it 'should strip out slashes and spaces' do it 'strips out slashes and spaces' do
global_milestone = GlobalMilestone.new(milestone.title, [milestone]) global_milestone = GlobalMilestone.new(milestone.title, [milestone])
expect(global_milestone.safe_title).to eq('git-test') expect(global_milestone.safe_title).to eq('git-test')
......
...@@ -116,7 +116,7 @@ describe Group, models: true do ...@@ -116,7 +116,7 @@ describe Group, models: true do
let(:user) { create(:user) } let(:user) { create(:user) }
before { group.add_users([user.id], GroupMember::GUEST) } before { group.add_users([user.id], GroupMember::GUEST) }
it "should update the group permission" do it "updates the group permission" do
expect(group.group_members.guests.map(&:user)).to include(user) expect(group.group_members.guests.map(&:user)).to include(user)
group.add_users([user.id], GroupMember::DEVELOPER) group.add_users([user.id], GroupMember::DEVELOPER)
expect(group.group_members.developers.map(&:user)).to include(user) expect(group.group_members.developers.map(&:user)).to include(user)
...@@ -128,12 +128,12 @@ describe Group, models: true do ...@@ -128,12 +128,12 @@ describe Group, models: true do
let(:user) { create(:user) } let(:user) { create(:user) }
before { group.add_user(user, GroupMember::MASTER) } before { group.add_user(user, GroupMember::MASTER) }
it "should be true if avatar is image" do it "is true if avatar is image" do
group.update_attribute(:avatar, 'uploads/avatar.png') group.update_attribute(:avatar, 'uploads/avatar.png')
expect(group.avatar_type).to be_truthy expect(group.avatar_type).to be_truthy
end end
it "should be false if avatar is html page" do it "is false if avatar is html page" do
group.update_attribute(:avatar, 'uploads/avatar.html') group.update_attribute(:avatar, 'uploads/avatar.html')
expect(group.avatar_type).to eq(["only images allowed"]) expect(group.avatar_type).to eq(["only images allowed"])
end end
......
...@@ -24,7 +24,7 @@ describe ProjectHook, models: true do ...@@ -24,7 +24,7 @@ describe ProjectHook, models: true do
end end
describe '.push_hooks' do describe '.push_hooks' do
it 'should return hooks for push events only' do it 'returns hooks for push events only' do
hook = create(:project_hook, push_events: true) hook = create(:project_hook, push_events: true)
create(:project_hook, push_events: false) create(:project_hook, push_events: false)
expect(ProjectHook.push_hooks).to eq([hook]) expect(ProjectHook.push_hooks).to eq([hook])
...@@ -32,7 +32,7 @@ describe ProjectHook, models: true do ...@@ -32,7 +32,7 @@ describe ProjectHook, models: true do
end end
describe '.tag_push_hooks' do describe '.tag_push_hooks' do
it 'should return hooks for tag push events only' do it 'returns hooks for tag push events only' do
hook = create(:project_hook, tag_push_events: true) hook = create(:project_hook, tag_push_events: true)
create(:project_hook, tag_push_events: false) create(:project_hook, tag_push_events: false)
expect(ProjectHook.tag_push_hooks).to eq([hook]) expect(ProjectHook.tag_push_hooks).to eq([hook])
......
...@@ -73,13 +73,13 @@ describe Key, models: true do ...@@ -73,13 +73,13 @@ describe Key, models: true do
end end
context 'callbacks' do context 'callbacks' do
it 'should add new key to authorized_file' do it 'adds new key to authorized_file' do
@key = build(:personal_key, id: 7) @key = build(:personal_key, id: 7)
expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, @key.shell_id, @key.key) expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, @key.shell_id, @key.key)
@key.save @key.save
end end
it 'should remove key from authorized_file' do it 'removes key from authorized_file' do
@key = create(:personal_key) @key = create(:personal_key)
expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, @key.shell_id, @key.key) expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, @key.shell_id, @key.key)
@key.destroy @key.destroy
......
...@@ -18,7 +18,7 @@ describe Label, models: true do ...@@ -18,7 +18,7 @@ describe Label, models: true do
describe 'validation' do describe 'validation' do
it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:project) }
it 'should validate color code' do it 'validates color code' do
expect(label).not_to allow_value('G-ITLAB').for(:color) expect(label).not_to allow_value('G-ITLAB').for(:color)
expect(label).not_to allow_value('AABBCC').for(:color) expect(label).not_to allow_value('AABBCC').for(:color)
expect(label).not_to allow_value('#AABBCCEE').for(:color) expect(label).not_to allow_value('#AABBCCEE').for(:color)
...@@ -30,7 +30,7 @@ describe Label, models: true do ...@@ -30,7 +30,7 @@ describe Label, models: true do
expect(label).to allow_value('#abcdef').for(:color) expect(label).to allow_value('#abcdef').for(:color)
end end
it 'should validate title' do it 'validates title' do
expect(label).not_to allow_value('G,ITLAB').for(:title) expect(label).not_to allow_value('G,ITLAB').for(:title)
expect(label).not_to allow_value('').for(:title) expect(label).not_to allow_value('').for(:title)
......
...@@ -5,12 +5,12 @@ describe LegacyDiffNote, models: true do ...@@ -5,12 +5,12 @@ describe LegacyDiffNote, models: true do
let!(:note) { create(:legacy_diff_note_on_commit, note: "+1 from me") } let!(:note) { create(:legacy_diff_note_on_commit, note: "+1 from me") }
let!(:commit) { note.noteable } let!(:commit) { note.noteable }
it "should save a valid note" do it "saves a valid note" do
expect(note.commit_id).to eq(commit.id) expect(note.commit_id).to eq(commit.id)
expect(note.noteable.id).to eq(commit.id) expect(note.noteable.id).to eq(commit.id)
end end
it "should be recognized by #legacy_diff_note?" do it "is recognized by #legacy_diff_note?" do
expect(note).to be_legacy_diff_note expect(note).to be_legacy_diff_note
end end
end end
......
...@@ -22,7 +22,7 @@ require 'spec_helper' ...@@ -22,7 +22,7 @@ require 'spec_helper'
describe GroupMember, models: true do describe GroupMember, models: true do
describe 'notifications' do describe 'notifications' do
describe "#after_create" do describe "#after_create" do
it "should send email to user" do it "sends email to user" do
membership = build(:group_member) membership = build(:group_member)
allow(membership).to receive(:notification_service). allow(membership).to receive(:notification_service).
...@@ -40,7 +40,7 @@ describe GroupMember, models: true do ...@@ -40,7 +40,7 @@ describe GroupMember, models: true do
and_return(double('NotificationService').as_null_object) and_return(double('NotificationService').as_null_object)
end end
it "should send email to user" do it "sends email to user" do
expect(@group_member).to receive(:notification_service) expect(@group_member).to receive(:notification_service)
@group_member.update_attribute(:access_level, GroupMember::MASTER) @group_member.update_attribute(:access_level, GroupMember::MASTER)
end end
......
...@@ -52,7 +52,7 @@ describe ProjectMember, models: true do ...@@ -52,7 +52,7 @@ describe ProjectMember, models: true do
master_todos master_todos
end end
it "destroy itself and delete associated todos" do it "destroys itself and delete associated todos" do
expect(owner.user.todos.size).to eq(2) expect(owner.user.todos.size).to eq(2)
expect(master.user.todos.size).to eq(3) expect(master.user.todos.size).to eq(3)
expect(Todo.count).to eq(5) expect(Todo.count).to eq(5)
......
...@@ -188,12 +188,12 @@ describe MergeRequest, models: true do ...@@ -188,12 +188,12 @@ describe MergeRequest, models: true do
create(:note, noteable: merge_request, project: merge_request.project) create(:note, noteable: merge_request, project: merge_request.project)
end end
it "should include notes for commits" do it "includes notes for commits" do
expect(merge_request.commits).not_to be_empty expect(merge_request.commits).not_to be_empty
expect(merge_request.mr_and_commit_notes.count).to eq(2) expect(merge_request.mr_and_commit_notes.count).to eq(2)
end end
it "should include notes for commits from target project as well" do it "includes notes for commits from target project as well" do
create(:note_on_commit, commit_id: merge_request.commits.first.id, create(:note_on_commit, commit_id: merge_request.commits.first.id,
project: merge_request.target_project) project: merge_request.target_project)
...@@ -304,7 +304,7 @@ describe MergeRequest, models: true do ...@@ -304,7 +304,7 @@ describe MergeRequest, models: true do
expect(subject.can_remove_source_branch?(user)).to be_falsey expect(subject.can_remove_source_branch?(user)).to be_falsey
end end
it "cant remove a root ref" do it "can't remove a root ref" do
subject.source_branch = "master" subject.source_branch = "master"
subject.target_branch = "feature" subject.target_branch = "feature"
......
...@@ -28,12 +28,12 @@ describe Milestone, models: true do ...@@ -28,12 +28,12 @@ describe Milestone, models: true do
end end
describe "unique milestone title per project" do describe "unique milestone title per project" do
it "shouldn't accept the same title in a project twice" do it "does not accept the same title in a project twice" do
new_milestone = Milestone.new(project: milestone.project, title: milestone.title) new_milestone = Milestone.new(project: milestone.project, title: milestone.title)
expect(new_milestone).not_to be_valid expect(new_milestone).not_to be_valid
end end
it "should accept the same title in another project" do it "accepts the same title in another project" do
project = build(:project) project = build(:project)
new_milestone = Milestone.new(project: project, title: milestone.title) new_milestone = Milestone.new(project: project, title: milestone.title)
...@@ -42,29 +42,29 @@ describe Milestone, models: true do ...@@ -42,29 +42,29 @@ describe Milestone, models: true do
end end
describe "#percent_complete" do describe "#percent_complete" do
it "should not count open issues" do it "does not count open issues" do
milestone.issues << issue milestone.issues << issue
expect(milestone.percent_complete(user)).to eq(0) expect(milestone.percent_complete(user)).to eq(0)
end end
it "should count closed issues" do it "counts closed issues" do
issue.close issue.close
milestone.issues << issue milestone.issues << issue
expect(milestone.percent_complete(user)).to eq(100) expect(milestone.percent_complete(user)).to eq(100)
end end
it "should recover from dividing by zero" do it "recovers from dividing by zero" do
expect(milestone.percent_complete(user)).to eq(0) expect(milestone.percent_complete(user)).to eq(0)
end end
end end
describe "#expires_at" do describe "#expires_at" do
it "should be nil when due_date is unset" do it "is nil when due_date is unset" do
milestone.update_attributes(due_date: nil) milestone.update_attributes(due_date: nil)
expect(milestone.expires_at).to be_nil expect(milestone.expires_at).to be_nil
end end
it "should not be nil when due_date is set" do it "is not nil when due_date is set" do
milestone.update_attributes(due_date: Date.tomorrow) milestone.update_attributes(due_date: Date.tomorrow)
expect(milestone.expires_at).to be_present expect(milestone.expires_at).to be_present
end end
...@@ -121,7 +121,7 @@ describe Milestone, models: true do ...@@ -121,7 +121,7 @@ describe Milestone, models: true do
create :merge_request, milestone: milestone create :merge_request, milestone: milestone
end end
it 'Should return total count of issues and merge requests assigned to milestone' do it 'returns total count of issues and merge requests assigned to milestone' do
expect(milestone.total_items_count(user)).to eq 2 expect(milestone.total_items_count(user)).to eq 2
end end
end end
...@@ -134,11 +134,11 @@ describe Milestone, models: true do ...@@ -134,11 +134,11 @@ describe Milestone, models: true do
create :issue create :issue
end end
it 'should be true if milestone active and all nested issues closed' do it 'returns true if milestone active and all nested issues closed' do
expect(milestone.can_be_closed?).to be_truthy expect(milestone.can_be_closed?).to be_truthy
end end
it 'should be false if milestone active and not all nested issues closed' do it 'returns false if milestone active and not all nested issues closed' do
issue.milestone = milestone issue.milestone = milestone
issue.save issue.save
......
...@@ -61,11 +61,11 @@ describe Namespace, models: true do ...@@ -61,11 +61,11 @@ describe Namespace, models: true do
allow(@namespace).to receive(:path_changed?).and_return(true) allow(@namespace).to receive(:path_changed?).and_return(true)
end end
it "should raise error when directory exists" do it "raises error when directory exists" do
expect { @namespace.move_dir }.to raise_error("namespace directory cannot be moved") expect { @namespace.move_dir }.to raise_error("namespace directory cannot be moved")
end end
it "should move dir if path changed" do it "moves dir if path changed" do
new_path = @namespace.path + "_new" new_path = @namespace.path + "_new"
allow(@namespace).to receive(:path_was).and_return(@namespace.path) allow(@namespace).to receive(:path_was).and_return(@namespace.path)
allow(@namespace).to receive(:path).and_return(new_path) allow(@namespace).to receive(:path).and_return(new_path)
...@@ -93,7 +93,7 @@ describe Namespace, models: true do ...@@ -93,7 +93,7 @@ describe Namespace, models: true do
before { namespace.destroy } before { namespace.destroy }
it "should remove its dirs when deleted" do it "removes its dirs when deleted" do
expect(File.exist?(path)).to be(false) expect(File.exist?(path)).to be(false)
end end
end end
......
...@@ -56,18 +56,18 @@ describe Note, models: true do ...@@ -56,18 +56,18 @@ describe Note, models: true do
let!(:note) { create(:note_on_commit, note: "+1 from me") } let!(:note) { create(:note_on_commit, note: "+1 from me") }
let!(:commit) { note.noteable } let!(:commit) { note.noteable }
it "should be accessible through #noteable" do it "is accessible through #noteable" do
expect(note.commit_id).to eq(commit.id) expect(note.commit_id).to eq(commit.id)
expect(note.noteable).to be_a(Commit) expect(note.noteable).to be_a(Commit)
expect(note.noteable).to eq(commit) expect(note.noteable).to eq(commit)
end end
it "should save a valid note" do it "saves a valid note" do
expect(note.commit_id).to eq(commit.id) expect(note.commit_id).to eq(commit.id)
note.noteable == commit note.noteable == commit
end end
it "should be recognized by #for_commit?" do it "is recognized by #for_commit?" do
expect(note).to be_for_commit expect(note).to be_for_commit
end end
......
...@@ -21,7 +21,7 @@ describe Project, models: true do ...@@ -21,7 +21,7 @@ describe Project, models: true do
let(:owner_actions) { Ability.project_owner_rules } let(:owner_actions) { Ability.project_owner_rules }
describe "Non member rules" do describe "Non member rules" do
it "should deny for non-project users any actions" do it "denies for non-project users any actions" do
owner_actions.each do |action| owner_actions.each do |action|
expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey
end end
...@@ -33,7 +33,7 @@ describe Project, models: true do ...@@ -33,7 +33,7 @@ describe Project, models: true do
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST) @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST)
end end
it "should allow for project user any guest actions" do it "allows for project user any guest actions" do
guest_actions.each do |action| guest_actions.each do |action|
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
end end
...@@ -45,7 +45,7 @@ describe Project, models: true do ...@@ -45,7 +45,7 @@ describe Project, models: true do
@p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER) @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER)
end end
it "should allow for project user any report actions" do it "allows for project user any report actions" do
report_actions.each do |action| report_actions.each do |action|
expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy
end end
...@@ -58,13 +58,13 @@ describe Project, models: true do ...@@ -58,13 +58,13 @@ describe Project, models: true do
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER) @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER)
end end
it "should deny for developer master-specific actions" do it "denies for developer master-specific actions" do
[dev_actions - report_actions].each do |action| [dev_actions - report_actions].each do |action|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end end
end end
it "should allow for project user any dev actions" do it "allows for project user any dev actions" do
dev_actions.each do |action| dev_actions.each do |action|
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
end end
...@@ -77,13 +77,13 @@ describe Project, models: true do ...@@ -77,13 +77,13 @@ describe Project, models: true do
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER) @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
end end
it "should deny for developer master-specific actions" do it "denies for developer master-specific actions" do
[master_actions - dev_actions].each do |action| [master_actions - dev_actions].each do |action|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end end
end end
it "should allow for project user any master actions" do it "allows for project user any master actions" do
master_actions.each do |action| master_actions.each do |action|
expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy
end end
...@@ -96,13 +96,13 @@ describe Project, models: true do ...@@ -96,13 +96,13 @@ describe Project, models: true do
@p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER) @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER)
end end
it "should deny for masters admin-specific actions" do it "denies for masters admin-specific actions" do
[owner_actions - master_actions].each do |action| [owner_actions - master_actions].each do |action|
expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey
end end
end end
it "should allow for project owner any admin actions" do it "allows for project owner any admin actions" do
owner_actions.each do |action| owner_actions.each do |action|
expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy
end end
......
...@@ -65,7 +65,7 @@ describe AsanaService, models: true do ...@@ -65,7 +65,7 @@ describe AsanaService, models: true do
) )
end end
it 'should call Asana service to create a story' do it 'calls Asana service to create a story' do
data = create_data_for_commits('Message from commit. related to #123456') data = create_data_for_commits('Message from commit. related to #123456')
expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.name_with_namespace} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}" expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.name_with_namespace} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}"
...@@ -76,7 +76,7 @@ describe AsanaService, models: true do ...@@ -76,7 +76,7 @@ describe AsanaService, models: true do
@asana.execute(data) @asana.execute(data)
end end
it 'should call Asana service to create a story and close a task' do it 'calls Asana service to create a story and close a task' do
data = create_data_for_commits('fix #456789') data = create_data_for_commits('fix #456789')
d1 = double('Asana::Task') d1 = double('Asana::Task')
expect(d1).to receive(:add_comment) expect(d1).to receive(:add_comment)
...@@ -86,7 +86,7 @@ describe AsanaService, models: true do ...@@ -86,7 +86,7 @@ describe AsanaService, models: true do
@asana.execute(data) @asana.execute(data)
end end
it 'should be able to close via url' do it 'is able to close via url' do
data = create_data_for_commits('closes https://app.asana.com/19292/956299/42') data = create_data_for_commits('closes https://app.asana.com/19292/956299/42')
d1 = double('Asana::Task') d1 = double('Asana::Task')
expect(d1).to receive(:add_comment) expect(d1).to receive(:add_comment)
...@@ -96,7 +96,7 @@ describe AsanaService, models: true do ...@@ -96,7 +96,7 @@ describe AsanaService, models: true do
@asana.execute(data) @asana.execute(data)
end end
it 'should allow multiple matches per line' do it 'allows multiple matches per line' do
message = <<-EOF message = <<-EOF
minor bigfix, refactoring, fixed #123 and Closes #456 work on #789 minor bigfix, refactoring, fixed #123 and Closes #456 work on #789
ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12 ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12
......
...@@ -44,7 +44,7 @@ describe AssemblaService, models: true do ...@@ -44,7 +44,7 @@ describe AssemblaService, models: true do
WebMock.stub_request(:post, @api_url) WebMock.stub_request(:post, @api_url)
end end
it "should call Assembla API" do it "calls Assembla API" do
@assembla_service.execute(@sample_data) @assembla_service.execute(@sample_data)
expect(WebMock).to have_requested(:post, @api_url).with( expect(WebMock).to have_requested(:post, @api_url).with(
body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
......
...@@ -56,7 +56,7 @@ describe ExternalWikiService, models: true do ...@@ -56,7 +56,7 @@ describe ExternalWikiService, models: true do
@service.destroy! @service.destroy!
end end
it 'should replace the wiki url' do it 'replaces the wiki url' do
wiki_path = get_project_wiki_path(project) wiki_path = get_project_wiki_path(project)
expect(wiki_path).to match('https://gitlab.com') expect(wiki_path).to match('https://gitlab.com')
end end
......
...@@ -57,7 +57,7 @@ describe FlowdockService, models: true do ...@@ -57,7 +57,7 @@ describe FlowdockService, models: true do
WebMock.stub_request(:post, @api_url) WebMock.stub_request(:post, @api_url)
end end
it "should call FlowDock API" do it "calls FlowDock API" do
@flowdock_service.execute(@sample_data) @flowdock_service.execute(@sample_data)
@sample_data[:commits].each do |commit| @sample_data[:commits].each do |commit|
# One request to Flowdock per new commit # One request to Flowdock per new commit
......
...@@ -57,7 +57,7 @@ describe GemnasiumService, models: true do ...@@ -57,7 +57,7 @@ describe GemnasiumService, models: true do
) )
@sample_data = Gitlab::PushDataBuilder.build_sample(project, user) @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
end end
it "should call Gemnasium service" do it "calls Gemnasium service" do
expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once
@gemnasium_service.execute(@sample_data) @gemnasium_service.execute(@sample_data)
end end
......
...@@ -54,7 +54,7 @@ describe GitlabIssueTrackerService, models: true do ...@@ -54,7 +54,7 @@ describe GitlabIssueTrackerService, models: true do
@service.destroy! @service.destroy!
end end
it 'should give the correct path' do it 'gives the correct path' do
expect(@service.project_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues") expect(@service.project_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues")
expect(@service.new_issue_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/new") expect(@service.new_issue_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/new")
expect(@service.issue_url(432)).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/432") expect(@service.issue_url(432)).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/432")
...@@ -71,7 +71,7 @@ describe GitlabIssueTrackerService, models: true do ...@@ -71,7 +71,7 @@ describe GitlabIssueTrackerService, models: true do
@service.destroy! @service.destroy!
end end
it 'should give the correct path' do it 'gives the correct path' do
expect(@service.project_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues") expect(@service.project_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues")
expect(@service.new_issue_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues/new") expect(@service.new_issue_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues/new")
expect(@service.issue_path(432)).to eq("/gitlab/root/#{project.path_with_namespace}/issues/432") expect(@service.issue_path(432)).to eq("/gitlab/root/#{project.path_with_namespace}/issues/432")
......
...@@ -61,7 +61,7 @@ describe HipchatService, models: true do ...@@ -61,7 +61,7 @@ describe HipchatService, models: true do
WebMock.stub_request(:post, api_url) WebMock.stub_request(:post, api_url)
end end
it 'should test and return errors' do it 'tests and return errors' do
allow(hipchat).to receive(:execute).and_raise(StandardError, 'no such room') allow(hipchat).to receive(:execute).and_raise(StandardError, 'no such room')
result = hipchat.test(push_sample_data) result = hipchat.test(push_sample_data)
...@@ -69,7 +69,7 @@ describe HipchatService, models: true do ...@@ -69,7 +69,7 @@ describe HipchatService, models: true do
expect(result[:result].to_s).to eq('no such room') expect(result[:result].to_s).to eq('no such room')
end end
it 'should use v1 if version is provided' do it 'uses v1 if version is provided' do
allow(hipchat).to receive(:api_version).and_return('v1') allow(hipchat).to receive(:api_version).and_return('v1')
expect(HipChat::Client).to receive(:new).with( expect(HipChat::Client).to receive(:new).with(
token, token,
...@@ -79,7 +79,7 @@ describe HipchatService, models: true do ...@@ -79,7 +79,7 @@ describe HipchatService, models: true do
hipchat.execute(push_sample_data) hipchat.execute(push_sample_data)
end end
it 'should use v2 as the version when nothing is provided' do it 'uses v2 as the version when nothing is provided' do
allow(hipchat).to receive(:api_version).and_return('') allow(hipchat).to receive(:api_version).and_return('')
expect(HipChat::Client).to receive(:new).with( expect(HipChat::Client).to receive(:new).with(
token, token,
...@@ -90,13 +90,13 @@ describe HipchatService, models: true do ...@@ -90,13 +90,13 @@ describe HipchatService, models: true do
end end
context 'push events' do context 'push events' do
it "should call Hipchat API for push events" do it "calls Hipchat API for push events" do
hipchat.execute(push_sample_data) hipchat.execute(push_sample_data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should create a push message" do it "creates a push message" do
message = hipchat.send(:create_push_message, push_sample_data) message = hipchat.send(:create_push_message, push_sample_data)
push_sample_data[:object_attributes] push_sample_data[:object_attributes]
...@@ -110,13 +110,13 @@ describe HipchatService, models: true do ...@@ -110,13 +110,13 @@ describe HipchatService, models: true do
context 'tag_push events' do context 'tag_push events' do
let(:push_sample_data) { Gitlab::PushDataBuilder.build(project, user, Gitlab::Git::BLANK_SHA, '1' * 40, 'refs/tags/test', []) } let(:push_sample_data) { Gitlab::PushDataBuilder.build(project, user, Gitlab::Git::BLANK_SHA, '1' * 40, 'refs/tags/test', []) }
it "should call Hipchat API for tag push events" do it "calls Hipchat API for tag push events" do
hipchat.execute(push_sample_data) hipchat.execute(push_sample_data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should create a tag push message" do it "creates a tag push message" do
message = hipchat.send(:create_push_message, push_sample_data) message = hipchat.send(:create_push_message, push_sample_data)
push_sample_data[:object_attributes] push_sample_data[:object_attributes]
...@@ -131,13 +131,13 @@ describe HipchatService, models: true do ...@@ -131,13 +131,13 @@ describe HipchatService, models: true do
let(:issue_service) { Issues::CreateService.new(project, user) } let(:issue_service) { Issues::CreateService.new(project, user) }
let(:issues_sample_data) { issue_service.hook_data(issue, 'open') } let(:issues_sample_data) { issue_service.hook_data(issue, 'open') }
it "should call Hipchat API for issue events" do it "calls Hipchat API for issue events" do
hipchat.execute(issues_sample_data) hipchat.execute(issues_sample_data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should create an issue message" do it "creates an issue message" do
message = hipchat.send(:create_issue_message, issues_sample_data) message = hipchat.send(:create_issue_message, issues_sample_data)
obj_attr = issues_sample_data[:object_attributes] obj_attr = issues_sample_data[:object_attributes]
...@@ -154,13 +154,13 @@ describe HipchatService, models: true do ...@@ -154,13 +154,13 @@ describe HipchatService, models: true do
let(:merge_service) { MergeRequests::CreateService.new(project, user) } let(:merge_service) { MergeRequests::CreateService.new(project, user) }
let(:merge_sample_data) { merge_service.hook_data(merge_request, 'open') } let(:merge_sample_data) { merge_service.hook_data(merge_request, 'open') }
it "should call Hipchat API for merge requests events" do it "calls Hipchat API for merge requests events" do
hipchat.execute(merge_sample_data) hipchat.execute(merge_sample_data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should create a merge request message" do it "creates a merge request message" do
message = hipchat.send(:create_merge_request_message, message = hipchat.send(:create_merge_request_message,
merge_sample_data) merge_sample_data)
...@@ -184,7 +184,7 @@ describe HipchatService, models: true do ...@@ -184,7 +184,7 @@ describe HipchatService, models: true do
note: 'a comment on a commit') note: 'a comment on a commit')
end end
it "should call Hipchat API for commit comment events" do it "calls Hipchat API for commit comment events" do
data = Gitlab::NoteDataBuilder.build(commit_note, user) data = Gitlab::NoteDataBuilder.build(commit_note, user)
hipchat.execute(data) hipchat.execute(data)
...@@ -216,7 +216,7 @@ describe HipchatService, models: true do ...@@ -216,7 +216,7 @@ describe HipchatService, models: true do
note: "merge request note") note: "merge request note")
end end
it "should call Hipchat API for merge request comment events" do it "calls Hipchat API for merge request comment events" do
data = Gitlab::NoteDataBuilder.build(merge_request_note, user) data = Gitlab::NoteDataBuilder.build(merge_request_note, user)
hipchat.execute(data) hipchat.execute(data)
...@@ -243,7 +243,7 @@ describe HipchatService, models: true do ...@@ -243,7 +243,7 @@ describe HipchatService, models: true do
note: "issue note") note: "issue note")
end end
it "should call Hipchat API for issue comment events" do it "calls Hipchat API for issue comment events" do
data = Gitlab::NoteDataBuilder.build(issue_note, user) data = Gitlab::NoteDataBuilder.build(issue_note, user)
hipchat.execute(data) hipchat.execute(data)
...@@ -269,7 +269,7 @@ describe HipchatService, models: true do ...@@ -269,7 +269,7 @@ describe HipchatService, models: true do
note: "snippet note") note: "snippet note")
end end
it "should call Hipchat API for snippet comment events" do it "calls Hipchat API for snippet comment events" do
data = Gitlab::NoteDataBuilder.build(snippet_note, user) data = Gitlab::NoteDataBuilder.build(snippet_note, user)
hipchat.execute(data) hipchat.execute(data)
...@@ -297,13 +297,13 @@ describe HipchatService, models: true do ...@@ -297,13 +297,13 @@ describe HipchatService, models: true do
context 'for failed' do context 'for failed' do
before { build.drop } before { build.drop }
it "should call Hipchat API" do it "calls Hipchat API" do
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should create a build message" do it "creates a build message" do
message = hipchat.send(:create_build_message, data) message = hipchat.send(:create_build_message, data)
project_url = project.web_url project_url = project.web_url
...@@ -325,13 +325,13 @@ describe HipchatService, models: true do ...@@ -325,13 +325,13 @@ describe HipchatService, models: true do
build.success build.success
end end
it "should call Hipchat API" do it "calls Hipchat API" do
hipchat.notify_only_broken_builds = false hipchat.notify_only_broken_builds = false
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
end end
it "should notify only broken" do it "notifies only broken" do
hipchat.notify_only_broken_builds = true hipchat.notify_only_broken_builds = true
hipchat.execute(data) hipchat.execute(data)
expect(WebMock).not_to have_requested(:post, api_url).once expect(WebMock).not_to have_requested(:post, api_url).once
......
...@@ -71,7 +71,7 @@ describe IrkerService, models: true do ...@@ -71,7 +71,7 @@ describe IrkerService, models: true do
@irker_server.close @irker_server.close
end end
it 'should send valid JSON messages to an Irker listener' do it 'sends valid JSON messages to an Irker listener' do
irker.execute(sample_data) irker.execute(sample_data)
conn = @irker_server.accept conn = @irker_server.accept
......
...@@ -75,7 +75,7 @@ describe JiraService, models: true do ...@@ -75,7 +75,7 @@ describe JiraService, models: true do
WebMock.stub_request(:post, @comment_url) WebMock.stub_request(:post, @comment_url)
end end
it "should call JIRA API" do it "calls JIRA API" do
@jira_service.execute(merge_request, @jira_service.execute(merge_request,
ExternalIssue.new("JIRA-123", project)) ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with( expect(WebMock).to have_requested(:post, @comment_url).with(
...@@ -128,7 +128,7 @@ describe JiraService, models: true do ...@@ -128,7 +128,7 @@ describe JiraService, models: true do
expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2") expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2")
end end
it "should reset password if url changed, even if setter called multiple times" do it "resets password if url changed, even if setter called multiple times" do
@jira_service.api_url = 'http://jira1.example.com/rest/api/2' @jira_service.api_url = 'http://jira1.example.com/rest/api/2'
@jira_service.api_url = 'http://jira1.example.com/rest/api/2' @jira_service.api_url = 'http://jira1.example.com/rest/api/2'
@jira_service.save @jira_service.save
...@@ -181,7 +181,7 @@ describe JiraService, models: true do ...@@ -181,7 +181,7 @@ describe JiraService, models: true do
@service.destroy! @service.destroy!
end end
it 'should be initialized' do it 'is initialized' do
expect(@service.title).to eq('JIRA') expect(@service.title).to eq('JIRA')
expect(@service.description).to eq("Jira issue tracker") expect(@service.description).to eq("Jira issue tracker")
end end
...@@ -197,7 +197,7 @@ describe JiraService, models: true do ...@@ -197,7 +197,7 @@ describe JiraService, models: true do
@service.destroy! @service.destroy!
end end
it "should be correct" do it "is correct" do
expect(@service.title).to eq('Jira One') expect(@service.title).to eq('Jira One')
expect(@service.description).to eq('Jira One issue tracker') expect(@service.description).to eq('Jira One issue tracker')
end end
...@@ -225,7 +225,7 @@ describe JiraService, models: true do ...@@ -225,7 +225,7 @@ describe JiraService, models: true do
@service.destroy! @service.destroy!
end end
it 'should be prepopulated with the settings' do it 'is prepopulated with the settings' do
expect(@service.properties["project_url"]).to eq('http://jira.sample/projects/project_a') expect(@service.properties["project_url"]).to eq('http://jira.sample/projects/project_a')
expect(@service.properties["issues_url"]).to eq("http://jira.sample/issues/:id") expect(@service.properties["issues_url"]).to eq("http://jira.sample/issues/:id")
expect(@service.properties["new_issue_url"]).to eq("http://jira.sample/projects/project_a/issues/new") expect(@service.properties["new_issue_url"]).to eq("http://jira.sample/projects/project_a/issues/new")
......
...@@ -72,7 +72,7 @@ describe PushoverService, models: true do ...@@ -72,7 +72,7 @@ describe PushoverService, models: true do
WebMock.stub_request(:post, api_url) WebMock.stub_request(:post, api_url)
end end
it 'should call Pushover API' do it 'calls Pushover API' do
pushover.execute(sample_data) pushover.execute(sample_data)
expect(WebMock).to have_requested(:post, api_url).once expect(WebMock).to have_requested(:post, api_url).once
......
...@@ -60,6 +60,7 @@ describe SlackService::NoteMessage, models: true do ...@@ -60,6 +60,7 @@ describe SlackService::NoteMessage, models: true do
title: "merge request title\ndetails\n" title: "merge request title\ndetails\n"
} }
end end
it 'returns a message regarding notes on a merge request' do it 'returns a message regarding notes on a merge request' do
message = SlackService::NoteMessage.new(@args) message = SlackService::NoteMessage.new(@args)
expect(message.pretext).to eq("Test User commented on " \ expect(message.pretext).to eq("Test User commented on " \
......
...@@ -47,7 +47,7 @@ describe SlackService::WikiPageMessage, models: true do ...@@ -47,7 +47,7 @@ describe SlackService::WikiPageMessage, models: true do
context 'when :action == "create"' do context 'when :action == "create"' do
before { args[:object_attributes][:action] = 'create' } before { args[:object_attributes][:action] = 'create' }
it 'it returns the attachment for a new wiki page' do it 'returns the attachment for a new wiki page' do
expect(subject.attachments).to eq([ expect(subject.attachments).to eq([
{ {
text: "Wiki page description", text: "Wiki page description",
...@@ -60,7 +60,7 @@ describe SlackService::WikiPageMessage, models: true do ...@@ -60,7 +60,7 @@ describe SlackService::WikiPageMessage, models: true do
context 'when :action == "update"' do context 'when :action == "update"' do
before { args[:object_attributes][:action] = 'update' } before { args[:object_attributes][:action] = 'update' }
it 'it returns the attachment for an updated wiki page' do it 'returns the attachment for an updated wiki page' do
expect(subject.attachments).to eq([ expect(subject.attachments).to eq([
{ {
text: "Wiki page description", text: "Wiki page description",
......
...@@ -93,31 +93,31 @@ describe SlackService, models: true do ...@@ -93,31 +93,31 @@ describe SlackService, models: true do
@wiki_page_sample_data = wiki_page_service.hook_data(@wiki_page, 'create') @wiki_page_sample_data = wiki_page_service.hook_data(@wiki_page, 'create')
end end
it "should call Slack API for push events" do it "calls Slack API for push events" do
slack.execute(push_sample_data) slack.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
it "should call Slack API for issue events" do it "calls Slack API for issue events" do
slack.execute(@issues_sample_data) slack.execute(@issues_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
it "should call Slack API for merge requests events" do it "calls Slack API for merge requests events" do
slack.execute(@merge_sample_data) slack.execute(@merge_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
it "should call Slack API for wiki page events" do it "calls Slack API for wiki page events" do
slack.execute(@wiki_page_sample_data) slack.execute(@wiki_page_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
it 'should use the username as an option for slack when configured' do it 'uses the username as an option for slack when configured' do
allow(slack).to receive(:username).and_return(username) allow(slack).to receive(:username).and_return(username)
expect(Slack::Notifier).to receive(:new). expect(Slack::Notifier).to receive(:new).
with(webhook_url, username: username). with(webhook_url, username: username).
...@@ -128,7 +128,7 @@ describe SlackService, models: true do ...@@ -128,7 +128,7 @@ describe SlackService, models: true do
slack.execute(push_sample_data) slack.execute(push_sample_data)
end end
it 'should use the channel as an option when it is configured' do it 'uses the channel as an option when it is configured' do
allow(slack).to receive(:channel).and_return(channel) allow(slack).to receive(:channel).and_return(channel)
expect(Slack::Notifier).to receive(:new). expect(Slack::Notifier).to receive(:new).
with(webhook_url, channel: channel). with(webhook_url, channel: channel).
...@@ -234,7 +234,7 @@ describe SlackService, models: true do ...@@ -234,7 +234,7 @@ describe SlackService, models: true do
note: 'a comment on a commit') note: 'a comment on a commit')
end end
it "should call Slack API for commit comment events" do it "calls Slack API for commit comment events" do
data = Gitlab::NoteDataBuilder.build(commit_note, user) data = Gitlab::NoteDataBuilder.build(commit_note, user)
slack.execute(data) slack.execute(data)
...@@ -248,7 +248,7 @@ describe SlackService, models: true do ...@@ -248,7 +248,7 @@ describe SlackService, models: true do
note: "merge request note") note: "merge request note")
end end
it "should call Slack API for merge request comment events" do it "calls Slack API for merge request comment events" do
data = Gitlab::NoteDataBuilder.build(merge_request_note, user) data = Gitlab::NoteDataBuilder.build(merge_request_note, user)
slack.execute(data) slack.execute(data)
...@@ -261,7 +261,7 @@ describe SlackService, models: true do ...@@ -261,7 +261,7 @@ describe SlackService, models: true do
create(:note_on_issue, project: project, note: "issue note") create(:note_on_issue, project: project, note: "issue note")
end end
it "should call Slack API for issue comment events" do it "calls Slack API for issue comment events" do
data = Gitlab::NoteDataBuilder.build(issue_note, user) data = Gitlab::NoteDataBuilder.build(issue_note, user)
slack.execute(data) slack.execute(data)
...@@ -275,7 +275,7 @@ describe SlackService, models: true do ...@@ -275,7 +275,7 @@ describe SlackService, models: true do
note: "snippet note") note: "snippet note")
end end
it "should call Slack API for snippet comment events" do it "calls Slack API for snippet comment events" do
data = Gitlab::NoteDataBuilder.build(snippet_note, user) data = Gitlab::NoteDataBuilder.build(snippet_note, user)
slack.execute(data) slack.execute(data)
......
...@@ -89,7 +89,7 @@ describe Project, models: true do ...@@ -89,7 +89,7 @@ describe Project, models: true do
it { is_expected.to validate_presence_of(:namespace) } it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:repository_storage) } it { is_expected.to validate_presence_of(:repository_storage) }
it 'should not allow new projects beyond user limits' do it 'does not allow new projects beyond user limits' do
project2 = build(:project) project2 = build(:project)
allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object) allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object)
expect(project2).not_to be_valid expect(project2).not_to be_valid
...@@ -98,7 +98,7 @@ describe Project, models: true do ...@@ -98,7 +98,7 @@ describe Project, models: true do
describe 'wiki path conflict' do describe 'wiki path conflict' do
context "when the new path has been used by the wiki of other Project" do context "when the new path has been used by the wiki of other Project" do
it 'should have an error on the name attribute' do it 'has an error on the name attribute' do
new_project = build_stubbed(:project, namespace_id: project.namespace_id, path: "#{project.path}.wiki") new_project = build_stubbed(:project, namespace_id: project.namespace_id, path: "#{project.path}.wiki")
expect(new_project).not_to be_valid expect(new_project).not_to be_valid
...@@ -107,7 +107,7 @@ describe Project, models: true do ...@@ -107,7 +107,7 @@ describe Project, models: true do
end end
context "when the new wiki path has been used by the path of other Project" do context "when the new wiki path has been used by the path of other Project" do
it 'should have an error on the name attribute' do it 'has an error on the name attribute' do
project_with_wiki_suffix = create(:project, path: 'foo.wiki') project_with_wiki_suffix = create(:project, path: 'foo.wiki')
new_project = build_stubbed(:project, namespace_id: project_with_wiki_suffix.namespace_id, path: 'foo') new_project = build_stubbed(:project, namespace_id: project_with_wiki_suffix.namespace_id, path: 'foo')
...@@ -125,7 +125,7 @@ describe Project, models: true do ...@@ -125,7 +125,7 @@ describe Project, models: true do
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
it "should not allow repository storages that don't match a label in the configuration" do it "does not allow repository storages that don't match a label in the configuration" do
expect(project2).not_to be_valid expect(project2).not_to be_valid
expect(project2.errors[:repository_storage].first).to match(/is not included in the list/) expect(project2.errors[:repository_storage].first).to match(/is not included in the list/)
end end
...@@ -172,12 +172,12 @@ describe Project, models: true do ...@@ -172,12 +172,12 @@ describe Project, models: true do
end end
describe 'project token' do describe 'project token' do
it 'should set an random token if none provided' do it 'sets an random token if none provided' do
project = FactoryGirl.create :empty_project, runners_token: '' project = FactoryGirl.create :empty_project, runners_token: ''
expect(project.runners_token).not_to eq('') expect(project.runners_token).not_to eq('')
end end
it 'should not set an random toke if one provided' do it 'does not set an random toke if one provided' do
project = FactoryGirl.create :empty_project, runners_token: 'my-token' project = FactoryGirl.create :empty_project, runners_token: 'my-token'
expect(project.runners_token).to eq('my-token') expect(project.runners_token).to eq('my-token')
end end
...@@ -225,7 +225,7 @@ describe Project, models: true do ...@@ -225,7 +225,7 @@ describe Project, models: true do
end end
end end
it 'should return valid url to repo' do it 'returns valid url to repo' do
project = Project.new(path: 'somewhere') project = Project.new(path: 'somewhere')
expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git') expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
end end
...@@ -279,7 +279,7 @@ describe Project, models: true do ...@@ -279,7 +279,7 @@ describe Project, models: true do
let(:last_event) { double(created_at: Time.now) } let(:last_event) { double(created_at: Time.now) }
describe 'last_activity' do describe 'last_activity' do
it 'should alias last_activity to last_event' do it 'alias last_activity to last_event' do
allow(project).to receive(:last_event).and_return(last_event) allow(project).to receive(:last_event).and_return(last_event)
expect(project.last_activity).to eq(last_event) expect(project.last_activity).to eq(last_event)
end end
...@@ -350,13 +350,13 @@ describe Project, models: true do ...@@ -350,13 +350,13 @@ describe Project, models: true do
let(:prev_commit_id) { merge_request.commits.last.id } let(:prev_commit_id) { merge_request.commits.last.id }
let(:commit_id) { merge_request.commits.first.id } let(:commit_id) { merge_request.commits.first.id }
it 'should close merge request if last commit from source branch was pushed to target branch' do it 'closes merge request if last commit from source branch was pushed to target branch' do
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user) project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user)
merge_request.reload merge_request.reload
expect(merge_request.merged?).to be_truthy expect(merge_request.merged?).to be_truthy
end end
it 'should update merge request commits with new one if pushed to source branch' do it 'updates merge request commits with new one if pushed to source branch' do
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user) project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user)
merge_request.reload merge_request.reload
expect(merge_request.diff_head_sha).to eq(commit_id) expect(merge_request.diff_head_sha).to eq(commit_id)
...@@ -433,11 +433,11 @@ describe Project, models: true do ...@@ -433,11 +433,11 @@ describe Project, models: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) } let(:ext_project) { create(:redmine_project) }
it "should be true if used internal tracker" do it "is true if used internal tracker" do
expect(project.default_issues_tracker?).to be_truthy expect(project.default_issues_tracker?).to be_truthy
end end
it "should be false if used other tracker" do it "is false if used other tracker" do
expect(ext_project.default_issues_tracker?).to be_falsey expect(ext_project.default_issues_tracker?).to be_falsey
end end
end end
...@@ -636,12 +636,12 @@ describe Project, models: true do ...@@ -636,12 +636,12 @@ describe Project, models: true do
describe '#avatar_type' do describe '#avatar_type' do
let(:project) { create(:project) } let(:project) { create(:project) }
it 'should be true if avatar is image' do it 'is true if avatar is image' do
project.update_attribute(:avatar, 'uploads/avatar.png') project.update_attribute(:avatar, 'uploads/avatar.png')
expect(project.avatar_type).to be_truthy expect(project.avatar_type).to be_truthy
end end
it 'should be false if avatar is html page' do it 'is false if avatar is html page' do
project.update_attribute(:avatar, 'uploads/avatar.html') project.update_attribute(:avatar, 'uploads/avatar.html')
expect(project.avatar_type).to eq(['only images allowed']) expect(project.avatar_type).to eq(['only images allowed'])
end end
...@@ -814,16 +814,16 @@ describe Project, models: true do ...@@ -814,16 +814,16 @@ describe Project, models: true do
context 'for shared runners disabled' do context 'for shared runners disabled' do
let(:shared_runners_enabled) { false } let(:shared_runners_enabled) { false }
it 'there are no runners available' do it 'has no runners available' do
expect(project.any_runners?).to be_falsey expect(project.any_runners?).to be_falsey
end end
it 'there is a specific runner' do it 'has a specific runner' do
project.runners << specific_runner project.runners << specific_runner
expect(project.any_runners?).to be_truthy expect(project.any_runners?).to be_truthy
end end
it 'there is a shared runner, but they are prohibited to use' do it 'has a shared runner, but they are prohibited to use' do
shared_runner shared_runner
expect(project.any_runners?).to be_falsey expect(project.any_runners?).to be_falsey
end end
...@@ -837,7 +837,7 @@ describe Project, models: true do ...@@ -837,7 +837,7 @@ describe Project, models: true do
context 'for shared runners enabled' do context 'for shared runners enabled' do
let(:shared_runners_enabled) { true } let(:shared_runners_enabled) { true }
it 'there is a shared runner' do it 'has a shared runner' do
shared_runner shared_runner
expect(project.any_runners?).to be_truthy expect(project.any_runners?).to be_truthy
end end
......
...@@ -340,14 +340,14 @@ describe Repository, models: true do ...@@ -340,14 +340,14 @@ describe Repository, models: true do
describe '#add_branch' do describe '#add_branch' do
context 'when pre hooks were successful' do context 'when pre hooks were successful' do
it 'should run without errors' do it 'runs without errors' do
hook = double(trigger: [true, nil]) hook = double(trigger: [true, nil])
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook) expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
expect { repository.add_branch(user, 'new_feature', 'master') }.not_to raise_error expect { repository.add_branch(user, 'new_feature', 'master') }.not_to raise_error
end end
it 'should create the branch' do it 'creates the branch' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil]) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil])
branch = repository.add_branch(user, 'new_feature', 'master') branch = repository.add_branch(user, 'new_feature', 'master')
...@@ -363,7 +363,7 @@ describe Repository, models: true do ...@@ -363,7 +363,7 @@ describe Repository, models: true do
end end
context 'when pre hooks failed' do context 'when pre hooks failed' do
it 'should get an error' do it 'gets an error' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do expect do
...@@ -371,7 +371,7 @@ describe Repository, models: true do ...@@ -371,7 +371,7 @@ describe Repository, models: true do
end.to raise_error(GitHooksService::PreReceiveError) end.to raise_error(GitHooksService::PreReceiveError)
end end
it 'should not create the branch' do it 'does not create the branch' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do expect do
...@@ -387,14 +387,14 @@ describe Repository, models: true do ...@@ -387,14 +387,14 @@ describe Repository, models: true do
let(:blank_sha) { '0000000000000000000000000000000000000000' } let(:blank_sha) { '0000000000000000000000000000000000000000' }
context 'when pre hooks were successful' do context 'when pre hooks were successful' do
it 'should run without errors' do it 'runs without errors' do
expect_any_instance_of(GitHooksService).to receive(:execute). expect_any_instance_of(GitHooksService).to receive(:execute).
with(user, project.repository.path_to_repo, old_rev, blank_sha, 'refs/heads/feature') with(user, project.repository.path_to_repo, old_rev, blank_sha, 'refs/heads/feature')
expect { repository.rm_branch(user, 'feature') }.not_to raise_error expect { repository.rm_branch(user, 'feature') }.not_to raise_error
end end
it 'should delete the branch' do it 'deletes the branch' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil]) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil])
expect { repository.rm_branch(user, 'feature') }.not_to raise_error expect { repository.rm_branch(user, 'feature') }.not_to raise_error
...@@ -404,7 +404,7 @@ describe Repository, models: true do ...@@ -404,7 +404,7 @@ describe Repository, models: true do
end end
context 'when pre hooks failed' do context 'when pre hooks failed' do
it 'should get an error' do it 'gets an error' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do expect do
...@@ -412,7 +412,7 @@ describe Repository, models: true do ...@@ -412,7 +412,7 @@ describe Repository, models: true do
end.to raise_error(GitHooksService::PreReceiveError) end.to raise_error(GitHooksService::PreReceiveError)
end end
it 'should not delete the branch' do it 'does not delete the branch' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do expect do
...@@ -433,13 +433,13 @@ describe Repository, models: true do ...@@ -433,13 +433,13 @@ describe Repository, models: true do
and_yield.and_return(true) and_yield.and_return(true)
end end
it 'should run without errors' do it 'runs without errors' do
expect do expect do
repository.commit_with_hooks(user, 'feature') { sample_commit.id } repository.commit_with_hooks(user, 'feature') { sample_commit.id }
end.not_to raise_error end.not_to raise_error
end end
it 'should ensure the autocrlf Git option is set to :input' do it 'ensures the autocrlf Git option is set to :input' do
expect(repository).to receive(:update_autocrlf_option) expect(repository).to receive(:update_autocrlf_option)
repository.commit_with_hooks(user, 'feature') { sample_commit.id } repository.commit_with_hooks(user, 'feature') { sample_commit.id }
...@@ -455,7 +455,7 @@ describe Repository, models: true do ...@@ -455,7 +455,7 @@ describe Repository, models: true do
end end
context 'when pre hooks failed' do context 'when pre hooks failed' do
it 'should get an error' do it 'gets an error' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do expect do
...@@ -715,7 +715,7 @@ describe Repository, models: true do ...@@ -715,7 +715,7 @@ describe Repository, models: true do
end end
describe '#merge' do describe '#merge' do
it 'should merge the code and return the commit id' do it 'merges the code and return the commit id' do
expect(merge_commit).to be_present expect(merge_commit).to be_present
expect(repository.blob_at(merge_commit.id, 'files/ruby/feature.rb')).to be_present expect(repository.blob_at(merge_commit.id, 'files/ruby/feature.rb')).to be_present
end end
...@@ -726,13 +726,13 @@ describe Repository, models: true do ...@@ -726,13 +726,13 @@ describe Repository, models: true do
let(:update_image_commit) { repository.commit('2f63565e7aac07bcdadb654e253078b727143ec4') } let(:update_image_commit) { repository.commit('2f63565e7aac07bcdadb654e253078b727143ec4') }
context 'when there is a conflict' do context 'when there is a conflict' do
it 'should abort the operation' do it 'aborts the operation' do
expect(repository.revert(user, new_image_commit, 'master')).to eq(false) expect(repository.revert(user, new_image_commit, 'master')).to eq(false)
end end
end end
context 'when commit was already reverted' do context 'when commit was already reverted' do
it 'should abort the operation' do it 'aborts the operation' do
repository.revert(user, update_image_commit, 'master') repository.revert(user, update_image_commit, 'master')
expect(repository.revert(user, update_image_commit, 'master')).to eq(false) expect(repository.revert(user, update_image_commit, 'master')).to eq(false)
...@@ -740,13 +740,13 @@ describe Repository, models: true do ...@@ -740,13 +740,13 @@ describe Repository, models: true do
end end
context 'when commit can be reverted' do context 'when commit can be reverted' do
it 'should revert the changes' do it 'reverts the changes' do
expect(repository.revert(user, update_image_commit, 'master')).to be_truthy expect(repository.revert(user, update_image_commit, 'master')).to be_truthy
end end
end end
context 'reverting a merge commit' do context 'reverting a merge commit' do
it 'should revert the changes' do it 'reverts the changes' do
merge_commit merge_commit
expect(repository.blob_at_branch('master', 'files/ruby/feature.rb')).to be_present expect(repository.blob_at_branch('master', 'files/ruby/feature.rb')).to be_present
...@@ -762,13 +762,13 @@ describe Repository, models: true do ...@@ -762,13 +762,13 @@ describe Repository, models: true do
let(:pickable_merge) { repository.commit('e56497bb5f03a90a51293fc6d516788730953899') } let(:pickable_merge) { repository.commit('e56497bb5f03a90a51293fc6d516788730953899') }
context 'when there is a conflict' do context 'when there is a conflict' do
it 'should abort the operation' do it 'aborts the operation' do
expect(repository.cherry_pick(user, conflict_commit, 'master')).to eq(false) expect(repository.cherry_pick(user, conflict_commit, 'master')).to eq(false)
end end
end end
context 'when commit was already cherry-picked' do context 'when commit was already cherry-picked' do
it 'should abort the operation' do it 'aborts the operation' do
repository.cherry_pick(user, pickable_commit, 'master') repository.cherry_pick(user, pickable_commit, 'master')
expect(repository.cherry_pick(user, pickable_commit, 'master')).to eq(false) expect(repository.cherry_pick(user, pickable_commit, 'master')).to eq(false)
...@@ -776,13 +776,13 @@ describe Repository, models: true do ...@@ -776,13 +776,13 @@ describe Repository, models: true do
end end
context 'when commit can be cherry-picked' do context 'when commit can be cherry-picked' do
it 'should cherry-pick the changes' do it 'cherry-picks the changes' do
expect(repository.cherry_pick(user, pickable_commit, 'master')).to be_truthy expect(repository.cherry_pick(user, pickable_commit, 'master')).to be_truthy
end end
end end
context 'cherry-picking a merge commit' do context 'cherry-picking a merge commit' do
it 'should cherry-pick the changes' do it 'cherry-picks the changes' do
expect(repository.blob_at_branch('master', 'foo/bar/.gitkeep')).to be_nil expect(repository.blob_at_branch('master', 'foo/bar/.gitkeep')).to be_nil
repository.cherry_pick(user, pickable_merge, 'master') repository.cherry_pick(user, pickable_merge, 'master')
......
...@@ -65,13 +65,13 @@ describe Service, models: true do ...@@ -65,13 +65,13 @@ describe Service, models: true do
end end
let(:project) { create(:project) } let(:project) { create(:project) }
describe 'should be prefilled for projects pushover service' do describe 'is prefilled for projects pushover service' do
before do before do
service_template service_template
project.build_missing_services project.build_missing_services
end end
it "should have all fields prefilled" do it "has all fields prefilled" do
service = project.pushover_service service = project.pushover_service
expect(service.template).to eq(false) expect(service.template).to eq(false)
expect(service.device).to eq('MyDevice') expect(service.device).to eq('MyDevice')
......
...@@ -166,7 +166,7 @@ describe User, models: true do ...@@ -166,7 +166,7 @@ describe User, models: true do
allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['*.example.com']) allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['*.example.com'])
end end
it 'should give priority to whitelist and allow info@test.example.com' do it 'gives priority to whitelist and allow info@test.example.com' do
user = build(:user, email: 'info@test.example.com') user = build(:user, email: 'info@test.example.com')
expect(user).to be_valid expect(user).to be_valid
end end
...@@ -304,18 +304,18 @@ describe User, models: true do ...@@ -304,18 +304,18 @@ describe User, models: true do
end end
describe '#generate_password' do describe '#generate_password' do
it "should execute callback when force_random_password specified" do it "executes callback when force_random_password specified" do
user = build(:user, force_random_password: true) user = build(:user, force_random_password: true)
expect(user).to receive(:generate_password) expect(user).to receive(:generate_password)
user.save user.save
end end
it "should not generate password by default" do it "does not generate password by default" do
user = create(:user, password: 'abcdefghe') user = create(:user, password: 'abcdefghe')
expect(user.password).to eq('abcdefghe') expect(user.password).to eq('abcdefghe')
end end
it "should generate password when forcing random password" do it "generates password when forcing random password" do
allow(Devise).to receive(:friendly_token).and_return('123456789') allow(Devise).to receive(:friendly_token).and_return('123456789')
user = create(:user, password: 'abcdefg', force_random_password: true) user = create(:user, password: 'abcdefg', force_random_password: true)
expect(user.password).to eq('12345678') expect(user.password).to eq('12345678')
...@@ -323,7 +323,7 @@ describe User, models: true do ...@@ -323,7 +323,7 @@ describe User, models: true do
end end
describe 'authentication token' do describe 'authentication token' do
it "should have authentication token" do it "has authentication token" do
user = create(:user) user = create(:user)
expect(user.authentication_token).not_to be_blank expect(user.authentication_token).not_to be_blank
end end
...@@ -430,7 +430,7 @@ describe User, models: true do ...@@ -430,7 +430,7 @@ describe User, models: true do
describe 'blocking user' do describe 'blocking user' do
let(:user) { create(:user, name: 'John Smith') } let(:user) { create(:user, name: 'John Smith') }
it "should block user" do it "blocks user" do
user.block user.block
expect(user.blocked?).to be_truthy expect(user.blocked?).to be_truthy
end end
...@@ -501,7 +501,7 @@ describe User, models: true do ...@@ -501,7 +501,7 @@ describe User, models: true do
describe 'with defaults' do describe 'with defaults' do
let(:user) { User.new } let(:user) { User.new }
it "should apply defaults to user" do it "applies defaults to user" do
expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit)
expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group) expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group)
expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme)
...@@ -512,7 +512,7 @@ describe User, models: true do ...@@ -512,7 +512,7 @@ describe User, models: true do
describe 'with default overrides' do describe 'with default overrides' do
let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true, theme_id: 1) } let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true, theme_id: 1) }
it "should apply defaults to user" do it "applies defaults to user" do
expect(user.projects_limit).to eq(123) expect(user.projects_limit).to eq(123)
expect(user.can_create_group).to be_falsey expect(user.can_create_group).to be_falsey
expect(user.theme_id).to eq(1) expect(user.theme_id).to eq(1)
...@@ -602,7 +602,7 @@ describe User, models: true do ...@@ -602,7 +602,7 @@ describe User, models: true do
describe 'by_username_or_id' do describe 'by_username_or_id' do
let(:user1) { create(:user, username: 'foo') } let(:user1) { create(:user, username: 'foo') }
it "should get the correct user" do it "gets the correct user" do
expect(User.by_username_or_id(user1.id)).to eq(user1) expect(User.by_username_or_id(user1.id)).to eq(user1)
expect(User.by_username_or_id('foo')).to eq(user1) expect(User.by_username_or_id('foo')).to eq(user1)
expect(User.by_username_or_id(-1)).to be_nil expect(User.by_username_or_id(-1)).to be_nil
...@@ -614,7 +614,7 @@ describe User, models: true do ...@@ -614,7 +614,7 @@ describe User, models: true do
let(:username) { 'John' } let(:username) { 'John' }
let!(:user) { create(:user, username: username) } let!(:user) { create(:user, username: username) }
it 'should get the correct user' do it 'gets the correct user' do
expect(User.by_login(user.email.upcase)).to eq user expect(User.by_login(user.email.upcase)).to eq user
expect(User.by_login(user.email)).to eq user expect(User.by_login(user.email)).to eq user
expect(User.by_login(username.downcase)).to eq user expect(User.by_login(username.downcase)).to eq user
...@@ -639,7 +639,7 @@ describe User, models: true do ...@@ -639,7 +639,7 @@ describe User, models: true do
describe 'all_ssh_keys' do describe 'all_ssh_keys' do
it { is_expected.to have_many(:keys).dependent(:destroy) } it { is_expected.to have_many(:keys).dependent(:destroy) }
it "should have all ssh keys" do it "has all ssh keys" do
user = create :user user = create :user
key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id
...@@ -650,12 +650,12 @@ describe User, models: true do ...@@ -650,12 +650,12 @@ describe User, models: true do
describe '#avatar_type' do describe '#avatar_type' do
let(:user) { create(:user) } let(:user) { create(:user) }
it "should be true if avatar is image" do it "is true if avatar is image" do
user.update_attribute(:avatar, 'uploads/avatar.png') user.update_attribute(:avatar, 'uploads/avatar.png')
expect(user.avatar_type).to be_truthy expect(user.avatar_type).to be_truthy
end end
it "should be false if avatar is html page" do it "is false if avatar is html page" do
user.update_attribute(:avatar, 'uploads/avatar.html') user.update_attribute(:avatar, 'uploads/avatar.html')
expect(user.avatar_type).to eq(["only images allowed"]) expect(user.avatar_type).to eq(["only images allowed"])
end end
......
...@@ -147,12 +147,12 @@ describe WikiPage, models: true do ...@@ -147,12 +147,12 @@ describe WikiPage, models: true do
@page = wiki.find_page("Delete Page") @page = wiki.find_page("Delete Page")
end end
it "should delete the page" do it "deletes the page" do
@page.delete @page.delete
expect(wiki.pages).to be_empty expect(wiki.pages).to be_empty
end end
it "should return true" do it "returns true" do
expect(@page.delete).to eq(true) expect(@page.delete).to eq(true)
end end
end end
...@@ -183,7 +183,7 @@ describe WikiPage, models: true do ...@@ -183,7 +183,7 @@ describe WikiPage, models: true do
destroy_page("Title") destroy_page("Title")
end end
it "should be replace a hyphen to a space" do it "replaces a hyphen to a space" do
@page.title = "Import-existing-repositories-into-GitLab" @page.title = "Import-existing-repositories-into-GitLab"
expect(@page.title).to eq("Import existing repositories into GitLab") expect(@page.title).to eq("Import existing repositories into GitLab")
end end
......
...@@ -41,19 +41,19 @@ describe API::Helpers, api: true do ...@@ -41,19 +41,19 @@ describe API::Helpers, api: true do
describe ".current_user" do describe ".current_user" do
describe "when authenticating using a user's private token" do describe "when authenticating using a user's private token" do
it "should return nil for an invalid token" do it "returns nil for an invalid token" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = 'invalid token' env[API::Helpers::PRIVATE_TOKEN_HEADER] = 'invalid token'
allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false } allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false }
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should return nil for a user without access" do it "returns nil for a user without access" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token
allow_any_instance_of(Gitlab::UserAccess).to receive(:allowed?).and_return(false) allow_any_instance_of(Gitlab::UserAccess).to receive(:allowed?).and_return(false)
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should leave user as is when sudo not specified" do it "leaves user as is when sudo not specified" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token
expect(current_user).to eq(user) expect(current_user).to eq(user)
clear_env clear_env
...@@ -65,19 +65,19 @@ describe API::Helpers, api: true do ...@@ -65,19 +65,19 @@ describe API::Helpers, api: true do
describe "when authenticating using a user's personal access tokens" do describe "when authenticating using a user's personal access tokens" do
let(:personal_access_token) { create(:personal_access_token, user: user) } let(:personal_access_token) { create(:personal_access_token, user: user) }
it "should return nil for an invalid token" do it "returns nil for an invalid token" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = 'invalid token' env[API::Helpers::PRIVATE_TOKEN_HEADER] = 'invalid token'
allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false } allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false }
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should return nil for a user without access" do it "returns nil for a user without access" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = personal_access_token.token env[API::Helpers::PRIVATE_TOKEN_HEADER] = personal_access_token.token
allow_any_instance_of(Gitlab::UserAccess).to receive(:allowed?).and_return(false) allow_any_instance_of(Gitlab::UserAccess).to receive(:allowed?).and_return(false)
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should leave user as is when sudo not specified" do it "leaves user as is when sudo not specified" do
env[API::Helpers::PRIVATE_TOKEN_HEADER] = personal_access_token.token env[API::Helpers::PRIVATE_TOKEN_HEADER] = personal_access_token.token
expect(current_user).to eq(user) expect(current_user).to eq(user)
clear_env clear_env
...@@ -100,7 +100,7 @@ describe API::Helpers, api: true do ...@@ -100,7 +100,7 @@ describe API::Helpers, api: true do
end end
end end
it "should change current user to sudo when admin" do it "changes current user to sudo when admin" do
set_env(admin, user.id) set_env(admin, user.id)
expect(current_user).to eq(user) expect(current_user).to eq(user)
set_param(admin, user.id) set_param(admin, user.id)
...@@ -111,7 +111,7 @@ describe API::Helpers, api: true do ...@@ -111,7 +111,7 @@ describe API::Helpers, api: true do
expect(current_user).to eq(user) expect(current_user).to eq(user)
end end
it "should throw an error when the current user is not an admin and attempting to sudo" do it "throws an error when the current user is not an admin and attempting to sudo" do
set_env(user, admin.id) set_env(user, admin.id)
expect { current_user }.to raise_error(Exception) expect { current_user }.to raise_error(Exception)
set_param(user, admin.id) set_param(user, admin.id)
...@@ -122,7 +122,7 @@ describe API::Helpers, api: true do ...@@ -122,7 +122,7 @@ describe API::Helpers, api: true do
expect { current_user }.to raise_error(Exception) expect { current_user }.to raise_error(Exception)
end end
it "should throw an error when the user cannot be found for a given id" do it "throws an error when the user cannot be found for a given id" do
id = user.id + admin.id id = user.id + admin.id
expect(user.id).not_to eq(id) expect(user.id).not_to eq(id)
expect(admin.id).not_to eq(id) expect(admin.id).not_to eq(id)
...@@ -133,7 +133,7 @@ describe API::Helpers, api: true do ...@@ -133,7 +133,7 @@ describe API::Helpers, api: true do
expect { current_user }.to raise_error(Exception) expect { current_user }.to raise_error(Exception)
end end
it "should throw an error when the user cannot be found for a given username" do it "throws an error when the user cannot be found for a given username" do
username = "#{user.username}#{admin.username}" username = "#{user.username}#{admin.username}"
expect(user.username).not_to eq(username) expect(user.username).not_to eq(username)
expect(admin.username).not_to eq(username) expect(admin.username).not_to eq(username)
...@@ -144,7 +144,7 @@ describe API::Helpers, api: true do ...@@ -144,7 +144,7 @@ describe API::Helpers, api: true do
expect { current_user }.to raise_error(Exception) expect { current_user }.to raise_error(Exception)
end end
it "should handle sudo's to oneself" do it "handles sudo's to oneself" do
set_env(admin, admin.id) set_env(admin, admin.id)
expect(current_user).to eq(admin) expect(current_user).to eq(admin)
set_param(admin, admin.id) set_param(admin, admin.id)
...@@ -155,7 +155,7 @@ describe API::Helpers, api: true do ...@@ -155,7 +155,7 @@ describe API::Helpers, api: true do
expect(current_user).to eq(admin) expect(current_user).to eq(admin)
end end
it "should handle multiple sudo's to oneself" do it "handles multiple sudo's to oneself" do
set_env(admin, user.id) set_env(admin, user.id)
expect(current_user).to eq(user) expect(current_user).to eq(user)
expect(current_user).to eq(user) expect(current_user).to eq(user)
...@@ -171,7 +171,7 @@ describe API::Helpers, api: true do ...@@ -171,7 +171,7 @@ describe API::Helpers, api: true do
expect(current_user).to eq(user) expect(current_user).to eq(user)
end end
it "should handle multiple sudo's to oneself using string ids" do it "handles multiple sudo's to oneself using string ids" do
set_env(admin, user.id.to_s) set_env(admin, user.id.to_s)
expect(current_user).to eq(user) expect(current_user).to eq(user)
expect(current_user).to eq(user) expect(current_user).to eq(user)
...@@ -183,7 +183,7 @@ describe API::Helpers, api: true do ...@@ -183,7 +183,7 @@ describe API::Helpers, api: true do
end end
describe '.sudo_identifier' do describe '.sudo_identifier' do
it "should return integers when input is an int" do it "returns integers when input is an int" do
set_env(admin, '123') set_env(admin, '123')
expect(sudo_identifier).to eq(123) expect(sudo_identifier).to eq(123)
set_env(admin, '0001234567890') set_env(admin, '0001234567890')
...@@ -195,7 +195,7 @@ describe API::Helpers, api: true do ...@@ -195,7 +195,7 @@ describe API::Helpers, api: true do
expect(sudo_identifier).to eq(1234567890) expect(sudo_identifier).to eq(1234567890)
end end
it "should return string when input is an is not an int" do it "returns string when input is an is not an int" do
set_env(admin, '12.30') set_env(admin, '12.30')
expect(sudo_identifier).to eq("12.30") expect(sudo_identifier).to eq("12.30")
set_env(admin, 'hello') set_env(admin, 'hello')
......
...@@ -22,7 +22,7 @@ describe API::API, api: true do ...@@ -22,7 +22,7 @@ describe API::API, api: true do
expect(json_response.first['name']).to eq(award_emoji.name) expect(json_response.first['name']).to eq(award_emoji.name)
end end
it "should return a 404 error when issue id not found" do it "returns a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/12345/award_emoji", user) get api("/projects/#{project.id}/issues/12345/award_emoji", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -124,13 +124,13 @@ describe API::API, api: true do ...@@ -124,13 +124,13 @@ describe API::API, api: true do
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
end end
it "should return a 400 bad request error if the name is not given" do it "returns a 400 bad request error if the name is not given" do
post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if the user is not authenticated" do it "returns a 401 unauthorized error if the user is not authenticated" do
post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji"), name: 'thumbsup' post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji"), name: 'thumbsup'
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
......
...@@ -13,7 +13,7 @@ describe API::API, api: true do ...@@ -13,7 +13,7 @@ describe API::API, api: true do
let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
describe "GET /projects/:id/repository/branches" do describe "GET /projects/:id/repository/branches" do
it "should return an array of project branches" do it "returns an array of project branches" do
project.repository.expire_cache project.repository.expire_cache
get api("/projects/#{project.id}/repository/branches", user) get api("/projects/#{project.id}/repository/branches", user)
...@@ -25,7 +25,7 @@ describe API::API, api: true do ...@@ -25,7 +25,7 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/repository/branches/:branch" do describe "GET /projects/:id/repository/branches/:branch" do
it "should return the branch information for a single branch" do it "returns the branch information for a single branch" do
get api("/projects/#{project.id}/repository/branches/#{branch_name}", user) get api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -36,12 +36,12 @@ describe API::API, api: true do ...@@ -36,12 +36,12 @@ describe API::API, api: true do
expect(json_response['developers_can_merge']).to eq(false) expect(json_response['developers_can_merge']).to eq(false)
end end
it "should return a 403 error if guest" do it "returns a 403 error if guest" do
get api("/projects/#{project.id}/repository/branches", user2) get api("/projects/#{project.id}/repository/branches", user2)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
it "should return a 404 error if branch is not available" do it "returns a 404 error if branch is not available" do
get api("/projects/#{project.id}/repository/branches/unknown", user) get api("/projects/#{project.id}/repository/branches/unknown", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
...@@ -138,17 +138,17 @@ describe API::API, api: true do ...@@ -138,17 +138,17 @@ describe API::API, api: true do
end end
end end
it "should return a 404 error if branch not found" do it "returns a 404 error if branch not found" do
put api("/projects/#{project.id}/repository/branches/unknown/protect", user) put api("/projects/#{project.id}/repository/branches/unknown/protect", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return a 403 error if guest" do it "returns a 403 error if guest" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
it "should return success when protect branch again" do it "returns success when protect branch again" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -156,7 +156,7 @@ describe API::API, api: true do ...@@ -156,7 +156,7 @@ describe API::API, api: true do
end end
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
it "should unprotect a single branch" do it "unprotects a single branch" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -165,12 +165,12 @@ describe API::API, api: true do ...@@ -165,12 +165,12 @@ describe API::API, api: true do
expect(json_response['protected']).to eq(false) expect(json_response['protected']).to eq(false)
end end
it "should return success when unprotect branch" do it "returns success when unprotect branch" do
put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user) put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return success when unprotect branch again" do it "returns success when unprotect branch again" do
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -178,7 +178,7 @@ describe API::API, api: true do ...@@ -178,7 +178,7 @@ describe API::API, api: true do
end end
describe "POST /projects/:id/repository/branches" do describe "POST /projects/:id/repository/branches" do
it "should create a new branch" do it "creates a new branch" do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'feature1', branch_name: 'feature1',
ref: branch_sha ref: branch_sha
...@@ -189,14 +189,14 @@ describe API::API, api: true do ...@@ -189,14 +189,14 @@ describe API::API, api: true do
expect(json_response['commit']['id']).to eq(branch_sha) expect(json_response['commit']['id']).to eq(branch_sha)
end end
it "should deny for user without push access" do it "denies for user without push access" do
post api("/projects/#{project.id}/repository/branches", user2), post api("/projects/#{project.id}/repository/branches", user2),
branch_name: branch_name, branch_name: branch_name,
ref: branch_sha ref: branch_sha
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
it 'should return 400 if branch name is invalid' do it 'returns 400 if branch name is invalid' do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new design', branch_name: 'new design',
ref: branch_sha ref: branch_sha
...@@ -204,7 +204,7 @@ describe API::API, api: true do ...@@ -204,7 +204,7 @@ describe API::API, api: true do
expect(json_response['message']).to eq('Branch name is invalid') expect(json_response['message']).to eq('Branch name is invalid')
end end
it 'should return 400 if branch already exists' do it 'returns 400 if branch already exists' do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design1', branch_name: 'new_design1',
ref: branch_sha ref: branch_sha
...@@ -217,7 +217,7 @@ describe API::API, api: true do ...@@ -217,7 +217,7 @@ describe API::API, api: true do
expect(json_response['message']).to eq('Branch already exists') expect(json_response['message']).to eq('Branch already exists')
end end
it 'should return 400 if ref name is invalid' do it 'returns 400 if ref name is invalid' do
post api("/projects/#{project.id}/repository/branches", user), post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design3', branch_name: 'new_design3',
ref: 'foo' ref: 'foo'
...@@ -231,25 +231,25 @@ describe API::API, api: true do ...@@ -231,25 +231,25 @@ describe API::API, api: true do
allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true) allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
end end
it "should remove branch" do it "removes branch" do
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['branch_name']).to eq(branch_name) expect(json_response['branch_name']).to eq(branch_name)
end end
it 'should return 404 if branch not exists' do it 'returns 404 if branch not exists' do
delete api("/projects/#{project.id}/repository/branches/foobar", user) delete api("/projects/#{project.id}/repository/branches/foobar", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should remove protected branch" do it "removes protected branch" do
project.protected_branches.create(name: branch_name) project.protected_branches.create(name: branch_name)
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
expect(response).to have_http_status(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('Protected branch cant be removed') expect(json_response['message']).to eq('Protected branch cant be removed')
end end
it "should not remove HEAD branch" do it "does not remove HEAD branch" do
delete api("/projects/#{project.id}/repository/branches/master", user) delete api("/projects/#{project.id}/repository/branches/master", user)
expect(response).to have_http_status(405) expect(response).to have_http_status(405)
expect(json_response['message']).to eq('Cannot remove HEAD branch') expect(json_response['message']).to eq('Cannot remove HEAD branch')
......
...@@ -18,7 +18,7 @@ describe API::API, api: true do ...@@ -18,7 +18,7 @@ describe API::API, api: true do
before { get api("/projects/#{project.id}/builds?#{query}", api_user) } before { get api("/projects/#{project.id}/builds?#{query}", api_user) }
context 'authorized user' do context 'authorized user' do
it 'should return project builds' do it 'returns project builds' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
...@@ -84,7 +84,7 @@ describe API::API, api: true do ...@@ -84,7 +84,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user) get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user)
end end
it 'should return project builds for specific commit' do it 'returns project builds for specific commit' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq 2 expect(json_response.size).to eq 2
...@@ -113,7 +113,7 @@ describe API::API, api: true do ...@@ -113,7 +113,7 @@ describe API::API, api: true do
get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", nil) get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", nil)
end end
it 'should not return project builds' do it 'does not return project builds' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
expect(json_response.except('message')).to be_empty expect(json_response.except('message')).to be_empty
end end
...@@ -125,7 +125,7 @@ describe API::API, api: true do ...@@ -125,7 +125,7 @@ describe API::API, api: true do
before { get api("/projects/#{project.id}/builds/#{build.id}", api_user) } before { get api("/projects/#{project.id}/builds/#{build.id}", api_user) }
context 'authorized user' do context 'authorized user' do
it 'should return specific build data' do it 'returns specific build data' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq('test') expect(json_response['name']).to eq('test')
end end
...@@ -134,7 +134,7 @@ describe API::API, api: true do ...@@ -134,7 +134,7 @@ describe API::API, api: true do
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build data' do it 'does not return specific build data' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
...@@ -152,7 +152,7 @@ describe API::API, api: true do ...@@ -152,7 +152,7 @@ describe API::API, api: true do
'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' } 'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' }
end end
it 'should return specific build artifacts' do it 'returns specific build artifacts' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response.headers).to include(download_headers) expect(response.headers).to include(download_headers)
end end
...@@ -161,13 +161,13 @@ describe API::API, api: true do ...@@ -161,13 +161,13 @@ describe API::API, api: true do
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build artifacts' do it 'does not return specific build artifacts' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
end end
it 'should not return build artifacts if not uploaded' do it 'does not return build artifacts if not uploaded' do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
...@@ -272,7 +272,7 @@ describe API::API, api: true do ...@@ -272,7 +272,7 @@ describe API::API, api: true do
end end
context 'authorized user' do context 'authorized user' do
it 'should return specific build trace' do it 'returns specific build trace' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response.body).to eq(build.trace) expect(response.body).to eq(build.trace)
end end
...@@ -281,7 +281,7 @@ describe API::API, api: true do ...@@ -281,7 +281,7 @@ describe API::API, api: true do
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not return specific build trace' do it 'does not return specific build trace' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
...@@ -292,7 +292,7 @@ describe API::API, api: true do ...@@ -292,7 +292,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
context 'user with :update_build persmission' do context 'user with :update_build persmission' do
it 'should cancel running or pending build' do it 'cancels running or pending build' do
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(project.builds.first.status).to eq('canceled') expect(project.builds.first.status).to eq('canceled')
end end
...@@ -301,7 +301,7 @@ describe API::API, api: true do ...@@ -301,7 +301,7 @@ describe API::API, api: true do
context 'user without :update_build permission' do context 'user without :update_build permission' do
let(:api_user) { reporter.user } let(:api_user) { reporter.user }
it 'should not cancel build' do it 'does not cancel build' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
...@@ -310,7 +310,7 @@ describe API::API, api: true do ...@@ -310,7 +310,7 @@ describe API::API, api: true do
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not cancel build' do it 'does not cancel build' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
...@@ -323,7 +323,7 @@ describe API::API, api: true do ...@@ -323,7 +323,7 @@ describe API::API, api: true do
context 'authorized user' do context 'authorized user' do
context 'user with :update_build permission' do context 'user with :update_build permission' do
it 'should retry non-running build' do it 'retries non-running build' do
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(project.builds.first.status).to eq('canceled') expect(project.builds.first.status).to eq('canceled')
expect(json_response['status']).to eq('pending') expect(json_response['status']).to eq('pending')
...@@ -333,7 +333,7 @@ describe API::API, api: true do ...@@ -333,7 +333,7 @@ describe API::API, api: true do
context 'user without :update_build permission' do context 'user without :update_build permission' do
let(:api_user) { reporter.user } let(:api_user) { reporter.user }
it 'should not retry build' do it 'does not retry build' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
...@@ -342,7 +342,7 @@ describe API::API, api: true do ...@@ -342,7 +342,7 @@ describe API::API, api: true do
context 'unauthorized user' do context 'unauthorized user' do
let(:api_user) { nil } let(:api_user) { nil }
it 'should not retry build' do it 'does not retry build' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
...@@ -356,14 +356,14 @@ describe API::API, api: true do ...@@ -356,14 +356,14 @@ describe API::API, api: true do
context 'build is erasable' do context 'build is erasable' do
let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) } let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
it 'should erase build content' do it 'erases build content' do
expect(response.status).to eq 201 expect(response.status).to eq 201
expect(build.trace).to be_empty expect(build.trace).to be_empty
expect(build.artifacts_file.exists?).to be_falsy expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy
end end
it 'should update build' do it 'updates build' do
expect(build.reload.erased_at).to be_truthy expect(build.reload.erased_at).to be_truthy
expect(build.reload.erased_by).to eq user expect(build.reload.erased_by).to eq user
end end
...@@ -372,7 +372,7 @@ describe API::API, api: true do ...@@ -372,7 +372,7 @@ describe API::API, api: true do
context 'build is not erasable' do context 'build is not erasable' do
let(:build) { create(:ci_build, :trace, project: project, pipeline: pipeline) } let(:build) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
it 'should respond with forbidden' do it 'responds with forbidden' do
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
......
...@@ -99,7 +99,7 @@ describe API::CommitStatuses, api: true do ...@@ -99,7 +99,7 @@ describe API::CommitStatuses, api: true do
context "guest user" do context "guest user" do
before { get api(get_url, guest) } before { get api(get_url, guest) }
it "should not return project commits" do it "does not return project commits" do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
...@@ -107,7 +107,7 @@ describe API::CommitStatuses, api: true do ...@@ -107,7 +107,7 @@ describe API::CommitStatuses, api: true do
context "unauthorized user" do context "unauthorized user" do
before { get api(get_url) } before { get api(get_url) }
it "should not return project commits" do it "does not return project commits" do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
...@@ -179,7 +179,7 @@ describe API::CommitStatuses, api: true do ...@@ -179,7 +179,7 @@ describe API::CommitStatuses, api: true do
context 'reporter user' do context 'reporter user' do
before { post api(post_url, reporter) } before { post api(post_url, reporter) }
it 'should not create commit status' do it 'does not create commit status' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
...@@ -187,7 +187,7 @@ describe API::CommitStatuses, api: true do ...@@ -187,7 +187,7 @@ describe API::CommitStatuses, api: true do
context 'guest user' do context 'guest user' do
before { post api(post_url, guest) } before { post api(post_url, guest) }
it 'should not create commit status' do it 'does not create commit status' do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
...@@ -195,7 +195,7 @@ describe API::CommitStatuses, api: true do ...@@ -195,7 +195,7 @@ describe API::CommitStatuses, api: true do
context 'unauthorized user' do context 'unauthorized user' do
before { post api(post_url) } before { post api(post_url) }
it 'should not create commit status' do it 'does not create commit status' do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
......
...@@ -17,7 +17,7 @@ describe API::API, api: true do ...@@ -17,7 +17,7 @@ describe API::API, api: true do
context "authorized user" do context "authorized user" do
before { project.team << [user2, :reporter] } before { project.team << [user2, :reporter] }
it "should return project commits" do it "returns project commits" do
get api("/projects/#{project.id}/repository/commits", user) get api("/projects/#{project.id}/repository/commits", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -27,14 +27,14 @@ describe API::API, api: true do ...@@ -27,14 +27,14 @@ describe API::API, api: true do
end end
context "unauthorized user" do context "unauthorized user" do
it "should not return project commits" do it "does not return project commits" do
get api("/projects/#{project.id}/repository/commits") get api("/projects/#{project.id}/repository/commits")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context "since optional parameter" do context "since optional parameter" do
it "should return project commits since provided parameter" do it "returns project commits since provided parameter" do
commits = project.repository.commits("master") commits = project.repository.commits("master")
since = commits.second.created_at since = commits.second.created_at
...@@ -47,7 +47,7 @@ describe API::API, api: true do ...@@ -47,7 +47,7 @@ describe API::API, api: true do
end end
context "until optional parameter" do context "until optional parameter" do
it "should return project commits until provided parameter" do it "returns project commits until provided parameter" do
commits = project.repository.commits("master") commits = project.repository.commits("master")
before = commits.second.created_at before = commits.second.created_at
...@@ -60,7 +60,7 @@ describe API::API, api: true do ...@@ -60,7 +60,7 @@ describe API::API, api: true do
end end
context "invalid xmlschema date parameters" do context "invalid xmlschema date parameters" do
it "should return an invalid parameter error message" do it "returns an invalid parameter error message" do
get api("/projects/#{project.id}/repository/commits?since=invalid-date", user) get api("/projects/#{project.id}/repository/commits?since=invalid-date", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
...@@ -71,7 +71,7 @@ describe API::API, api: true do ...@@ -71,7 +71,7 @@ describe API::API, api: true do
describe "GET /projects:id/repository/commits/:sha" do describe "GET /projects:id/repository/commits/:sha" do
context "authorized user" do context "authorized user" do
it "should return a commit by sha" do it "returns a commit by sha" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -82,18 +82,18 @@ describe API::API, api: true do ...@@ -82,18 +82,18 @@ describe API::API, api: true do
expect(json_response['stats']['total']).to eq(project.repository.commit.stats.total) expect(json_response['stats']['total']).to eq(project.repository.commit.stats.total)
end end
it "should return a 404 error if not found" do it "returns a 404 error if not found" do
get api("/projects/#{project.id}/repository/commits/invalid_sha", user) get api("/projects/#{project.id}/repository/commits/invalid_sha", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return nil for commit without CI" do it "returns nil for commit without CI" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['status']).to be_nil expect(json_response['status']).to be_nil
end end
it "should return status for CI" do it "returns status for CI" do
pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master') pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master')
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -102,7 +102,7 @@ describe API::API, api: true do ...@@ -102,7 +102,7 @@ describe API::API, api: true do
end end
context "unauthorized user" do context "unauthorized user" do
it "should not return the selected commit" do it "does not return the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}") get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
...@@ -113,7 +113,7 @@ describe API::API, api: true do ...@@ -113,7 +113,7 @@ describe API::API, api: true do
context "authorized user" do context "authorized user" do
before { project.team << [user2, :reporter] } before { project.team << [user2, :reporter] }
it "should return the diff of the selected commit" do it "returns the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -122,14 +122,14 @@ describe API::API, api: true do ...@@ -122,14 +122,14 @@ describe API::API, api: true do
expect(json_response.first.keys).to include "diff" expect(json_response.first.keys).to include "diff"
end end
it "should return a 404 error if invalid commit" do it "returns a 404 error if invalid commit" do
get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user) get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context "unauthorized user" do context "unauthorized user" do
it "should not return the diff of the selected commit" do it "does not return the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff") get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
...@@ -138,7 +138,7 @@ describe API::API, api: true do ...@@ -138,7 +138,7 @@ describe API::API, api: true do
describe 'GET /projects:id/repository/commits/:sha/comments' do describe 'GET /projects:id/repository/commits/:sha/comments' do
context 'authorized user' do context 'authorized user' do
it 'should return merge_request comments' do it 'returns merge_request comments' do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -147,14 +147,14 @@ describe API::API, api: true do ...@@ -147,14 +147,14 @@ describe API::API, api: true do
expect(json_response.first['author']['id']).to eq(user.id) expect(json_response.first['author']['id']).to eq(user.id)
end end
it 'should return a 404 error if merge_request_id not found' do it 'returns a 404 error if merge_request_id not found' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments", user) get api("/projects/#{project.id}/repository/commits/1234ab/comments", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'unauthorized user' do context 'unauthorized user' do
it 'should not return the diff of the selected commit' do it 'does not return the diff of the selected commit' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments") get api("/projects/#{project.id}/repository/commits/1234ab/comments")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
...@@ -163,7 +163,7 @@ describe API::API, api: true do ...@@ -163,7 +163,7 @@ describe API::API, api: true do
describe 'POST /projects:id/repository/commits/:sha/comments' do describe 'POST /projects:id/repository/commits/:sha/comments' do
context 'authorized user' do context 'authorized user' do
it 'should return comment' do it 'returns comment' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment' post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment') expect(json_response['note']).to eq('My comment')
...@@ -172,7 +172,7 @@ describe API::API, api: true do ...@@ -172,7 +172,7 @@ describe API::API, api: true do
expect(json_response['line_type']).to be_nil expect(json_response['line_type']).to be_nil
end end
it 'should return the inline comment' do it 'returns the inline comment' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.raw_diffs.first.new_path, line: 7, line_type: 'new' post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.raw_diffs.first.new_path, line: 7, line_type: 'new'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment') expect(json_response['note']).to eq('My comment')
...@@ -181,19 +181,19 @@ describe API::API, api: true do ...@@ -181,19 +181,19 @@ describe API::API, api: true do
expect(json_response['line_type']).to eq('new') expect(json_response['line_type']).to eq('new')
end end
it 'should return 400 if note is missing' do it 'returns 400 if note is missing' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it 'should return 404 if note is attached to non existent commit' do it 'returns 404 if note is attached to non existent commit' do
post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment' post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'unauthorized user' do context 'unauthorized user' do
it 'should not return the diff of the selected commit' do it 'does not return the diff of the selected commit' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments") post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
......
...@@ -9,7 +9,7 @@ describe API::API, api: true do ...@@ -9,7 +9,7 @@ describe API::API, api: true do
before { project.team << [user, :developer] } before { project.team << [user, :developer] }
describe "GET /projects/:id/repository/files" do describe "GET /projects/:id/repository/files" do
it "should return file info" do it "returns file info" do
params = { params = {
file_path: file_path, file_path: file_path,
ref: 'master', ref: 'master',
...@@ -23,12 +23,12 @@ describe API::API, api: true do ...@@ -23,12 +23,12 @@ describe API::API, api: true do
expect(Base64.decode64(json_response['content']).lines.first).to eq("require 'fileutils'\n") expect(Base64.decode64(json_response['content']).lines.first).to eq("require 'fileutils'\n")
end end
it "should return a 400 bad request if no params given" do it "returns a 400 bad request if no params given" do
get api("/projects/#{project.id}/repository/files", user) get api("/projects/#{project.id}/repository/files", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 404 if such file does not exist" do it "returns a 404 if such file does not exist" do
params = { params = {
file_path: 'app/models/application.rb', file_path: 'app/models/application.rb',
ref: 'master', ref: 'master',
...@@ -49,18 +49,18 @@ describe API::API, api: true do ...@@ -49,18 +49,18 @@ describe API::API, api: true do
} }
end end
it "should create a new file in project repo" do it "creates a new file in project repo" do
post api("/projects/#{project.id}/repository/files", user), valid_params post api("/projects/#{project.id}/repository/files", user), valid_params
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['file_path']).to eq('newfile.rb') expect(json_response['file_path']).to eq('newfile.rb')
end end
it "should return a 400 bad request if no params given" do it "returns a 400 bad request if no params given" do
post api("/projects/#{project.id}/repository/files", user) post api("/projects/#{project.id}/repository/files", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 400 if editor fails to create file" do it "returns a 400 if editor fails to create file" do
allow_any_instance_of(Repository).to receive(:commit_file). allow_any_instance_of(Repository).to receive(:commit_file).
and_return(false) and_return(false)
...@@ -79,13 +79,13 @@ describe API::API, api: true do ...@@ -79,13 +79,13 @@ describe API::API, api: true do
} }
end end
it "should update existing file in project repo" do it "updates existing file in project repo" do
put api("/projects/#{project.id}/repository/files", user), valid_params put api("/projects/#{project.id}/repository/files", user), valid_params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
end end
it "should return a 400 bad request if no params given" do it "returns a 400 bad request if no params given" do
put api("/projects/#{project.id}/repository/files", user) put api("/projects/#{project.id}/repository/files", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
...@@ -100,18 +100,18 @@ describe API::API, api: true do ...@@ -100,18 +100,18 @@ describe API::API, api: true do
} }
end end
it "should delete existing file in project repo" do it "deletes existing file in project repo" do
delete api("/projects/#{project.id}/repository/files", user), valid_params delete api("/projects/#{project.id}/repository/files", user), valid_params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['file_path']).to eq(file_path) expect(json_response['file_path']).to eq(file_path)
end end
it "should return a 400 bad request if no params given" do it "returns a 400 bad request if no params given" do
delete api("/projects/#{project.id}/repository/files", user) delete api("/projects/#{project.id}/repository/files", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 400 if fails to create file" do it "returns a 400 if fails to create file" do
allow_any_instance_of(Repository).to receive(:remove_file).and_return(false) allow_any_instance_of(Repository).to receive(:remove_file).and_return(false)
delete api("/projects/#{project.id}/repository/files", user), valid_params delete api("/projects/#{project.id}/repository/files", user), valid_params
......
...@@ -20,7 +20,7 @@ describe API::API, api: true do ...@@ -20,7 +20,7 @@ describe API::API, api: true do
before { user3 } before { user3 }
context 'when authenticated' do context 'when authenticated' do
it 'should fork if user has sufficient access to project' do it 'forks if user has sufficient access to project' do
post api("/projects/fork/#{project.id}", user2) post api("/projects/fork/#{project.id}", user2)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
...@@ -30,7 +30,7 @@ describe API::API, api: true do ...@@ -30,7 +30,7 @@ describe API::API, api: true do
expect(json_response['forked_from_project']['id']).to eq(project.id) expect(json_response['forked_from_project']['id']).to eq(project.id)
end end
it 'should fork if user is admin' do it 'forks if user is admin' do
post api("/projects/fork/#{project.id}", admin) post api("/projects/fork/#{project.id}", admin)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['name']).to eq(project.name) expect(json_response['name']).to eq(project.name)
...@@ -40,20 +40,20 @@ describe API::API, api: true do ...@@ -40,20 +40,20 @@ describe API::API, api: true do
expect(json_response['forked_from_project']['id']).to eq(project.id) expect(json_response['forked_from_project']['id']).to eq(project.id)
end end
it 'should fail on missing project access for the project to fork' do it 'fails on missing project access for the project to fork' do
post api("/projects/fork/#{project.id}", user3) post api("/projects/fork/#{project.id}", user3)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
it 'should fail if forked project exists in the user namespace' do it 'fails if forked project exists in the user namespace' do
post api("/projects/fork/#{project.id}", user) post api("/projects/fork/#{project.id}", user)
expect(response).to have_http_status(409) expect(response).to have_http_status(409)
expect(json_response['message']['name']).to eq(['has already been taken']) expect(json_response['message']['name']).to eq(['has already been taken'])
expect(json_response['message']['path']).to eq(['has already been taken']) expect(json_response['message']['path']).to eq(['has already been taken'])
end end
it 'should fail if project to fork from does not exist' do it 'fails if project to fork from does not exist' do
post api('/projects/fork/424242', user) post api('/projects/fork/424242', user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
...@@ -61,7 +61,7 @@ describe API::API, api: true do ...@@ -61,7 +61,7 @@ describe API::API, api: true do
end end
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'returns authentication error' do
post api("/projects/fork/#{project.id}") post api("/projects/fork/#{project.id}")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
expect(json_response['message']).to eq('401 Unauthorized') expect(json_response['message']).to eq('401 Unauthorized')
......
...@@ -28,7 +28,7 @@ describe API::API, api: true do ...@@ -28,7 +28,7 @@ describe API::API, api: true do
describe "GET /groups/:id/members" do describe "GET /groups/:id/members" do
context "when authenticated as user that is part or the group" do context "when authenticated as user that is part or the group" do
it "each user: should return an array of members groups of group3" do it "each user: returns an array of members groups of group3" do
[owner, master, developer, reporter, guest].each do |user| [owner, master, developer, reporter, guest].each do |user|
get api("/groups/#{group_with_members.id}/members", user) get api("/groups/#{group_with_members.id}/members", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -52,14 +52,14 @@ describe API::API, api: true do ...@@ -52,14 +52,14 @@ describe API::API, api: true do
describe "POST /groups/:id/members" do describe "POST /groups/:id/members" do
context "when not a member of the group" do context "when not a member of the group" do
it "should not add guest as member of group_no_members when adding being done by person outside the group" do it "does not add guest as member of group_no_members when adding being done by person outside the group" do
post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context "when a member of the group" do context "when a member of the group" do
it "should return ok and add new member" do it "returns ok and add new member" do
new_user = create(:user) new_user = create(:user)
expect do expect do
...@@ -71,7 +71,7 @@ describe API::API, api: true do ...@@ -71,7 +71,7 @@ describe API::API, api: true do
expect(json_response['access_level']).to eq(GroupMember::MASTER) expect(json_response['access_level']).to eq(GroupMember::MASTER)
end end
it "should not allow guest to modify group members" do it "does not allow guest to modify group members" do
new_user = create(:user) new_user = create(:user)
expect do expect do
...@@ -81,22 +81,22 @@ describe API::API, api: true do ...@@ -81,22 +81,22 @@ describe API::API, api: true do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
it "should return error if member already exists" do it "returns error if member already exists" do
post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER
expect(response).to have_http_status(409) expect(response).to have_http_status(409)
end end
it "should return a 400 error when user id is not given" do it "returns a 400 error when user id is not given" do
post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 400 error when access level is not given" do it "returns a 400 error when access level is not given" do
post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "returns a 422 error when access level is not known" do
post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id, access_level: 1234 post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id, access_level: 1234
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
...@@ -105,7 +105,7 @@ describe API::API, api: true do ...@@ -105,7 +105,7 @@ describe API::API, api: true do
describe 'PUT /groups/:id/members/:user_id' do describe 'PUT /groups/:id/members/:user_id' do
context 'when not a member of the group' do context 'when not a member of the group' do
it 'should return a 409 error if the user is not a group member' do it 'returns a 409 error if the user is not a group member' do
put( put(
api("/groups/#{group_no_members.id}/members/#{developer.id}", api("/groups/#{group_no_members.id}/members/#{developer.id}",
owner), access_level: GroupMember::MASTER owner), access_level: GroupMember::MASTER
...@@ -115,7 +115,7 @@ describe API::API, api: true do ...@@ -115,7 +115,7 @@ describe API::API, api: true do
end end
context 'when a member of the group' do context 'when a member of the group' do
it 'should return ok and update member access level' do it 'returns ok and update member access level' do
put( put(
api("/groups/#{group_with_members.id}/members/#{reporter.id}", api("/groups/#{group_with_members.id}/members/#{reporter.id}",
owner), owner),
...@@ -132,7 +132,7 @@ describe API::API, api: true do ...@@ -132,7 +132,7 @@ describe API::API, api: true do
expect(json_reporter['access_level']).to eq(GroupMember::MASTER) expect(json_reporter['access_level']).to eq(GroupMember::MASTER)
end end
it 'should not allow guest to modify group members' do it 'does not allow guest to modify group members' do
put( put(
api("/groups/#{group_with_members.id}/members/#{developer.id}", api("/groups/#{group_with_members.id}/members/#{developer.id}",
guest), guest),
...@@ -149,14 +149,14 @@ describe API::API, api: true do ...@@ -149,14 +149,14 @@ describe API::API, api: true do
expect(json_developer['access_level']).to eq(GroupMember::DEVELOPER) expect(json_developer['access_level']).to eq(GroupMember::DEVELOPER)
end end
it 'should return a 400 error when access level is not given' do it 'returns a 400 error when access level is not given' do
put( put(
api("/groups/#{group_with_members.id}/members/#{master.id}", owner) api("/groups/#{group_with_members.id}/members/#{master.id}", owner)
) )
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it 'should return a 422 error when access level is not known' do it 'returns a 422 error when access level is not known' do
put( put(
api("/groups/#{group_with_members.id}/members/#{master.id}", owner), api("/groups/#{group_with_members.id}/members/#{master.id}", owner),
access_level: 1234 access_level: 1234
...@@ -168,7 +168,7 @@ describe API::API, api: true do ...@@ -168,7 +168,7 @@ describe API::API, api: true do
describe 'DELETE /groups/:id/members/:user_id' do describe 'DELETE /groups/:id/members/:user_id' do
context 'when not a member of the group' do context 'when not a member of the group' do
it "should not delete guest's membership of group_with_members" do it "does not delete guest's membership of group_with_members" do
random_user = create(:user) random_user = create(:user)
delete api("/groups/#{group_with_members.id}/members/#{owner.id}", random_user) delete api("/groups/#{group_with_members.id}/members/#{owner.id}", random_user)
...@@ -177,7 +177,7 @@ describe API::API, api: true do ...@@ -177,7 +177,7 @@ describe API::API, api: true do
end end
context "when a member of the group" do context "when a member of the group" do
it "should delete guest's membership of group" do it "deletes guest's membership of group" do
expect do expect do
delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner) delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner)
end.to change { group_with_members.members.count }.by(-1) end.to change { group_with_members.members.count }.by(-1)
...@@ -185,12 +185,12 @@ describe API::API, api: true do ...@@ -185,12 +185,12 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return a 404 error when user id is not known" do it "returns a 404 error when user id is not known" do
delete api("/groups/#{group_with_members.id}/members/1328", owner) delete api("/groups/#{group_with_members.id}/members/1328", owner)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should not allow guest to modify group members" do it "does not allow guest to modify group members" do
delete api("/groups/#{group_with_members.id}/members/#{master.id}", guest) delete api("/groups/#{group_with_members.id}/members/#{master.id}", guest)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
......
...@@ -21,14 +21,14 @@ describe API::API, api: true do ...@@ -21,14 +21,14 @@ describe API::API, api: true do
describe "GET /groups" do describe "GET /groups" do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "returns authentication error" do
get api("/groups") get api("/groups")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated as user" do context "when authenticated as user" do
it "normal user: should return an array of groups of user1" do it "normal user: returns an array of groups of user1" do
get api("/groups", user1) get api("/groups", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -38,7 +38,7 @@ describe API::API, api: true do ...@@ -38,7 +38,7 @@ describe API::API, api: true do
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "admin: should return an array of all groups" do it "admin: returns an array of all groups" do
get api("/groups", admin) get api("/groups", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -70,12 +70,12 @@ describe API::API, api: true do ...@@ -70,12 +70,12 @@ describe API::API, api: true do
expect(json_response['shared_projects'][0]['id']).to eq(project.id) expect(json_response['shared_projects'][0]['id']).to eq(project.id)
end end
it "should not return a non existing group" do it "does not return a non existing group" do
get api("/groups/1328", user1) get api("/groups/1328", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should not return a group not attached to user1" do it "does not return a group not attached to user1" do
get api("/groups/#{group2.id}", user1) get api("/groups/#{group2.id}", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -83,31 +83,31 @@ describe API::API, api: true do ...@@ -83,31 +83,31 @@ describe API::API, api: true do
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should return any existing group" do it "returns any existing group" do
get api("/groups/#{group2.id}", admin) get api("/groups/#{group2.id}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group2.name) expect(json_response['name']).to eq(group2.name)
end end
it "should not return a non existing group" do it "does not return a non existing group" do
get api("/groups/1328", admin) get api("/groups/1328", admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'when using group path in URL' do context 'when using group path in URL' do
it 'should return any existing group' do it 'returns any existing group' do
get api("/groups/#{group1.path}", admin) get api("/groups/#{group1.path}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group1.name) expect(json_response['name']).to eq(group1.name)
end end
it 'should not return a non existing group' do it 'does not return a non existing group' do
get api('/groups/unknown', admin) get api('/groups/unknown', admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it 'should not return a group not attached to user1' do it 'does not return a group not attached to user1' do
get api("/groups/#{group2.path}", user1) get api("/groups/#{group2.path}", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -161,7 +161,7 @@ describe API::API, api: true do ...@@ -161,7 +161,7 @@ describe API::API, api: true do
describe "GET /groups/:id/projects" do describe "GET /groups/:id/projects" do
context "when authenticated as user" do context "when authenticated as user" do
it "should return the group's projects" do it "returns the group's projects" do
get api("/groups/#{group1.id}/projects", user1) get api("/groups/#{group1.id}/projects", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -170,12 +170,12 @@ describe API::API, api: true do ...@@ -170,12 +170,12 @@ describe API::API, api: true do
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
end end
it "should not return a non existing group" do it "does not return a non existing group" do
get api("/groups/1328/projects", user1) get api("/groups/1328/projects", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should not return a group not attached to user1" do it "does not return a group not attached to user1" do
get api("/groups/#{group2.id}/projects", user1) get api("/groups/#{group2.id}/projects", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -215,12 +215,12 @@ describe API::API, api: true do ...@@ -215,12 +215,12 @@ describe API::API, api: true do
expect(project_names).to match_array([project1.name, project3.name]) expect(project_names).to match_array([project1.name, project3.name])
end end
it 'should not return a non existing group' do it 'does not return a non existing group' do
get api('/groups/unknown/projects', admin) get api('/groups/unknown/projects', admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it 'should not return a group not attached to user1' do it 'does not return a group not attached to user1' do
get api("/groups/#{group2.path}/projects", user1) get api("/groups/#{group2.path}/projects", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -230,30 +230,30 @@ describe API::API, api: true do ...@@ -230,30 +230,30 @@ describe API::API, api: true do
describe "POST /groups" do describe "POST /groups" do
context "when authenticated as user without group permissions" do context "when authenticated as user without group permissions" do
it "should not create group" do it "does not create group" do
post api("/groups", user1), attributes_for(:group) post api("/groups", user1), attributes_for(:group)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as user with group permissions" do context "when authenticated as user with group permissions" do
it "should create group" do it "creates group" do
post api("/groups", user3), attributes_for(:group) post api("/groups", user3), attributes_for(:group)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
end end
it "should not create group, duplicate" do it "does not create group, duplicate" do
post api("/groups", user3), { name: 'Duplicate Test', path: group2.path } post api("/groups", user3), { name: 'Duplicate Test', path: group2.path }
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
expect(response.message).to eq("Bad Request") expect(response.message).to eq("Bad Request")
end end
it "should return 400 bad request error if name not given" do it "returns 400 bad request error if name not given" do
post api("/groups", user3), { path: group2.path } post api("/groups", user3), { path: group2.path }
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return 400 bad request error if path not given" do it "returns 400 bad request error if path not given" do
post api("/groups", user3), { name: 'test' } post api("/groups", user3), { name: 'test' }
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
...@@ -262,24 +262,24 @@ describe API::API, api: true do ...@@ -262,24 +262,24 @@ describe API::API, api: true do
describe "DELETE /groups/:id" do describe "DELETE /groups/:id" do
context "when authenticated as user" do context "when authenticated as user" do
it "should remove group" do it "removes group" do
delete api("/groups/#{group1.id}", user1) delete api("/groups/#{group1.id}", user1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should not remove a group if not an owner" do it "does not remove a group if not an owner" do
user4 = create(:user) user4 = create(:user)
group1.add_master(user4) group1.add_master(user4)
delete api("/groups/#{group1.id}", user3) delete api("/groups/#{group1.id}", user3)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
it "should not remove a non existing group" do it "does not remove a non existing group" do
delete api("/groups/1328", user1) delete api("/groups/1328", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should not remove a group not attached to user1" do it "does not remove a group not attached to user1" do
delete api("/groups/#{group2.id}", user1) delete api("/groups/#{group2.id}", user1)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -287,12 +287,12 @@ describe API::API, api: true do ...@@ -287,12 +287,12 @@ describe API::API, api: true do
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should remove any existing group" do it "removes any existing group" do
delete api("/groups/#{group2.id}", admin) delete api("/groups/#{group2.id}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should not remove a non existing group" do it "does not remove a non existing group" do
delete api("/groups/1328", admin) delete api("/groups/1328", admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
...@@ -308,14 +308,14 @@ describe API::API, api: true do ...@@ -308,14 +308,14 @@ describe API::API, api: true do
end end
context "when authenticated as user" do context "when authenticated as user" do
it "should not transfer project to group" do it "does not transfer project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", user2) post api("/groups/#{group1.id}/projects/#{project.id}", user2)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should transfer project to group" do it "transfers project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", admin) post api("/groups/#{group1.id}/projects/#{project.id}", admin)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
end end
......
This diff is collapsed.
...@@ -12,20 +12,20 @@ describe API::API, api: true do ...@@ -12,20 +12,20 @@ describe API::API, api: true do
before { admin } before { admin }
context 'when unauthenticated' do context 'when unauthenticated' do
it 'should return authentication error' do it 'returns authentication error' do
get api("/keys/#{key.id}") get api("/keys/#{key.id}")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'should return 404 for non-existing key' do it 'returns 404 for non-existing key' do
get api('/keys/999999', admin) get api('/keys/999999', admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
it 'should return single ssh key with user information' do it 'returns single ssh key with user information' do
user.keys << key user.keys << key
user.save user.save
get api("/keys/#{key.id}", admin) get api("/keys/#{key.id}", admin)
......
...@@ -12,7 +12,7 @@ describe API::API, api: true do ...@@ -12,7 +12,7 @@ describe API::API, api: true do
end end
describe 'GET /projects/:id/labels' do describe 'GET /projects/:id/labels' do
it 'should return project labels' do it 'returns project labels' do
get api("/projects/#{project.id}/labels", user) get api("/projects/#{project.id}/labels", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -22,7 +22,7 @@ describe API::API, api: true do ...@@ -22,7 +22,7 @@ describe API::API, api: true do
end end
describe 'POST /projects/:id/labels' do describe 'POST /projects/:id/labels' do
it 'should return created label when all params' do it 'returns created label when all params' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAABB', color: '#FFAABB',
...@@ -33,7 +33,7 @@ describe API::API, api: true do ...@@ -33,7 +33,7 @@ describe API::API, api: true do
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
end end
it 'should return created label when only required params' do it 'returns created label when only required params' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo & Bar', name: 'Foo & Bar',
color: '#FFAABB' color: '#FFAABB'
...@@ -43,17 +43,17 @@ describe API::API, api: true do ...@@ -43,17 +43,17 @@ describe API::API, api: true do
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
end end
it 'should return a 400 bad request if name not given' do it 'returns a 400 bad request if name not given' do
post api("/projects/#{project.id}/labels", user), color: '#FFAABB' post api("/projects/#{project.id}/labels", user), color: '#FFAABB'
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it 'should return a 400 bad request if color not given' do it 'returns a 400 bad request if color not given' do
post api("/projects/#{project.id}/labels", user), name: 'Foobar' post api("/projects/#{project.id}/labels", user), name: 'Foobar'
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it 'should return 400 for invalid color' do it 'returns 400 for invalid color' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAA' color: '#FFAA'
...@@ -61,7 +61,7 @@ describe API::API, api: true do ...@@ -61,7 +61,7 @@ describe API::API, api: true do
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
it 'should return 400 for too long color code' do it 'returns 400 for too long color code' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAAFFFF' color: '#FFAAFFFF'
...@@ -69,7 +69,7 @@ describe API::API, api: true do ...@@ -69,7 +69,7 @@ describe API::API, api: true do
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
it 'should return 400 for invalid name' do it 'returns 400 for invalid name' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: ',', name: ',',
color: '#FFAABB' color: '#FFAABB'
...@@ -77,7 +77,7 @@ describe API::API, api: true do ...@@ -77,7 +77,7 @@ describe API::API, api: true do
expect(json_response['message']['title']).to eq(['is invalid']) expect(json_response['message']['title']).to eq(['is invalid'])
end end
it 'should return 409 if label already exists' do it 'returns 409 if label already exists' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FFAABB' color: '#FFAABB'
...@@ -87,25 +87,25 @@ describe API::API, api: true do ...@@ -87,25 +87,25 @@ describe API::API, api: true do
end end
describe 'DELETE /projects/:id/labels' do describe 'DELETE /projects/:id/labels' do
it 'should return 200 for existing label' do it 'returns 200 for existing label' do
delete api("/projects/#{project.id}/labels", user), name: 'label1' delete api("/projects/#{project.id}/labels", user), name: 'label1'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'should return 404 for non existing label' do it 'returns 404 for non existing label' do
delete api("/projects/#{project.id}/labels", user), name: 'label2' delete api("/projects/#{project.id}/labels", user), name: 'label2'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Label Not Found') expect(json_response['message']).to eq('404 Label Not Found')
end end
it 'should return 400 for wrong parameters' do it 'returns 400 for wrong parameters' do
delete api("/projects/#{project.id}/labels", user) delete api("/projects/#{project.id}/labels", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
end end
describe 'PUT /projects/:id/labels' do describe 'PUT /projects/:id/labels' do
it 'should return 200 if name and colors and description are changed' do it 'returns 200 if name and colors and description are changed' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
new_name: 'New Label', new_name: 'New Label',
...@@ -117,7 +117,7 @@ describe API::API, api: true do ...@@ -117,7 +117,7 @@ describe API::API, api: true do
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
end end
it 'should return 200 if name is changed' do it 'returns 200 if name is changed' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
new_name: 'New Label' new_name: 'New Label'
...@@ -126,7 +126,7 @@ describe API::API, api: true do ...@@ -126,7 +126,7 @@ describe API::API, api: true do
expect(json_response['color']).to eq(label1.color) expect(json_response['color']).to eq(label1.color)
end end
it 'should return 200 if colors is changed' do it 'returns 200 if colors is changed' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FFFFFF' color: '#FFFFFF'
...@@ -135,7 +135,7 @@ describe API::API, api: true do ...@@ -135,7 +135,7 @@ describe API::API, api: true do
expect(json_response['color']).to eq('#FFFFFF') expect(json_response['color']).to eq('#FFFFFF')
end end
it 'should return 200 if description is changed' do it 'returns 200 if description is changed' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
description: 'test' description: 'test'
...@@ -144,27 +144,27 @@ describe API::API, api: true do ...@@ -144,27 +144,27 @@ describe API::API, api: true do
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
end end
it 'should return 404 if label does not exist' do it 'returns 404 if label does not exist' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label2', name: 'label2',
new_name: 'label3' new_name: 'label3'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it 'should return 400 if no label name given' do it 'returns 400 if no label name given' do
put api("/projects/#{project.id}/labels", user), new_name: 'label2' put api("/projects/#{project.id}/labels", user), new_name: 'label2'
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('400 (Bad request) "name" not given') expect(json_response['message']).to eq('400 (Bad request) "name" not given')
end end
it 'should return 400 if no new parameters given' do it 'returns 400 if no new parameters given' do
put api("/projects/#{project.id}/labels", user), name: 'label1' put api("/projects/#{project.id}/labels", user), name: 'label1'
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Required parameters '\ expect(json_response['message']).to eq('Required parameters '\
'"new_name" or "color" missing') '"new_name" or "color" missing')
end end
it 'should return 400 for invalid name' do it 'returns 400 for invalid name' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
new_name: ',', new_name: ',',
...@@ -173,7 +173,7 @@ describe API::API, api: true do ...@@ -173,7 +173,7 @@ describe API::API, api: true do
expect(json_response['message']['title']).to eq(['is invalid']) expect(json_response['message']['title']).to eq(['is invalid'])
end end
it 'should return 400 when color code is too short' do it 'returns 400 when color code is too short' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
color: '#FF' color: '#FF'
...@@ -181,7 +181,7 @@ describe API::API, api: true do ...@@ -181,7 +181,7 @@ describe API::API, api: true do
expect(json_response['message']['color']).to eq(['must be a valid color code']) expect(json_response['message']['color']).to eq(['must be a valid color code'])
end end
it 'should return 400 for too long color code' do it 'returns 400 for too long color code' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAAFFFF' color: '#FFAAFFFF'
...@@ -192,7 +192,7 @@ describe API::API, api: true do ...@@ -192,7 +192,7 @@ describe API::API, api: true do
describe "POST /projects/:id/labels/:label_id/subscription" do describe "POST /projects/:id/labels/:label_id/subscription" do
context "when label_id is a label title" do context "when label_id is a label title" do
it "should subscribe to the label" do it "subscribes to the label" do
post api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.title}/subscription", user)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -202,7 +202,7 @@ describe API::API, api: true do ...@@ -202,7 +202,7 @@ describe API::API, api: true do
end end
context "when label_id is a label ID" do context "when label_id is a label ID" do
it "should subscribe to the label" do it "subscribes to the label" do
post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -214,7 +214,7 @@ describe API::API, api: true do ...@@ -214,7 +214,7 @@ describe API::API, api: true do
context "when user is already subscribed to label" do context "when user is already subscribed to label" do
before { label1.subscribe(user) } before { label1.subscribe(user) }
it "should return 304" do it "returns 304" do
post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response).to have_http_status(304) expect(response).to have_http_status(304)
...@@ -222,7 +222,7 @@ describe API::API, api: true do ...@@ -222,7 +222,7 @@ describe API::API, api: true do
end end
context "when label ID is not found" do context "when label ID is not found" do
it "should a return 404 error" do it "returns 404 error" do
post api("/projects/#{project.id}/labels/1234/subscription", user) post api("/projects/#{project.id}/labels/1234/subscription", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -234,7 +234,7 @@ describe API::API, api: true do ...@@ -234,7 +234,7 @@ describe API::API, api: true do
before { label1.subscribe(user) } before { label1.subscribe(user) }
context "when label_id is a label title" do context "when label_id is a label title" do
it "should unsubscribe from the label" do it "unsubscribes from the label" do
delete api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.title}/subscription", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -244,7 +244,7 @@ describe API::API, api: true do ...@@ -244,7 +244,7 @@ describe API::API, api: true do
end end
context "when label_id is a label ID" do context "when label_id is a label ID" do
it "should unsubscribe from the label" do it "unsubscribes from the label" do
delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -256,7 +256,7 @@ describe API::API, api: true do ...@@ -256,7 +256,7 @@ describe API::API, api: true do
context "when user is already unsubscribed from label" do context "when user is already unsubscribed from label" do
before { label1.unsubscribe(user) } before { label1.unsubscribe(user) }
it "should return 304" do it "returns 304" do
delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
expect(response).to have_http_status(304) expect(response).to have_http_status(304)
...@@ -264,7 +264,7 @@ describe API::API, api: true do ...@@ -264,7 +264,7 @@ describe API::API, api: true do
end end
context "when label ID is not found" do context "when label ID is not found" do
it "should a return 404 error" do it "returns 404 error" do
delete api("/projects/#{project.id}/labels/1234/subscription", user) delete api("/projects/#{project.id}/labels/1234/subscription", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
......
This diff is collapsed.
...@@ -10,14 +10,14 @@ describe API::API, api: true do ...@@ -10,14 +10,14 @@ describe API::API, api: true do
before { project.team << [user, :developer] } before { project.team << [user, :developer] }
describe 'GET /projects/:id/milestones' do describe 'GET /projects/:id/milestones' do
it 'should return project milestones' do it 'returns project milestones' do
get api("/projects/#{project.id}/milestones", user) get api("/projects/#{project.id}/milestones", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(milestone.title) expect(json_response.first['title']).to eq(milestone.title)
end end
it 'should return a 401 error if user not authenticated' do it 'returns a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones") get api("/projects/#{project.id}/milestones")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
...@@ -42,14 +42,14 @@ describe API::API, api: true do ...@@ -42,14 +42,14 @@ describe API::API, api: true do
end end
describe 'GET /projects/:id/milestones/:milestone_id' do describe 'GET /projects/:id/milestones/:milestone_id' do
it 'should return a project milestone by id' do it 'returns a project milestone by id' do
get api("/projects/#{project.id}/milestones/#{milestone.id}", user) get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq(milestone.title) expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid) expect(json_response['iid']).to eq(milestone.iid)
end end
it 'should return a project milestone by iid' do it 'returns a project milestone by iid' do
get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user) get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user)
expect(response.status).to eq 200 expect(response.status).to eq 200
...@@ -58,26 +58,26 @@ describe API::API, api: true do ...@@ -58,26 +58,26 @@ describe API::API, api: true do
expect(json_response.first['id']).to eq closed_milestone.id expect(json_response.first['id']).to eq closed_milestone.id
end end
it 'should return 401 error if user not authenticated' do it 'returns 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}") get api("/projects/#{project.id}/milestones/#{milestone.id}")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
it 'should return a 404 error if milestone id not found' do it 'returns a 404 error if milestone id not found' do
get api("/projects/#{project.id}/milestones/1234", user) get api("/projects/#{project.id}/milestones/1234", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
describe 'POST /projects/:id/milestones' do describe 'POST /projects/:id/milestones' do
it 'should create a new project milestone' do it 'creates a new project milestone' do
post api("/projects/#{project.id}/milestones", user), title: 'new milestone' post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['title']).to eq('new milestone') expect(json_response['title']).to eq('new milestone')
expect(json_response['description']).to be_nil expect(json_response['description']).to be_nil
end end
it 'should create a new project milestone with description and due date' do it 'creates a new project milestone with description and due date' do
post api("/projects/#{project.id}/milestones", user), post api("/projects/#{project.id}/milestones", user),
title: 'new milestone', description: 'release', due_date: '2013-03-02' title: 'new milestone', description: 'release', due_date: '2013-03-02'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -85,21 +85,21 @@ describe API::API, api: true do ...@@ -85,21 +85,21 @@ describe API::API, api: true do
expect(json_response['due_date']).to eq('2013-03-02') expect(json_response['due_date']).to eq('2013-03-02')
end end
it 'should return a 400 error if title is missing' do it 'returns a 400 error if title is missing' do
post api("/projects/#{project.id}/milestones", user) post api("/projects/#{project.id}/milestones", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
end end
describe 'PUT /projects/:id/milestones/:milestone_id' do describe 'PUT /projects/:id/milestones/:milestone_id' do
it 'should update a project milestone' do it 'updates a project milestone' do
put api("/projects/#{project.id}/milestones/#{milestone.id}", user), put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
title: 'updated title' title: 'updated title'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title') expect(json_response['title']).to eq('updated title')
end end
it 'should return a 404 error if milestone id not found' do it 'returns a 404 error if milestone id not found' do
put api("/projects/#{project.id}/milestones/1234", user), put api("/projects/#{project.id}/milestones/1234", user),
title: 'updated title' title: 'updated title'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -107,7 +107,7 @@ describe API::API, api: true do ...@@ -107,7 +107,7 @@ describe API::API, api: true do
end end
describe 'PUT /projects/:id/milestones/:milestone_id to close milestone' do describe 'PUT /projects/:id/milestones/:milestone_id to close milestone' do
it 'should update a project milestone' do it 'updates a project milestone' do
put api("/projects/#{project.id}/milestones/#{milestone.id}", user), put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close' state_event: 'close'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -117,7 +117,7 @@ describe API::API, api: true do ...@@ -117,7 +117,7 @@ describe API::API, api: true do
end end
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
it 'should create an activity event when an milestone is closed' do it 'creates an activity event when an milestone is closed' do
expect(Event).to receive(:create) expect(Event).to receive(:create)
put api("/projects/#{project.id}/milestones/#{milestone.id}", user), put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
...@@ -129,14 +129,14 @@ describe API::API, api: true do ...@@ -129,14 +129,14 @@ describe API::API, api: true do
before do before do
milestone.issues << create(:issue, project: project) milestone.issues << create(:issue, project: project)
end end
it 'should return project issues for a particular milestone' do it 'returns project issues for a particular milestone' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['milestone']['title']).to eq(milestone.title) expect(json_response.first['milestone']['title']).to eq(milestone.title)
end end
it 'should return a 401 error if user not authenticated' do it 'returns a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues") get api("/projects/#{project.id}/milestones/#{milestone.id}/issues")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
......
...@@ -9,14 +9,14 @@ describe API::API, api: true do ...@@ -9,14 +9,14 @@ describe API::API, api: true do
describe "GET /namespaces" do describe "GET /namespaces" do
context "when unauthenticated" do context "when unauthenticated" do
it "should return authentication error" do it "returns authentication error" do
get api("/namespaces") get api("/namespaces")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "admin: should return an array of all namespaces" do it "admin: returns an array of all namespaces" do
get api("/namespaces", admin) get api("/namespaces", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -24,7 +24,7 @@ describe API::API, api: true do ...@@ -24,7 +24,7 @@ describe API::API, api: true do
expect(json_response.length).to eq(Namespace.count) expect(json_response.length).to eq(Namespace.count)
end end
it "admin: should return an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{group1.name}", admin) get api("/namespaces?search=#{group1.name}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -34,7 +34,7 @@ describe API::API, api: true do ...@@ -34,7 +34,7 @@ describe API::API, api: true do
end end
context "when authenticated as a regular user" do context "when authenticated as a regular user" do
it "user: should return an array of namespaces" do it "user: returns an array of namespaces" do
get api("/namespaces", user) get api("/namespaces", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -42,7 +42,7 @@ describe API::API, api: true do ...@@ -42,7 +42,7 @@ describe API::API, api: true do
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
it "admin: should return an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{user.username}", user) get api("/namespaces?search=#{user.username}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
......
...@@ -37,7 +37,7 @@ describe API::API, api: true do ...@@ -37,7 +37,7 @@ describe API::API, api: true do
end end
context "when noteable is an Issue" do context "when noteable is an Issue" do
it "should return an array of issue notes" do it "returns an array of issue notes" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -45,14 +45,14 @@ describe API::API, api: true do ...@@ -45,14 +45,14 @@ describe API::API, api: true do
expect(json_response.first['body']).to eq(issue_note.note) expect(json_response.first['body']).to eq(issue_note.note)
end end
it "should return a 404 error when issue id not found" do it "returns a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/12345/notes", user) get api("/projects/#{project.id}/issues/12345/notes", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
context "and current user cannot view the notes" do context "and current user cannot view the notes" do
it "should return an empty array" do it "returns an empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -71,7 +71,7 @@ describe API::API, api: true do ...@@ -71,7 +71,7 @@ describe API::API, api: true do
end end
context "and current user can view the note" do context "and current user can view the note" do
it "should return an empty array" do it "returns an empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -83,7 +83,7 @@ describe API::API, api: true do ...@@ -83,7 +83,7 @@ describe API::API, api: true do
end end
context "when noteable is a Snippet" do context "when noteable is a Snippet" do
it "should return an array of snippet notes" do it "returns an array of snippet notes" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -91,7 +91,7 @@ describe API::API, api: true do ...@@ -91,7 +91,7 @@ describe API::API, api: true do
expect(json_response.first['body']).to eq(snippet_note.note) expect(json_response.first['body']).to eq(snippet_note.note)
end end
it "should return a 404 error when snippet id not found" do it "returns a 404 error when snippet id not found" do
get api("/projects/#{project.id}/snippets/42/notes", user) get api("/projects/#{project.id}/snippets/42/notes", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -105,7 +105,7 @@ describe API::API, api: true do ...@@ -105,7 +105,7 @@ describe API::API, api: true do
end end
context "when noteable is a Merge Request" do context "when noteable is a Merge Request" do
it "should return an array of merge_requests notes" do it "returns an array of merge_requests notes" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -113,7 +113,7 @@ describe API::API, api: true do ...@@ -113,7 +113,7 @@ describe API::API, api: true do
expect(json_response.first['body']).to eq(merge_request_note.note) expect(json_response.first['body']).to eq(merge_request_note.note)
end end
it "should return a 404 error if merge request id not found" do it "returns a 404 error if merge request id not found" do
get api("/projects/#{project.id}/merge_requests/4444/notes", user) get api("/projects/#{project.id}/merge_requests/4444/notes", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -129,21 +129,21 @@ describe API::API, api: true do ...@@ -129,21 +129,21 @@ describe API::API, api: true do
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
context "when noteable is an Issue" do context "when noteable is an Issue" do
it "should return an issue note by id" do it "returns an issue note by id" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq(issue_note.note) expect(json_response['body']).to eq(issue_note.note)
end end
it "should return a 404 error if issue note not found" do it "returns a 404 error if issue note not found" do
get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user) get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
context "and current user cannot view the note" do context "and current user cannot view the note" do
it "should return a 404 error" do it "returns a 404 error" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -160,7 +160,7 @@ describe API::API, api: true do ...@@ -160,7 +160,7 @@ describe API::API, api: true do
end end
context "and current user can view the note" do context "and current user can view the note" do
it "should return an issue note by id" do it "returns an issue note by id" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -171,14 +171,14 @@ describe API::API, api: true do ...@@ -171,14 +171,14 @@ describe API::API, api: true do
end end
context "when noteable is a Snippet" do context "when noteable is a Snippet" do
it "should return a snippet note by id" do it "returns a snippet note by id" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['body']).to eq(snippet_note.note) expect(json_response['body']).to eq(snippet_note.note)
end end
it "should return a 404 error if snippet note not found" do it "returns a 404 error if snippet note not found" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user) get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -188,7 +188,7 @@ describe API::API, api: true do ...@@ -188,7 +188,7 @@ describe API::API, api: true do
describe "POST /projects/:id/noteable/:noteable_id/notes" do describe "POST /projects/:id/noteable/:noteable_id/notes" do
context "when noteable is an Issue" do context "when noteable is an Issue" do
it "should create a new issue note" do it "creates a new issue note" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -196,13 +196,13 @@ describe API::API, api: true do ...@@ -196,13 +196,13 @@ describe API::API, api: true do
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
end end
it "should return a 400 bad request error if body not given" do it "returns a 400 bad request error if body not given" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user) post api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if user not authenticated" do it "returns a 401 unauthorized error if user not authenticated" do
post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!'
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
...@@ -223,7 +223,7 @@ describe API::API, api: true do ...@@ -223,7 +223,7 @@ describe API::API, api: true do
end end
context "when noteable is a Snippet" do context "when noteable is a Snippet" do
it "should create a new snippet note" do it "creates a new snippet note" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!' post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -231,13 +231,13 @@ describe API::API, api: true do ...@@ -231,13 +231,13 @@ describe API::API, api: true do
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
end end
it "should return a 400 bad request error if body not given" do it "returns a 400 bad request error if body not given" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 401 unauthorized error if user not authenticated" do it "returns a 401 unauthorized error if user not authenticated" do
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!' post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!'
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
...@@ -267,7 +267,7 @@ describe API::API, api: true do ...@@ -267,7 +267,7 @@ describe API::API, api: true do
end end
describe "POST /projects/:id/noteable/:noteable_id/notes to test observer on create" do describe "POST /projects/:id/noteable/:noteable_id/notes to test observer on create" do
it "should create an activity event when an issue note is created" do it "creates an activity event when an issue note is created" do
expect(Event).to receive(:create) expect(Event).to receive(:create)
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!' post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
...@@ -276,7 +276,7 @@ describe API::API, api: true do ...@@ -276,7 +276,7 @@ describe API::API, api: true do
describe 'PUT /projects/:id/noteable/:noteable_id/notes/:note_id' do describe 'PUT /projects/:id/noteable/:noteable_id/notes/:note_id' do
context 'when noteable is an Issue' do context 'when noteable is an Issue' do
it 'should return modified note' do it 'returns modified note' do
put api("/projects/#{project.id}/issues/#{issue.id}/"\ put api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user), body: 'Hello!' "notes/#{issue_note.id}", user), body: 'Hello!'
...@@ -284,14 +284,14 @@ describe API::API, api: true do ...@@ -284,14 +284,14 @@ describe API::API, api: true do
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
it 'should return a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user), put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user),
body: 'Hello!' body: 'Hello!'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it 'should return a 400 bad request error if body not given' do it 'returns a 400 bad request error if body not given' do
put api("/projects/#{project.id}/issues/#{issue.id}/"\ put api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user) "notes/#{issue_note.id}", user)
...@@ -300,7 +300,7 @@ describe API::API, api: true do ...@@ -300,7 +300,7 @@ describe API::API, api: true do
end end
context 'when noteable is a Snippet' do context 'when noteable is a Snippet' do
it 'should return modified note' do it 'returns modified note' do
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user), body: 'Hello!' "notes/#{snippet_note.id}", user), body: 'Hello!'
...@@ -308,7 +308,7 @@ describe API::API, api: true do ...@@ -308,7 +308,7 @@ describe API::API, api: true do
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
it 'should return a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/12345", user), body: "Hello!" "notes/12345", user), body: "Hello!"
...@@ -317,7 +317,7 @@ describe API::API, api: true do ...@@ -317,7 +317,7 @@ describe API::API, api: true do
end end
context 'when noteable is a Merge Request' do context 'when noteable is a Merge Request' do
it 'should return modified note' do it 'returns modified note' do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
"notes/#{merge_request_note.id}", user), body: 'Hello!' "notes/#{merge_request_note.id}", user), body: 'Hello!'
...@@ -325,7 +325,7 @@ describe API::API, api: true do ...@@ -325,7 +325,7 @@ describe API::API, api: true do
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
it 'should return a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
"notes/12345", user), body: "Hello!" "notes/12345", user), body: "Hello!"
......
...@@ -20,7 +20,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -20,7 +20,7 @@ describe API::API, 'ProjectHooks', api: true do
describe "GET /projects/:id/hooks" do describe "GET /projects/:id/hooks" do
context "authorized user" do context "authorized user" do
it "should return project hooks" do it "returns project hooks" do
get api("/projects/#{project.id}/hooks", user) get api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -38,7 +38,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -38,7 +38,7 @@ describe API::API, 'ProjectHooks', api: true do
end end
context "unauthorized user" do context "unauthorized user" do
it "should not access project hooks" do it "does not access project hooks" do
get api("/projects/#{project.id}/hooks", user3) get api("/projects/#{project.id}/hooks", user3)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
...@@ -47,7 +47,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -47,7 +47,7 @@ describe API::API, 'ProjectHooks', api: true do
describe "GET /projects/:id/hooks/:hook_id" do describe "GET /projects/:id/hooks/:hook_id" do
context "authorized user" do context "authorized user" do
it "should return a project hook" do it "returns a project hook" do
get api("/projects/#{project.id}/hooks/#{hook.id}", user) get api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['url']).to eq(hook.url) expect(json_response['url']).to eq(hook.url)
...@@ -59,27 +59,27 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -59,27 +59,27 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
end end
it "should return a 404 error if hook id is not available" do it "returns a 404 error if hook id is not available" do
get api("/projects/#{project.id}/hooks/1234", user) get api("/projects/#{project.id}/hooks/1234", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context "unauthorized user" do context "unauthorized user" do
it "should not access an existing hook" do it "does not access an existing hook" do
get api("/projects/#{project.id}/hooks/#{hook.id}", user3) get api("/projects/#{project.id}/hooks/#{hook.id}", user3)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
it "should return a 404 error if hook id is not available" do it "returns a 404 error if hook id is not available" do
get api("/projects/#{project.id}/hooks/1234", user) get api("/projects/#{project.id}/hooks/1234", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
describe "POST /projects/:id/hooks" do describe "POST /projects/:id/hooks" do
it "should add hook to project" do it "adds hook to project" do
expect do expect do
post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true
end.to change {project.hooks.count}.by(1) end.to change {project.hooks.count}.by(1)
...@@ -94,19 +94,19 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -94,19 +94,19 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['enable_ssl_verification']).to eq(true) expect(json_response['enable_ssl_verification']).to eq(true)
end end
it "should return a 400 error if url not given" do it "returns a 400 error if url not given" do
post api("/projects/#{project.id}/hooks", user) post api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error if url not valid" do it "returns a 422 error if url not valid" do
post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com" post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
end end
describe "PUT /projects/:id/hooks/:hook_id" do describe "PUT /projects/:id/hooks/:hook_id" do
it "should update an existing project hook" do it "updates an existing project hook" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user), put api("/projects/#{project.id}/hooks/#{hook.id}", user),
url: 'http://example.org', push_events: false url: 'http://example.org', push_events: false
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -119,46 +119,46 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -119,46 +119,46 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
end end
it "should return 404 error if hook id not found" do it "returns 404 error if hook id not found" do
put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org' put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return 400 error if url is not given" do it "returns 400 error if url is not given" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user) put api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error if url is not valid" do it "returns a 422 error if url is not valid" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com' put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
end end
describe "DELETE /projects/:id/hooks/:hook_id" do describe "DELETE /projects/:id/hooks/:hook_id" do
it "should delete hook from project" do it "deletes hook from project" do
expect do expect do
delete api("/projects/#{project.id}/hooks/#{hook.id}", user) delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
end.to change {project.hooks.count}.by(-1) end.to change {project.hooks.count}.by(-1)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return success when deleting hook" do it "returns success when deleting hook" do
delete api("/projects/#{project.id}/hooks/#{hook.id}", user) delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return a 404 error when deleting non existent hook" do it "returns a 404 error when deleting non existent hook" do
delete api("/projects/#{project.id}/hooks/42", user) delete api("/projects/#{project.id}/hooks/42", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return a 405 error if hook id not given" do it "returns a 405 error if hook id not given" do
delete api("/projects/#{project.id}/hooks", user) delete api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(405) expect(response).to have_http_status(405)
end end
it "shold return a 404 if a user attempts to delete project hooks he/she does not own" do it "returns a 404 if a user attempts to delete project hooks he/she does not own" do
test_user = create(:user) test_user = create(:user)
other_project = create(:project) other_project = create(:project)
other_project.team << [test_user, :master] other_project.team << [test_user, :master]
......
...@@ -13,7 +13,7 @@ describe API::API, api: true do ...@@ -13,7 +13,7 @@ describe API::API, api: true do
before { project_member } before { project_member }
before { project_member2 } before { project_member2 }
it "should return project team members" do it "returns project team members" do
get api("/projects/#{project.id}/members", user) get api("/projects/#{project.id}/members", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -29,7 +29,7 @@ describe API::API, api: true do ...@@ -29,7 +29,7 @@ describe API::API, api: true do
expect(json_response.first['username']).to eq(user.username) expect(json_response.first['username']).to eq(user.username)
end end
it "should return a 404 error if id not found" do it "returns a 404 error if id not found" do
get api("/projects/9999/members", user) get api("/projects/9999/members", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
...@@ -38,21 +38,21 @@ describe API::API, api: true do ...@@ -38,21 +38,21 @@ describe API::API, api: true do
describe "GET /projects/:id/members/:user_id" do describe "GET /projects/:id/members/:user_id" do
before { project_member } before { project_member }
it "should return project team member" do it "returns project team member" do
get api("/projects/#{project.id}/members/#{user.id}", user) get api("/projects/#{project.id}/members/#{user.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user.username) expect(json_response['username']).to eq(user.username)
expect(json_response['access_level']).to eq(ProjectMember::MASTER) expect(json_response['access_level']).to eq(ProjectMember::MASTER)
end end
it "should return a 404 error if user id not found" do it "returns a 404 error if user id not found" do
get api("/projects/#{project.id}/members/1234", user) get api("/projects/#{project.id}/members/1234", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
describe "POST /projects/:id/members" do describe "POST /projects/:id/members" do
it "should add user to project team" do it "adds user to project team" do
expect do expect do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER
end.to change { ProjectMember.count }.by(1) end.to change { ProjectMember.count }.by(1)
...@@ -62,7 +62,7 @@ describe API::API, api: true do ...@@ -62,7 +62,7 @@ describe API::API, api: true do
expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER)
end end
it "should return a 201 status if user is already project member" do it "returns a 201 status if user is already project member" do
post api("/projects/#{project.id}/members", user), post api("/projects/#{project.id}/members", user),
user_id: user2.id, user_id: user2.id,
access_level: ProjectMember::DEVELOPER access_level: ProjectMember::DEVELOPER
...@@ -75,17 +75,17 @@ describe API::API, api: true do ...@@ -75,17 +75,17 @@ describe API::API, api: true do
expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER)
end end
it "should return a 400 error when user id is not given" do it "returns a 400 error when user id is not given" do
post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 400 error when access level is not given" do it "returns a 400 error when access level is not given" do
post api("/projects/#{project.id}/members", user), user_id: user2.id post api("/projects/#{project.id}/members", user), user_id: user2.id
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "returns a 422 error when access level is not known" do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: 1234 post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: 1234
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
...@@ -94,24 +94,24 @@ describe API::API, api: true do ...@@ -94,24 +94,24 @@ describe API::API, api: true do
describe "PUT /projects/:id/members/:user_id" do describe "PUT /projects/:id/members/:user_id" do
before { project_member2 } before { project_member2 }
it "should update project team member" do it "updates project team member" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user3.username) expect(json_response['username']).to eq(user3.username)
expect(json_response['access_level']).to eq(ProjectMember::MASTER) expect(json_response['access_level']).to eq(ProjectMember::MASTER)
end end
it "should return a 404 error if user_id is not found" do it "returns a 404 error if user_id is not found" do
put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return a 400 error when access level is not given" do it "returns a 400 error when access level is not given" do
put api("/projects/#{project.id}/members/#{user3.id}", user) put api("/projects/#{project.id}/members/#{user3.id}", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should return a 422 error when access level is not known" do it "returns a 422 error when access level is not known" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: 123 put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: 123
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
...@@ -123,13 +123,13 @@ describe API::API, api: true do ...@@ -123,13 +123,13 @@ describe API::API, api: true do
project_member2 project_member2
end end
it "should remove user from project team" do it "removes user from project team" do
expect do expect do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
end.to change { ProjectMember.count }.by(-1) end.to change { ProjectMember.count }.by(-1)
end end
it "should return 200 if team member is not part of a project" do it "returns 200 if team member is not part of a project" do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
expect do expect do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
...@@ -137,13 +137,13 @@ describe API::API, api: true do ...@@ -137,13 +137,13 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return 200 if team member already removed" do it "returns 200 if team member already removed" do
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return 200 OK when the user was not member" do it "returns 200 OK when the user was not member" do
expect do expect do
delete api("/projects/#{project.id}/members/1000000", user) delete api("/projects/#{project.id}/members/1000000", user)
end.to change { ProjectMember.count }.by(0) end.to change { ProjectMember.count }.by(0)
......
...@@ -17,7 +17,7 @@ describe API::API, api: true do ...@@ -17,7 +17,7 @@ describe API::API, api: true do
end end
describe 'GET /projects/:project_id/snippets/' do describe 'GET /projects/:project_id/snippets/' do
it 'all snippets available to team member' do it 'returns all snippets available to team member' do
project = create(:project, :public) project = create(:project, :public)
user = create(:user) user = create(:user)
project.team << [user, :developer] project.team << [user, :developer]
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ describe API::API, api: true do ...@@ -16,7 +16,7 @@ describe API::API, api: true do
context "authorized user" do context "authorized user" do
before { project.team << [user2, :reporter] } before { project.team << [user2, :reporter] }
it "should return project commits" do it "returns project commits" do
get api("/projects/#{project.id}/repository/tree", user) get api("/projects/#{project.id}/repository/tree", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -26,7 +26,7 @@ describe API::API, api: true do ...@@ -26,7 +26,7 @@ describe API::API, api: true do
expect(json_response.first['mode']).to eq('040000') expect(json_response.first['mode']).to eq('040000')
end end
it 'should return a 404 for unknown ref' do it 'returns a 404 for unknown ref' do
get api("/projects/#{project.id}/repository/tree?ref_name=foo", user) get api("/projects/#{project.id}/repository/tree?ref_name=foo", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -36,7 +36,7 @@ describe API::API, api: true do ...@@ -36,7 +36,7 @@ describe API::API, api: true do
end end
context "unauthorized user" do context "unauthorized user" do
it "should not return project commits" do it "does not return project commits" do
get api("/projects/#{project.id}/repository/tree") get api("/projects/#{project.id}/repository/tree")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
...@@ -44,41 +44,41 @@ describe API::API, api: true do ...@@ -44,41 +44,41 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/repository/blobs/:sha" do describe "GET /projects/:id/repository/blobs/:sha" do
it "should get the raw file contents" do it "gets the raw file contents" do
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user) get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return 404 for invalid branch_name" do it "returns 404 for invalid branch_name" do
get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user) get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return 404 for invalid file" do it "returns 404 for invalid file" do
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user) get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
it "should return a 400 error if filepath is missing" do it "returns a 400 error if filepath is missing" do
get api("/projects/#{project.id}/repository/blobs/master", user) get api("/projects/#{project.id}/repository/blobs/master", user)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
end end
describe "GET /projects/:id/repository/commits/:sha/blob" do describe "GET /projects/:id/repository/commits/:sha/blob" do
it "should get the raw file contents" do it "gets the raw file contents" do
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
end end
describe "GET /projects/:id/repository/raw_blobs/:sha" do describe "GET /projects/:id/repository/raw_blobs/:sha" do
it "should get the raw file contents" do it "gets the raw file contents" do
get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user) get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'should return a 404 for unknown blob' do it 'returns a 404 for unknown blob' do
get api("/projects/#{project.id}/repository/raw_blobs/123456", user) get api("/projects/#{project.id}/repository/raw_blobs/123456", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
...@@ -88,7 +88,7 @@ describe API::API, api: true do ...@@ -88,7 +88,7 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/repository/archive(.:format)?:sha" do describe "GET /projects/:id/repository/archive(.:format)?:sha" do
it "should get the archive" do it "gets the archive" do
get api("/projects/#{project.id}/repository/archive", user) get api("/projects/#{project.id}/repository/archive", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -97,7 +97,7 @@ describe API::API, api: true do ...@@ -97,7 +97,7 @@ describe API::API, api: true do
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/)
end end
it "should get the archive.zip" do it "gets the archive.zip" do
get api("/projects/#{project.id}/repository/archive.zip", user) get api("/projects/#{project.id}/repository/archive.zip", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -106,7 +106,7 @@ describe API::API, api: true do ...@@ -106,7 +106,7 @@ describe API::API, api: true do
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
end end
it "should get the archive.tar.bz2" do it "gets the archive.tar.bz2" do
get api("/projects/#{project.id}/repository/archive.tar.bz2", user) get api("/projects/#{project.id}/repository/archive.tar.bz2", user)
repo_name = project.repository.name.gsub("\.git", "") repo_name = project.repository.name.gsub("\.git", "")
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -115,28 +115,28 @@ describe API::API, api: true do ...@@ -115,28 +115,28 @@ describe API::API, api: true do
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/) expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/)
end end
it "should return 404 for invalid sha" do it "returns 404 for invalid sha" do
get api("/projects/#{project.id}/repository/archive/?sha=xxx", user) get api("/projects/#{project.id}/repository/archive/?sha=xxx", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
describe 'GET /projects/:id/repository/compare' do describe 'GET /projects/:id/repository/compare' do
it "should compare branches" do it "compares branches" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature' get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare tags" do it "compares tags" do
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0' get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare commits" do it "compares commits" do
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_empty expect(json_response['commits']).to be_empty
...@@ -144,14 +144,14 @@ describe API::API, api: true do ...@@ -144,14 +144,14 @@ describe API::API, api: true do
expect(json_response['compare_same_ref']).to be_falsey expect(json_response['compare_same_ref']).to be_falsey
end end
it "should compare commits in reverse order" do it "compares commits in reverse order" do
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_present expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present expect(json_response['diffs']).to be_present
end end
it "should compare same refs" do it "compares same refs" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master' get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['commits']).to be_empty expect(json_response['commits']).to be_empty
...@@ -161,7 +161,7 @@ describe API::API, api: true do ...@@ -161,7 +161,7 @@ describe API::API, api: true do
end end
describe 'GET /projects/:id/repository/contributors' do describe 'GET /projects/:id/repository/contributors' do
it 'should return valid data' do it 'returns valid data' do
get api("/projects/#{project.id}/repository/contributors", user) get api("/projects/#{project.id}/repository/contributors", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
......
This diff is collapsed.
...@@ -11,13 +11,13 @@ describe API::API, api: true do ...@@ -11,13 +11,13 @@ describe API::API, api: true do
describe "PUT /projects/:id/services/#{service.dasherize}" do describe "PUT /projects/:id/services/#{service.dasherize}" do
include_context service include_context service
it "should update #{service} settings" do it "updates #{service} settings" do
put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "should return if required fields missing" do it "returns if required fields missing" do
attrs = service_attrs attrs = service_attrs
required_attributes = service_attrs_list.select do |attr| required_attributes = service_attrs_list.select do |attr|
...@@ -42,7 +42,7 @@ describe API::API, api: true do ...@@ -42,7 +42,7 @@ describe API::API, api: true do
describe "DELETE /projects/:id/services/#{service.dasherize}" do describe "DELETE /projects/:id/services/#{service.dasherize}" do
include_context service include_context service
it "should delete #{service}" do it "deletes #{service}" do
delete api("/projects/#{project.id}/services/#{dashed_service}", user) delete api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -62,26 +62,26 @@ describe API::API, api: true do ...@@ -62,26 +62,26 @@ describe API::API, api: true do
service_object.save service_object.save
end end
it 'should return authentication error when unauthenticated' do it 'returns authentication error when unauthenticated' do
get api("/projects/#{project.id}/services/#{dashed_service}") get api("/projects/#{project.id}/services/#{dashed_service}")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
it "should return all properties of service #{service} when authenticated as admin" do it "returns all properties of service #{service} when authenticated as admin" do
get api("/projects/#{project.id}/services/#{dashed_service}", admin) get api("/projects/#{project.id}/services/#{dashed_service}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map)
end end
it "should return properties of service #{service} other than passwords when authenticated as project owner" do it "returns properties of service #{service} other than passwords when authenticated as project owner" do
get api("/projects/#{project.id}/services/#{dashed_service}", user) get api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords)
end end
it "should return error when authenticated but not a project owner" do it "returns error when authenticated but not a project owner" do
project.team << [user2, :developer] project.team << [user2, :developer]
get api("/projects/#{project.id}/services/#{dashed_service}", user2) get api("/projects/#{project.id}/services/#{dashed_service}", user2)
......
...@@ -7,7 +7,7 @@ describe API::API, api: true do ...@@ -7,7 +7,7 @@ describe API::API, api: true do
describe "POST /session" do describe "POST /session" do
context "when valid password" do context "when valid password" do
it "should return private token" do it "returns private token" do
post api("/session"), email: user.email, password: '12345678' post api("/session"), email: user.email, password: '12345678'
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -20,7 +20,7 @@ describe API::API, api: true do ...@@ -20,7 +20,7 @@ describe API::API, api: true do
end end
context 'when email has case-typo and password is valid' do context 'when email has case-typo and password is valid' do
it 'should return private token' do it 'returns private token' do
post api('/session'), email: user.email.upcase, password: '12345678' post api('/session'), email: user.email.upcase, password: '12345678'
expect(response.status).to eq 201 expect(response.status).to eq 201
...@@ -33,7 +33,7 @@ describe API::API, api: true do ...@@ -33,7 +33,7 @@ describe API::API, api: true do
end end
context 'when login has case-typo and password is valid' do context 'when login has case-typo and password is valid' do
it 'should return private token' do it 'returns private token' do
post api('/session'), login: user.username.upcase, password: '12345678' post api('/session'), login: user.username.upcase, password: '12345678'
expect(response.status).to eq 201 expect(response.status).to eq 201
...@@ -46,7 +46,7 @@ describe API::API, api: true do ...@@ -46,7 +46,7 @@ describe API::API, api: true do
end end
context "when invalid password" do context "when invalid password" do
it "should return authentication error" do it "returns authentication error" do
post api("/session"), email: user.email, password: '123' post api("/session"), email: user.email, password: '123'
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
...@@ -56,7 +56,7 @@ describe API::API, api: true do ...@@ -56,7 +56,7 @@ describe API::API, api: true do
end end
context "when empty password" do context "when empty password" do
it "should return authentication error" do it "returns authentication error" do
post api("/session"), email: user.email post api("/session"), email: user.email
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
...@@ -66,7 +66,7 @@ describe API::API, api: true do ...@@ -66,7 +66,7 @@ describe API::API, api: true do
end end
context "when empty name" do context "when empty name" do
it "should return authentication error" do it "returns authentication error" do
post api("/session"), password: user.password post api("/session"), password: user.password
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
......
...@@ -7,7 +7,7 @@ describe API::API, 'Settings', api: true do ...@@ -7,7 +7,7 @@ describe API::API, 'Settings', api: true do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
describe "GET /application/settings" do describe "GET /application/settings" do
it "should return application settings" do it "returns application settings" do
get api("/application/settings", admin) get api("/application/settings", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Hash expect(json_response).to be_an Hash
...@@ -23,7 +23,7 @@ describe API::API, 'Settings', api: true do ...@@ -23,7 +23,7 @@ describe API::API, 'Settings', api: true do
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
it "should update application settings" do it "updates application settings" do
put api("/application/settings", admin), put api("/application/settings", admin),
default_projects_limit: 3, signin_enabled: false, repository_storage: 'custom' default_projects_limit: 3, signin_enabled: false, repository_storage: 'custom'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
......
...@@ -11,21 +11,21 @@ describe API::API, api: true do ...@@ -11,21 +11,21 @@ describe API::API, api: true do
describe "GET /hooks" do describe "GET /hooks" do
context "when no user" do context "when no user" do
it "should return authentication error" do it "returns authentication error" do
get api("/hooks") get api("/hooks")
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end end
end end
context "when not an admin" do context "when not an admin" do
it "should return forbidden error" do it "returns forbidden error" do
get api("/hooks", user) get api("/hooks", user)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context "when authenticated as admin" do context "when authenticated as admin" do
it "should return an array of hooks" do it "returns an array of hooks" do
get api("/hooks", admin) get api("/hooks", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
...@@ -35,18 +35,18 @@ describe API::API, api: true do ...@@ -35,18 +35,18 @@ describe API::API, api: true do
end end
describe "POST /hooks" do describe "POST /hooks" do
it "should create new hook" do it "creates new hook" do
expect do expect do
post api("/hooks", admin), url: 'http://example.com' post api("/hooks", admin), url: 'http://example.com'
end.to change { SystemHook.count }.by(1) end.to change { SystemHook.count }.by(1)
end end
it "should respond with 400 if url not given" do it "responds with 400 if url not given" do
post api("/hooks", admin) post api("/hooks", admin)
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end end
it "should not create new hook without url" do it "does not create new hook without url" do
expect do expect do
post api("/hooks", admin) post api("/hooks", admin)
end.not_to change { SystemHook.count } end.not_to change { SystemHook.count }
...@@ -54,26 +54,26 @@ describe API::API, api: true do ...@@ -54,26 +54,26 @@ describe API::API, api: true do
end end
describe "GET /hooks/:id" do describe "GET /hooks/:id" do
it "should return hook by id" do it "returns hook by id" do
get api("/hooks/#{hook.id}", admin) get api("/hooks/#{hook.id}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['event_name']).to eq('project_create') expect(json_response['event_name']).to eq('project_create')
end end
it "should return 404 on failure" do it "returns 404 on failure" do
get api("/hooks/404", admin) get api("/hooks/404", admin)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
describe "DELETE /hooks/:id" do describe "DELETE /hooks/:id" do
it "should delete a hook" do it "deletes a hook" do
expect do expect do
delete api("/hooks/#{hook.id}", admin) delete api("/hooks/#{hook.id}", admin)
end.to change { SystemHook.count }.by(-1) end.to change { SystemHook.count }.by(-1)
end end
it "should return success if hook id not found" do it "returns success if hook id not found" do
delete api("/hooks/12345", admin) delete api("/hooks/12345", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -19,7 +19,7 @@ describe CreateSnippetService, services: true do ...@@ -19,7 +19,7 @@ describe CreateSnippetService, services: true do
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end end
it 'non-admins should not be able to create a public snippet' do it 'non-admins are not able to create a public snippet' do
snippet = create_snippet(nil, @user, @opts) snippet = create_snippet(nil, @user, @opts)
expect(snippet.errors.messages).to have_key(:visibility_level) expect(snippet.errors.messages).to have_key(:visibility_level)
expect(snippet.errors.messages[:visibility_level].first).to( expect(snippet.errors.messages[:visibility_level].first).to(
...@@ -27,7 +27,7 @@ describe CreateSnippetService, services: true do ...@@ -27,7 +27,7 @@ describe CreateSnippetService, services: true do
) )
end end
it 'admins should be able to create a public snippet' do it 'admins are able to create a public snippet' do
snippet = create_snippet(nil, @admin, @opts) snippet = create_snippet(nil, @admin, @opts)
expect(snippet.errors.any?).to be_falsey expect(snippet.errors.any?).to be_falsey
expect(snippet.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC) expect(snippet.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
......
This diff is collapsed.
...@@ -17,7 +17,7 @@ describe GitHooksService, services: true do ...@@ -17,7 +17,7 @@ describe GitHooksService, services: true do
describe '#execute' do describe '#execute' do
context 'when receive hooks were successful' do context 'when receive hooks were successful' do
it 'should call post-receive hook' do it 'calls post-receive hook' do
hook = double(trigger: [true, nil]) hook = double(trigger: [true, nil])
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook) expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
...@@ -26,7 +26,7 @@ describe GitHooksService, services: true do ...@@ -26,7 +26,7 @@ describe GitHooksService, services: true do
end end
context 'when pre-receive hook failed' do context 'when pre-receive hook failed' do
it 'should not call post-receive hook' do it 'does not call post-receive hook' do
expect(service).to receive(:run_hook).with('pre-receive').and_return([false, '']) expect(service).to receive(:run_hook).with('pre-receive').and_return([false, ''])
expect(service).not_to receive(:run_hook).with('post-receive') expect(service).not_to receive(:run_hook).with('post-receive')
...@@ -37,7 +37,7 @@ describe GitHooksService, services: true do ...@@ -37,7 +37,7 @@ describe GitHooksService, services: true do
end end
context 'when update hook failed' do context 'when update hook failed' do
it 'should not call post-receive hook' do it 'does not call post-receive hook' do
expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil]) expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil])
expect(service).to receive(:run_hook).with('update').and_return([false, '']) expect(service).to receive(:run_hook).with('update').and_return([false, ''])
expect(service).not_to receive(:run_hook).with('post-receive') expect(service).not_to receive(:run_hook).with('post-receive')
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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