From 2375b437bd2f4287e04b11050aae011b314bcd6b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 23 Mar 2016 20:49:17 +0800 Subject: Fix a typo --- spec/lib/gitlab/email/receiver_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 36267faeb93..f381a3907f3 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -24,7 +24,7 @@ describe Gitlab::Email::Receiver, lib: true do end end - context "when no sent notificiation for the reply key could be found" do + context "when no sent notification for the reply key could be found" do let(:email_raw) { fixture_file('emails/wrong_reply_key.eml') } it "raises a SentNotificationNotFoundError" do -- cgit v1.2.1 From 6cfd028278e7fe22c2776b9ce70a5b92223115f9 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 23 Mar 2016 22:20:22 +0800 Subject: Implement #3243 New Issue by email So we extend Gitlab::Email::Receiver for this new behaviour, however we might want to split it into another class for better testing it. Another issue is that, currently it's using this to parse project identifier: Gitlab::IncomingEmail.key_from_address Which is using: Gitlab.config.incoming_email.address for the receiver name. This is probably `reply` because it's used for replying to a specific issue. We might want to introduce another config for this, or just use `reply` instead of `incoming`. I'll prefer to introduce a new config for this, or just change `reply` to `incoming` because it would make sense for replying to there, too. The email template used in tests were copied and modified from: `emails/valid_reply.eml` which I hope is ok. --- spec/lib/gitlab/email/receiver_spec.rb | 66 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 12 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index f381a3907f3..e7391a33751 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -15,6 +15,20 @@ describe Gitlab::Email::Receiver, lib: true do let!(:sent_notification) { SentNotification.record(noteable, user.id, reply_key) } let(:receiver) { described_class.new(email_raw) } + let(:markdown) { "![image](uploads/image.png)" } + + def setup_attachment + allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( + [ + { + url: "uploads/image.png", + is_image: true, + alt: "image", + markdown: markdown + } + ] + ) + end context "when the recipient address doesn't include a reply key" do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "") } @@ -108,19 +122,8 @@ describe Gitlab::Email::Receiver, lib: true do end context "when everything is fine" do - let(:markdown) { "![image](uploads/image.png)" } - before do - allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( - [ - { - url: "uploads/image.png", - is_image: true, - alt: "image", - markdown: markdown - } - ] - ) + setup_attachment end it "creates a comment" do @@ -161,4 +164,43 @@ describe Gitlab::Email::Receiver, lib: true do end end end + + context "when it's trying to create a new issue" do + before do + setup_attachment + stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo") + end + + let(:sent_notification) {} + let!(:user) { create(:user, email: 'jake@adventuretime.ooo') } + let(:namespace) { create(:namespace, path: 'gitlabhq') } + let(:project) { create(:project, :public, namespace: namespace) } + let(:email_raw) { fixture_file('emails/valid_new_issue.eml') } + + context "when everything is fine" do + it "creates a new issue" do + expect { receiver.execute }.to change { project.issues.count }.by(1) + issue = project.issues.last + + expect(issue.author).to eq(user) + expect(issue.title).to eq('New Issue by email') + expect(issue.description).to include('reply by email') + expect(issue.description).to include(markdown) + end + end + + context "something is wrong" do + context "when the issue could not be saved" do + before do + project + + allow_any_instance_of(Issue).to receive(:persisted?).and_return(false) + end + + it "raises an InvalidIssueError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidIssueError) + end + end + end + end end -- cgit v1.2.1 From 347ee6cc912d49680d2f6b90134142c656868333 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 31 Mar 2016 21:56:37 +0800 Subject: Alloy empty reply for new issues, but not response --- spec/lib/gitlab/email/receiver_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index e7391a33751..4336f0f9e53 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -167,7 +167,6 @@ describe Gitlab::Email::Receiver, lib: true do context "when it's trying to create a new issue" do before do - setup_attachment stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo") end @@ -179,6 +178,8 @@ describe Gitlab::Email::Receiver, lib: true do context "when everything is fine" do it "creates a new issue" do + setup_attachment + expect { receiver.execute }.to change { project.issues.count }.by(1) issue = project.issues.last @@ -187,6 +188,19 @@ describe Gitlab::Email::Receiver, lib: true do expect(issue.description).to include('reply by email') expect(issue.description).to include(markdown) end + + context "when the reply is blank" do + let!(:email_raw) { fixture_file("emails/valid_new_issue_empty.eml") } + + it "creates a new issue" do + expect { receiver.execute }.to change { project.issues.count }.by(1) + issue = project.issues.last + + expect(issue.author).to eq(user) + expect(issue.title).to eq('New Issue by email') + expect(issue.description).to eq('') + end + end end context "something is wrong" do -- cgit v1.2.1 From a065c8d5d82d7db3a01b1c23571ea010c82f7a31 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 7 Apr 2016 04:39:45 +0800 Subject: Create a new issue via: incoming+group/project+AUTH_TOKEN@... --- spec/lib/gitlab/email/receiver_spec.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 4336f0f9e53..d1b52b9d086 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -171,7 +171,13 @@ describe Gitlab::Email::Receiver, lib: true do end let(:sent_notification) {} - let!(:user) { create(:user, email: 'jake@adventuretime.ooo') } + let!(:user) do + create( + :user, + email: 'jake@adventuretime.ooo', + authentication_token: 'auth_token' + ) + end let(:namespace) { create(:namespace, path: 'gitlabhq') } let(:project) { create(:project, :public, namespace: namespace) } let(:email_raw) { fixture_file('emails/valid_new_issue.eml') } @@ -215,6 +221,18 @@ describe Gitlab::Email::Receiver, lib: true do expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidIssueError) end end + + context "when the authentication_token token didn't match" do + let!(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } + + before do + project + end + + it "raises an UserNotAuthorizedError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) + end + end end end end -- cgit v1.2.1 From 8156475ea501221c3ba1bf3280e8368b354839bc Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 7 Apr 2016 05:27:28 +0800 Subject: Report better errors. TODO: Enable skipped test --- spec/lib/gitlab/email/receiver_spec.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index d1b52b9d086..c0fc18a9f83 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -210,10 +210,12 @@ describe Gitlab::Email::Receiver, lib: true do end context "something is wrong" do + before do + project + end + context "when the issue could not be saved" do before do - project - allow_any_instance_of(Issue).to receive(:persisted?).and_return(false) end @@ -225,11 +227,24 @@ describe Gitlab::Email::Receiver, lib: true do context "when the authentication_token token didn't match" do let!(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } - before do - project + it "raises an UserNotAuthorizedError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) end + end + + context "when project is private" do + let(:project) { create(:project, :private, namespace: namespace) } + + it "raises a ProjectNotFound if the user is not a member" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::ProjectNotFound) + end + + it "raises a UserNotAuthorizedError if the user has no sufficient permission" do + skip("Find a role which can :read_project but can't :create_issue") + + project.update(group: create(:group)) + project.group.add_guest(user) - it "raises an UserNotAuthorizedError" do expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) end end -- cgit v1.2.1 From c337e748d385fea5c768a8e7de55975dca7fa484 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 18 May 2016 17:19:25 -0500 Subject: so we use separate classes to handle different tasks --- spec/lib/gitlab/email/receiver_spec.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index c0fc18a9f83..58c525f4048 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -34,7 +34,7 @@ describe Gitlab::Email::Receiver, lib: true do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "") } it "raises a SentNotificationNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::SentNotificationNotFoundError) + expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) end end @@ -42,7 +42,7 @@ describe Gitlab::Email::Receiver, lib: true do let(:email_raw) { fixture_file('emails/wrong_reply_key.eml') } it "raises a SentNotificationNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::SentNotificationNotFoundError) + expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) end end @@ -50,7 +50,7 @@ describe Gitlab::Email::Receiver, lib: true do let(:email_raw) { "" } it "raises an EmptyEmailError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::EmptyEmailError) + expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) end end @@ -59,7 +59,7 @@ describe Gitlab::Email::Receiver, lib: true do let!(:email_raw) { fixture_file("emails/auto_reply.eml") } it "raises an AutoGeneratedEmailError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::AutoGeneratedEmailError) + expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError) end end @@ -69,7 +69,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises a UserNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotFoundError) + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) end end @@ -79,7 +79,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises a UserBlockedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserBlockedError) + expect { receiver.execute }.to raise_error(Gitlab::Email::UserBlockedError) end end @@ -89,7 +89,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises a UserNotAuthorizedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) end end @@ -99,7 +99,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises a NoteableNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::NoteableNotFoundError) + expect { receiver.execute }.to raise_error(Gitlab::Email::NoteableNotFoundError) end end @@ -107,7 +107,7 @@ describe Gitlab::Email::Receiver, lib: true do let!(:email_raw) { fixture_file("emails/no_content_reply.eml") } it "raises an EmptyEmailError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::EmptyEmailError) + expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) end end @@ -117,7 +117,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises an InvalidNoteError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidNoteError) + expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidNoteError) end end @@ -220,7 +220,7 @@ describe Gitlab::Email::Receiver, lib: true do end it "raises an InvalidIssueError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidIssueError) + expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidIssueError) end end @@ -228,7 +228,7 @@ describe Gitlab::Email::Receiver, lib: true do let!(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } it "raises an UserNotAuthorizedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) end end @@ -236,7 +236,7 @@ describe Gitlab::Email::Receiver, lib: true do let(:project) { create(:project, :private, namespace: namespace) } it "raises a ProjectNotFound if the user is not a member" do - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::ProjectNotFound) + expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) end it "raises a UserNotAuthorizedError if the user has no sufficient permission" do @@ -245,7 +245,7 @@ describe Gitlab::Email::Receiver, lib: true do project.update(group: create(:group)) project.group.add_guest(user) - expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) end end end -- cgit v1.2.1 From a7c823a5730fade9d8cc2c992c0f80cc12b1c0a7 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 18 May 2016 17:57:14 -0500 Subject: Give ProjectNotFound when the project is not readable --- spec/lib/gitlab/email/receiver_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 58c525f4048..a9b93044a08 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -88,8 +88,8 @@ describe Gitlab::Email::Receiver, lib: true do project.update_attribute(:visibility_level, Project::PRIVATE) end - it "raises a UserNotAuthorizedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) + it "raises a ProjectNotFound" do + expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) end end -- cgit v1.2.1 From 4b341dea5547889fd8fe6239d28c453de194c7db Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 20 May 2016 12:52:53 -0500 Subject: Actually there's no such case --- spec/lib/gitlab/email/receiver_spec.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index a9b93044a08..c08e184c4c3 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -238,15 +238,6 @@ describe Gitlab::Email::Receiver, lib: true do it "raises a ProjectNotFound if the user is not a member" do expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) end - - it "raises a UserNotAuthorizedError if the user has no sufficient permission" do - skip("Find a role which can :read_project but can't :create_issue") - - project.update(group: create(:group)) - project.group.add_guest(user) - - expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) - end end end end -- cgit v1.2.1 From 9436a444f3e890ad48b64c26ec95ffde4ed9e87c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 20 May 2016 13:05:57 -0500 Subject: Rename reply_key to mail_key --- spec/lib/gitlab/email/receiver_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index c08e184c4c3..e892da7bb46 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -6,13 +6,13 @@ describe Gitlab::Email::Receiver, lib: true do stub_config_setting(host: 'localhost') end - let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } + let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } let(:email_raw) { fixture_file('emails/valid_reply.eml') } let(:project) { create(:project, :public) } let(:noteable) { create(:issue, project: project) } let(:user) { create(:user) } - let!(:sent_notification) { SentNotification.record(noteable, user.id, reply_key) } + let!(:sent_notification) { SentNotification.record(noteable, user.id, mail_key) } let(:receiver) { described_class.new(email_raw) } let(:markdown) { "![image](uploads/image.png)" } @@ -30,16 +30,16 @@ describe Gitlab::Email::Receiver, lib: true do ) end - context "when the recipient address doesn't include a reply key" do - let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "") } + context "when the recipient address doesn't include a mail key" do + let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") } it "raises a SentNotificationNotFoundError" do expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) end end - context "when no sent notification for the reply key could be found" do - let(:email_raw) { fixture_file('emails/wrong_reply_key.eml') } + context "when no sent notification for the mail key could be found" do + let(:email_raw) { fixture_file('emails/wrong_mail_key.eml') } it "raises a SentNotificationNotFoundError" do expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) @@ -55,7 +55,7 @@ describe Gitlab::Email::Receiver, lib: true do end context "when the email was auto generated" do - let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } + let!(:mail_key) { '636ca428858779856c226bb145ef4fad' } let!(:email_raw) { fixture_file("emails/auto_reply.eml") } it "raises an AutoGeneratedEmailError" do @@ -147,8 +147,8 @@ describe Gitlab::Email::Receiver, lib: true do stub_incoming_email_setting(enabled: true, address: nil) end - shared_examples 'an email that contains a reply key' do |header| - it "fetches the reply key from the #{header} header and creates a comment" do + shared_examples 'an email that contains a mail key' do |header| + it "fetches the mail key from the #{header} header and creates a comment" do expect { receiver.execute }.to change { noteable.notes.count }.by(1) note = noteable.notes.last @@ -157,10 +157,10 @@ describe Gitlab::Email::Receiver, lib: true do end end - context 'reply key is in the References header' do + context 'mail key is in the References header' do let(:email_raw) { fixture_file('emails/reply_without_subaddressing_and_key_inside_references.eml') } - it_behaves_like 'an email that contains a reply key', 'References' + it_behaves_like 'an email that contains a mail key', 'References' end end end -- cgit v1.2.1 From a7f6b75e7fba69964e84a0ae96c77650c66bb031 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 20 May 2016 15:36:25 -0500 Subject: Fix a missed rename --- spec/lib/gitlab/incoming_email_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/incoming_email_spec.rb b/spec/lib/gitlab/incoming_email_spec.rb index afb3e26f8fb..bb1fe089206 100644 --- a/spec/lib/gitlab/incoming_email_spec.rb +++ b/spec/lib/gitlab/incoming_email_spec.rb @@ -43,9 +43,9 @@ describe Gitlab::IncomingEmail, lib: true do end end - context 'self.key_from_fallback_reply_message_id' do + context 'self.key_from_fallback_reply_mail_id' do it 'returns reply key' do - expect(described_class.key_from_fallback_reply_message_id('reply-key@localhost')).to eq('key') + expect(described_class.key_from_fallback_reply_mail_id('reply-key@localhost')).to eq('key') end end end -- cgit v1.2.1 From c2bc15a7669b8f21b12314f8607a02cf7d8b4828 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 20 May 2016 17:38:08 -0500 Subject: Use the authentication_token for finding the user --- spec/lib/gitlab/email/receiver_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index e892da7bb46..a9e2be0ad47 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -224,11 +224,11 @@ describe Gitlab::Email::Receiver, lib: true do end end - context "when the authentication_token token didn't match" do + context "when we can't find the authentication_token" do let!(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } - it "raises an UserNotAuthorizedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotAuthorizedError) + it "raises an UserNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) end end -- cgit v1.2.1 From 32eae15f2f7ada5b5008f0fe9fb46f349cd4f367 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 20 May 2016 18:21:58 -0500 Subject: It's for Message-ID so it should be message_id --- spec/lib/gitlab/incoming_email_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/incoming_email_spec.rb b/spec/lib/gitlab/incoming_email_spec.rb index bb1fe089206..1dcf2c0668b 100644 --- a/spec/lib/gitlab/incoming_email_spec.rb +++ b/spec/lib/gitlab/incoming_email_spec.rb @@ -43,9 +43,9 @@ describe Gitlab::IncomingEmail, lib: true do end end - context 'self.key_from_fallback_reply_mail_id' do + context 'self.key_from_fallback_message_id' do it 'returns reply key' do - expect(described_class.key_from_fallback_reply_mail_id('reply-key@localhost')).to eq('key') + expect(described_class.key_from_fallback_message_id('reply-key@localhost')).to eq('key') end end end -- cgit v1.2.1 From 1f5d55907a05fefbda17f7a4f45f58f2b522aee2 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 24 May 2016 01:19:20 +0800 Subject: Merge the places where exceptions could be raised --- spec/lib/gitlab/email/receiver_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index a9e2be0ad47..7291e478d90 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -30,6 +30,14 @@ describe Gitlab::Email::Receiver, lib: true do ) end + context "when we cannot find a capable handler" do + let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "!!!") } + + it "raises a UnknownIncomingEmail" do + expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail) + end + end + context "when the recipient address doesn't include a mail key" do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") } -- cgit v1.2.1 From 8c0b619d40e4d113ef592f4ae7a4b6afa320f225 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 24 May 2016 17:30:36 +0800 Subject: Split tests into their own classes --- spec/lib/gitlab/email/email_shared_blocks.rb | 41 ++++ .../email/handler/create_issue_handler_spec.rb | 79 +++++++ .../email/handler/create_note_handler_spec.rb | 116 ++++++++++ spec/lib/gitlab/email/receiver_spec.rb | 236 +-------------------- 4 files changed, 239 insertions(+), 233 deletions(-) create mode 100644 spec/lib/gitlab/email/email_shared_blocks.rb create mode 100644 spec/lib/gitlab/email/handler/create_issue_handler_spec.rb create mode 100644 spec/lib/gitlab/email/handler/create_note_handler_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/email_shared_blocks.rb b/spec/lib/gitlab/email/email_shared_blocks.rb new file mode 100644 index 00000000000..eeaf427d39d --- /dev/null +++ b/spec/lib/gitlab/email/email_shared_blocks.rb @@ -0,0 +1,41 @@ + +shared_context :email_shared_context do + let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } + let(:receiver) { Gitlab::Email::Receiver.new(email_raw) } + let(:markdown) { "![image](uploads/image.png)" } + + def setup_attachment + allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( + [ + { + url: "uploads/image.png", + is_image: true, + alt: "image", + markdown: markdown + } + ] + ) + end +end + +shared_examples :email_shared_examples do + context "when the user could not be found" do + before do + user.destroy + end + + it "raises a UserNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) + end + end + + context "when the user is not authorized to the project" do + before do + project.update_attribute(:visibility_level, Project::PRIVATE) + end + + it "raises a ProjectNotFound" do + expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) + end + end +end diff --git a/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb b/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb new file mode 100644 index 00000000000..e1153154778 --- /dev/null +++ b/spec/lib/gitlab/email/handler/create_issue_handler_spec.rb @@ -0,0 +1,79 @@ +require 'spec_helper' +require_relative '../email_shared_blocks' + +describe Gitlab::Email::Handler::CreateIssueHandler, lib: true do + include_context :email_shared_context + it_behaves_like :email_shared_examples + + before do + stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo") + stub_config_setting(host: 'localhost') + end + + let(:email_raw) { fixture_file('emails/valid_new_issue.eml') } + let(:namespace) { create(:namespace, path: 'gitlabhq') } + + let!(:project) { create(:project, :public, namespace: namespace) } + let!(:user) do + create( + :user, + email: 'jake@adventuretime.ooo', + authentication_token: 'auth_token' + ) + end + + context "when everything is fine" do + it "creates a new issue" do + setup_attachment + + expect { receiver.execute }.to change { project.issues.count }.by(1) + issue = project.issues.last + + expect(issue.author).to eq(user) + expect(issue.title).to eq('New Issue by email') + expect(issue.description).to include('reply by email') + expect(issue.description).to include(markdown) + end + + context "when the reply is blank" do + let(:email_raw) { fixture_file("emails/valid_new_issue_empty.eml") } + + it "creates a new issue" do + expect { receiver.execute }.to change { project.issues.count }.by(1) + issue = project.issues.last + + expect(issue.author).to eq(user) + expect(issue.title).to eq('New Issue by email') + expect(issue.description).to eq('') + end + end + end + + context "something is wrong" do + context "when the issue could not be saved" do + before do + allow_any_instance_of(Issue).to receive(:persisted?).and_return(false) + end + + it "raises an InvalidIssueError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidIssueError) + end + end + + context "when we can't find the authentication_token" do + let(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } + + it "raises an UserNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) + end + end + + context "when project is private" do + let(:project) { create(:project, :private, namespace: namespace) } + + it "raises a ProjectNotFound if the user is not a member" do + expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) + end + end + end +end diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb new file mode 100644 index 00000000000..9b7fb6a1a4b --- /dev/null +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -0,0 +1,116 @@ +require 'spec_helper' +require_relative '../email_shared_blocks' + +describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do + include_context :email_shared_context + it_behaves_like :email_shared_examples + + before do + stub_incoming_email_setting(enabled: true, address: "reply+%{key}@appmail.adventuretime.ooo") + stub_config_setting(host: 'localhost') + end + + let(:email_raw) { fixture_file('emails/valid_reply.eml') } + let(:project) { create(:project, :public) } + let(:noteable) { create(:issue, project: project) } + let(:user) { create(:user) } + + let!(:sent_notification) { SentNotification.record(noteable, user.id, mail_key) } + + context "when the recipient address doesn't include a mail key" do + let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") } + + it "raises a SentNotificationNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) + end + end + + context "when no sent notification for the mail key could be found" do + let(:email_raw) { fixture_file('emails/wrong_mail_key.eml') } + + it "raises a SentNotificationNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) + end + end + + context "when the email was auto generated" do + let!(:mail_key) { '636ca428858779856c226bb145ef4fad' } + let!(:email_raw) { fixture_file("emails/auto_reply.eml") } + + it "raises an AutoGeneratedEmailError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError) + end + end + + context "when the noteable could not be found" do + before do + noteable.destroy + end + + it "raises a NoteableNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::NoteableNotFoundError) + end + end + + context "when the note could not be saved" do + before do + allow_any_instance_of(Note).to receive(:persisted?).and_return(false) + end + + it "raises an InvalidNoteError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidNoteError) + end + end + + context "when the reply is blank" do + let!(:email_raw) { fixture_file("emails/no_content_reply.eml") } + + it "raises an EmptyEmailError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) + end + end + + context "when everything is fine" do + before do + setup_attachment + end + + it "creates a comment" do + expect { receiver.execute }.to change { noteable.notes.count }.by(1) + note = noteable.notes.last + + expect(note.author).to eq(sent_notification.recipient) + expect(note.note).to include("I could not disagree more.") + end + + it "adds all attachments" do + receiver.execute + + note = noteable.notes.last + + expect(note.note).to include(markdown) + end + + context 'when sub-addressing is not supported' do + before do + stub_incoming_email_setting(enabled: true, address: nil) + end + + shared_examples 'an email that contains a mail key' do |header| + it "fetches the mail key from the #{header} header and creates a comment" do + expect { receiver.execute }.to change { noteable.notes.count }.by(1) + note = noteable.notes.last + + expect(note.author).to eq(sent_notification.recipient) + expect(note.note).to include('I could not disagree more.') + end + end + + context 'mail key is in the References header' do + let(:email_raw) { fixture_file('emails/reply_without_subaddressing_and_key_inside_references.eml') } + + it_behaves_like 'an email that contains a mail key', 'References' + end + end + end +end diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 7291e478d90..2a86b427806 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -1,34 +1,8 @@ -require "spec_helper" +require 'spec_helper' +require_relative 'email_shared_blocks' describe Gitlab::Email::Receiver, lib: true do - before do - stub_incoming_email_setting(enabled: true, address: "reply+%{key}@appmail.adventuretime.ooo") - stub_config_setting(host: 'localhost') - end - - let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } - let(:email_raw) { fixture_file('emails/valid_reply.eml') } - - let(:project) { create(:project, :public) } - let(:noteable) { create(:issue, project: project) } - let(:user) { create(:user) } - let!(:sent_notification) { SentNotification.record(noteable, user.id, mail_key) } - - let(:receiver) { described_class.new(email_raw) } - let(:markdown) { "![image](uploads/image.png)" } - - def setup_attachment - allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( - [ - { - url: "uploads/image.png", - is_image: true, - alt: "image", - markdown: markdown - } - ] - ) - end + include_context :email_shared_context context "when we cannot find a capable handler" do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "!!!") } @@ -38,22 +12,6 @@ describe Gitlab::Email::Receiver, lib: true do end end - context "when the recipient address doesn't include a mail key" do - let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") } - - it "raises a SentNotificationNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) - end - end - - context "when no sent notification for the mail key could be found" do - let(:email_raw) { fixture_file('emails/wrong_mail_key.eml') } - - it "raises a SentNotificationNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) - end - end - context "when the email is blank" do let(:email_raw) { "" } @@ -61,192 +19,4 @@ describe Gitlab::Email::Receiver, lib: true do expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) end end - - context "when the email was auto generated" do - let!(:mail_key) { '636ca428858779856c226bb145ef4fad' } - let!(:email_raw) { fixture_file("emails/auto_reply.eml") } - - it "raises an AutoGeneratedEmailError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError) - end - end - - context "when the user could not be found" do - before do - user.destroy - end - - it "raises a UserNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) - end - end - - context "when the user has been blocked" do - before do - user.block - end - - it "raises a UserBlockedError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::UserBlockedError) - end - end - - context "when the user is not authorized to create a note" do - before do - project.update_attribute(:visibility_level, Project::PRIVATE) - end - - it "raises a ProjectNotFound" do - expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) - end - end - - context "when the noteable could not be found" do - before do - noteable.destroy - end - - it "raises a NoteableNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::NoteableNotFoundError) - end - end - - context "when the reply is blank" do - let!(:email_raw) { fixture_file("emails/no_content_reply.eml") } - - it "raises an EmptyEmailError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::EmptyEmailError) - end - end - - context "when the note could not be saved" do - before do - allow_any_instance_of(Note).to receive(:persisted?).and_return(false) - end - - it "raises an InvalidNoteError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidNoteError) - end - end - - context "when everything is fine" do - before do - setup_attachment - end - - it "creates a comment" do - expect { receiver.execute }.to change { noteable.notes.count }.by(1) - note = noteable.notes.last - - expect(note.author).to eq(sent_notification.recipient) - expect(note.note).to include("I could not disagree more.") - end - - it "adds all attachments" do - receiver.execute - - note = noteable.notes.last - - expect(note.note).to include(markdown) - end - - context 'when sub-addressing is not supported' do - before do - stub_incoming_email_setting(enabled: true, address: nil) - end - - shared_examples 'an email that contains a mail key' do |header| - it "fetches the mail key from the #{header} header and creates a comment" do - expect { receiver.execute }.to change { noteable.notes.count }.by(1) - note = noteable.notes.last - - expect(note.author).to eq(sent_notification.recipient) - expect(note.note).to include('I could not disagree more.') - end - end - - context 'mail key is in the References header' do - let(:email_raw) { fixture_file('emails/reply_without_subaddressing_and_key_inside_references.eml') } - - it_behaves_like 'an email that contains a mail key', 'References' - end - end - end - - context "when it's trying to create a new issue" do - before do - stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.adventuretime.ooo") - end - - let(:sent_notification) {} - let!(:user) do - create( - :user, - email: 'jake@adventuretime.ooo', - authentication_token: 'auth_token' - ) - end - let(:namespace) { create(:namespace, path: 'gitlabhq') } - let(:project) { create(:project, :public, namespace: namespace) } - let(:email_raw) { fixture_file('emails/valid_new_issue.eml') } - - context "when everything is fine" do - it "creates a new issue" do - setup_attachment - - expect { receiver.execute }.to change { project.issues.count }.by(1) - issue = project.issues.last - - expect(issue.author).to eq(user) - expect(issue.title).to eq('New Issue by email') - expect(issue.description).to include('reply by email') - expect(issue.description).to include(markdown) - end - - context "when the reply is blank" do - let!(:email_raw) { fixture_file("emails/valid_new_issue_empty.eml") } - - it "creates a new issue" do - expect { receiver.execute }.to change { project.issues.count }.by(1) - issue = project.issues.last - - expect(issue.author).to eq(user) - expect(issue.title).to eq('New Issue by email') - expect(issue.description).to eq('') - end - end - end - - context "something is wrong" do - before do - project - end - - context "when the issue could not be saved" do - before do - allow_any_instance_of(Issue).to receive(:persisted?).and_return(false) - end - - it "raises an InvalidIssueError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::InvalidIssueError) - end - end - - context "when we can't find the authentication_token" do - let!(:email_raw) { fixture_file("emails/wrong_authentication_token.eml") } - - it "raises an UserNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::UserNotFoundError) - end - end - - context "when project is private" do - let(:project) { create(:project, :private, namespace: namespace) } - - it "raises a ProjectNotFound if the user is not a member" do - expect { receiver.execute }.to raise_error(Gitlab::Email::ProjectNotFound) - end - end - end - end end -- cgit v1.2.1 From 4befcc353dfca081ea35cedc5be7687f6e0b97e4 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 15 Jun 2016 17:59:44 +0800 Subject: Add missing require in tests --- spec/lib/gitlab/email/email_shared_blocks.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/email_shared_blocks.rb b/spec/lib/gitlab/email/email_shared_blocks.rb index eeaf427d39d..c1dc1003831 100644 --- a/spec/lib/gitlab/email/email_shared_blocks.rb +++ b/spec/lib/gitlab/email/email_shared_blocks.rb @@ -1,3 +1,4 @@ +require 'gitlab/email/receiver' shared_context :email_shared_context do let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } -- cgit v1.2.1 From 176fa21cb75f404b401e021f0cdcc6a138c207eb Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 20 Jun 2016 19:15:54 +0800 Subject: raise UnknownIncomingEmail when there's no mail_key: So that we don't have to pretend that CreateNoteHandler could handle a nil mail_key. Also, since NilClass#=~ would just return nil for any regular expression, we could just match it without checking nilness. Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3363#note_12566407 --- spec/lib/gitlab/email/handler/create_note_handler_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb index 9b7fb6a1a4b..a2119b0dadf 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -20,8 +20,8 @@ describe Gitlab::Email::Handler::CreateNoteHandler, lib: true do context "when the recipient address doesn't include a mail key" do let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(mail_key, "") } - it "raises a SentNotificationNotFoundError" do - expect { receiver.execute }.to raise_error(Gitlab::Email::SentNotificationNotFoundError) + it "raises a UnknownIncomingEmail" do + expect { receiver.execute }.to raise_error(Gitlab::Email::UnknownIncomingEmail) end end -- cgit v1.2.1 From cf53d798736f7c86459c3e6635a83875e6101373 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Jul 2016 13:07:03 +0200 Subject: Extract jobs config to separate key in config hash --- spec/lib/gitlab/ci/config/node/global_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index c87c9e97bc8..88194bf9453 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -22,7 +22,9 @@ describe Gitlab::Ci::Config::Node::Global do variables: { VAR: 'value' }, after_script: ['make clean'], stages: ['build', 'pages'], - cache: { key: 'k', untracked: true, paths: ['public/'] } } + cache: { key: 'k', untracked: true, paths: ['public/'] }, + rspec: { script: 'rspec' }, + spinach: { script: 'spinach' } } end describe '#process!' do @@ -120,6 +122,14 @@ describe Gitlab::Ci::Config::Node::Global do .to eq(key: 'k', untracked: true, paths: ['public/']) end end + + describe '#jobs' do + it 'returns jobs configuration' do + expect(global.jobs) + .to eq(rspec: { script: 'rspec' }, + spinach: { script: 'spinach' }) + end + end end end -- cgit v1.2.1 From 5b7f211cbba06f7c43b55b4a38704073564a099f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Jul 2016 13:35:50 +0200 Subject: Add new CI config entry that holds jobs definition --- spec/lib/gitlab/ci/config/node/global_spec.rb | 4 +-- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 36 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/jobs_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 88194bf9453..8f2f9e171d1 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do end it 'creates node object for each entry' do - expect(global.nodes.count).to eq 8 + expect(global.nodes.count).to eq 9 end it 'creates node object using valid class' do @@ -139,7 +139,7 @@ describe Gitlab::Ci::Config::Node::Global do describe '#nodes' do it 'instantizes all nodes' do - expect(global.nodes.count).to eq 8 + expect(global.nodes.count).to eq 9 end it 'contains undefined nodes' do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb new file mode 100644 index 00000000000..3afa3de06c6 --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Jobs do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is correct' do + let(:config) { { rspec: { script: 'rspec' } } } + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq(rspec: { script: 'rspec' }) + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not correct' do + context 'incorrect config value type' do + let(:config) { ['incorrect'] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'jobs config should be a hash' + end + end + end + end + end +end -- cgit v1.2.1 From e00ae9a87720bccda634dc85c018f5ec1d03a883 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Jul 2016 14:04:22 +0200 Subject: Add new CI config entry for single job in pipeline --- spec/lib/gitlab/ci/config/node/job_spec.rb | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/lib/gitlab/ci/config/node/job_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb new file mode 100644 index 00000000000..7dd25a23c83 --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Job do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is correct' do + let(:config) { { script: 'rspec' } } + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq(script: 'rspec') + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not correct' do + context 'incorrect config value type' do + let(:config) { ['incorrect'] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'job config should be a hash' + end + end + end + end + end +end -- cgit v1.2.1 From 6ae80732bb3b503e2d15acb2cab527c17e22e34b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Jul 2016 14:17:09 +0200 Subject: Add ability to define nodes in new CI config entry --- spec/lib/gitlab/ci/config/node/global_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 8f2f9e171d1..254cb28190c 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -31,24 +31,24 @@ describe Gitlab::Ci::Config::Node::Global do before { global.process! } it 'creates nodes hash' do - expect(global.nodes).to be_an Array + expect(global.descendants).to be_an Array end it 'creates node object for each entry' do - expect(global.nodes.count).to eq 9 + expect(global.descendants.count).to eq 9 end it 'creates node object using valid class' do - expect(global.nodes.first) + expect(global.descendants.first) .to be_an_instance_of Gitlab::Ci::Config::Node::Script - expect(global.nodes.second) + expect(global.descendants.second) .to be_an_instance_of Gitlab::Ci::Config::Node::Image end it 'sets correct description for nodes' do - expect(global.nodes.first.description) + expect(global.descendants.first.description) .to eq 'Script that will be executed before each job.' - expect(global.nodes.second.description) + expect(global.descendants.second.description) .to eq 'Docker image that will be used to execute jobs.' end end @@ -139,11 +139,11 @@ describe Gitlab::Ci::Config::Node::Global do describe '#nodes' do it 'instantizes all nodes' do - expect(global.nodes.count).to eq 9 + expect(global.descendants.count).to eq 9 end it 'contains undefined nodes' do - expect(global.nodes.first) + expect(global.descendants.first) .to be_an_instance_of Gitlab::Ci::Config::Node::Undefined end end -- cgit v1.2.1 From dbab56a9519039bb6a83974c31b90b1283b8479c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Jul 2016 14:48:17 +0200 Subject: Create composite job entries in new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 ++-- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index bad439bc489..49a786191b8 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1043,11 +1043,11 @@ EOT end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings") end - it "returns errors if there are unknown parameters" do + it "returns error if job configuration is invalid" do config = YAML.dump({ extra: "bundle update" }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:extra config should be a hash") end it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 3afa3de06c6..7f80e11cea3 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -4,6 +4,8 @@ describe Gitlab::Ci::Config::Node::Jobs do let(:entry) { described_class.new(config) } describe 'validations' do + before { entry.process! } + context 'when entry config value is correct' do let(:config) { { rspec: { script: 'rspec' } } } @@ -33,4 +35,19 @@ describe Gitlab::Ci::Config::Node::Jobs do end end end + + describe '#descendants' do + before { entry.process! } + + let(:config) do + { rspec: { script: 'rspec' }, + spinach: { script: 'spinach' } } + end + + it 'creates two descendant nodes' do + expect(entry.descendants.count).to eq 2 + expect(entry.descendants) + .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) + end + end end -- cgit v1.2.1 From b1b0c18b8c66857964eaaa5704a0744aacb707dd Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Jul 2016 12:58:43 +0200 Subject: Add hidden job in new CI config that is irrelevant --- spec/lib/gitlab/ci/config/node/hidden_job_spec.rb | 48 +++++++++++++++++++++++ spec/lib/gitlab/ci/config/node/job_spec.rb | 6 +++ spec/lib/gitlab/ci/config/node/jobs_spec.rb | 23 ++++++++--- 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/hidden_job_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb b/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb new file mode 100644 index 00000000000..ab865c3522e --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::HiddenJob do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is correct' do + let(:config) { { image: 'ruby:2.2' } } + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq(image: 'ruby:2.2') + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not correct' do + context 'incorrect config value type' do + let(:config) { ['incorrect'] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'hidden job config should be a hash' + end + end + end + end + end + + describe '#leaf?' do + it 'is a leaf' do + expect(entry).to be_leaf + end + end + + describe '#relevant?' do + it 'is not a relevant entry' do + expect(entry).not_to be_relevant + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 7dd25a23c83..15c7f9bc394 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -33,4 +33,10 @@ describe Gitlab::Ci::Config::Node::Job do end end end + + describe '#relevant?' do + it 'is a relevant entry' do + expect(entry).to be_relevant + end + end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 7f80e11cea3..b2d2a92d9e8 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -36,18 +36,29 @@ describe Gitlab::Ci::Config::Node::Jobs do end end - describe '#descendants' do + context 'when valid job entries processed' do before { entry.process! } let(:config) do { rspec: { script: 'rspec' }, - spinach: { script: 'spinach' } } + spinach: { script: 'spinach' }, + '.hidden'.to_sym => {} } end - it 'creates two descendant nodes' do - expect(entry.descendants.count).to eq 2 - expect(entry.descendants) - .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) + describe '#descendants' do + it 'creates valid descendant nodes' do + expect(entry.descendants.count).to eq 3 + expect(entry.descendants.first(2)) + .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) + expect(entry.descendants.last) + .to be_an_instance_of(Gitlab::Ci::Config::Node::HiddenJob) + end + end + + describe '#value' do + it 'returns value of visible jobs only' do + expect(entry.value.keys).to eq [:rspec, :spinach] + end end end end -- cgit v1.2.1 From 4491bf28e10da258701b316f397c5802f5f9974e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Jul 2016 14:08:19 +0200 Subject: Move CI job config validations to new classes --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 9 +++++- spec/lib/gitlab/ci/config/node/global_spec.rb | 7 +++-- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 42 +++++++++++++++++++-------- 3 files changed, 43 insertions(+), 15 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 49a786191b8..ac058ba1595 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1061,7 +1061,14 @@ EOT config = YAML.dump({ before_script: ["bundle update"] }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs config should contain at least one visible job") + end + + it "returns errors if there are no visible jobs defined" do + config = YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => {} }) + expect do + GitlabCiYamlProcessor.new(config, path) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs config should contain at least one visible job") end it "returns errors if job allow_failure parameter is not an boolean" do diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 254cb28190c..a98de73c06c 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -108,7 +108,10 @@ describe Gitlab::Ci::Config::Node::Global do end context 'when deprecated types key defined' do - let(:hash) { { types: ['test', 'deploy'] } } + let(:hash) do + { types: ['test', 'deploy'], + rspec: { script: 'rspec' } } + end it 'returns array of types as stages' do expect(global.stages).to eq %w[test deploy] @@ -174,7 +177,7 @@ describe Gitlab::Ci::Config::Node::Global do # details. # context 'when entires specified but not defined' do - let(:hash) { { variables: nil } } + let(:hash) { { variables: nil, rspec: { script: 'rspec' } } } before { global.process! } describe '#variables' do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index b2d2a92d9e8..7ec28b642b4 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -4,17 +4,9 @@ describe Gitlab::Ci::Config::Node::Jobs do let(:entry) { described_class.new(config) } describe 'validations' do - before { entry.process! } - context 'when entry config value is correct' do let(:config) { { rspec: { script: 'rspec' } } } - describe '#value' do - it 'returns key value' do - expect(entry.value).to eq(rspec: { script: 'rspec' }) - end - end - describe '#valid?' do it 'is valid' do expect(entry).to be_valid @@ -23,15 +15,34 @@ describe Gitlab::Ci::Config::Node::Jobs do end context 'when entry value is not correct' do - context 'incorrect config value type' do - let(:config) { ['incorrect'] } + describe '#errors' do + context 'incorrect config value type' do + let(:config) { ['incorrect'] } - describe '#errors' do - it 'saves errors' do + it 'returns error about incorrect type' do expect(entry.errors) .to include 'jobs config should be a hash' end end + + context 'when no visible jobs present' do + let(:config) { { '.hidden'.to_sym => {} } } + + context 'when not processed' do + it 'is valid' do + expect(entry.errors).to be_empty + end + end + + context 'when processed' do + before { entry.process! } + + it 'returns error about no visible jobs defined' do + expect(entry.errors) + .to include 'jobs config should contain at least one visible job' + end + end + end end end end @@ -45,6 +56,13 @@ describe Gitlab::Ci::Config::Node::Jobs do '.hidden'.to_sym => {} } end + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq(rspec: { script: 'rspec' }, + spinach: { script: 'spinach' }) + end + end + describe '#descendants' do it 'creates valid descendant nodes' do expect(entry.descendants.count).to eq 3 -- cgit v1.2.1 From b0ae0d730f4eda34cd712477a828dddd888ba474 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Jul 2016 10:23:47 +0200 Subject: Use only node factory to create CI config entries --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index 91ddef7bfbf..5a26bb6df02 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -5,6 +5,18 @@ describe Gitlab::Ci::Config::Node::Factory do let(:factory) { described_class.new(entry_class) } let(:entry_class) { Gitlab::Ci::Config::Node::Script } + describe '.fabricate' do + it 'fabricates entry with attributes set' do + fabricated = described_class + .fabricate(entry_class, ['ls'], + parent: factory, key: :test) + + expect(fabricated.parent).to be factory + expect(fabricated.key).to eq :test + expect(fabricated.value).to eq ['ls'] + end + end + context 'when setting up a value' do it 'creates entry with valid value' do entry = factory -- cgit v1.2.1 From fea7762485c75003381891bc892bc6049f8a2105 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Jul 2016 12:41:31 +0200 Subject: Delegate methods to default CI entry if undefined --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 6 ++- spec/lib/gitlab/ci/config/node/undefined_spec.rb | 59 ++++++++++++++++++------ 2 files changed, 48 insertions(+), 17 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index 5a26bb6df02..5b856d44989 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -9,11 +9,13 @@ describe Gitlab::Ci::Config::Node::Factory do it 'fabricates entry with attributes set' do fabricated = described_class .fabricate(entry_class, ['ls'], - parent: factory, key: :test) + parent: true, key: :test) - expect(fabricated.parent).to be factory + expect(fabricated.parent).to be true expect(fabricated.key).to eq :test expect(fabricated.value).to eq ['ls'] + expect(fabricated.attributes) + .to eq(parent: true, key: :test, description: nil) end end diff --git a/spec/lib/gitlab/ci/config/node/undefined_spec.rb b/spec/lib/gitlab/ci/config/node/undefined_spec.rb index 0c6608d906d..417b4a0ad6f 100644 --- a/spec/lib/gitlab/ci/config/node/undefined_spec.rb +++ b/spec/lib/gitlab/ci/config/node/undefined_spec.rb @@ -2,33 +2,62 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Undefined do let(:undefined) { described_class.new(entry) } - let(:entry) { Class.new } + let(:entry) { spy('Entry') } - describe '#leaf?' do - it 'is leaf node' do - expect(undefined).to be_leaf + context 'when entry does not have a default value' do + before { allow(entry).to receive(:default).and_return(nil) } + + describe '#leaf?' do + it 'is leaf node' do + expect(undefined).to be_leaf + end end - end - describe '#valid?' do - it 'is always valid' do - expect(undefined).to be_valid + describe '#valid?' do + it 'is always valid' do + expect(undefined).to be_valid + end end - end - describe '#errors' do - it 'is does not contain errors' do - expect(undefined.errors).to be_empty + describe '#errors' do + it 'is does not contain errors' do + expect(undefined.errors).to be_empty + end + end + + describe '#value' do + it 'returns nil' do + expect(undefined.value).to eq nil + end end end - describe '#value' do + context 'when entry has a default value' do before do allow(entry).to receive(:default).and_return('some value') + allow(entry).to receive(:value).and_return('some value') end - it 'returns default value for entry' do - expect(undefined.value).to eq 'some value' + describe '#value' do + it 'returns default value for entry' do + expect(undefined.value).to eq 'some value' + end + end + + describe '#errors' do + it 'delegates errors to default entry' do + expect(entry).to receive(:errors) + + undefined.errors + end + end + + describe '#valid?' do + it 'delegates valid? to default entry' do + expect(entry).to receive(:valid?) + + undefined.valid? + end end end -- cgit v1.2.1 From 9410aecca87a1c03f7e7fb1e5e1073460c71b6e5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Jul 2016 13:39:13 +0200 Subject: Add scaffold of CI config for the job stage entry --- spec/lib/gitlab/ci/config/node/stage_spec.rb | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/lib/gitlab/ci/config/node/stage_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb new file mode 100644 index 00000000000..653d613ba6e --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Stage do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is correct' do + let(:config) { :stage1 } + + describe '#value' do + it 'returns a stage key' do + expect(entry.value).to eq config + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'when entry config is incorrect' do + let(:config) { { test: true } } + + describe '#errors' do + it 'reports errors' do + expect(entry.errors) + .to include 'stage config should be a string or symbol' + end + end + + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + end + end + end + end + end + + describe '.default' do + it 'returns default stage' do + expect(described_class.default).to eq :test + end + end +end -- cgit v1.2.1 From a7ac2f74944430d75b090f78cd9c1cf1d24379f6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Jul 2016 15:00:35 +0200 Subject: Simplify CI config entry node factory, use attribs --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index 5b856d44989..c912b1b2044 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -5,24 +5,10 @@ describe Gitlab::Ci::Config::Node::Factory do let(:factory) { described_class.new(entry_class) } let(:entry_class) { Gitlab::Ci::Config::Node::Script } - describe '.fabricate' do - it 'fabricates entry with attributes set' do - fabricated = described_class - .fabricate(entry_class, ['ls'], - parent: true, key: :test) - - expect(fabricated.parent).to be true - expect(fabricated.key).to eq :test - expect(fabricated.value).to eq ['ls'] - expect(fabricated.attributes) - .to eq(parent: true, key: :test, description: nil) - end - end - context 'when setting up a value' do it 'creates entry with valid value' do entry = factory - .with(value: ['ls', 'pwd']) + .value(['ls', 'pwd']) .create! expect(entry.value).to eq ['ls', 'pwd'] @@ -31,7 +17,7 @@ describe Gitlab::Ci::Config::Node::Factory do context 'when setting description' do it 'creates entry with description' do entry = factory - .with(value: ['ls', 'pwd']) + .value(['ls', 'pwd']) .with(description: 'test description') .create! @@ -43,7 +29,8 @@ describe Gitlab::Ci::Config::Node::Factory do context 'when setting key' do it 'creates entry with custom key' do entry = factory - .with(value: ['ls', 'pwd'], key: 'test key') + .value(['ls', 'pwd']) + .with(key: 'test key') .create! expect(entry.key).to eq 'test key' @@ -55,7 +42,8 @@ describe Gitlab::Ci::Config::Node::Factory do it 'creates entry with valid parent' do entry = factory - .with(value: 'ls', parent: parent) + .value('ls') + .with(parent: parent) .create! expect(entry.parent).to eq parent @@ -74,7 +62,7 @@ describe Gitlab::Ci::Config::Node::Factory do context 'when creating entry with nil value' do it 'creates an undefined entry' do entry = factory - .with(value: nil) + .value(nil) .create! expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Undefined -- cgit v1.2.1 From 3da57c800bf0c4fe3c45dbea3cff4179f6aa124f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Jul 2016 15:15:44 +0200 Subject: Require reference to CI config for some entries --- spec/lib/gitlab/ci/config/node/stage_spec.rb | 31 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 653d613ba6e..92150ea5337 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Stage do - let(:entry) { described_class.new(config) } + let(:entry) { described_class.new(config, global: global) } + let(:global) { spy('Global') } describe 'validations' do context 'when entry config value is correct' do - let(:config) { :stage1 } + let(:config) { :build } describe '#value' do it 'returns a stage key' do @@ -18,20 +19,32 @@ describe Gitlab::Ci::Config::Node::Stage do expect(entry).to be_valid end end + end + + context 'when entry config is incorrect' do + describe '#errors' do + context 'when reference to global node is not set' do + let(:entry) { described_class.new(config) } + + it 'raises error' do + expect { entry } + .to raise_error Gitlab::Ci::Config::Node::Entry::InvalidError + end + end - context 'when entry config is incorrect' do - let(:config) { { test: true } } + context 'when value has a wrong type' do + let(:config) { { test: true } } - describe '#errors' do - it 'reports errors' do + it 'reports errors about wrong type' do expect(entry.errors) .to include 'stage config should be a string or symbol' end end - describe '#valid?' do - it 'is not valid' do - expect(entry).not_to be_valid + context 'when stage is not present in global configuration' do + pending 'reports error about missing stage' do + expect(entry.errors) + .to include 'stage config should be one of test, stage' end end end -- cgit v1.2.1 From 8baee987beaea8197d28ee9715ef23f5813566e5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 8 Jul 2016 11:27:36 +0200 Subject: Extract internal attributes validator for CI entry --- spec/lib/gitlab/ci/config/node/stage_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 92150ea5337..4047d46c80f 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -27,8 +27,10 @@ describe Gitlab::Ci::Config::Node::Stage do let(:entry) { described_class.new(config) } it 'raises error' do - expect { entry } - .to raise_error Gitlab::Ci::Config::Node::Entry::InvalidError + expect { entry }.to raise_error( + Gitlab::Ci::Config::Node::Entry::InvalidError, + /Entry needs global attribute set internally./ + ) end end -- cgit v1.2.1 From 1ac62de2c12a26e6f5158cdb4f008a71729b39fc Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 8 Jul 2016 12:51:47 +0200 Subject: Extract CI entry node validator and improve naming --- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 7ec28b642b4..1ecc3e18d4e 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -35,7 +35,10 @@ describe Gitlab::Ci::Config::Node::Jobs do end context 'when processed' do - before { entry.process! } + before do + entry.process! + entry.validate! + end it 'returns error about no visible jobs defined' do expect(entry.errors) -- cgit v1.2.1 From d9142f2c97524fc2d5af7dda79b849d1e23f4910 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 8 Jul 2016 13:31:41 +0200 Subject: Add CI config known stage validation for job stage --- spec/lib/gitlab/ci/config/node/stage_spec.rb | 54 ++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 4047d46c80f..95b46d76adb 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -1,33 +1,33 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Stage do - let(:entry) { described_class.new(config, global: global) } + let(:stage) { described_class.new(config, global: global) } let(:global) { spy('Global') } describe 'validations' do - context 'when entry config value is correct' do + context 'when stage config value is correct' do let(:config) { :build } describe '#value' do it 'returns a stage key' do - expect(entry.value).to eq config + expect(stage.value).to eq config end end describe '#valid?' do it 'is valid' do - expect(entry).to be_valid + expect(stage).to be_valid end end end - context 'when entry config is incorrect' do + context 'when stage config is incorrect' do describe '#errors' do context 'when reference to global node is not set' do - let(:entry) { described_class.new(config) } + let(:stage) { described_class.new(config) } it 'raises error' do - expect { entry }.to raise_error( + expect { stage }.to raise_error( Gitlab::Ci::Config::Node::Entry::InvalidError, /Entry needs global attribute set internally./ ) @@ -38,21 +38,53 @@ describe Gitlab::Ci::Config::Node::Stage do let(:config) { { test: true } } it 'reports errors about wrong type' do - expect(entry.errors) + expect(stage.errors) .to include 'stage config should be a string or symbol' end end context 'when stage is not present in global configuration' do - pending 'reports error about missing stage' do - expect(entry.errors) - .to include 'stage config should be one of test, stage' + let(:config) { :unknown } + + before do + allow(global) + .to receive(:stages).and_return([:test, :deploy]) + end + + it 'reports error about missing stage' do + stage.validate! + + expect(stage.errors) + .to include 'stage config should be one of ' \ + 'defined stages (test, deploy)' end end end end end + describe '#known?' do + before do + allow(global).to receive(:stages).and_return([:test, :deploy]) + end + + context 'when stage is not known' do + let(:config) { :unknown } + + it 'returns false' do + expect(stage.known?).to be false + end + end + + context 'when stage is known' do + let(:config) { :test } + + it 'returns false' do + expect(stage.known?).to be true + end + end + end + describe '.default' do it 'returns default stage' do expect(described_class.default).to eq :test -- cgit v1.2.1 From ccbdb4022ac87f7c30e970922be64bcea0b406e9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 9 Jul 2016 14:56:41 +0200 Subject: Integrate CI job stage entry into CI configuration --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 6 +++--- spec/lib/gitlab/ci/config/node/global_spec.rb | 4 ++-- spec/lib/gitlab/ci/config/node/job_spec.rb | 12 ++++++++++-- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 7 ++++--- spec/lib/gitlab/ci/config/node/stage_spec.rb | 18 +++++++++++------- 5 files changed, 30 insertions(+), 17 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index ac058ba1595..03477e1ca13 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1082,21 +1082,21 @@ EOT config = YAML.dump({ rspec: { script: "test", type: 1 } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be a string") end it "returns errors if job stage is not a pre-defined stage" do config = YAML.dump({ rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test, deploy)") end it "returns errors if job stage is not a defined stage" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test)") end it "returns errors if stages is not an array" do diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index a98de73c06c..0c56b59db0c 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -129,8 +129,8 @@ describe Gitlab::Ci::Config::Node::Global do describe '#jobs' do it 'returns jobs configuration' do expect(global.jobs) - .to eq(rspec: { script: 'rspec' }, - spinach: { script: 'spinach' }) + .to eq(rspec: { script: 'rspec', stage: 'test' }, + spinach: { script: 'spinach', stage: 'test' }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 15c7f9bc394..2a4296448fb 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -1,15 +1,23 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do - let(:entry) { described_class.new(config) } + let(:entry) { described_class.new(config, global: global) } + let(:global) { spy('Global') } describe 'validations' do + before do + entry.process! + entry.validate! + end + context 'when entry config value is correct' do let(:config) { { script: 'rspec' } } describe '#value' do it 'returns key value' do - expect(entry.value).to eq(script: 'rspec') + expect(entry.value) + .to eq(script: 'rspec', + stage: 'test') end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 1ecc3e18d4e..52018958dcf 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Jobs do - let(:entry) { described_class.new(config) } + let(:entry) { described_class.new(config, global: spy) } describe 'validations' do context 'when entry config value is correct' do @@ -61,8 +61,9 @@ describe Gitlab::Ci::Config::Node::Jobs do describe '#value' do it 'returns key value' do - expect(entry.value).to eq(rspec: { script: 'rspec' }, - spinach: { script: 'spinach' }) + expect(entry.value) + .to eq(rspec: { script: 'rspec', stage: 'test' }, + spinach: { script: 'spinach', stage: 'test' }) end end diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 95b46d76adb..6deeca1a6c0 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -6,7 +6,11 @@ describe Gitlab::Ci::Config::Node::Stage do describe 'validations' do context 'when stage config value is correct' do - let(:config) { :build } + let(:config) { 'build' } + + before do + allow(global).to receive(:stages).and_return(%w[build]) + end describe '#value' do it 'returns a stage key' do @@ -39,16 +43,16 @@ describe Gitlab::Ci::Config::Node::Stage do it 'reports errors about wrong type' do expect(stage.errors) - .to include 'stage config should be a string or symbol' + .to include 'stage config should be a string' end end context 'when stage is not present in global configuration' do - let(:config) { :unknown } + let(:config) { 'unknown' } before do allow(global) - .to receive(:stages).and_return([:test, :deploy]) + .to receive(:stages).and_return(%w[test deploy]) end it 'reports error about missing stage' do @@ -65,7 +69,7 @@ describe Gitlab::Ci::Config::Node::Stage do describe '#known?' do before do - allow(global).to receive(:stages).and_return([:test, :deploy]) + allow(global).to receive(:stages).and_return(%w[test deploy]) end context 'when stage is not known' do @@ -77,7 +81,7 @@ describe Gitlab::Ci::Config::Node::Stage do end context 'when stage is known' do - let(:config) { :test } + let(:config) { 'test' } it 'returns false' do expect(stage.known?).to be true @@ -87,7 +91,7 @@ describe Gitlab::Ci::Config::Node::Stage do describe '.default' do it 'returns default stage' do - expect(described_class.default).to eq :test + expect(described_class.default).to eq 'test' end end end -- cgit v1.2.1 From 9edced40dd7398d1aa553a5454f95ae629da2276 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 9 Jul 2016 16:51:26 +0200 Subject: Use node factory to assemble global CI config entry --- spec/lib/gitlab/ci/config/node/global_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 0c56b59db0c..10e5f05a2d5 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do end it 'creates node object for each entry' do - expect(global.descendants.count).to eq 9 + expect(global.descendants.count).to eq 8 end it 'creates node object using valid class' do @@ -142,7 +142,7 @@ describe Gitlab::Ci::Config::Node::Global do describe '#nodes' do it 'instantizes all nodes' do - expect(global.descendants.count).to eq 9 + expect(global.descendants.count).to eq 8 end it 'contains undefined nodes' do -- cgit v1.2.1 From 2480701436bf84281e4afd65eb0d4c2d642754b9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 9 Jul 2016 18:43:26 +0200 Subject: Extend CI job entries fabrication and validation --- spec/lib/gitlab/ci/config/node/global_spec.rb | 2 +- spec/lib/gitlab/ci/config/node/hidden_job_spec.rb | 10 ++++++++ spec/lib/gitlab/ci/config/node/job_spec.rb | 10 ++++++++ spec/lib/gitlab/ci/config/node/jobs_spec.rb | 30 +++++++++++------------ 4 files changed, 36 insertions(+), 16 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 10e5f05a2d5..3e1c197fe61 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -137,7 +137,7 @@ describe Gitlab::Ci::Config::Node::Global do end context 'when most of entires not defined' do - let(:hash) { { cache: { key: 'a' }, rspec: {} } } + let(:hash) { { cache: { key: 'a' }, rspec: { script: %w[ls] } } } before { global.process! } describe '#nodes' do diff --git a/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb b/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb index ab865c3522e..cc44e2cc054 100644 --- a/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/hidden_job_spec.rb @@ -31,6 +31,16 @@ describe Gitlab::Ci::Config::Node::HiddenJob do end end end + + context 'when config is empty' do + let(:config) { {} } + + describe '#valid' do + it 'is invalid' do + expect(entry).not_to be_valid + end + end + end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 2a4296448fb..f841936ee6b 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -39,6 +39,16 @@ describe Gitlab::Ci::Config::Node::Job do end end end + + context 'when config is empty' do + let(:config) { {} } + + describe '#valid' do + it 'is invalid' do + expect(entry).not_to be_valid + end + end + end end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 52018958dcf..b0171174157 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -4,6 +4,11 @@ describe Gitlab::Ci::Config::Node::Jobs do let(:entry) { described_class.new(config, global: spy) } describe 'validations' do + before do + entry.process! + entry.validate! + end + context 'when entry config value is correct' do let(:config) { { rspec: { script: 'rspec' } } } @@ -25,25 +30,20 @@ describe Gitlab::Ci::Config::Node::Jobs do end end - context 'when no visible jobs present' do - let(:config) { { '.hidden'.to_sym => {} } } + context 'when job is unspecified' do + let(:config) { { rspec: nil } } - context 'when not processed' do - it 'is valid' do - expect(entry.errors).to be_empty - end + it 'is not valid' do + expect(entry).not_to be_valid end + end - context 'when processed' do - before do - entry.process! - entry.validate! - end + context 'when no visible jobs present' do + let(:config) { { '.hidden'.to_sym => { script: [] } } } - it 'returns error about no visible jobs defined' do - expect(entry.errors) - .to include 'jobs config should contain at least one visible job' - end + it 'returns error about no visible jobs defined' do + expect(entry.errors) + .to include 'jobs config should contain at least one visible job' end end end -- cgit v1.2.1 From 3c5b1da2a1f15be9e032ec23f56de0af8002ec6b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 10 Jul 2016 13:54:39 +0200 Subject: Add before_script node to CI job entry config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- spec/lib/gitlab/ci/config/node/job_spec.rb | 46 +++++++++++++++++++--------- 2 files changed, 33 insertions(+), 15 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 03477e1ca13..230106b74ae 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -970,7 +970,7 @@ EOT config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array of strings") end it "returns errors if after_script parameter is invalid" do diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index f841936ee6b..032fbb9c27f 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -4,23 +4,15 @@ describe Gitlab::Ci::Config::Node::Job do let(:entry) { described_class.new(config, global: global) } let(:global) { spy('Global') } - describe 'validations' do - before do - entry.process! - entry.validate! - end + before do + entry.process! + entry.validate! + end + describe 'validations' do context 'when entry config value is correct' do let(:config) { { script: 'rspec' } } - describe '#value' do - it 'returns key value' do - expect(entry.value) - .to eq(script: 'rspec', - stage: 'test') - end - end - describe '#valid?' do it 'is valid' do expect(entry).to be_valid @@ -33,7 +25,7 @@ describe Gitlab::Ci::Config::Node::Job do let(:config) { ['incorrect'] } describe '#errors' do - it 'saves errors' do + it 'reports error about a config type' do expect(entry.errors) .to include 'job config should be a hash' end @@ -52,6 +44,32 @@ describe Gitlab::Ci::Config::Node::Job do end end + describe '#value' do + context 'when entry is correct' do + let(:config) do + { before_script: %w[ls pwd], + script: 'rspec' } + end + + it 'returns correct value' do + expect(entry.value) + .to eq(before_script: %w[ls pwd], + script: 'rspec', + stage: 'test') + end + end + + context 'when entry is incorrect' do + let(:config) { {} } + + it 'raises error' do + expect { entry.value }.to raise_error( + Gitlab::Ci::Config::Node::Entry::InvalidError + ) + end + end + end + describe '#relevant?' do it 'is a relevant entry' do expect(entry).to be_relevant -- cgit v1.2.1 From 489e9be4e83621ae6f3db311398bf32e1065d1a8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 10 Jul 2016 14:35:53 +0200 Subject: Add CI job script node in new config processor --- spec/lib/gitlab/ci/config/node/global_spec.rb | 4 +- spec/lib/gitlab/ci/config/node/job_script_spec.rb | 49 +++++++++++++++++++++++ spec/lib/gitlab/ci/config/node/job_spec.rb | 2 +- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 4 +- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/job_script_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 3e1c197fe61..786fc5bb6ce 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -129,8 +129,8 @@ describe Gitlab::Ci::Config::Node::Global do describe '#jobs' do it 'returns jobs configuration' do expect(global.jobs) - .to eq(rspec: { script: 'rspec', stage: 'test' }, - spinach: { script: 'spinach', stage: 'test' }) + .to eq(rspec: { script: %w[rspec], stage: 'test' }, + spinach: { script: %w[spinach], stage: 'test' }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_script_spec.rb b/spec/lib/gitlab/ci/config/node/job_script_spec.rb new file mode 100644 index 00000000000..6e2ecb6e0ad --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/job_script_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::JobScript do + let(:entry) { described_class.new(config) } + + context 'when entry config value is an array' do + let(:config) { ['ls', 'pwd'] } + + describe '#value' do + it 'returns array of strings' do + expect(entry.value).to eq config + end + end + + describe '#errors' do + it 'does not append errors' do + expect(entry.errors).to be_empty + end + end + end + + context 'when entry config value is a string' do + let(:config) { 'ls' } + + describe '#value' do + it 'returns array with single element' do + expect(entry.value).to eq ['ls'] + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not valid' do + let(:config) { 1 } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'job script config should be a ' \ + 'string or an array of strings' + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 032fbb9c27f..3bcac73809d 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -54,7 +54,7 @@ describe Gitlab::Ci::Config::Node::Job do it 'returns correct value' do expect(entry.value) .to eq(before_script: %w[ls pwd], - script: 'rspec', + script: %w[rspec], stage: 'test') end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index b0171174157..255646a001a 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -62,8 +62,8 @@ describe Gitlab::Ci::Config::Node::Jobs do describe '#value' do it 'returns key value' do expect(entry.value) - .to eq(rspec: { script: 'rspec', stage: 'test' }, - spinach: { script: 'spinach', stage: 'test' }) + .to eq(rspec: { script: %w[rspec], stage: 'test' }, + spinach: { script: %w[spinach], stage: 'test' }) end end -- cgit v1.2.1 From 500b61e14f384eec545c207fa9324906daf2e148 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 10 Jul 2016 14:41:14 +0200 Subject: Move after script CI job confg to new processor --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- spec/lib/gitlab/ci/config/node/job_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 230106b74ae..a80b0ce5a57 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -984,7 +984,7 @@ EOT config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: after_script should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array of strings") end it "returns errors if image parameter is invalid" do diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 3bcac73809d..77efc73632d 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -48,14 +48,16 @@ describe Gitlab::Ci::Config::Node::Job do context 'when entry is correct' do let(:config) do { before_script: %w[ls pwd], - script: 'rspec' } + script: 'rspec', + after_script: %w[cleanup] } end it 'returns correct value' do expect(entry.value) .to eq(before_script: %w[ls pwd], script: %w[rspec], - stage: 'test') + stage: 'test', + after_script: %w[cleanup]) end end -- cgit v1.2.1 From 8f7c98ee2a34cb063428bea81f1420579549a1a5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 10 Jul 2016 20:26:37 +0200 Subject: Rename CI config job script entry node to commands --- spec/lib/gitlab/ci/config/node/commands_spec.rb | 49 +++++++++++++++++++++++ spec/lib/gitlab/ci/config/node/job_script_spec.rb | 49 ----------------------- 2 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/commands_spec.rb delete mode 100644 spec/lib/gitlab/ci/config/node/job_script_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/commands_spec.rb b/spec/lib/gitlab/ci/config/node/commands_spec.rb new file mode 100644 index 00000000000..e373c40706f --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/commands_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Commands do + let(:entry) { described_class.new(config) } + + context 'when entry config value is an array' do + let(:config) { ['ls', 'pwd'] } + + describe '#value' do + it 'returns array of strings' do + expect(entry.value).to eq config + end + end + + describe '#errors' do + it 'does not append errors' do + expect(entry.errors).to be_empty + end + end + end + + context 'when entry config value is a string' do + let(:config) { 'ls' } + + describe '#value' do + it 'returns array with single element' do + expect(entry.value).to eq ['ls'] + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not valid' do + let(:config) { 1 } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'commands config should be a ' \ + 'string or an array of strings' + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/job_script_spec.rb b/spec/lib/gitlab/ci/config/node/job_script_spec.rb deleted file mode 100644 index 6e2ecb6e0ad..00000000000 --- a/spec/lib/gitlab/ci/config/node/job_script_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::JobScript do - let(:entry) { described_class.new(config) } - - context 'when entry config value is an array' do - let(:config) { ['ls', 'pwd'] } - - describe '#value' do - it 'returns array of strings' do - expect(entry.value).to eq config - end - end - - describe '#errors' do - it 'does not append errors' do - expect(entry.errors).to be_empty - end - end - end - - context 'when entry config value is a string' do - let(:config) { 'ls' } - - describe '#value' do - it 'returns array with single element' do - expect(entry.value).to eq ['ls'] - end - end - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when entry value is not valid' do - let(:config) { 1 } - - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'job script config should be a ' \ - 'string or an array of strings' - end - end - end -end -- cgit v1.2.1 From 80587064eb798f5bf2b18dbb8e65e5a55d1db085 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 10 Jul 2016 20:59:18 +0200 Subject: Require parent when using node factory in CI config --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 43 +++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index c912b1b2044..bc6bf32ffbf 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -2,22 +2,40 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Factory do describe '#create!' do - let(:factory) { described_class.new(entry_class) } - let(:entry_class) { Gitlab::Ci::Config::Node::Script } + let(:factory) { described_class.new(node) } + let(:node) { Gitlab::Ci::Config::Node::Script } + let(:parent) { double('parent') } + let(:global) { double('global') } - context 'when setting up a value' do + before do + allow(parent).to receive(:global).and_return(global) + end + + context 'when setting a concrete value' do it 'creates entry with valid value' do entry = factory .value(['ls', 'pwd']) + .parent(parent) .create! expect(entry.value).to eq ['ls', 'pwd'] end + it 'sets parent and global attributes' do + entry = factory + .value('ls') + .parent(parent) + .create! + + expect(entry.global).to eq global + expect(entry.parent).to eq parent + end + context 'when setting description' do it 'creates entry with description' do entry = factory .value(['ls', 'pwd']) + .parent(parent) .with(description: 'test description') .create! @@ -30,6 +48,7 @@ describe Gitlab::Ci::Config::Node::Factory do it 'creates entry with custom key' do entry = factory .value(['ls', 'pwd']) + .parent(parent) .with(key: 'test key') .create! @@ -38,20 +57,21 @@ describe Gitlab::Ci::Config::Node::Factory do end context 'when setting a parent' do - let(:parent) { Object.new } + let(:object) { Object.new } it 'creates entry with valid parent' do entry = factory .value('ls') - .with(parent: parent) + .parent(parent) + .with(parent: object) .create! - expect(entry.parent).to eq parent + expect(entry.parent).to eq object end end end - context 'when not setting up a value' do + context 'when not setting a value' do it 'raises error' do expect { factory.create! }.to raise_error( Gitlab::Ci::Config::Node::Factory::InvalidFactory @@ -59,10 +79,19 @@ describe Gitlab::Ci::Config::Node::Factory do end end + context 'when not setting parent object' do + it 'raises error' do + expect { factory.value('ls').create! }.to raise_error( + Gitlab::Ci::Config::Node::Factory::InvalidFactory + ) + end + end + context 'when creating entry with nil value' do it 'creates an undefined entry' do entry = factory .value(nil) + .parent(parent) .create! expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Undefined -- cgit v1.2.1 From 8c9c3eda7a305c43d7cf3d50b868292d0b612b5b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Jul 2016 12:56:21 +0200 Subject: Prevalidate CI entries recursively on processed --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index a80b0ce5a57..1017f79cc6e 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1065,7 +1065,7 @@ EOT end it "returns errors if there are no visible jobs defined" do - config = YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => {} }) + config = YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => { script: 'ls' } }) expect do GitlabCiYamlProcessor.new(config, path) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs config should contain at least one visible job") -- cgit v1.2.1 From d41d3301474ffd7022e41daad4ddf67590ac9f95 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Jul 2016 13:03:19 +0200 Subject: Add CI config node that is unspecified null entry --- spec/lib/gitlab/ci/config/node/null_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/lib/gitlab/ci/config/node/null_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/null_spec.rb b/spec/lib/gitlab/ci/config/node/null_spec.rb new file mode 100644 index 00000000000..63b23ed0bd1 --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/null_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Null do + let(:null) { described_class.new } + + describe '#leaf?' do + it 'is leaf node' do + expect(null).to be_leaf + end + end + + describe '#valid?' do + it 'is always valid' do + expect(null).to be_valid + end + end + + describe '#errors' do + it 'is does not contain errors' do + expect(null.errors).to be_empty + end + end + + describe '#value' do + it 'returns nil' do + expect(null.value).to eq nil + end + end +end -- cgit v1.2.1 From 06641a3fee4ebdaada3007a51866a7fb927d21de Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Jul 2016 14:10:18 +0200 Subject: Simplify undefined node definition in CI config --- spec/lib/gitlab/ci/config/node/global_spec.rb | 4 +- spec/lib/gitlab/ci/config/node/null_spec.rb | 14 ++++- spec/lib/gitlab/ci/config/node/undefined_spec.rb | 67 ++++++------------------ 3 files changed, 30 insertions(+), 55 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 786fc5bb6ce..1945b0326cc 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -233,9 +233,9 @@ describe Gitlab::Ci::Config::Node::Global do end end - describe '#defined?' do + describe '#specified?' do it 'is concrete entry that is defined' do - expect(global.defined?).to be true + expect(global.specified?).to be true end end end diff --git a/spec/lib/gitlab/ci/config/node/null_spec.rb b/spec/lib/gitlab/ci/config/node/null_spec.rb index 63b23ed0bd1..1ab5478dcfa 100644 --- a/spec/lib/gitlab/ci/config/node/null_spec.rb +++ b/spec/lib/gitlab/ci/config/node/null_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Null do - let(:null) { described_class.new } + let(:null) { described_class.new(nil) } describe '#leaf?' do it 'is leaf node' do @@ -26,4 +26,16 @@ describe Gitlab::Ci::Config::Node::Null do expect(null.value).to eq nil end end + + describe '#relevant?' do + it 'is not relevant' do + expect(null.relevant?).to eq false + end + end + + describe '#specified?' do + it 'is not defined' do + expect(null.specified?).to eq false + end + end end diff --git a/spec/lib/gitlab/ci/config/node/undefined_spec.rb b/spec/lib/gitlab/ci/config/node/undefined_spec.rb index 417b4a0ad6f..2d43e1c1a9d 100644 --- a/spec/lib/gitlab/ci/config/node/undefined_spec.rb +++ b/spec/lib/gitlab/ci/config/node/undefined_spec.rb @@ -4,66 +4,29 @@ describe Gitlab::Ci::Config::Node::Undefined do let(:undefined) { described_class.new(entry) } let(:entry) { spy('Entry') } - context 'when entry does not have a default value' do - before { allow(entry).to receive(:default).and_return(nil) } - - describe '#leaf?' do - it 'is leaf node' do - expect(undefined).to be_leaf - end - end - - describe '#valid?' do - it 'is always valid' do - expect(undefined).to be_valid - end - end - - describe '#errors' do - it 'is does not contain errors' do - expect(undefined.errors).to be_empty - end - end - - describe '#value' do - it 'returns nil' do - expect(undefined.value).to eq nil - end + describe '#valid?' do + it 'delegates method to entry' do + expect(undefined.valid).to eq entry end end - context 'when entry has a default value' do - before do - allow(entry).to receive(:default).and_return('some value') - allow(entry).to receive(:value).and_return('some value') + describe '#errors' do + it 'delegates method to entry' do + expect(undefined.errors).to eq entry end + end - describe '#value' do - it 'returns default value for entry' do - expect(undefined.value).to eq 'some value' - end - end - - describe '#errors' do - it 'delegates errors to default entry' do - expect(entry).to receive(:errors) - - undefined.errors - end - end - - describe '#valid?' do - it 'delegates valid? to default entry' do - expect(entry).to receive(:valid?) - - undefined.valid? - end + describe '#value' do + it 'delegates method to entry' do + expect(undefined.value).to eq entry end end - describe '#undefined?' do - it 'is not a defined entry' do - expect(undefined.defined?).to be false + describe '#specified?' do + it 'is always false' do + allow(entry).to receive(:specified?).and_return(true) + + expect(undefined.specified?).to be false end end end -- cgit v1.2.1 From b228787f5afa34b153e6b52d6b0d88248cc3e099 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Jul 2016 14:58:48 +0200 Subject: Do not raise when getting value of invalid CI node --- spec/lib/gitlab/ci/config/node/global_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 1945b0326cc..3ffbe9c2e97 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -209,10 +209,8 @@ describe Gitlab::Ci::Config::Node::Global do end describe '#before_script' do - it 'raises error' do - expect { global.before_script }.to raise_error( - Gitlab::Ci::Config::Node::Entry::InvalidError - ) + it 'returns nil' do + expect(global.before_script).to be_nil end end end -- cgit v1.2.1 From de4c9a273867864a9033dab0624e0cfd72201384 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 13 Jul 2016 12:22:33 +0200 Subject: Improve CI stage configuration entry validations --- spec/lib/gitlab/ci/config/node/stage_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 6deeca1a6c0..004012f8b38 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -28,10 +28,10 @@ describe Gitlab::Ci::Config::Node::Stage do context 'when stage config is incorrect' do describe '#errors' do context 'when reference to global node is not set' do - let(:stage) { described_class.new(config) } + let(:stage) { described_class.new('test') } it 'raises error' do - expect { stage }.to raise_error( + expect { stage.validate! }.to raise_error( Gitlab::Ci::Config::Node::Entry::InvalidError, /Entry needs global attribute set internally./ ) -- cgit v1.2.1 From 6920390aad683dcc73109be5a23b647c918f9309 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 13 Jul 2016 14:38:10 +0200 Subject: Add before script and commands to CI job entry --- spec/lib/gitlab/ci/config/node/job_spec.rb | 117 +++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 77efc73632d..635362611a0 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -60,14 +60,62 @@ describe Gitlab::Ci::Config::Node::Job do after_script: %w[cleanup]) end end + end + + describe '#before_script' do + context 'when global entry has before script' do + before do + allow(global).to receive(:before_script) + .and_return(%w[ls pwd]) + end - context 'when entry is incorrect' do - let(:config) { {} } + context 'when before script is overridden' do + let(:config) do + { before_script: %w[whoami], + script: 'rspec' } + end - it 'raises error' do - expect { entry.value }.to raise_error( - Gitlab::Ci::Config::Node::Entry::InvalidError - ) + it 'returns correct script' do + expect(entry.before_script).to eq %w[whoami] + end + end + + context 'when before script is not overriden' do + let(:config) do + { script: %w[spinach] } + end + + it 'returns correct script' do + expect(entry.before_script).to eq %w[ls pwd] + end + end + end + + context 'when global entry does not have before script' do + before do + allow(global).to receive(:before_script) + .and_return(nil) + end + + context 'when job has before script' do + let(:config) do + { before_script: %w[whoami], + script: 'rspec' } + end + + it 'returns correct script' do + expect(entry.before_script).to eq %w[whoami] + end + end + + context 'when job does not have before script' do + let(:config) do + { script: %w[ls test] } + end + + it 'returns correct script' do + expect(entry.before_script).to eq [] + end end end end @@ -77,4 +125,61 @@ describe Gitlab::Ci::Config::Node::Job do expect(entry).to be_relevant end end + + describe '#commands' do + context 'when global entry has before script' do + before do + allow(global).to receive(:before_script) + .and_return(%w[ls pwd]) + end + + context 'when before script is overridden' do + let(:config) do + { before_script: %w[whoami], + script: 'rspec' } + end + + it 'returns correct commands' do + expect(entry.commands).to eq "whoami\nrspec" + end + end + + context 'when before script is not overriden' do + let(:config) do + { script: %w[rspec spinach] } + end + + it 'returns correct commands' do + expect(entry.commands).to eq "ls\npwd\nrspec\nspinach" + end + end + end + + context 'when global entry does not have before script' do + before do + allow(global).to receive(:before_script) + .and_return(nil) + end + context 'when job has before script' do + let(:config) do + { before_script: %w[whoami], + script: 'rspec' } + end + + it 'returns correct commands' do + expect(entry.commands).to eq "whoami\nrspec" + end + end + + context 'when job does not have before script' do + let(:config) do + { script: %w[ls test] } + end + + it 'returns correct commands' do + expect(entry.commands).to eq "ls\ntest" + end + end + end + end end -- cgit v1.2.1 From 036e297ca3c39f90aebc76d5acb2e01f32364d0d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 13 Jul 2016 15:04:12 +0200 Subject: Expose CI job commands and use in legacy processor --- spec/lib/gitlab/ci/config/node/global_spec.rb | 12 +++++++++--- spec/lib/gitlab/ci/config/node/job_spec.rb | 3 ++- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 11 ++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 3ffbe9c2e97..f46359f7ee6 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -23,7 +23,7 @@ describe Gitlab::Ci::Config::Node::Global do after_script: ['make clean'], stages: ['build', 'pages'], cache: { key: 'k', untracked: true, paths: ['public/'] }, - rspec: { script: 'rspec' }, + rspec: { script: %w[rspec ls] }, spinach: { script: 'spinach' } } end @@ -129,8 +129,14 @@ describe Gitlab::Ci::Config::Node::Global do describe '#jobs' do it 'returns jobs configuration' do expect(global.jobs) - .to eq(rspec: { script: %w[rspec], stage: 'test' }, - spinach: { script: %w[spinach], stage: 'test' }) + .to eq(rspec: { before_script: %w[ls pwd], + script: %w[rspec ls], + commands: "ls\npwd\nrspec\nls", + stage: 'test' }, + spinach: { before_script: %w[ls pwd], + script: %w[spinach], + commands: "ls\npwd\nspinach", + stage: 'test' }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 635362611a0..816c0f275d6 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -56,6 +56,7 @@ describe Gitlab::Ci::Config::Node::Job do expect(entry.value) .to eq(before_script: %w[ls pwd], script: %w[rspec], + commands: "ls\npwd\nrspec", stage: 'test', after_script: %w[cleanup]) end @@ -114,7 +115,7 @@ describe Gitlab::Ci::Config::Node::Job do end it 'returns correct script' do - expect(entry.before_script).to eq [] + expect(entry.before_script).to be_nil end end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 255646a001a..60ab1d2150d 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Jobs do - let(:entry) { described_class.new(config, global: spy) } + let(:entry) { described_class.new(config, global: global) } + let(:global) { double('global', before_script: nil, stages: %w[test]) } describe 'validations' do before do @@ -62,8 +63,12 @@ describe Gitlab::Ci::Config::Node::Jobs do describe '#value' do it 'returns key value' do expect(entry.value) - .to eq(rspec: { script: %w[rspec], stage: 'test' }, - spinach: { script: %w[spinach], stage: 'test' }) + .to eq(rspec: { script: %w[rspec], + commands: 'rspec', + stage: 'test' }, + spinach: { script: %w[spinach], + commands: 'spinach', + stage: 'test' }) end end -- cgit v1.2.1 From 56ae9f6ba933939ced7c8e0eea5abbb34a0a68be Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 13:14:09 +0200 Subject: Improve CI job entry validations in new config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 ++-- spec/lib/gitlab/ci/config/node/global_spec.rb | 14 ++++++-------- spec/lib/gitlab/ci/config/node/job_spec.rb | 16 +++++++++++++--- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 1017f79cc6e..e88f5cfc6dd 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -998,14 +998,14 @@ EOT config = YAML.dump({ '' => { script: "test" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "job name should be non-empty string") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:job name can't be blank") end it "returns errors if job name is non-string" do config = YAML.dump({ 10 => { script: "test" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "job name should be non-empty string") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:10 name should be a symbol") end it "returns errors if job image parameter is invalid" do diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index f46359f7ee6..fa5ff016995 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -129,14 +129,12 @@ describe Gitlab::Ci::Config::Node::Global do describe '#jobs' do it 'returns jobs configuration' do expect(global.jobs) - .to eq(rspec: { before_script: %w[ls pwd], - script: %w[rspec ls], - commands: "ls\npwd\nrspec\nls", - stage: 'test' }, - spinach: { before_script: %w[ls pwd], - script: %w[spinach], - commands: "ls\npwd\nspinach", - stage: 'test' }) + .to eq(rspec: { script: %w[rspec ls], + stage: 'test', + commands: "ls\npwd\nrspec\nls" }, + spinach: { script: %w[spinach], + stage: 'test', + commands: "ls\npwd\nspinach" }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 816c0f275d6..2ac7509cb6d 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do - let(:entry) { described_class.new(config, global: global) } - let(:global) { spy('Global') } + let(:entry) { described_class.new(config, attributes) } + let(:attributes) { { key: :rspec, global: global } } + let(:global) { double('global', stages: %w[test]) } before do entry.process! @@ -18,6 +19,15 @@ describe Gitlab::Ci::Config::Node::Job do expect(entry).to be_valid end end + + context 'when job name is empty' do + let(:attributes) { { key: '', global: global } } + + it 'reports error' do + expect(entry.errors) + .to include "job name can't be blank" + end + end end context 'when entry value is not correct' do @@ -27,7 +37,7 @@ describe Gitlab::Ci::Config::Node::Job do describe '#errors' do it 'reports error about a config type' do expect(entry.errors) - .to include 'job config should be a hash' + .to include 'rspec config should be a hash' end end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 60ab1d2150d..fe7ae61ed81 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -34,8 +34,8 @@ describe Gitlab::Ci::Config::Node::Jobs do context 'when job is unspecified' do let(:config) { { rspec: nil } } - it 'is not valid' do - expect(entry).not_to be_valid + it 'reports error' do + expect(entry.errors).to include "rspec config can't be blank" end end -- cgit v1.2.1 From f7c80e9f31944c0001c9bef23d1a8efe33e4adce Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 15:05:46 +0200 Subject: Revert references to global node in CI job entry --- spec/lib/gitlab/ci/config/node/global_spec.rb | 6 +- spec/lib/gitlab/ci/config/node/job_spec.rb | 116 -------------------------- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 2 - 3 files changed, 2 insertions(+), 122 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index fa5ff016995..dfcaebe35be 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -130,11 +130,9 @@ describe Gitlab::Ci::Config::Node::Global do it 'returns jobs configuration' do expect(global.jobs) .to eq(rspec: { script: %w[rspec ls], - stage: 'test', - commands: "ls\npwd\nrspec\nls" }, + stage: 'test' }, spinach: { script: %w[spinach], - stage: 'test', - commands: "ls\npwd\nspinach" }) + stage: 'test' }) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 2ac7509cb6d..ee3eea9c27a 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -66,131 +66,15 @@ describe Gitlab::Ci::Config::Node::Job do expect(entry.value) .to eq(before_script: %w[ls pwd], script: %w[rspec], - commands: "ls\npwd\nrspec", stage: 'test', after_script: %w[cleanup]) end end end - describe '#before_script' do - context 'when global entry has before script' do - before do - allow(global).to receive(:before_script) - .and_return(%w[ls pwd]) - end - - context 'when before script is overridden' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[whoami] - end - end - - context 'when before script is not overriden' do - let(:config) do - { script: %w[spinach] } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[ls pwd] - end - end - end - - context 'when global entry does not have before script' do - before do - allow(global).to receive(:before_script) - .and_return(nil) - end - - context 'when job has before script' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct script' do - expect(entry.before_script).to eq %w[whoami] - end - end - - context 'when job does not have before script' do - let(:config) do - { script: %w[ls test] } - end - - it 'returns correct script' do - expect(entry.before_script).to be_nil - end - end - end - end - describe '#relevant?' do it 'is a relevant entry' do expect(entry).to be_relevant end end - - describe '#commands' do - context 'when global entry has before script' do - before do - allow(global).to receive(:before_script) - .and_return(%w[ls pwd]) - end - - context 'when before script is overridden' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "whoami\nrspec" - end - end - - context 'when before script is not overriden' do - let(:config) do - { script: %w[rspec spinach] } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "ls\npwd\nrspec\nspinach" - end - end - end - - context 'when global entry does not have before script' do - before do - allow(global).to receive(:before_script) - .and_return(nil) - end - context 'when job has before script' do - let(:config) do - { before_script: %w[whoami], - script: 'rspec' } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "whoami\nrspec" - end - end - - context 'when job does not have before script' do - let(:config) do - { script: %w[ls test] } - end - - it 'returns correct commands' do - expect(entry.commands).to eq "ls\ntest" - end - end - end - end end diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index fe7ae61ed81..40837b5f857 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -64,10 +64,8 @@ describe Gitlab::Ci::Config::Node::Jobs do it 'returns key value' do expect(entry.value) .to eq(rspec: { script: %w[rspec], - commands: 'rspec', stage: 'test' }, spinach: { script: %w[spinach], - commands: 'spinach', stage: 'test' }) end end -- cgit v1.2.1 From 3e16b015b969a4d5d28240e76bffd382b0772f49 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 15:23:52 +0200 Subject: Revert logical validation in CI job stage entry --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 +- spec/lib/gitlab/ci/config/node/stage_spec.rb | 71 +++------------------------- 2 files changed, 8 insertions(+), 67 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index e88f5cfc6dd..daa02faf6fb 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1089,14 +1089,14 @@ EOT config = YAML.dump({ rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test, deploy)") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy") end it "returns errors if job stage is not a defined stage" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test)") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test") end it "returns errors if stages is not an array" do diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/node/stage_spec.rb index 004012f8b38..fb9ec70762a 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/node/stage_spec.rb @@ -1,17 +1,12 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Stage do - let(:stage) { described_class.new(config, global: global) } - let(:global) { spy('Global') } + let(:stage) { described_class.new(config) } describe 'validations' do context 'when stage config value is correct' do let(:config) { 'build' } - before do - allow(global).to receive(:stages).and_return(%w[build]) - end - describe '#value' do it 'returns a stage key' do expect(stage.value).to eq config @@ -25,66 +20,12 @@ describe Gitlab::Ci::Config::Node::Stage do end end - context 'when stage config is incorrect' do - describe '#errors' do - context 'when reference to global node is not set' do - let(:stage) { described_class.new('test') } - - it 'raises error' do - expect { stage.validate! }.to raise_error( - Gitlab::Ci::Config::Node::Entry::InvalidError, - /Entry needs global attribute set internally./ - ) - end - end - - context 'when value has a wrong type' do - let(:config) { { test: true } } - - it 'reports errors about wrong type' do - expect(stage.errors) - .to include 'stage config should be a string' - end - end - - context 'when stage is not present in global configuration' do - let(:config) { 'unknown' } - - before do - allow(global) - .to receive(:stages).and_return(%w[test deploy]) - end - - it 'reports error about missing stage' do - stage.validate! - - expect(stage.errors) - .to include 'stage config should be one of ' \ - 'defined stages (test, deploy)' - end - end - end - end - end - - describe '#known?' do - before do - allow(global).to receive(:stages).and_return(%w[test deploy]) - end - - context 'when stage is not known' do - let(:config) { :unknown } - - it 'returns false' do - expect(stage.known?).to be false - end - end - - context 'when stage is known' do - let(:config) { 'test' } + context 'when value has a wrong type' do + let(:config) { { test: true } } - it 'returns false' do - expect(stage.known?).to be true + it 'reports errors about wrong type' do + expect(stage.errors) + .to include 'stage config should be a string' end end end -- cgit v1.2.1 From 5923741fe690a688591ad36da894b3103954a437 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 15:45:29 +0200 Subject: Remove references to global entry in new CI config --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 8 +------- spec/lib/gitlab/ci/config/node/job_spec.rb | 6 ++---- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 3 +-- 3 files changed, 4 insertions(+), 13 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index bc6bf32ffbf..4e6f2419e13 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -5,11 +5,6 @@ describe Gitlab::Ci::Config::Node::Factory do let(:factory) { described_class.new(node) } let(:node) { Gitlab::Ci::Config::Node::Script } let(:parent) { double('parent') } - let(:global) { double('global') } - - before do - allow(parent).to receive(:global).and_return(global) - end context 'when setting a concrete value' do it 'creates entry with valid value' do @@ -21,13 +16,12 @@ describe Gitlab::Ci::Config::Node::Factory do expect(entry.value).to eq ['ls', 'pwd'] end - it 'sets parent and global attributes' do + it 'sets parent attributes' do entry = factory .value('ls') .parent(parent) .create! - expect(entry.global).to eq global expect(entry.parent).to eq parent end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index ee3eea9c27a..4c7ac9949cc 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do - let(:entry) { described_class.new(config, attributes) } - let(:attributes) { { key: :rspec, global: global } } - let(:global) { double('global', stages: %w[test]) } + let(:entry) { described_class.new(config, key: :rspec) } before do entry.process! @@ -21,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Job do end context 'when job name is empty' do - let(:attributes) { { key: '', global: global } } + let(:entry) { described_class.new(config, key: ''.to_sym) } it 'reports error' do expect(entry.errors) diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 40837b5f857..c4c130abb6d 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Jobs do - let(:entry) { described_class.new(config, global: global) } - let(:global) { double('global', before_script: nil, stages: %w[test]) } + let(:entry) { described_class.new(config) } describe 'validations' do before do -- cgit v1.2.1 From 615c9730e7783e82287d2b65f58da6336d3d2410 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 14 Jul 2016 16:01:18 +0200 Subject: Remove job cache configfrom legacy yaml processor --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index daa02faf6fb..c9602bcca22 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1201,21 +1201,21 @@ EOT config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { key: 1 } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:key parameter should be a string") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:cache:key config should be a string or symbol") end it "returns errors if job cache:untracked is not an array of strings" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { untracked: "string" } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:untracked parameter should be an boolean") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:cache:untracked config should be a boolean value") end it "returns errors if job cache:paths is not an array of strings" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", cache: { paths: "string" } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: cache:paths parameter should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:cache:paths config should be an array of strings") end it "returns errors if job dependencies is not an array of strings" do -- cgit v1.2.1 From 41bcbdd8c2412769a376cd37541ad6e65a1af1f2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 15 Jul 2016 21:07:51 +0200 Subject: Add metadata to new CI config and expose job name --- spec/lib/gitlab/ci/config/node/factory_spec.rb | 37 ++++++++++---------------- spec/lib/gitlab/ci/config/node/global_spec.rb | 13 +++++---- spec/lib/gitlab/ci/config/node/job_spec.rb | 9 ++++--- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 12 +++++---- 4 files changed, 34 insertions(+), 37 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/node/factory_spec.rb index 4e6f2419e13..d26185ba585 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/node/factory_spec.rb @@ -4,32 +4,20 @@ describe Gitlab::Ci::Config::Node::Factory do describe '#create!' do let(:factory) { described_class.new(node) } let(:node) { Gitlab::Ci::Config::Node::Script } - let(:parent) { double('parent') } context 'when setting a concrete value' do it 'creates entry with valid value' do entry = factory .value(['ls', 'pwd']) - .parent(parent) .create! expect(entry.value).to eq ['ls', 'pwd'] end - it 'sets parent attributes' do - entry = factory - .value('ls') - .parent(parent) - .create! - - expect(entry.parent).to eq parent - end - context 'when setting description' do it 'creates entry with description' do entry = factory .value(['ls', 'pwd']) - .parent(parent) .with(description: 'test description') .create! @@ -42,7 +30,6 @@ describe Gitlab::Ci::Config::Node::Factory do it 'creates entry with custom key' do entry = factory .value(['ls', 'pwd']) - .parent(parent) .with(key: 'test key') .create! @@ -56,7 +43,6 @@ describe Gitlab::Ci::Config::Node::Factory do it 'creates entry with valid parent' do entry = factory .value('ls') - .parent(parent) .with(parent: object) .create! @@ -73,23 +59,28 @@ describe Gitlab::Ci::Config::Node::Factory do end end - context 'when not setting parent object' do - it 'raises error' do - expect { factory.value('ls').create! }.to raise_error( - Gitlab::Ci::Config::Node::Factory::InvalidFactory - ) - end - end - context 'when creating entry with nil value' do it 'creates an undefined entry' do entry = factory .value(nil) - .parent(parent) .create! expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Undefined end end + + context 'when passing metadata' do + let(:node) { spy('node') } + + it 'passes metadata as a parameter' do + factory + .value('some value') + .metadata(some: 'hash') + .create! + + expect(node).to have_received(:new) + .with('some value', { some: 'hash' }) + end + end end end diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index dfcaebe35be..2a071b57c72 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -128,11 +128,14 @@ describe Gitlab::Ci::Config::Node::Global do describe '#jobs' do it 'returns jobs configuration' do - expect(global.jobs) - .to eq(rspec: { script: %w[rspec ls], - stage: 'test' }, - spinach: { script: %w[spinach], - stage: 'test' }) + expect(global.jobs).to eq( + rspec: { name: :rspec, + script: %w[rspec ls], + stage: 'test' }, + spinach: { name: :spinach, + script: %w[spinach], + stage: 'test' } + ) end end end diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 4c7ac9949cc..b2559e6e73c 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do - let(:entry) { described_class.new(config, key: :rspec) } + let(:entry) { described_class.new(config, name: :rspec) } before do entry.process! @@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Job do end context 'when job name is empty' do - let(:entry) { described_class.new(config, key: ''.to_sym) } + let(:entry) { described_class.new(config, name: ''.to_sym) } it 'reports error' do expect(entry.errors) @@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Job do describe '#errors' do it 'reports error about a config type' do expect(entry.errors) - .to include 'rspec config should be a hash' + .to include 'job config should be a hash' end end end @@ -62,7 +62,8 @@ describe Gitlab::Ci::Config::Node::Job do it 'returns correct value' do expect(entry.value) - .to eq(before_script: %w[ls pwd], + .to eq(name: :rspec, + before_script: %w[ls pwd], script: %w[rspec], stage: 'test', after_script: %w[cleanup]) diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index c4c130abb6d..4f08f2f9b69 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -61,11 +61,13 @@ describe Gitlab::Ci::Config::Node::Jobs do describe '#value' do it 'returns key value' do - expect(entry.value) - .to eq(rspec: { script: %w[rspec], - stage: 'test' }, - spinach: { script: %w[spinach], - stage: 'test' }) + expect(entry.value).to eq( + rspec: { name: :rspec, + script: %w[rspec], + stage: 'test' }, + spinach: { name: :spinach, + script: %w[spinach], + stage: 'test' }) end end -- cgit v1.2.1 From 4bb60b0789a31061cbc81af90b7d5dc558f985b3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 15 Jul 2016 21:39:26 +0200 Subject: Simplify CI config and remove logical validation --- spec/lib/gitlab/ci/config/node/job_spec.rb | 5 +---- spec/lib/gitlab/ci/config/node/jobs_spec.rb | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index b2559e6e73c..2721908c5d7 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -3,10 +3,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do let(:entry) { described_class.new(config, name: :rspec) } - before do - entry.process! - entry.validate! - end + before { entry.process! } describe 'validations' do context 'when entry config value is correct' do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 4f08f2f9b69..b8d9c70479c 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -4,10 +4,7 @@ describe Gitlab::Ci::Config::Node::Jobs do let(:entry) { described_class.new(config) } describe 'validations' do - before do - entry.process! - entry.validate! - end + before { entry.process! } context 'when entry config value is correct' do let(:config) { { rspec: { script: 'rspec' } } } -- cgit v1.2.1 From 17084d42aa4f2a9d58d6b6d30656d5b7cfffe007 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 15 Jul 2016 22:35:29 +0200 Subject: Simplify abstract class for CI config entry nodes --- spec/lib/gitlab/ci/config/node/global_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 2a071b57c72..2f87d270b36 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -51,11 +51,11 @@ describe Gitlab::Ci::Config::Node::Global do expect(global.descendants.second.description) .to eq 'Docker image that will be used to execute jobs.' end - end - describe '#leaf?' do - it 'is not leaf' do - expect(global).not_to be_leaf + describe '#leaf?' do + it 'is not leaf' do + expect(global).not_to be_leaf + end end end @@ -65,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do expect(global.before_script).to be nil end end + + describe '#leaf?' do + it 'is leaf' do + expect(global).to be_leaf + end + end end context 'when processed' do -- cgit v1.2.1 From 27e88efceb9d59affebf93be040b0a9b0bf31b2f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 09:54:38 +0200 Subject: Move job image and services nodes to new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index d629bd252e2..6e6898e758c 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1012,7 +1012,7 @@ EOT config = YAML.dump({ rspec: { script: "test", image: ["test"] } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:image config should be a string") end it "returns errors if services parameter is not an array" do @@ -1033,14 +1033,14 @@ EOT config = YAML.dump({ rspec: { script: "test", services: "test" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:services config should be an array of strings") end it "returns errors if job services parameter is not an array of strings" do config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:services config should be an array of strings") end it "returns error if job configuration is invalid" do @@ -1054,7 +1054,7 @@ EOT config = YAML.dump({ extra: { services: "test" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:extra:services config should be an array of strings") end it "returns errors if there are no jobs defined" do -- cgit v1.2.1 From 1bf9e34713b414f0e1ac8bbfe464a4cd5300581f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 12:37:42 +0200 Subject: Move except and only job nodes to new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 +- spec/lib/gitlab/ci/config/node/while_spec.rb | 56 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/while_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 6e6898e758c..429ffd6ef35 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -163,7 +163,7 @@ module Ci shared_examples 'raises an error' do it do - expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: only parameter should be an array of strings or regexps') + expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:only config should be an array of strings or regexps') end end @@ -319,7 +319,7 @@ module Ci shared_examples 'raises an error' do it do - expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: except parameter should be an array of strings or regexps') + expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:except config should be an array of strings or regexps') end end diff --git a/spec/lib/gitlab/ci/config/node/while_spec.rb b/spec/lib/gitlab/ci/config/node/while_spec.rb new file mode 100644 index 00000000000..aac2ed7b3db --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/while_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::While do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is valid' do + context 'when config is a branch or tag name' do + let(:config) { %w[master feature/branch] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq config + end + end + end + + context 'when config is a regexp' do + let(:config) { ['/^issue-.*$/'] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when config is a special keyword' do + let(:config) { %w[tags triggers branches] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + end + + context 'when entry value is not valid' do + let(:config) { [1] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'while config should be an array of strings or regexps' + end + end + end + end +end -- cgit v1.2.1 From 47fa9f33ca552e085df2158db41b614a79f3651f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 13:09:00 +0200 Subject: Move job variables config entry to new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 429ffd6ef35..fe2c109f463 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -534,7 +534,7 @@ module Ci expect { GitlabCiYamlProcessor.new(config, path) } .to raise_error(GitlabCiYamlProcessor::ValidationError, - /job: variables should be a map/) + /jobs:rspec:variables config should be a hash of key value pairs/) end end -- cgit v1.2.1 From 24b686ebb64e2f5a02d812e9aa726f1ba0868c2e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 14:15:01 +0200 Subject: Move job artifacts configuration new CI config code --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 12 +++--- spec/lib/gitlab/ci/config/node/artifacts_spec.rb | 34 +++++++++++++++++ .../lib/gitlab/ci/config/node/attributable_spec.rb | 43 ++++++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/artifacts_spec.rb create mode 100644 spec/lib/gitlab/ci/config/node/attributable_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index fe2c109f463..28849bcf3f4 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1138,42 +1138,42 @@ EOT config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { name: 1 } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:name parameter should be a string") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts name should be a string") end it "returns errors if job artifacts:when is not an a predefined value" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { when: 1 } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:when parameter should be on_success, on_failure or always") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts when should be on_success, on_failure or always") end it "returns errors if job artifacts:expire_in is not an a string" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: 1 } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts expire in should be a duration") end it "returns errors if job artifacts:expire_in is not an a valid duration" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: "7 elephants" } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts expire in should be a duration") end it "returns errors if job artifacts:untracked is not an array of strings" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { untracked: "string" } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:untracked parameter should be an boolean") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts untracked should be a boolean value") end it "returns errors if job artifacts:paths is not an array of strings" do config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { paths: "string" } } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:paths parameter should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:artifacts paths should be an array of strings") end it "returns errors if cache:untracked is not an array of strings" do diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb new file mode 100644 index 00000000000..4973f7d599a --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Artifacts do + let(:entry) { described_class.new(config) } + + describe 'validation' do + context 'when entry config value is correct' do + let(:config) { { paths: %w[public/] } } + + describe '#value' do + it 'returns image string' do + expect(entry.value).to eq config + end + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when entry value is not correct' do + let(:config) { { name: 10 } } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'artifacts name should be a string' + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/attributable_spec.rb b/spec/lib/gitlab/ci/config/node/attributable_spec.rb new file mode 100644 index 00000000000..24d9daafd88 --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/attributable_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Attributable do + let(:node) { Class.new } + let(:instance) { node.new } + + before do + node.include(described_class) + + node.class_eval do + attributes :name, :test + end + end + + context 'config is a hash' do + before do + allow(instance) + .to receive(:config) + .and_return({ name: 'some name', test: 'some test' }) + end + + it 'returns the value of config' do + expect(instance.name).to eq 'some name' + expect(instance.test).to eq 'some test' + end + + it 'returns no method error for unknown attributes' do + expect { instance.unknown }.to raise_error(NoMethodError) + end + end + + context 'config is not a hash' do + before do + allow(instance) + .to receive(:config) + .and_return('some test') + end + + it 'returns nil' do + expect(instance.test).to be_nil + end + end +end -- cgit v1.2.1 From 7cef4f1908d99743bf1dfb9c1cfdd6b2936b2b3d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 15:38:06 +0200 Subject: Improve valid keys validation for CI config nodes --- spec/lib/gitlab/ci/config/node/artifacts_spec.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb index 4973f7d599a..418a88cabac 100644 --- a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb +++ b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb @@ -21,12 +21,23 @@ describe Gitlab::Ci::Config::Node::Artifacts do end context 'when entry value is not correct' do - let(:config) { { name: 10 } } - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'artifacts name should be a string' + context 'when value of attribute is invalid' do + let(:config) { { name: 10 } } + + it 'reports error' do + expect(entry.errors) + .to include 'artifacts name should be a string' + end + end + + context 'when there is uknown key' do + let(:config) { { test: 100 } } + + it 'reports error' do + expect(entry.errors) + .to include 'artifacts config contains unknown keys: test' + end end end end -- cgit v1.2.1 From 6d466733a2ab90f2a4d9904e7bfe1ef887568210 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 15:46:24 +0200 Subject: Validate allowed keys only in new CI config --- spec/lib/gitlab/ci/config/node/job_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index 2721908c5d7..1484fb60dd8 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -46,6 +46,16 @@ describe Gitlab::Ci::Config::Node::Job do end end end + + context 'when unknown keys detected' do + let(:config) { { unknown: true } } + + describe '#valid' do + it 'is not valid' do + expect(entry).not_to be_valid + end + end + end end end -- cgit v1.2.1 From 943ae747eac04e19c2614a5b48f41387c6d150d3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 18 Jul 2016 16:33:20 +0200 Subject: Move tags and allow_failure CI entries to new config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 28849bcf3f4..d354ddb7b13 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -956,7 +956,7 @@ EOT config = YAML.dump({ rspec: { script: "test", tags: "mysql" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec tags should be an array of strings") end it "returns errors if before_script parameter is invalid" do @@ -1075,7 +1075,7 @@ EOT config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec allow failure should be a boolean value") end it "returns errors if job stage is not a string" do -- cgit v1.2.1 From bb8bf6427d80cb4858318a44e395a2d1cd9115b7 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 19 Jul 2016 13:08:28 +0200 Subject: Move job environment validation to new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index d354ddb7b13..9735af27aa1 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -754,7 +754,7 @@ module Ci let(:environment) { 1 } it 'raises error' do - expect { builds }.to raise_error("deploy_to_production job: environment parameter #{Gitlab::Regex.environment_name_regex_message}") + expect { builds }.to raise_error("jobs:deploy_to_production environment #{Gitlab::Regex.environment_name_regex_message}") end end @@ -762,7 +762,7 @@ module Ci let(:environment) { 'production staging' } it 'raises error' do - expect { builds }.to raise_error("deploy_to_production job: environment parameter #{Gitlab::Regex.environment_name_regex_message}") + expect { builds }.to raise_error("jobs:deploy_to_production environment #{Gitlab::Regex.environment_name_regex_message}") end end end @@ -1131,7 +1131,7 @@ EOT config = YAML.dump({ rspec: { script: "test", when: 1 } }) expect do GitlabCiYamlProcessor.new(config, path) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: when parameter should be on_success, on_failure or always") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec when should be on_success, on_failure or always") end it "returns errors if job artifacts:name is not an a string" do -- cgit v1.2.1 From f83bccfe4f98281ed80c95189c5f7ed77799b2b3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 20 Jul 2016 10:59:49 +0200 Subject: Add minor readability, style improvements in CI config --- spec/lib/gitlab/ci/config/node/artifacts_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb index 418a88cabac..beed29b18ae 100644 --- a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb +++ b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb @@ -31,7 +31,7 @@ describe Gitlab::Ci::Config::Node::Artifacts do end end - context 'when there is uknown key' do + context 'when there is an unknown key present' do let(:config) { { test: 100 } } it 'reports error' do -- cgit v1.2.1 From dff10976da42cc729069cddf0f032347fe2f6b14 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 20 Jul 2016 14:15:18 +0200 Subject: Move job dependencies entry to the new CI config --- spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 5785b7e59fb..61490555ff5 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1239,7 +1239,7 @@ EOT config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", dependencies: "string" } }) expect do GitlabCiYamlProcessor.new(config) - end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: dependencies parameter should be an array of strings") + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec dependencies should be an array of strings") end end -- cgit v1.2.1 From f7807c5b68b59f6a5b984ee64a6c82a3bd993d92 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 18 Jul 2016 18:17:43 -0500 Subject: Submit all issues on public projects to Akismet if enabled. --- spec/lib/gitlab/akismet_helper_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/akismet_helper_spec.rb b/spec/lib/gitlab/akismet_helper_spec.rb index 88a71528867..b08396da4d2 100644 --- a/spec/lib/gitlab/akismet_helper_spec.rb +++ b/spec/lib/gitlab/akismet_helper_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::AkismetHelper, type: :helper do - let(:project) { create(:project) } + let(:project) { create(:project, :public) } let(:user) { create(:user) } before do @@ -11,13 +11,13 @@ describe Gitlab::AkismetHelper, type: :helper do end describe '#check_for_spam?' do - it 'returns true for non-member' do - expect(helper.check_for_spam?(project, user)).to eq(true) + it 'returns true for public project' do + expect(helper.check_for_spam?(project)).to eq(true) end - it 'returns false for member' do - project.team << [user, :guest] - expect(helper.check_for_spam?(project, user)).to eq(false) + it 'returns false for private project' do + project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE) + expect(helper.check_for_spam?(project)).to eq(false) end end -- cgit v1.2.1 From 905f8d763ab1184dc0b1e4bf6f18d7981753a860 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 28 Jul 2016 15:08:57 +0200 Subject: Reduce instrumentation overhead This reduces the overhead of the method instrumentation code primarily by reducing the number of method calls. There are also some other small optimisations such as not casting timing values to Floats (there's no particular need for this), using Symbols for method call metric names, and reducing the number of Hash lookups for instrumented methods. The exact impact depends on the code being executed. For example, for a method that's only called once the difference won't be very noticeable. However, for methods that are called many times the difference can be more significant. For example, the loading time of a large commit (nrclark/dummy_project@81ebdea5df2fb42e59257cb3eaad671a5c53ca36) was reduced from around 19 seconds to around 15 seconds using these changes. --- spec/lib/gitlab/metrics/instrumentation_spec.rb | 12 ++++++++---- spec/lib/gitlab/metrics/system_spec.rb | 12 ++++++------ spec/lib/gitlab/metrics/transaction_spec.rb | 16 ++++------------ spec/lib/gitlab/metrics_spec.rb | 6 ++++++ 4 files changed, 24 insertions(+), 22 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb index 8809b7e3f12..d88bcae41fb 100644 --- a/spec/lib/gitlab/metrics/instrumentation_spec.rb +++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb @@ -39,6 +39,12 @@ describe Gitlab::Metrics::Instrumentation do allow(@dummy).to receive(:name).and_return('Dummy') end + describe '.series' do + it 'returns a String' do + expect(described_class.series).to be_an_instance_of(String) + end + end + describe '.configure' do it 'yields self' do described_class.configure do |c| @@ -78,8 +84,7 @@ describe Gitlab::Metrics::Instrumentation do allow(described_class).to receive(:transaction). and_return(transaction) - expect(transaction).to receive(:measure_method). - with('Dummy.foo') + expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure) @dummy.foo end @@ -157,8 +162,7 @@ describe Gitlab::Metrics::Instrumentation do allow(described_class).to receive(:transaction). and_return(transaction) - expect(transaction).to receive(:measure_method). - with('Dummy#bar') + expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure) @dummy.new.bar end diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index cf0e282c2fb..9e2ea89a712 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -28,20 +28,20 @@ describe Gitlab::Metrics::System do end describe '.cpu_time' do - it 'returns a Float' do - expect(described_class.cpu_time).to be_an_instance_of(Float) + it 'returns a Fixnum' do + expect(described_class.cpu_time).to be_an_instance_of(Fixnum) end end describe '.real_time' do - it 'returns a Float' do - expect(described_class.real_time).to be_an_instance_of(Float) + it 'returns a Fixnum' do + expect(described_class.real_time).to be_an_instance_of(Fixnum) end end describe '.monotonic_time' do - it 'returns a Float' do - expect(described_class.monotonic_time).to be_an_instance_of(Float) + it 'returns a Fixnum' do + expect(described_class.monotonic_time).to be_an_instance_of(Fixnum) end end end diff --git a/spec/lib/gitlab/metrics/transaction_spec.rb b/spec/lib/gitlab/metrics/transaction_spec.rb index 3b1c67a2147..f1a191d9410 100644 --- a/spec/lib/gitlab/metrics/transaction_spec.rb +++ b/spec/lib/gitlab/metrics/transaction_spec.rb @@ -46,19 +46,11 @@ describe Gitlab::Metrics::Transaction do end end - describe '#measure_method' do - it 'adds a new method if it does not exist already' do - transaction.measure_method('Foo#bar') { 'foo' } + describe '#method_call_for' do + it 'returns a MethodCall' do + method = transaction.method_call_for('Foo#bar') - expect(transaction.methods['Foo#bar']). - to be_an_instance_of(Gitlab::Metrics::MethodCall) - end - - it 'adds timings to an existing method call' do - transaction.measure_method('Foo#bar') { 'foo' } - transaction.measure_method('Foo#bar') { 'foo' } - - expect(transaction.methods['Foo#bar'].call_count).to eq(2) + expect(method).to be_an_instance_of(Gitlab::Metrics::MethodCall) end end diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 96f7eabbca6..84f9475a0f8 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -147,4 +147,10 @@ describe Gitlab::Metrics do end end end + + describe '#series_prefix' do + it 'returns a String' do + expect(described_class.series_prefix).to be_an_instance_of(String) + end + end end -- cgit v1.2.1 From 828f6eb6e50e6193fad9dbdd95d9dd56506e4064 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Fri, 8 Jul 2016 11:45:02 +0530 Subject: Enforce "No One Can Push" during git operations. 1. The crux of this change is in `UserAccess`, which looks through all the access levels, asking each if the user has access to push/merge for the current project. 2. Update the `protected_branches` factory to create access levels as necessary. 3. Fix and augment `user_access` and `git_access` specs. --- spec/lib/gitlab/git_access_spec.rb | 78 +++++++++++++++++++++---------------- spec/lib/gitlab/user_access_spec.rb | 4 +- 2 files changed, 46 insertions(+), 36 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index ae064a878b0..324bb500025 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -217,29 +217,32 @@ describe Gitlab::GitAccess, lib: true do run_permission_checks(permissions_matrix) end - context "when 'developers can push' is turned on for the #{protected_branch_type} protected branch" do - before { create(:protected_branch, name: protected_branch_name, developers_can_push: true, project: project) } + context "when developers are allowed to push into the #{protected_branch_type} protected branch" do + before { create(:protected_branch, :developers_can_push, name: protected_branch_name, project: project) } run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true })) end - context "when 'developers can merge' is turned on for the #{protected_branch_type} protected branch" do - before { create(:protected_branch, name: protected_branch_name, developers_can_merge: true, project: project) } + context "developers are allowed to merge into the #{protected_branch_type} protected branch" do + before { create(:protected_branch, :developers_can_merge, name: protected_branch_name, project: project) } context "when a merge request exists for the given source/target branch" do context "when the merge request is in progress" do before do - create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', state: 'locked', in_progress_merge_commit_sha: merge_into_protected_branch) + create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', + state: 'locked', in_progress_merge_commit_sha: merge_into_protected_branch) end - run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: true })) - end + context "when the merge request is not in progress" do + before do + create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', in_progress_merge_commit_sha: nil) + end - context "when the merge request is not in progress" do - before do - create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', in_progress_merge_commit_sha: nil) + run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) end + end + context "when a merge request does not exist for the given source/target branch" do run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) end end @@ -249,44 +252,51 @@ describe Gitlab::GitAccess, lib: true do end end - context "when 'developers can merge' and 'developers can push' are turned on for the #{protected_branch_type} protected branch" do - before { create(:protected_branch, name: protected_branch_name, developers_can_merge: true, developers_can_push: true, project: project) } + context "when developers are allowed to push and merge into the #{protected_branch_type} protected branch" do + before { create(:protected_branch, :developers_can_merge, :developers_can_push, name: protected_branch_name, project: project) } run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true })) end end - describe 'deploy key permissions' do - let(:key) { create(:deploy_key) } - let(:actor) { key } + context "when no one is allowed to push to the #{protected_branch_name} protected branch" do + before { create(:protected_branch, :no_one_can_push, name: protected_branch_name, project: project) } - context 'push code' do - subject { access.check('git-receive-pack') } + run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, + master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false })) + end + end - context 'when project is authorized' do - before { key.projects << project } + describe 'deploy key permissions' do + let(:key) { create(:deploy_key) } + let(:actor) { key } - it { expect(subject).not_to be_allowed } - end + context 'push code' do + subject { access.check('git-receive-pack') } - context 'when unauthorized' do - context 'to public project' do - let(:project) { create(:project, :public) } + context 'when project is authorized' do + before { key.projects << project } - it { expect(subject).not_to be_allowed } - end + it { expect(subject).not_to be_allowed } + end - context 'to internal project' do - let(:project) { create(:project, :internal) } + context 'when unauthorized' do + context 'to public project' do + let(:project) { create(:project, :public) } - it { expect(subject).not_to be_allowed } - end + it { expect(subject).not_to be_allowed } + end - context 'to private project' do - let(:project) { create(:project, :internal) } + context 'to internal project' do + let(:project) { create(:project, :internal) } - it { expect(subject).not_to be_allowed } - end + it { expect(subject).not_to be_allowed } + end + + context 'to private project' do + let(:project) { create(:project, :internal) } + + it { expect(subject).not_to be_allowed } end end end diff --git a/spec/lib/gitlab/user_access_spec.rb b/spec/lib/gitlab/user_access_spec.rb index aa9ec243498..5bb095366fa 100644 --- a/spec/lib/gitlab/user_access_spec.rb +++ b/spec/lib/gitlab/user_access_spec.rb @@ -44,7 +44,7 @@ describe Gitlab::UserAccess, lib: true do describe 'push to protected branch if allowed for developers' do before do - @branch = create :protected_branch, project: project, developers_can_push: true + @branch = create :protected_branch, :developers_can_push, project: project end it 'returns true if user is a master' do @@ -65,7 +65,7 @@ describe Gitlab::UserAccess, lib: true do describe 'merge to protected branch if allowed for developers' do before do - @branch = create :protected_branch, project: project, developers_can_merge: true + @branch = create :protected_branch, :developers_can_merge, project: project end it 'returns true if user is a master' do -- cgit v1.2.1 From c647540c1010fd1e51bced1db90947aa00c83fa8 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Fri, 8 Jul 2016 14:46:13 +0530 Subject: Fix all specs related to changes in !5081. 1. Remove `Project#developers_can_push_to_protected_branch?` since it isn't used anymore. 2. Remove `Project#developers_can_merge_to_protected_branch?` since it isn't used anymore. --- spec/lib/gitlab/git_access_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 324bb500025..8d7497f76f5 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -230,7 +230,7 @@ describe Gitlab::GitAccess, lib: true do context "when the merge request is in progress" do before do create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', - state: 'locked', in_progress_merge_commit_sha: merge_into_protected_branch) + state: 'locked', in_progress_merge_commit_sha: merge_into_protected_branch) end context "when the merge request is not in progress" do -- cgit v1.2.1 From cc1cebdcc536244d97bdf6c767c2f1875c71cdf5 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 14 Jul 2016 11:46:13 +0530 Subject: Admins count as masters too. 1. In the context of protected branches. 2. Test this behaviour. --- spec/lib/gitlab/git_access_spec.rb | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 8d7497f76f5..c6f03525aab 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -151,7 +151,13 @@ describe Gitlab::GitAccess, lib: true do def self.run_permission_checks(permissions_matrix) permissions_matrix.keys.each do |role| describe "#{role} access" do - before { project.team << [user, role] } + before do + if role == :admin + user.update_attribute(:admin, true) + else + project.team << [user, role] + end + end permissions_matrix[role].each do |action, allowed| context action do @@ -165,6 +171,17 @@ describe Gitlab::GitAccess, lib: true do end permissions_matrix = { + admin: { + push_new_branch: true, + push_master: true, + push_protected_branch: true, + push_remove_protected_branch: false, + push_tag: true, + push_new_tag: true, + push_all: true, + merge_into_protected_branch: true + }, + master: { push_new_branch: true, push_master: true, @@ -257,13 +274,14 @@ describe Gitlab::GitAccess, lib: true do run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: true, push_all: true, merge_into_protected_branch: true })) end - end - context "when no one is allowed to push to the #{protected_branch_name} protected branch" do - before { create(:protected_branch, :no_one_can_push, name: protected_branch_name, project: project) } + context "when no one is allowed to push to the #{protected_branch_name} protected branch" do + before { create(:protected_branch, :no_one_can_push, name: protected_branch_name, project: project) } - run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, - master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false })) + run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, + master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, + admin: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false })) + end end end -- cgit v1.2.1 From a72d4491903ad4f6730565df6391667e8ba8b71f Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Mon, 25 Jul 2016 14:59:05 +0530 Subject: Remove duplicate specs from `git_access_spec` - Likely introduced during an improper conflict resolution. --- spec/lib/gitlab/git_access_spec.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index c6f03525aab..8447305a316 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -250,23 +250,21 @@ describe Gitlab::GitAccess, lib: true do state: 'locked', in_progress_merge_commit_sha: merge_into_protected_branch) end - context "when the merge request is not in progress" do - before do - create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', in_progress_merge_commit_sha: nil) - end + run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: true })) + end - run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) + context "when the merge request is not in progress" do + before do + create(:merge_request, source_project: project, source_branch: unprotected_branch, target_branch: 'feature', in_progress_merge_commit_sha: nil) end + + run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) end context "when a merge request does not exist for the given source/target branch" do run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) end end - - context "when a merge request does not exist for the given source/target branch" do - run_permission_checks(permissions_matrix.deep_merge(developer: { merge_into_protected_branch: false })) - end end context "when developers are allowed to push and merge into the #{protected_branch_type} protected branch" do -- cgit v1.2.1 From 002ad215818450d2cbbc5fa065850a953dc7ada8 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 20 Jul 2016 20:13:02 +0200 Subject: Method for returning issues readable by a user The method Ability.issues_readable_by_user takes a list of users and an optional user and returns an Array of issues readable by said user. This method in turn is used by Banzai::ReferenceParser::IssueParser#nodes_visible_to_user so this method no longer needs to get all the available abilities just to check if a user has the "read_issue" ability. To test this I benchmarked an issue with 222 comments on my development environment. Using these changes the time spent in nodes_visible_to_user was reduced from around 120 ms to around 40 ms. --- spec/lib/banzai/reference_parser/issue_parser_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb index 514c752546d..85cfe728b6a 100644 --- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb @@ -16,17 +16,17 @@ describe Banzai::ReferenceParser::IssueParser, lib: true do end it 'returns the nodes when the user can read the issue' do - expect(Ability.abilities).to receive(:allowed?). - with(user, :read_issue, issue). - and_return(true) + expect(Ability).to receive(:issues_readable_by_user). + with([issue], user). + and_return([issue]) expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) end it 'returns an empty Array when the user can not read the issue' do - expect(Ability.abilities).to receive(:allowed?). - with(user, :read_issue, issue). - and_return(false) + expect(Ability).to receive(:issues_readable_by_user). + with([issue], user). + and_return([]) expect(subject.nodes_visible_to_user(user, [link])).to eq([]) end -- cgit v1.2.1 From a42cce1b966046c21ec48b18435d38e68a20f7fa Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 29 Jul 2016 12:30:38 +0200 Subject: Improve code, remove unused validator, improve names --- spec/lib/gitlab/ci/config/node/artifacts_spec.rb | 2 +- spec/lib/gitlab/ci/config/node/trigger_spec.rb | 56 ++++++++++++++++++++++++ spec/lib/gitlab/ci/config/node/while_spec.rb | 56 ------------------------ 3 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 spec/lib/gitlab/ci/config/node/trigger_spec.rb delete mode 100644 spec/lib/gitlab/ci/config/node/while_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb index beed29b18ae..c09a0a9c793 100644 --- a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb +++ b/spec/lib/gitlab/ci/config/node/artifacts_spec.rb @@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Node::Artifacts do let(:config) { { paths: %w[public/] } } describe '#value' do - it 'returns image string' do + it 'returns artifacs configuration' do expect(entry.value).to eq config end end diff --git a/spec/lib/gitlab/ci/config/node/trigger_spec.rb b/spec/lib/gitlab/ci/config/node/trigger_spec.rb new file mode 100644 index 00000000000..a4a3e36754e --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/trigger_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::Trigger do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is valid' do + context 'when config is a branch or tag name' do + let(:config) { %w[master feature/branch] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq config + end + end + end + + context 'when config is a regexp' do + let(:config) { ['/^issue-.*$/'] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when config is a special keyword' do + let(:config) { %w[tags triggers branches] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + end + + context 'when entry value is not valid' do + let(:config) { [1] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'trigger config should be an array of strings or regexps' + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/while_spec.rb b/spec/lib/gitlab/ci/config/node/while_spec.rb deleted file mode 100644 index aac2ed7b3db..00000000000 --- a/spec/lib/gitlab/ci/config/node/while_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::While do - let(:entry) { described_class.new(config) } - - describe 'validations' do - context 'when entry config value is valid' do - context 'when config is a branch or tag name' do - let(:config) { %w[master feature/branch] } - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - - describe '#value' do - it 'returns key value' do - expect(entry.value).to eq config - end - end - end - - context 'when config is a regexp' do - let(:config) { ['/^issue-.*$/'] } - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - - context 'when config is a special keyword' do - let(:config) { %w[tags triggers branches] } - - describe '#valid?' do - it 'is valid' do - expect(entry).to be_valid - end - end - end - end - - context 'when entry value is not valid' do - let(:config) { [1] } - - describe '#errors' do - it 'saves errors' do - expect(entry.errors) - .to include 'while config should be an array of strings or regexps' - end - end - end - end -end -- cgit v1.2.1 From aad0ae71620d8e988faf75587a612b933df00366 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 22 Jul 2016 12:10:45 +0200 Subject: squashed - fixed label and milestone association problems, updated specs and refactored reader class a bit --- spec/lib/gitlab/import_export/project.json | 176 ++++++--------------- .../import_export/project_tree_restorer_spec.rb | 12 ++ .../import_export/project_tree_saver_spec.rb | 30 ++-- 3 files changed, 77 insertions(+), 141 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json index b1a5d72c624..b5550ca1963 100644 --- a/spec/lib/gitlab/import_export/project.json +++ b/spec/lib/gitlab/import_export/project.json @@ -18,7 +18,6 @@ "position": 0, "branch_name": null, "description": "Aliquam enim illo et possimus.", - "milestone_id": 18, "state": "opened", "iid": 10, "updated_by_id": null, @@ -27,6 +26,52 @@ "due_date": null, "moved_to_id": null, "test_ee_field": "test", + "milestone": { + "id": 1, + "title": "v0.0", + "project_id": 8, + "description": "test milestone", + "due_date": null, + "created_at": "2016-06-14T15:02:04.415Z", + "updated_at": "2016-06-14T15:02:04.415Z", + "state": "active", + "iid": 1, + "events": [ + { + "id": 487, + "target_type": "Milestone", + "target_id": 1, + "title": null, + "data": null, + "project_id": 46, + "created_at": "2016-06-14T15:02:04.418Z", + "updated_at": "2016-06-14T15:02:04.418Z", + "action": 1, + "author_id": 18 + } + ] + }, + "label_links": [ + { + "id": 2, + "label_id": 2, + "target_id": 3, + "target_type": "Issue", + "created_at": "2016-07-22T08:57:02.840Z", + "updated_at": "2016-07-22T08:57:02.840Z", + "label": { + "id": 2, + "title": "test2", + "color": "#428bca", + "project_id": 8, + "created_at": "2016-07-22T08:55:44.161Z", + "updated_at": "2016-07-22T08:55:44.161Z", + "template": false, + "description": "", + "priority": null + } + } + ], "notes": [ { "id": 351, @@ -233,7 +278,6 @@ "position": 0, "branch_name": null, "description": "Voluptate vel reprehenderit facilis omnis voluptas magnam tenetur.", - "milestone_id": 16, "state": "opened", "iid": 9, "updated_by_id": null, @@ -447,7 +491,6 @@ "position": 0, "branch_name": null, "description": "Ea recusandae neque autem tempora.", - "milestone_id": 16, "state": "closed", "iid": 8, "updated_by_id": null, @@ -661,7 +704,6 @@ "position": 0, "branch_name": null, "description": "Maiores architecto quos in dolorem.", - "milestone_id": 17, "state": "opened", "iid": 7, "updated_by_id": null, @@ -875,7 +917,6 @@ "position": 0, "branch_name": null, "description": "Ut aut ut et tenetur velit aut id modi.", - "milestone_id": 16, "state": "opened", "iid": 6, "updated_by_id": null, @@ -1089,7 +1130,6 @@ "position": 0, "branch_name": null, "description": "Dicta nisi nihil non ipsa velit.", - "milestone_id": 20, "state": "closed", "iid": 5, "updated_by_id": null, @@ -1303,7 +1343,6 @@ "position": 0, "branch_name": null, "description": "Ut et explicabo vel voluptatem consequuntur ut sed.", - "milestone_id": 19, "state": "closed", "iid": 4, "updated_by_id": null, @@ -1517,7 +1556,6 @@ "position": 0, "branch_name": null, "description": "Non asperiores velit accusantium voluptate.", - "milestone_id": 18, "state": "closed", "iid": 3, "updated_by_id": null, @@ -1731,7 +1769,6 @@ "position": 0, "branch_name": null, "description": "Molestiae corporis magnam et fugit aliquid nulla quia.", - "milestone_id": 17, "state": "closed", "iid": 2, "updated_by_id": null, @@ -1945,7 +1982,6 @@ "position": 0, "branch_name": null, "description": "Quod ad architecto qui est sed quia.", - "milestone_id": 20, "state": "closed", "iid": 1, "updated_by_id": null, @@ -2259,117 +2295,6 @@ "author_id": 25 } ] - }, - { - "id": 18, - "title": "v2.0", - "project_id": 5, - "description": "Error dolorem rerum aut nulla.", - "due_date": null, - "created_at": "2016-06-14T15:02:04.576Z", - "updated_at": "2016-06-14T15:02:04.576Z", - "state": "active", - "iid": 3, - "events": [ - { - "id": 242, - "target_type": "Milestone", - "target_id": 18, - "title": null, - "data": null, - "project_id": 36, - "created_at": "2016-06-14T15:02:04.579Z", - "updated_at": "2016-06-14T15:02:04.579Z", - "action": 1, - "author_id": 1 - }, - { - "id": 58, - "target_type": "Milestone", - "target_id": 18, - "title": null, - "data": null, - "project_id": 5, - "created_at": "2016-06-14T15:02:04.579Z", - "updated_at": "2016-06-14T15:02:04.579Z", - "action": 1, - "author_id": 22 - } - ] - }, - { - "id": 17, - "title": "v1.0", - "project_id": 5, - "description": "Molestiae perspiciatis voluptates doloremque commodi veniam consequatur.", - "due_date": null, - "created_at": "2016-06-14T15:02:04.569Z", - "updated_at": "2016-06-14T15:02:04.569Z", - "state": "active", - "iid": 2, - "events": [ - { - "id": 243, - "target_type": "Milestone", - "target_id": 17, - "title": null, - "data": null, - "project_id": 36, - "created_at": "2016-06-14T15:02:04.570Z", - "updated_at": "2016-06-14T15:02:04.570Z", - "action": 1, - "author_id": 1 - }, - { - "id": 57, - "target_type": "Milestone", - "target_id": 17, - "title": null, - "data": null, - "project_id": 5, - "created_at": "2016-06-14T15:02:04.570Z", - "updated_at": "2016-06-14T15:02:04.570Z", - "action": 1, - "author_id": 20 - } - ] - }, - { - "id": 16, - "title": "v0.0", - "project_id": 5, - "description": "Velit numquam et sed sit.", - "due_date": null, - "created_at": "2016-06-14T15:02:04.561Z", - "updated_at": "2016-06-14T15:02:04.561Z", - "state": "closed", - "iid": 1, - "events": [ - { - "id": 244, - "target_type": "Milestone", - "target_id": 16, - "title": null, - "data": null, - "project_id": 36, - "created_at": "2016-06-14T15:02:04.563Z", - "updated_at": "2016-06-14T15:02:04.563Z", - "action": 1, - "author_id": 26 - }, - { - "id": 56, - "target_type": "Milestone", - "target_id": 16, - "title": null, - "data": null, - "project_id": 5, - "created_at": "2016-06-14T15:02:04.563Z", - "updated_at": "2016-06-14T15:02:04.563Z", - "action": 1, - "author_id": 26 - } - ] } ], "snippets": [ @@ -2471,7 +2396,6 @@ "title": "Cannot be automatically merged", "created_at": "2016-06-14T15:02:36.568Z", "updated_at": "2016-06-14T15:02:56.815Z", - "milestone_id": null, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -2909,7 +2833,6 @@ "title": "Can be automatically merged", "created_at": "2016-06-14T15:02:36.418Z", "updated_at": "2016-06-14T15:02:57.013Z", - "milestone_id": null, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -3194,7 +3117,6 @@ "title": "Qui accusantium et inventore facilis doloribus occaecati officiis.", "created_at": "2016-06-14T15:02:25.168Z", "updated_at": "2016-06-14T15:02:59.521Z", - "milestone_id": 17, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -3479,7 +3401,6 @@ "title": "In voluptas aut sequi voluptatem ullam vel corporis illum consequatur.", "created_at": "2016-06-14T15:02:24.760Z", "updated_at": "2016-06-14T15:02:59.749Z", - "milestone_id": 20, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -4170,7 +4091,6 @@ "title": "Voluptates consequatur eius nemo amet libero animi illum delectus tempore.", "created_at": "2016-06-14T15:02:24.415Z", "updated_at": "2016-06-14T15:02:59.958Z", - "milestone_id": 17, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -4719,7 +4639,6 @@ "title": "In a rerum harum nihil accusamus aut quia nobis non.", "created_at": "2016-06-14T15:02:24.000Z", "updated_at": "2016-06-14T15:03:00.225Z", - "milestone_id": 19, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -5219,7 +5138,6 @@ "title": "Corporis provident similique perspiciatis dolores eos animi.", "created_at": "2016-06-14T15:02:23.767Z", "updated_at": "2016-06-14T15:03:00.475Z", - "milestone_id": 18, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -5480,7 +5398,6 @@ "title": "Eligendi reprehenderit doloribus quia et sit id.", "created_at": "2016-06-14T15:02:23.014Z", "updated_at": "2016-06-14T15:03:00.685Z", - "milestone_id": 20, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, @@ -6171,7 +6088,6 @@ "title": "Et ipsam voluptas velit sequi illum ut.", "created_at": "2016-06-14T15:02:22.825Z", "updated_at": "2016-06-14T15:03:00.904Z", - "milestone_id": 16, "state": "opened", "merge_status": "unchecked", "target_project_id": 5, diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 6ae20c943b1..32c0d6462f1 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -60,6 +60,18 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do expect { restored_project_json }.to change(MergeRequestDiff.where.not(st_diffs: nil), :count).by(9) end + + it 'has labels associated to label links, associated to issues' do + restored_project_json + + expect(Label.first.label_links.first.target).not_to be_nil + end + + it 'has milestones associated to issues' do + restored_project_json + + expect(Milestone.find_by_description('test milestone').issues).not_to be_empty + end end end end diff --git a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb index 057ef6e76a0..3a86a4ce07c 100644 --- a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb @@ -31,10 +31,6 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json).to include({ "visibility_level" => 20 }) end - it 'has events' do - expect(saved_project_json['milestones'].first['events']).not_to be_empty - end - it 'has milestones' do expect(saved_project_json['milestones']).not_to be_empty end @@ -43,8 +39,12 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json['merge_requests']).not_to be_empty end - it 'has labels' do - expect(saved_project_json['labels']).not_to be_empty + it 'has merge request\'s milestones' do + expect(saved_project_json['merge_requests'].first['milestone']).not_to be_empty + end + + it 'has events' do + expect(saved_project_json['merge_requests'].first['milestone']['events']).not_to be_empty end it 'has snippets' do @@ -103,6 +103,14 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json['pipelines'].first['notes']).not_to be_empty end + it 'has labels with no associations' do + expect(saved_project_json['labels']).not_to be_empty + end + + it 'has labels associated to records' do + expect(saved_project_json['issues'].first['label_links'].first['label']).not_to be_empty + end + it 'does not complain about non UTF-8 characters in MR diffs' do ActiveRecord::Base.connection.execute("UPDATE merge_request_diffs SET st_diffs = '---\n- :diff: !binary |-\n LS0tIC9kZXYvbnVsbAorKysgYi9pbWFnZXMvbnVjb3IucGRmCkBAIC0wLDAg\n KzEsMTY3OSBAQAorJVBERi0xLjUNJeLjz9MNCisxIDAgb2JqDTw8L01ldGFk\n YXR'") @@ -113,19 +121,19 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do def setup_project issue = create(:issue, assignee: user) - label = create(:label) snippet = create(:project_snippet) release = create(:release) project = create(:project, :public, issues: [issue], - labels: [label], snippets: [snippet], releases: [release] ) - - merge_request = create(:merge_request, source_project: project) + label = create(:label, project: project) + create(:label_link, label: label, target: issue) + milestone = create(:milestone, project: project) + merge_request = create(:merge_request, source_project: project, milestone: milestone) commit_status = create(:commit_status, project: project) ci_pipeline = create(:ci_pipeline, @@ -135,7 +143,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do statuses: [commit_status]) create(:ci_build, pipeline: ci_pipeline, project: project) - milestone = create(:milestone, project: project) + create(:milestone, project: project) create(:note, noteable: issue, project: project) create(:note, noteable: merge_request, project: project) create(:note, noteable: snippet, project: project) -- cgit v1.2.1 From 3fe18525ddca414017d330e992999bad05002fa8 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 31 Jul 2016 20:51:12 -0700 Subject: Trim extra displayed carriage returns in diffs and files with CRLFs Closes #20440 --- spec/lib/gitlab/highlight_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 364532e94e3..80a9473d6aa 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -17,6 +17,18 @@ describe Gitlab::Highlight, lib: true do expect(lines[21]).to eq(%Q{ unless File.directory?(path)\n}) expect(lines[26]).to eq(%Q{ @cmd_status = 0\n}) end + + describe 'with CRLF' do + let(:branch) { 'crlf-diff' } + let(:blob) { repository.blob_at_branch(branch, path) } + let(:lines) do + Gitlab::Highlight.highlight_lines(project.repository, 'crlf-diff-test', 'files/whitespace') + end + + it 'strips extra LFs' do + expect(lines[0]).to eq("test ") + end + end end describe 'custom highlighting from .gitattributes' do -- cgit v1.2.1 From fe25d1d5cfdd8c52854b459b49bbead1a608822c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Aug 2016 13:16:04 +0200 Subject: Fix specs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/lib/gitlab/highlight_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 80a9473d6aa..fc021416d92 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -22,7 +22,7 @@ describe Gitlab::Highlight, lib: true do let(:branch) { 'crlf-diff' } let(:blob) { repository.blob_at_branch(branch, path) } let(:lines) do - Gitlab::Highlight.highlight_lines(project.repository, 'crlf-diff-test', 'files/whitespace') + Gitlab::Highlight.highlight_lines(project.repository, 'crlf-diff', 'files/whitespace') end it 'strips extra LFs' do -- cgit v1.2.1 From 701e5ccbe6018129130ee70a78f213c406c93fcf Mon Sep 17 00:00:00 2001 From: winniehell Date: Mon, 1 Aug 2016 03:58:31 +0200 Subject: Add failing tests for #19028 --- spec/lib/banzai/filter/relative_link_filter_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index 9921171f2aa..224baca8030 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -78,12 +78,24 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do end context 'with a valid repository' do + it 'rebuilds absolute URL for a file in the repo' do + doc = filter(link('/doc/api/README.md')) + expect(doc.at_css('a')['href']). + to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" + end + it 'rebuilds relative URL for a file in the repo' do doc = filter(link('doc/api/README.md')) expect(doc.at_css('a')['href']). to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end + it 'rebuilds relative URL for a file in the repo with leading ./' do + doc = filter(link('./doc/api/README.md')) + expect(doc.at_css('a')['href']). + to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" + end + it 'rebuilds relative URL for a file in the repo up one directory' do relative_link = link('../api/README.md') doc = filter(relative_link, requested_path: 'doc/update/7.14-to-8.0.md') -- cgit v1.2.1 From 8f359ea9170b984ad43d126e17628c31ac3a1f14 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Tue, 26 Jul 2016 09:21:42 +0200 Subject: Move to Gitlab::Diff::FileCollection Instead calling diff_collection.count use diff_collection.size which is cache on the diff_collection --- spec/lib/gitlab/email/message/repository_push_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/message/repository_push_spec.rb b/spec/lib/gitlab/email/message/repository_push_spec.rb index c19f33e2224..c1d07329983 100644 --- a/spec/lib/gitlab/email/message/repository_push_spec.rb +++ b/spec/lib/gitlab/email/message/repository_push_spec.rb @@ -62,12 +62,12 @@ describe Gitlab::Email::Message::RepositoryPush do describe '#diffs_count' do subject { message.diffs_count } - it { is_expected.to eq compare.diffs.count } + it { is_expected.to eq compare.diffs.size } end describe '#compare' do subject { message.compare } - it { is_expected.to be_an_instance_of Gitlab::Git::Compare } + it { is_expected.to be_an_instance_of Compare } end describe '#compare_timeout' do -- cgit v1.2.1 From 1d0c7b74920a94e488e6a2c090abb3e525438053 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Wed, 27 Jul 2016 13:09:52 +0200 Subject: Introduce Compare model in the codebase. This object will manage Gitlab::Git::Compare instances --- spec/lib/gitlab/email/message/repository_push_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/message/repository_push_spec.rb b/spec/lib/gitlab/email/message/repository_push_spec.rb index c1d07329983..5b966bddb6a 100644 --- a/spec/lib/gitlab/email/message/repository_push_spec.rb +++ b/spec/lib/gitlab/email/message/repository_push_spec.rb @@ -16,9 +16,12 @@ describe Gitlab::Email::Message::RepositoryPush do { author_id: author.id, ref: 'master', action: :push, compare: compare, send_from_committer_email: true } end - let(:compare) do + let(:raw_compare) do Gitlab::Git::Compare.new(project.repository.raw_repository, - sample_image_commit.id, sample_commit.id) + sample_image_commit.id, sample_commit.id) + end + let(:compare) do + Compare.decorate(raw_compare, project) end describe '#project' do @@ -62,7 +65,7 @@ describe Gitlab::Email::Message::RepositoryPush do describe '#diffs_count' do subject { message.diffs_count } - it { is_expected.to eq compare.diffs.size } + it { is_expected.to eq raw_compare.diffs.size } end describe '#compare' do @@ -72,7 +75,7 @@ describe Gitlab::Email::Message::RepositoryPush do describe '#compare_timeout' do subject { message.compare_timeout } - it { is_expected.to eq compare.diffs.overflow? } + it { is_expected.to eq raw_compare.diffs.overflow? } end describe '#reverse_compare?' do -- cgit v1.2.1 From c86c1905b5574cac234315598d8d715fcaee3ea7 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Wed, 27 Jul 2016 19:00:34 +0200 Subject: switch from diff_file_collection to diffs So we have raw_diffs too --- spec/lib/gitlab/diff/file_spec.rb | 2 +- spec/lib/gitlab/diff/highlight_spec.rb | 2 +- spec/lib/gitlab/diff/line_mapper_spec.rb | 2 +- spec/lib/gitlab/diff/parallel_diff_spec.rb | 2 +- spec/lib/gitlab/diff/parser_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index e883a6eb9c2..0650cb291e5 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Diff::File, lib: true do let(:project) { create(:project) } let(:commit) { project.commit(sample_commit.id) } - let(:diff) { commit.diffs.first } + let(:diff) { commit.raw_diffs.first } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: project.repository) } describe '#diff_lines' do diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index 88e4115c453..1c2ddeed692 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Diff::Highlight, lib: true do let(:project) { create(:project) } let(:commit) { project.commit(sample_commit.id) } - let(:diff) { commit.diffs.first } + let(:diff) { commit.raw_diffs.first } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: project.repository) } describe '#highlight' do diff --git a/spec/lib/gitlab/diff/line_mapper_spec.rb b/spec/lib/gitlab/diff/line_mapper_spec.rb index 4e50e03bb7e..4b943fa382d 100644 --- a/spec/lib/gitlab/diff/line_mapper_spec.rb +++ b/spec/lib/gitlab/diff/line_mapper_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Diff::LineMapper, lib: true do let(:project) { create(:project) } let(:repository) { project.repository } let(:commit) { project.commit(sample_commit.id) } - let(:diffs) { commit.diffs } + let(:diffs) { commit.raw_diffs } let(:diff) { diffs.first } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: repository) } subject { described_class.new(diff_file) } diff --git a/spec/lib/gitlab/diff/parallel_diff_spec.rb b/spec/lib/gitlab/diff/parallel_diff_spec.rb index 2aa5ae44f54..af18d3c25a6 100644 --- a/spec/lib/gitlab/diff/parallel_diff_spec.rb +++ b/spec/lib/gitlab/diff/parallel_diff_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Diff::ParallelDiff, lib: true do let(:project) { create(:project) } let(:repository) { project.repository } let(:commit) { project.commit(sample_commit.id) } - let(:diffs) { commit.diffs } + let(:diffs) { commit.raw_diffs } let(:diff) { diffs.first } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: repository) } subject { described_class.new(diff_file) } diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb index c3359627652..b983d73f8be 100644 --- a/spec/lib/gitlab/diff/parser_spec.rb +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Diff::Parser, lib: true do let(:project) { create(:project) } let(:commit) { project.commit(sample_commit.id) } - let(:diff) { commit.diffs.first } + let(:diff) { commit.raw_diffs.first } let(:parser) { Gitlab::Diff::Parser.new } describe '#parse' do -- cgit v1.2.1 From f87eb2502023fb0c17d29aef398058c62736c9ca Mon Sep 17 00:00:00 2001 From: James Lopez Date: Wed, 3 Aug 2016 13:00:34 +0200 Subject: Fix Import/Export error checking versions --- .../gitlab/import_export/version_checker_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/lib/gitlab/import_export/version_checker_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/import_export/version_checker_spec.rb b/spec/lib/gitlab/import_export/version_checker_spec.rb new file mode 100644 index 00000000000..90c6d1c67f6 --- /dev/null +++ b/spec/lib/gitlab/import_export/version_checker_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Gitlab::ImportExport::VersionChecker, services: true do + describe 'bundle a project Git repo' do + let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: '') } + let(:version) { Gitlab::ImportExport.version } + + before do + allow(File).to receive(:open).and_return(version) + end + + it 'returns true if Import/Export have the same version' do + expect(described_class.check!(shared: shared)).to be true + end + + context 'newer version' do + let(:version) { '900.0'} + + it 'returns false if export version is newer' do + expect(described_class.check!(shared: shared)).to be false + end + + it 'shows the correct error message' do + described_class.check!(shared: shared) + + expect(shared.errors.first).to eq("Import version mismatch: Required <= #{Gitlab::ImportExport.version} but was #{version}") + end + end + end +end -- cgit v1.2.1 From fa54a8e984949227b2b56ecd20e37e0c6ba498cd Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Thu, 4 Aug 2016 11:56:58 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20close=20issues=20on=20original=20projec?= =?UTF-8?q?t=20from=20a=20fork?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paco Guzman --- spec/lib/gitlab/closing_issue_extractor_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb index e9b8ce6b5bb..de3f64249a2 100644 --- a/spec/lib/gitlab/closing_issue_extractor_spec.rb +++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb @@ -3,10 +3,12 @@ require 'spec_helper' describe Gitlab::ClosingIssueExtractor, lib: true do let(:project) { create(:project) } let(:project2) { create(:project) } + let(:forked_project) { Projects::ForkService.new(project, project.creator).execute } let(:issue) { create(:issue, project: project) } let(:issue2) { create(:issue, project: project2) } let(:reference) { issue.to_reference } let(:cross_reference) { issue2.to_reference(project) } + let(:fork_cross_reference) { issue.to_reference(forked_project) } subject { described_class.new(project, project.creator) } @@ -278,6 +280,15 @@ describe Gitlab::ClosingIssueExtractor, lib: true do end end + context "with a cross-project fork reference" do + subject { described_class.new(forked_project, forked_project.creator) } + + it do + message = "Closes #{fork_cross_reference}" + expect(subject.closed_by_message(message)).to be_empty + end + end + context "with an invalid URL" do it do message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)}" -- cgit v1.2.1 From c9e15be9ab37f2e209d6f51a19fb0e0e11f17db9 Mon Sep 17 00:00:00 2001 From: winniehell Date: Fri, 5 Aug 2016 00:53:08 +0200 Subject: Add failing test for #7032 --- spec/lib/banzai/filter/relative_link_filter_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index 224baca8030..bda8d2ce38a 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -84,6 +84,11 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end + it 'ignores absolute URLs with two leading slashes' do + doc = filter(link('//doc/api/README.md')) + expect(doc.at_css('a')['href']).to eq '//doc/api/README.md' + end + it 'rebuilds relative URL for a file in the repo' do doc = filter(link('doc/api/README.md')) expect(doc.at_css('a')['href']). -- cgit v1.2.1