From bafd30f92cfb754fe6864c9cd595df10b52b11f2 Mon Sep 17 00:00:00 2001 From: Andrey Krivko Date: Wed, 22 Oct 2014 22:29:26 +0700 Subject: Session API: Use case-insensitive authentication like in UI --- spec/models/user_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6ad57b06e06..6d865cfc691 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -287,6 +287,20 @@ describe User do end end + describe '.by_login' do + let(:username) { 'John' } + let!(:user) { create(:user, username: username) } + + it 'should get the correct user' do + expect(User.by_login(user.email.upcase)).to eq user + expect(User.by_login(user.email)).to eq user + expect(User.by_login(username.downcase)).to eq user + expect(User.by_login(username)).to eq user + expect(User.by_login(nil)).to be_nil + expect(User.by_login('')).to be_nil + end + end + describe 'all_ssh_keys' do it { should have_many(:keys).dependent(:destroy) } -- cgit v1.2.1 From 54ded5d95b16ea09be50dc7a9347fb6d5c02b1d9 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sat, 1 Nov 2014 22:26:12 +0100 Subject: Continue strings with backslash instead of append --- spec/models/slack_message_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/slack_message_spec.rb b/spec/models/slack_message_spec.rb index 1cd58534702..a07273e99af 100644 --- a/spec/models/slack_message_spec.rb +++ b/spec/models/slack_message_spec.rb @@ -26,11 +26,11 @@ describe SlackMessage do it 'returns a message regarding pushes' do subject.pretext.should == - 'user_name pushed to branch of ' << + 'user_name pushed to branch of '\ ' ()' subject.attachments.should == [ { - text: ": message1 - author1\n" << + text: ": message1 - author1\n"\ ": message2 - author2", color: color, } @@ -45,7 +45,7 @@ describe SlackMessage do it 'returns a message regarding a new branch' do subject.pretext.should == - 'user_name pushed new branch to ' << + 'user_name pushed new branch to '\ '' subject.attachments.should be_empty end -- cgit v1.2.1 From c49cb40f65d75a54c8471cb5207512ec145593cc Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 3 Nov 2014 20:17:02 +0100 Subject: Remove dead Event#new_branch? method --- spec/models/event_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 1fdd959da9d..10beafc4994 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -60,7 +60,6 @@ describe Event do it { @event.push?.should be_true } it { @event.proper?.should be_true } - it { @event.new_branch?.should be_true } it { @event.tag?.should be_false } it { @event.branch_name.should == "master" } it { @event.author.should == @user } -- cgit v1.2.1 From c3be1517ae3c576f7f4248b82b611a833fe06675 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 3 Nov 2014 20:35:06 +0100 Subject: Factor '0' * 40 blank ref constants --- spec/models/event_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 1fdd959da9d..1f1bc9ac737 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -36,7 +36,7 @@ describe Event do @user = project.owner data = { - before: "0000000000000000000000000000000000000000", + before: Gitlab::Git::BLANK_SHA, after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e", ref: "refs/heads/master", user_id: @user.id, -- cgit v1.2.1 From 5a8ec1f6712ea044500c015e55f7515007a8285e Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 5 Nov 2014 12:18:26 +0100 Subject: Create a failing test where commit in mr creates a mr mention note. --- spec/models/note_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/models') diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 2d839e9611b..6ab7162c15c 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -249,6 +249,12 @@ describe Note do its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } end + context 'commit contained in a merge request' do + subject { Note.create_cross_reference_note(mergereq.commits.first, mergereq, author, project) } + + it { should be_nil } + end + context 'commit from issue' do subject { Note.create_cross_reference_note(commit, issue, author, project) } -- cgit v1.2.1 From 4a41d4b7d246c4e5f9a9062c7dd417510b0bae0c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 5 Nov 2014 16:21:35 +0200 Subject: Modify tests to match new gitlab_ci_service logic Signed-off-by: Dmitriy Zaporozhets --- spec/models/gitlab_ci_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb index ebc377047be..83277058fbb 100644 --- a/spec/models/gitlab_ci_service_spec.rb +++ b/spec/models/gitlab_ci_service_spec.rb @@ -34,11 +34,11 @@ describe GitlabCiService do end describe :commit_status_path do - it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c/status.json?token=verySecret"} + it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} end describe :build_page do - it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c"} + it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} end end end -- cgit v1.2.1 From 2139e3519b1f1023478bec087cf94f2ec237c0c7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 11 Nov 2014 16:49:26 +0200 Subject: Refactor merge request refresh logic on push Signed-off-by: Dmitriy Zaporozhets --- spec/models/project_spec.rb | 57 --------------------------------------------- 1 file changed, 57 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 48b58400a1e..70a15cac1a8 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -145,63 +145,6 @@ describe Project do end end - describe 'comment merge requests with commits' do - before do - @user = create(:user) - group = create(:group) - group.add_owner(@user) - - @project = create(:project, namespace: group) - @fork_project = Projects::ForkService.new(@project, @user).execute - @merge_request = create(:merge_request, source_project: @project, - source_branch: 'master', - target_branch: 'feature', - target_project: @project) - @fork_merge_request = create(:merge_request, source_project: @fork_project, - source_branch: 'master', - target_branch: 'feature', - target_project: @project) - - @commits = @merge_request.commits - end - - context 'push to origin repo source branch' do - before do - @project.comment_mr_with_commits('master', @commits, @user) - end - - it { @merge_request.notes.should_not be_empty } - it { @fork_merge_request.notes.should be_empty } - end - - context 'push to origin repo target branch' do - before do - @project.comment_mr_with_commits('feature', @commits, @user) - end - - it { @merge_request.notes.should be_empty } - it { @fork_merge_request.notes.should be_empty } - end - - context 'push to fork repo source branch' do - before do - @fork_project.comment_mr_with_commits('master', @commits, @user) - end - - it { @merge_request.notes.should be_empty } - it { @fork_merge_request.notes.should_not be_empty } - end - - context 'push to fork repo target branch' do - before do - @fork_project.comment_mr_with_commits('feature', @commits, @user) - end - - it { @merge_request.notes.should be_empty } - it { @fork_merge_request.notes.should be_empty } - end - end - describe :find_with_namespace do context 'with namespace' do before do -- cgit v1.2.1 From 3a5ed5260b24051939575d1934ce9b8392cac09f Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Thu, 27 Nov 2014 13:34:39 +0200 Subject: Supporting for multiple omniauth provider for the same user --- spec/models/user_spec.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6d865cfc691..8be7f733a5b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -62,6 +62,7 @@ describe User do it { should have_many(:assigned_issues).dependent(:destroy) } it { should have_many(:merge_requests).dependent(:destroy) } it { should have_many(:assigned_merge_requests).dependent(:destroy) } + it { should have_many(:identities).dependent(:destroy) } end describe "Mass assignment" do @@ -361,24 +362,29 @@ describe User do end describe :ldap_user? do - let(:user) { build(:user, :ldap) } - it "is true if provider name starts with ldap" do - user.provider = 'ldapmain' + user = create(:omniauth_user, provider: 'ldapmain') expect( user.ldap_user? ).to be_true end it "is false for other providers" do - user.provider = 'other-provider' + user = create(:omniauth_user, provider: 'other-provider') expect( user.ldap_user? ).to be_false end it "is false if no extern_uid is provided" do - user.extern_uid = nil + user = create(:omniauth_user, extern_uid: nil) expect( user.ldap_user? ).to be_false end end + describe :ldap_identity do + it "returns ldap identity" do + user = create :omniauth_user + user.ldap_identity.provider.should_not be_empty + end + end + describe '#full_website_url' do let(:user) { create(:user) } -- cgit v1.2.1 From 57a65ede77b7bbae6e3b2a7aa52135de7b0c2f8e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Jan 2015 09:53:35 -0800 Subject: Improve application settings and write tests --- spec/models/application_setting_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spec/models/application_setting_spec.rb (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb new file mode 100644 index 00000000000..3a8d52c11c4 --- /dev/null +++ b/spec/models/application_setting_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe ApplicationSetting, models: true do + describe 'should exists on start' do + it { ApplicationSetting.count.should_not be_zero } + end +end -- cgit v1.2.1 From 939c046a9872c1d7c38d73dc08860681ecebd1f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Jan 2015 13:21:00 -0800 Subject: Fix feature and tests --- spec/models/application_setting_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 3a8d52c11c4..039775dddda 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1,7 +1,5 @@ require 'spec_helper' describe ApplicationSetting, models: true do - describe 'should exists on start' do - it { ApplicationSetting.count.should_not be_zero } - end + it { ApplicationSetting.create_from_defaults.should be_valid } end -- cgit v1.2.1 From bba8e59a044f34a02000b752a70198fb74236b1d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 12 Jan 2015 09:08:25 -0800 Subject: Fix test hook and tests --- spec/models/assembla_service_spec.rb | 2 +- spec/models/flowdock_service_spec.rb | 2 +- spec/models/gemnasium_service_spec.rb | 2 +- spec/models/pushover_service_spec.rb | 2 +- spec/models/slack_service_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/assembla_service_spec.rb b/spec/models/assembla_service_spec.rb index 4300090eb13..005dd41fea9 100644 --- a/spec/models/assembla_service_spec.rb +++ b/spec/models/assembla_service_spec.rb @@ -33,7 +33,7 @@ describe AssemblaService, models: true do token: 'verySecret', subdomain: 'project_name' ) - @sample_data = GitPushService.new.sample_data(project, user) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' WebMock.stub_request(:post, @api_url) end diff --git a/spec/models/flowdock_service_spec.rb b/spec/models/flowdock_service_spec.rb index 5540f0fa988..ac156719b43 100644 --- a/spec/models/flowdock_service_spec.rb +++ b/spec/models/flowdock_service_spec.rb @@ -32,7 +32,7 @@ describe FlowdockService do service_hook: true, token: 'verySecret' ) - @sample_data = GitPushService.new.sample_data(project, user) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) @api_url = 'https://api.flowdock.com/v1/git/verySecret' WebMock.stub_request(:post, @api_url) end diff --git a/spec/models/gemnasium_service_spec.rb b/spec/models/gemnasium_service_spec.rb index 60ffa6f8b05..2c560c11dac 100644 --- a/spec/models/gemnasium_service_spec.rb +++ b/spec/models/gemnasium_service_spec.rb @@ -33,7 +33,7 @@ describe GemnasiumService do token: 'verySecret', api_key: 'GemnasiumUserApiKey' ) - @sample_data = GitPushService.new.sample_data(project, user) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) end it "should call Gemnasium service" do Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once diff --git a/spec/models/pushover_service_spec.rb b/spec/models/pushover_service_spec.rb index 59db69d7572..f2813d66c7d 100644 --- a/spec/models/pushover_service_spec.rb +++ b/spec/models/pushover_service_spec.rb @@ -36,7 +36,7 @@ describe PushoverService do let(:pushover) { PushoverService.new } let(:user) { create(:user) } let(:project) { create(:project) } - let(:sample_data) { GitPushService.new.sample_data(project, user) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } let(:api_key) { 'verySecret' } let(:user_key) { 'verySecret' } diff --git a/spec/models/slack_service_spec.rb b/spec/models/slack_service_spec.rb index d4840391967..34594072409 100644 --- a/spec/models/slack_service_spec.rb +++ b/spec/models/slack_service_spec.rb @@ -34,7 +34,7 @@ describe SlackService do let(:slack) { SlackService.new } let(:user) { create(:user) } let(:project) { create(:project) } - let(:sample_data) { GitPushService.new.sample_data(project, user) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } before do -- cgit v1.2.1 From 089516209c0c9c618b359aaa59e26395e2f67405 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Thu, 15 Jan 2015 12:19:34 +0100 Subject: Fixed tests --- spec/models/wiki_page_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index d065431ee3a..78877db61b7 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -36,7 +36,7 @@ describe WikiPage do end it "sets the version attribute" do - @wiki_page.version.should be_a Grit::Commit + @wiki_page.version.should be_a Gollum::Git::Commit end end end -- cgit v1.2.1 From b21a2d821a4e16aba1609dfa1e01ba455e8ccd8f Mon Sep 17 00:00:00 2001 From: jubianchi Date: Wed, 17 Sep 2014 19:08:35 +0200 Subject: Allow commit messages to close several issues at once (thanks @123Haynes for his work and help) --- spec/models/commit_spec.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index a6ec44da4be..7a2a7a4ce9b 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -57,16 +57,12 @@ eos let(:other_issue) { create :issue, project: other_project } it 'detects issues that this commit is marked as closing' do - stub_const('Gitlab::ClosingIssueExtractor::ISSUE_CLOSING_REGEX', - /Fixes #\d+/) commit.stub(safe_message: "Fixes ##{issue.iid}") commit.closes_issues(project).should == [issue] end it 'does not detect issues from other projects' do ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}" - stub_const('Gitlab::ClosingIssueExtractor::ISSUE_CLOSING_REGEX', - /^([Cc]loses|[Ff]ixes)/) commit.stub(safe_message: "Fixes #{ext_ref}") commit.closes_issues(project).should be_empty end -- cgit v1.2.1 From 98ee4a1fa73183cacf6c470b56e34afccec1c5dc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 22 Jan 2015 09:40:03 -0800 Subject: Annotate models --- spec/models/application_setting_spec.rb | 15 +++++++++++++++ spec/models/merge_request_spec.rb | 1 + spec/models/project_spec.rb | 2 ++ spec/models/protected_branch_spec.rb | 11 ++++++----- spec/models/user_spec.rb | 5 ++--- 5 files changed, 26 insertions(+), 8 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 039775dddda..1723eba9ec3 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: application_settings +# +# id :integer not null, primary key +# default_projects_limit :integer +# signup_enabled :boolean +# signin_enabled :boolean +# gravatar_enabled :boolean +# sign_in_text :text +# created_at :datetime +# updated_at :datetime +# home_page_url :string(255) +# + require 'spec_helper' describe ApplicationSetting, models: true do diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 7b0d261d72f..9585cf09768 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -18,6 +18,7 @@ # iid :integer # description :text # position :integer default(0) +# locked_at :datetime # require 'spec_helper' diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 70a15cac1a8..2a278176371 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -24,6 +24,8 @@ # import_status :string(255) # repository_size :float default(0.0) # star_count :integer default(0), not null +# import_type :string(255) +# import_source :string(255) # require 'spec_helper' diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index af48c2c6d9e..b0f57e8a206 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -2,11 +2,12 @@ # # Table name: protected_branches # -# id :integer not null, primary key -# project_id :integer not null -# name :string(255) not null -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# project_id :integer not null +# name :string(255) not null +# created_at :datetime +# updated_at :datetime +# developers_can_push :boolean default(FALSE), not null # require 'spec_helper' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8be7f733a5b..83341e516a5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -26,8 +26,6 @@ # bio :string(255) # failed_attempts :integer default(0) # locked_at :datetime -# extern_uid :string(255) -# provider :string(255) # username :string(255) # can_create_group :boolean default(TRUE), not null # can_create_team :boolean default(TRUE), not null @@ -36,7 +34,6 @@ # notification_level :integer default(1), not null # password_expires_at :datetime # created_by_id :integer -# last_credential_check_at :datetime # avatar :string(255) # confirmation_token :string(255) # confirmed_at :datetime @@ -44,6 +41,8 @@ # unconfirmed_email :string(255) # hide_no_ssh_key :boolean default(FALSE) # website_url :string(255) default(""), not null +# last_credential_check_at :datetime +# github_access_token :string(255) # require 'spec_helper' -- cgit v1.2.1 From 7c701acf573f95cce7f8b1b7756de5d73404f09b Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 23 Jan 2015 11:01:09 -0800 Subject: Do a check which issue tracker is used inside the project. --- spec/models/project_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 70a15cac1a8..9d633e78187 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -195,16 +195,16 @@ describe Project do end end - describe :used_default_issues_tracker? do + describe :default_issues_tracker? do let(:project) { create(:project) } let(:ext_project) { create(:redmine_project) } it "should be true if used internal tracker" do - project.used_default_issues_tracker?.should be_true + project.default_issues_tracker?.should be_true end it "should be false if used other tracker" do - ext_project.used_default_issues_tracker?.should be_false + ext_project.default_issues_tracker?.should be_false end end -- cgit v1.2.1 From 42bac7f9f27b0e8fb113e452fc2106882262172d Mon Sep 17 00:00:00 2001 From: Steven Thonus Date: Sat, 25 Jan 2014 18:15:44 +0100 Subject: adding avatar to project settings page added avatar removal show project avatar on dashboard, projects page, project page added rspec and feature tests added project avatar from repository new default project icon added added copying af avatar to forking of project added generated icon fixed avatar fork hound fix style fix test fix --- spec/models/project_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2a278176371..87d26f98b44 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -26,6 +26,7 @@ # star_count :integer default(0), not null # import_type :string(255) # import_source :string(255) +# avatar :string(255) # require 'spec_helper' @@ -310,4 +311,18 @@ describe Project do expect(project.star_count).to eq(0) end end + + describe :avatar_type do + let(:project) { create(:project) } + + it 'should be true if avatar is image' do + project.update_attribute(:avatar, 'uploads/avatar.png') + project.avatar_type.should be_true + end + + it 'should be false if avatar is html page' do + project.update_attribute(:avatar, 'uploads/avatar.html') + project.avatar_type.should == ['only images allowed'] + end + end end -- cgit v1.2.1 From 70c44a0da2bdeead90a99fe79e7c047d38b8ca5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Rosen=C3=B6gger?= <123haynes@gmail.com> Date: Mon, 19 Jan 2015 21:37:20 +0100 Subject: Fix tests, merge conflicts, some minor issues and make the project avatar feature mergable --- spec/models/project_spec.rb | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 87d26f98b44..c9bdeb43f6f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -14,7 +14,7 @@ # merge_requests_enabled :boolean default(TRUE), not null # wiki_enabled :boolean default(TRUE), not null # namespace_id :integer -# issues_tracker :string(255) default("gitlab"), not null +# issues_tracker :string(255) default('gitlab'), not null # issues_tracker_id :string(255) # snippets_enabled :boolean default(TRUE), not null # last_activity_at :datetime @@ -32,7 +32,7 @@ require 'spec_helper' describe Project do - describe "Associations" do + describe 'Associations' do it { should belong_to(:group) } it { should belong_to(:namespace) } it { should belong_to(:creator).class_name('User') } @@ -53,10 +53,10 @@ describe Project do it { should have_one(:pushover_service).dependent(:destroy) } end - describe "Mass assignment" do + describe 'Mass assignment' do end - describe "Validation" do + describe 'Validation' do let!(:project) { create(:project) } it { should validate_presence_of(:name) } @@ -71,7 +71,7 @@ describe Project do it { should ensure_length_of(:issues_tracker_id).is_within(0..255) } it { should validate_presence_of(:namespace) } - it "should not allow new projects beyond user limits" do + it 'should not allow new projects beyond user limits' do project2 = build(:project) project2.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object) project2.should_not be_valid @@ -79,7 +79,7 @@ describe Project do end end - describe "Respond to" do + describe 'Respond to' do it { should respond_to(:url_to_repo) } it { should respond_to(:repo_exists?) } it { should respond_to(:satellite) } @@ -90,27 +90,27 @@ describe Project do it { should respond_to(:path_with_namespace) } end - it "should return valid url to repo" do - project = Project.new(path: "somewhere") - project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + "somewhere.git" + it 'should return valid url to repo' do + project = Project.new(path: 'somewhere') + project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git' end - it "returns the full web URL for this repo" do - project = Project.new(path: "somewhere") + it 'returns the full web URL for this repo' do + project = Project.new(path: 'somewhere') project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere" end - it "returns the web URL without the protocol for this repo" do - project = Project.new(path: "somewhere") - project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.url.split("://")[1]}/somewhere" + it 'returns the web URL without the protocol for this repo' do + project = Project.new(path: 'somewhere') + project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere" end - describe "last_activity methods" do + describe 'last_activity methods' do let(:project) { create(:project) } let(:last_event) { double(created_at: Time.now) } - describe "last_activity" do - it "should alias last_activity to last_event" do + describe 'last_activity' do + it 'should alias last_activity to last_event' do project.stub(last_event: last_event) project.last_activity.should == last_event end @@ -135,13 +135,13 @@ describe Project do let(:prev_commit_id) { merge_request.commits.last.id } let(:commit_id) { merge_request.commits.first.id } - it "should close merge request if last commit from source branch was pushed to target branch" do + it 'should close merge request if last commit from source branch was pushed to target branch' do project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user) merge_request.reload merge_request.merged?.should be_true end - it "should update merge request commits with new one if pushed to source branch" do + it 'should update merge request commits with new one if pushed to source branch' do project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user) merge_request.reload merge_request.last_commit.id.should == commit_id @@ -167,14 +167,14 @@ describe Project do @project = create(:project, name: 'gitlabhq', namespace: @group) end - it { @project.to_param.should == "gitlab/gitlabhq" } + it { @project.to_param.should == 'gitlab/gitlabhq' } end end describe :repository do let(:project) { create(:project) } - it "should return valid repo" do + it 'should return valid repo' do project.repository.should be_kind_of(Repository) end end @@ -185,15 +185,15 @@ describe Project do let(:not_existed_issue) { create(:issue) } let(:ext_project) { create(:redmine_project) } - it "should be true or if used internal tracker and issue exists" do + it 'should be true or if used internal tracker and issue exists' do project.issue_exists?(existed_issue.iid).should be_true end - it "should be false or if used internal tracker and issue not exists" do + it 'should be false or if used internal tracker and issue not exists' do project.issue_exists?(not_existed_issue.iid).should be_false end - it "should always be true if used other tracker" do + it 'should always be true if used other tracker' do ext_project.issue_exists?(rand(100)).should be_true end end @@ -202,11 +202,11 @@ describe Project do let(:project) { create(:project) } let(:ext_project) { create(:redmine_project) } - it "should be true if used internal tracker" do + it 'should be true if used internal tracker' do project.used_default_issues_tracker?.should be_true end - it "should be false if used other tracker" do + it 'should be false if used other tracker' do ext_project.used_default_issues_tracker?.should be_false end end @@ -215,15 +215,15 @@ describe Project do let(:project) { create(:project) } let(:ext_project) { create(:redmine_project) } - it "should be true for projects with external issues tracker if issues enabled" do + it 'should be true for projects with external issues tracker if issues enabled' do ext_project.can_have_issues_tracker_id?.should be_true end - it "should be false for projects with internal issue tracker if issues enabled" do + it 'should be false for projects with internal issue tracker if issues enabled' do project.can_have_issues_tracker_id?.should be_false end - it "should be always false if issues disabled" do + it 'should be always false if issues disabled' do project.issues_enabled = false ext_project.issues_enabled = false -- cgit v1.2.1 From aad6ceaef9ccfba8e058012a0877b80c103a3838 Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Sun, 25 Jan 2015 16:33:54 +0100 Subject: Allow configuring protection of the default branch upon first push --- spec/models/application_setting_spec.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 1723eba9ec3..ac68e3d925f 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -2,15 +2,16 @@ # # Table name: application_settings # -# id :integer not null, primary key -# default_projects_limit :integer -# signup_enabled :boolean -# signin_enabled :boolean -# gravatar_enabled :boolean -# sign_in_text :text -# created_at :datetime -# updated_at :datetime -# home_page_url :string(255) +# id :integer not null, primary key +# default_projects_limit :integer +# default_branch_protection :interger +# signup_enabled :boolean +# signin_enabled :boolean +# gravatar_enabled :boolean +# sign_in_text :text +# created_at :datetime +# updated_at :datetime +# home_page_url :string(255) # require 'spec_helper' -- cgit v1.2.1 From 2a4502111e03c233861b545ae3ff3afd95614c4a Mon Sep 17 00:00:00 2001 From: Marco Wessel Date: Sun, 25 Jan 2015 22:23:28 +0100 Subject: Spelling error --- spec/models/application_setting_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index ac68e3d925f..cd6d03e6c1a 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -4,7 +4,7 @@ # # id :integer not null, primary key # default_projects_limit :integer -# default_branch_protection :interger +# default_branch_protection :integer # signup_enabled :boolean # signin_enabled :boolean # gravatar_enabled :boolean -- cgit v1.2.1 From 33913f9b8fef1f8df45dc26239faf8fa4cffc982 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 26 Jan 2015 22:08:27 -0800 Subject: Make issue tracker service fields required. --- spec/models/jira_service_spec.rb | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 spec/models/jira_service_spec.rb (limited to 'spec/models') diff --git a/spec/models/jira_service_spec.rb b/spec/models/jira_service_spec.rb new file mode 100644 index 00000000000..0c73a68c924 --- /dev/null +++ b/spec/models/jira_service_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe JiraService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Validations" do + context "active" do + before do + subject.active = true + end + + it { should validate_presence_of :project_url } + it { should validate_presence_of :issues_url } + it { should validate_presence_of :new_issue_url } + end + end + + describe 'description and title' do + let(:project) { create(:project) } + + context 'when it is not set' do + before do + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be initialized' do + expect(@service.title).to eq('JIRA') + expect(@service.description).to eq("Jira issue tracker") + end + end + + context 'when it is set' do + before do + properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' } + @service = project.create_jira_service(active: true, properties: properties) + end + + after do + @service.destroy! + end + + it "should be correct" do + expect(@service.title).to eq('Jira One') + expect(@service.description).to eq('Jira One issue tracker') + end + end + end + + describe 'project and issue urls' do + let(:project) { create(:project) } + + context 'when gitlab.yml was initialized' do + before do + settings = { "jira" => { + "title" => "Jira", + "project_url" => "http://jira.sample/projects/project_a", + "issues_url" => "http://jira.sample/issues/:id", + "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" + } + } + Gitlab.config.stub(:issues_tracker).and_return(settings) + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be prepopulated with the settings' do + expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a') + expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id") + expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new") + end + end + end +end -- cgit v1.2.1 From 93bc2d5202e5802bd31419d05232b62355516a53 Mon Sep 17 00:00:00 2001 From: Boyan Tabakov Date: Thu, 21 Aug 2014 13:53:32 +0300 Subject: Added support for firing system hooks on group create/destroy and adding/removing users to group. Added tests and updated docs. Also adding 'user_id' field in the hooks for adding/removing user from team. --- spec/models/system_hook_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'spec/models') diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb index 4ab5261dc9d..8deb732de9c 100644 --- a/spec/models/system_hook_spec.rb +++ b/spec/models/system_hook_spec.rb @@ -61,5 +61,40 @@ describe SystemHook do project.project_members.destroy_all WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once end + + it 'group create hook' do + create(:group) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_create/ + ).once + end + + it 'group destroy hook' do + group = create(:group) + group.destroy + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_destroy/ + ).once + end + + it 'group member create hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_add_to_group/ + ).once + end + + it 'group member destroy hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + group.group_members.destroy_all + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_remove_from_group/ + ).once + end + end end -- cgit v1.2.1 From ed17adfbcd7f279747ac8f23da079808299b06e6 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 29 Jan 2015 12:15:15 -0500 Subject: Update shoulda-matchers This outdated gem was the cause of those annoying MiniTest errors. Also updates one use of `ensure_inclusion_of` which was deprecated in favor of `validate_inclusion_of`. --- spec/models/members_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb index 6866c4794c2..cea653ec285 100644 --- a/spec/models/members_spec.rb +++ b/spec/models/members_spec.rb @@ -10,7 +10,7 @@ describe Member do it { should validate_presence_of(:user) } it { should validate_presence_of(:source) } - it { should ensure_inclusion_of(:access_level).in_array(Gitlab::Access.values) } + it { should validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } end describe "Delegate methods" do -- cgit v1.2.1 From ab6f7164e03139889c09a6a207e9df3481e57b3b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 30 Jan 2015 15:40:04 -0500 Subject: Make the structure of spec/models match app/models --- spec/models/assembla_service_spec.rb | 48 ---------- spec/models/buildbox_service_spec.rb | 73 --------------- spec/models/flowdock_service_spec.rb | 47 ---------- spec/models/gemnasium_service_spec.rb | 43 --------- spec/models/gitlab_ci_service_spec.rb | 44 --------- spec/models/group_member_spec.rb | 46 ---------- spec/models/hooks/project_hook_spec.rb | 36 ++++++++ spec/models/hooks/service_hook_spec.rb | 24 +++++ spec/models/hooks/system_hook_spec.rb | 100 +++++++++++++++++++++ spec/models/hooks/web_hook_spec.rb | 74 +++++++++++++++ spec/models/jira_service_spec.rb | 83 ----------------- spec/models/members/group_member_spec.rb | 46 ++++++++++ spec/models/members/project_member_spec.rb | 92 +++++++++++++++++++ spec/models/project_hook_spec.rb | 36 -------- spec/models/project_member_spec.rb | 92 ------------------- .../project_services/assembla_service_spec.rb | 48 ++++++++++ .../project_services/buildbox_service_spec.rb | 73 +++++++++++++++ .../project_services/flowdock_service_spec.rb | 47 ++++++++++ .../project_services/gemnasium_service_spec.rb | 43 +++++++++ .../project_services/gitlab_ci_service_spec.rb | 44 +++++++++ spec/models/project_services/jira_service_spec.rb | 83 +++++++++++++++++ .../project_services/pushover_service_spec.rb | 69 ++++++++++++++ spec/models/project_services/slack_message_spec.rb | 65 ++++++++++++++ spec/models/project_services/slack_service_spec.rb | 57 ++++++++++++ spec/models/pushover_service_spec.rb | 69 -------------- spec/models/service_hook_spec.rb | 24 ----- spec/models/slack_message_spec.rb | 65 -------------- spec/models/slack_service_spec.rb | 57 ------------ spec/models/system_hook_spec.rb | 100 --------------------- spec/models/web_hook_spec.rb | 74 --------------- 30 files changed, 901 insertions(+), 901 deletions(-) delete mode 100644 spec/models/assembla_service_spec.rb delete mode 100644 spec/models/buildbox_service_spec.rb delete mode 100644 spec/models/flowdock_service_spec.rb delete mode 100644 spec/models/gemnasium_service_spec.rb delete mode 100644 spec/models/gitlab_ci_service_spec.rb delete mode 100644 spec/models/group_member_spec.rb create mode 100644 spec/models/hooks/project_hook_spec.rb create mode 100644 spec/models/hooks/service_hook_spec.rb create mode 100644 spec/models/hooks/system_hook_spec.rb create mode 100644 spec/models/hooks/web_hook_spec.rb delete mode 100644 spec/models/jira_service_spec.rb create mode 100644 spec/models/members/group_member_spec.rb create mode 100644 spec/models/members/project_member_spec.rb delete mode 100644 spec/models/project_hook_spec.rb delete mode 100644 spec/models/project_member_spec.rb create mode 100644 spec/models/project_services/assembla_service_spec.rb create mode 100644 spec/models/project_services/buildbox_service_spec.rb create mode 100644 spec/models/project_services/flowdock_service_spec.rb create mode 100644 spec/models/project_services/gemnasium_service_spec.rb create mode 100644 spec/models/project_services/gitlab_ci_service_spec.rb create mode 100644 spec/models/project_services/jira_service_spec.rb create mode 100644 spec/models/project_services/pushover_service_spec.rb create mode 100644 spec/models/project_services/slack_message_spec.rb create mode 100644 spec/models/project_services/slack_service_spec.rb delete mode 100644 spec/models/pushover_service_spec.rb delete mode 100644 spec/models/service_hook_spec.rb delete mode 100644 spec/models/slack_message_spec.rb delete mode 100644 spec/models/slack_service_spec.rb delete mode 100644 spec/models/system_hook_spec.rb delete mode 100644 spec/models/web_hook_spec.rb (limited to 'spec/models') diff --git a/spec/models/assembla_service_spec.rb b/spec/models/assembla_service_spec.rb deleted file mode 100644 index 005dd41fea9..00000000000 --- a/spec/models/assembla_service_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe AssemblaService, models: true do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @assembla_service = AssemblaService.new - @assembla_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret', - subdomain: 'project_name' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' - WebMock.stub_request(:post, @api_url) - end - - it "should call Assembla API" do - @assembla_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( - body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ - ).once - end - end -end diff --git a/spec/models/buildbox_service_spec.rb b/spec/models/buildbox_service_spec.rb deleted file mode 100644 index 1d9ca51be16..00000000000 --- a/spec/models/buildbox_service_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe BuildboxService do - describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe 'commits methods' do - before do - @project = Project.new - @project.stub( - default_branch: 'default-brancho' - ) - - @service = BuildboxService.new - @service.stub( - project: @project, - service_hook: true, - project_url: 'https://buildbox.io/account-name/example-project', - token: 'secret-sauce-webhook-token:secret-sauce-status-token' - ) - end - - describe :webhook_url do - it 'returns the webhook url' do - @service.webhook_url.should == - 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token' - end - end - - describe :commit_status_path do - it 'returns the correct status page' do - @service.commit_status_path('2ab7834c').should == - 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c' - end - end - - describe :build_page do - it 'returns the correct build page' do - @service.build_page('2ab7834c').should == - 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c' - end - end - - describe :builds_page do - it 'returns the correct path to the builds page' do - @service.builds_path.should == - 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho' - end - end - - describe :status_img_path do - it 'returns the correct path to the status image' do - @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg' - end - end - end -end diff --git a/spec/models/flowdock_service_spec.rb b/spec/models/flowdock_service_spec.rb deleted file mode 100644 index ac156719b43..00000000000 --- a/spec/models/flowdock_service_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe FlowdockService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @flowdock_service = FlowdockService.new - @flowdock_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - @api_url = 'https://api.flowdock.com/v1/git/verySecret' - WebMock.stub_request(:post, @api_url) - end - - it "should call FlowDock API" do - @flowdock_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( - body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ - ).once - end - end -end diff --git a/spec/models/gemnasium_service_spec.rb b/spec/models/gemnasium_service_spec.rb deleted file mode 100644 index 2c560c11dac..00000000000 --- a/spec/models/gemnasium_service_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe GemnasiumService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @gemnasium_service = GemnasiumService.new - @gemnasium_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret', - api_key: 'GemnasiumUserApiKey' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - end - it "should call Gemnasium service" do - Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once - @gemnasium_service.execute(@sample_data) - end - end -end diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb deleted file mode 100644 index 83277058fbb..00000000000 --- a/spec/models/gitlab_ci_service_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe GitlabCiService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Mass assignment" do - end - - describe 'commits methods' do - before do - @service = GitlabCiService.new - @service.stub( - service_hook: true, - project_url: 'http://ci.gitlab.org/projects/2', - token: 'verySecret' - ) - end - - describe :commit_status_path do - it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} - end - - describe :build_page do - it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} - end - end -end diff --git a/spec/models/group_member_spec.rb b/spec/models/group_member_spec.rb deleted file mode 100644 index 38657de6793..00000000000 --- a/spec/models/group_member_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# == Schema Information -# -# Table name: members -# -# id :integer not null, primary key -# access_level :integer not null -# source_id :integer not null -# source_type :string(255) not null -# user_id :integer not null -# notification_level :integer not null -# type :string(255) -# created_at :datetime -# updated_at :datetime -# - -require 'spec_helper' - -describe GroupMember do - context 'notification' do - describe "#after_create" do - it "should send email to user" do - membership = build(:group_member) - membership.stub(notification_service: double('NotificationService').as_null_object) - membership.should_receive(:notification_service) - membership.save - end - end - - describe "#after_update" do - before do - @membership = create :group_member - @membership.stub(notification_service: double('NotificationService').as_null_object) - end - - it "should send email to user" do - @membership.should_receive(:notification_service) - @membership.update_attribute(:access_level, GroupMember::MASTER) - end - - it "does not send an email when the access level has not changed" do - @membership.should_not_receive(:notification_service) - @membership.update_attribute(:access_level, GroupMember::OWNER) - end - end - end -end diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb new file mode 100644 index 00000000000..4e0d50d7f3f --- /dev/null +++ b/spec/models/hooks/project_hook_spec.rb @@ -0,0 +1,36 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require 'spec_helper' + +describe ProjectHook do + describe '.push_hooks' do + it 'should return hooks for push events only' do + hook = create(:project_hook, push_events: true) + hook2 = create(:project_hook, push_events: false) + expect(ProjectHook.push_hooks).to eq([hook]) + end + end + + describe '.tag_push_hooks' do + it 'should return hooks for tag push events only' do + hook = create(:project_hook, tag_push_events: true) + hook2 = create(:project_hook, tag_push_events: false) + expect(ProjectHook.tag_push_hooks).to eq([hook]) + end + end +end diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb new file mode 100644 index 00000000000..6ec82438dfe --- /dev/null +++ b/spec/models/hooks/service_hook_spec.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require "spec_helper" + +describe ServiceHook do + describe "Associations" do + it { should belong_to :service } + end +end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb new file mode 100644 index 00000000000..8deb732de9c --- /dev/null +++ b/spec/models/hooks/system_hook_spec.rb @@ -0,0 +1,100 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require "spec_helper" + +describe SystemHook do + describe "execute" do + before(:each) do + @system_hook = create(:system_hook) + WebMock.stub_request(:post, @system_hook.url) + end + + it "project_create hook" do + Projects::CreateService.new(create(:user), name: 'empty').execute + WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once + end + + it "project_destroy hook" do + user = create(:user) + project = create(:empty_project, namespace: user.namespace) + Projects::DestroyService.new(project, user, {}).execute + WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once + end + + it "user_create hook" do + create(:user) + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once + end + + it "user_destroy hook" do + user = create(:user) + user.destroy + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once + end + + it "project_create hook" do + user = create(:user) + project = create(:project) + project.team << [user, :master] + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once + end + + it "project_destroy hook" do + user = create(:user) + project = create(:project) + project.team << [user, :master] + project.project_members.destroy_all + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once + end + + it 'group create hook' do + create(:group) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_create/ + ).once + end + + it 'group destroy hook' do + group = create(:group) + group.destroy + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_destroy/ + ).once + end + + it 'group member create hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_add_to_group/ + ).once + end + + it 'group member destroy hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + group.group_members.destroy_all + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_remove_from_group/ + ).once + end + + end +end diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb new file mode 100644 index 00000000000..e9c04ee89cb --- /dev/null +++ b/spec/models/hooks/web_hook_spec.rb @@ -0,0 +1,74 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require 'spec_helper' + +describe ProjectHook do + describe "Associations" do + it { should belong_to :project } + end + + describe "Mass assignment" do + end + + describe "Validations" do + it { should validate_presence_of(:url) } + + context "url format" do + it { should allow_value("http://example.com").for(:url) } + it { should allow_value("https://excample.com").for(:url) } + it { should allow_value("http://test.com/api").for(:url) } + it { should allow_value("http://test.com/api?key=abc").for(:url) } + it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) } + + it { should_not allow_value("example.com").for(:url) } + it { should_not allow_value("ftp://example.com").for(:url) } + it { should_not allow_value("herp-and-derp").for(:url) } + end + end + + describe "execute" do + before(:each) do + @project_hook = create(:project_hook) + @project = create(:project) + @project.hooks << [@project_hook] + @data = { before: 'oldrev', after: 'newrev', ref: 'ref'} + + WebMock.stub_request(:post, @project_hook.url) + end + + it "POSTs to the web hook URL" do + @project_hook.execute(@data) + WebMock.should have_requested(:post, @project_hook.url).once + end + + it "POSTs the data as JSON" do + json = @data.to_json + + @project_hook.execute(@data) + WebMock.should have_requested(:post, @project_hook.url).with(body: json).once + end + + it "catches exceptions" do + WebHook.should_receive(:post).and_raise("Some HTTP Post error") + + lambda { + @project_hook.execute(@data) + }.should raise_error + end + end +end diff --git a/spec/models/jira_service_spec.rb b/spec/models/jira_service_spec.rb deleted file mode 100644 index 0c73a68c924..00000000000 --- a/spec/models/jira_service_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'spec_helper' - -describe JiraService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Validations" do - context "active" do - before do - subject.active = true - end - - it { should validate_presence_of :project_url } - it { should validate_presence_of :issues_url } - it { should validate_presence_of :new_issue_url } - end - end - - describe 'description and title' do - let(:project) { create(:project) } - - context 'when it is not set' do - before do - @service = project.create_jira_service(active: true) - end - - after do - @service.destroy! - end - - it 'should be initialized' do - expect(@service.title).to eq('JIRA') - expect(@service.description).to eq("Jira issue tracker") - end - end - - context 'when it is set' do - before do - properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' } - @service = project.create_jira_service(active: true, properties: properties) - end - - after do - @service.destroy! - end - - it "should be correct" do - expect(@service.title).to eq('Jira One') - expect(@service.description).to eq('Jira One issue tracker') - end - end - end - - describe 'project and issue urls' do - let(:project) { create(:project) } - - context 'when gitlab.yml was initialized' do - before do - settings = { "jira" => { - "title" => "Jira", - "project_url" => "http://jira.sample/projects/project_a", - "issues_url" => "http://jira.sample/issues/:id", - "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" - } - } - Gitlab.config.stub(:issues_tracker).and_return(settings) - @service = project.create_jira_service(active: true) - end - - after do - @service.destroy! - end - - it 'should be prepopulated with the settings' do - expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a') - expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id") - expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new") - end - end - end -end diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb new file mode 100644 index 00000000000..38657de6793 --- /dev/null +++ b/spec/models/members/group_member_spec.rb @@ -0,0 +1,46 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe GroupMember do + context 'notification' do + describe "#after_create" do + it "should send email to user" do + membership = build(:group_member) + membership.stub(notification_service: double('NotificationService').as_null_object) + membership.should_receive(:notification_service) + membership.save + end + end + + describe "#after_update" do + before do + @membership = create :group_member + @membership.stub(notification_service: double('NotificationService').as_null_object) + end + + it "should send email to user" do + @membership.should_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::MASTER) + end + + it "does not send an email when the access level has not changed" do + @membership.should_not_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::OWNER) + end + end + end +end diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb new file mode 100644 index 00000000000..9b5f89b6d7d --- /dev/null +++ b/spec/models/members/project_member_spec.rb @@ -0,0 +1,92 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe ProjectMember do + describe :import_team do + before do + @abilities = Six.new + @abilities << Ability + + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + @project_1.team << [ @user_1, :developer ] + @project_2.team << [ @user_2, :reporter ] + + @status = @project_2.team.import(@project_1) + end + + it { @status.should be_true } + + describe 'project 2 should get user 1 as developer. user_2 should not be changed' do + it { @project_2.users.should include(@user_1) } + it { @project_2.users.should include(@user_2) } + + it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true } + it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true } + end + + describe 'project 1 should not be changed' do + it { @project_1.users.should include(@user_1) } + it { @project_1.users.should_not include(@user_2) } + end + end + + describe :add_users_into_projects do + before do + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + ProjectMember.add_users_into_projects( + [@project_1.id, @project_2.id], + [@user_1.id, @user_2.id], + ProjectMember::MASTER + ) + end + + it { @project_1.users.should include(@user_1) } + it { @project_1.users.should include(@user_2) } + + + it { @project_2.users.should include(@user_1) } + it { @project_2.users.should include(@user_2) } + end + + describe :truncate_teams do + before do + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + @project_1.team << [ @user_1, :developer] + @project_2.team << [ @user_2, :reporter] + + ProjectMember.truncate_teams([@project_1.id, @project_2.id]) + end + + it { @project_1.users.should be_empty } + it { @project_2.users.should be_empty } + end +end diff --git a/spec/models/project_hook_spec.rb b/spec/models/project_hook_spec.rb deleted file mode 100644 index 4e0d50d7f3f..00000000000 --- a/spec/models/project_hook_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require 'spec_helper' - -describe ProjectHook do - describe '.push_hooks' do - it 'should return hooks for push events only' do - hook = create(:project_hook, push_events: true) - hook2 = create(:project_hook, push_events: false) - expect(ProjectHook.push_hooks).to eq([hook]) - end - end - - describe '.tag_push_hooks' do - it 'should return hooks for tag push events only' do - hook = create(:project_hook, tag_push_events: true) - hook2 = create(:project_hook, tag_push_events: false) - expect(ProjectHook.tag_push_hooks).to eq([hook]) - end - end -end diff --git a/spec/models/project_member_spec.rb b/spec/models/project_member_spec.rb deleted file mode 100644 index 9b5f89b6d7d..00000000000 --- a/spec/models/project_member_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# == Schema Information -# -# Table name: members -# -# id :integer not null, primary key -# access_level :integer not null -# source_id :integer not null -# source_type :string(255) not null -# user_id :integer not null -# notification_level :integer not null -# type :string(255) -# created_at :datetime -# updated_at :datetime -# - -require 'spec_helper' - -describe ProjectMember do - describe :import_team do - before do - @abilities = Six.new - @abilities << Ability - - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - @project_1.team << [ @user_1, :developer ] - @project_2.team << [ @user_2, :reporter ] - - @status = @project_2.team.import(@project_1) - end - - it { @status.should be_true } - - describe 'project 2 should get user 1 as developer. user_2 should not be changed' do - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } - - it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true } - it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true } - end - - describe 'project 1 should not be changed' do - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should_not include(@user_2) } - end - end - - describe :add_users_into_projects do - before do - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - ProjectMember.add_users_into_projects( - [@project_1.id, @project_2.id], - [@user_1.id, @user_2.id], - ProjectMember::MASTER - ) - end - - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should include(@user_2) } - - - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } - end - - describe :truncate_teams do - before do - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - @project_1.team << [ @user_1, :developer] - @project_2.team << [ @user_2, :reporter] - - ProjectMember.truncate_teams([@project_1.id, @project_2.id]) - end - - it { @project_1.users.should be_empty } - it { @project_2.users.should be_empty } - end -end diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb new file mode 100644 index 00000000000..005dd41fea9 --- /dev/null +++ b/spec/models/project_services/assembla_service_spec.rb @@ -0,0 +1,48 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe AssemblaService, models: true do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @assembla_service = AssemblaService.new + @assembla_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret', + subdomain: 'project_name' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' + WebMock.stub_request(:post, @api_url) + end + + it "should call Assembla API" do + @assembla_service.execute(@sample_data) + WebMock.should have_requested(:post, @api_url).with( + body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ + ).once + end + end +end diff --git a/spec/models/project_services/buildbox_service_spec.rb b/spec/models/project_services/buildbox_service_spec.rb new file mode 100644 index 00000000000..1d9ca51be16 --- /dev/null +++ b/spec/models/project_services/buildbox_service_spec.rb @@ -0,0 +1,73 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe BuildboxService do + describe 'Associations' do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe 'commits methods' do + before do + @project = Project.new + @project.stub( + default_branch: 'default-brancho' + ) + + @service = BuildboxService.new + @service.stub( + project: @project, + service_hook: true, + project_url: 'https://buildbox.io/account-name/example-project', + token: 'secret-sauce-webhook-token:secret-sauce-status-token' + ) + end + + describe :webhook_url do + it 'returns the webhook url' do + @service.webhook_url.should == + 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token' + end + end + + describe :commit_status_path do + it 'returns the correct status page' do + @service.commit_status_path('2ab7834c').should == + 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c' + end + end + + describe :build_page do + it 'returns the correct build page' do + @service.build_page('2ab7834c').should == + 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c' + end + end + + describe :builds_page do + it 'returns the correct path to the builds page' do + @service.builds_path.should == + 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho' + end + end + + describe :status_img_path do + it 'returns the correct path to the status image' do + @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg' + end + end + end +end diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb new file mode 100644 index 00000000000..ac156719b43 --- /dev/null +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -0,0 +1,47 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe FlowdockService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @flowdock_service = FlowdockService.new + @flowdock_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + @api_url = 'https://api.flowdock.com/v1/git/verySecret' + WebMock.stub_request(:post, @api_url) + end + + it "should call FlowDock API" do + @flowdock_service.execute(@sample_data) + WebMock.should have_requested(:post, @api_url).with( + body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ + ).once + end + end +end diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb new file mode 100644 index 00000000000..2c560c11dac --- /dev/null +++ b/spec/models/project_services/gemnasium_service_spec.rb @@ -0,0 +1,43 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe GemnasiumService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @gemnasium_service = GemnasiumService.new + @gemnasium_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret', + api_key: 'GemnasiumUserApiKey' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + end + it "should call Gemnasium service" do + Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once + @gemnasium_service.execute(@sample_data) + end + end +end diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb new file mode 100644 index 00000000000..83277058fbb --- /dev/null +++ b/spec/models/project_services/gitlab_ci_service_spec.rb @@ -0,0 +1,44 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe GitlabCiService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Mass assignment" do + end + + describe 'commits methods' do + before do + @service = GitlabCiService.new + @service.stub( + service_hook: true, + project_url: 'http://ci.gitlab.org/projects/2', + token: 'verySecret' + ) + end + + describe :commit_status_path do + it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} + end + + describe :build_page do + it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} + end + end +end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb new file mode 100644 index 00000000000..0c73a68c924 --- /dev/null +++ b/spec/models/project_services/jira_service_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe JiraService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Validations" do + context "active" do + before do + subject.active = true + end + + it { should validate_presence_of :project_url } + it { should validate_presence_of :issues_url } + it { should validate_presence_of :new_issue_url } + end + end + + describe 'description and title' do + let(:project) { create(:project) } + + context 'when it is not set' do + before do + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be initialized' do + expect(@service.title).to eq('JIRA') + expect(@service.description).to eq("Jira issue tracker") + end + end + + context 'when it is set' do + before do + properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' } + @service = project.create_jira_service(active: true, properties: properties) + end + + after do + @service.destroy! + end + + it "should be correct" do + expect(@service.title).to eq('Jira One') + expect(@service.description).to eq('Jira One issue tracker') + end + end + end + + describe 'project and issue urls' do + let(:project) { create(:project) } + + context 'when gitlab.yml was initialized' do + before do + settings = { "jira" => { + "title" => "Jira", + "project_url" => "http://jira.sample/projects/project_a", + "issues_url" => "http://jira.sample/issues/:id", + "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" + } + } + Gitlab.config.stub(:issues_tracker).and_return(settings) + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be prepopulated with the settings' do + expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a') + expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id") + expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new") + end + end + end +end diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb new file mode 100644 index 00000000000..f2813d66c7d --- /dev/null +++ b/spec/models/project_services/pushover_service_spec.rb @@ -0,0 +1,69 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe PushoverService do + describe 'Associations' do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe 'Validations' do + context 'active' do + before do + subject.active = true + end + + it { should validate_presence_of :api_key } + it { should validate_presence_of :user_key } + it { should validate_presence_of :priority } + end + end + + describe 'Execute' do + let(:pushover) { PushoverService.new } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + + let(:api_key) { 'verySecret' } + let(:user_key) { 'verySecret' } + let(:device) { 'myDevice' } + let(:priority) { 0 } + let(:sound) { 'bike' } + let(:api_url) { 'https://api.pushover.net/1/messages.json' } + + before do + pushover.stub( + project: project, + project_id: project.id, + service_hook: true, + api_key: api_key, + user_key: user_key, + device: device, + priority: priority, + sound: sound + ) + + WebMock.stub_request(:post, api_url) + end + + it 'should call Pushover API' do + pushover.execute(sample_data) + + WebMock.should have_requested(:post, api_url).once + end + end +end diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb new file mode 100644 index 00000000000..c530fad619b --- /dev/null +++ b/spec/models/project_services/slack_message_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe SlackMessage do + subject { SlackMessage.new(args) } + + let(:args) { + { + after: 'after', + before: 'before', + project_name: 'project_name', + ref: 'refs/heads/master', + user_name: 'user_name', + project_url: 'url' + } + } + + let(:color) { '#345' } + + context 'push' do + before do + args[:commits] = [ + { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } }, + { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } }, + ] + end + + it 'returns a message regarding pushes' do + subject.pretext.should == + 'user_name pushed to branch of '\ + ' ()' + subject.attachments.should == [ + { + text: ": message1 - author1\n"\ + ": message2 - author2", + color: color, + } + ] + end + end + + context 'new branch' do + before do + args[:before] = '000000' + end + + it 'returns a message regarding a new branch' do + subject.pretext.should == + 'user_name pushed new branch to '\ + '' + subject.attachments.should be_empty + end + end + + context 'removed branch' do + before do + args[:after] = '000000' + end + + it 'returns a message regarding a removed branch' do + subject.pretext.should == + 'user_name removed branch master from ' + subject.attachments.should be_empty + end + end +end diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb new file mode 100644 index 00000000000..34594072409 --- /dev/null +++ b/spec/models/project_services/slack_service_spec.rb @@ -0,0 +1,57 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe SlackService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Validations" do + context "active" do + before do + subject.active = true + end + + it { should validate_presence_of :webhook } + end + end + + describe "Execute" do + let(:slack) { SlackService.new } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } + + before do + slack.stub( + project: project, + project_id: project.id, + service_hook: true, + webhook: webhook_url + ) + + WebMock.stub_request(:post, webhook_url) + end + + it "should call Slack API" do + slack.execute(sample_data) + + WebMock.should have_requested(:post, webhook_url).once + end + end +end diff --git a/spec/models/pushover_service_spec.rb b/spec/models/pushover_service_spec.rb deleted file mode 100644 index f2813d66c7d..00000000000 --- a/spec/models/pushover_service_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe PushoverService do - describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe 'Validations' do - context 'active' do - before do - subject.active = true - end - - it { should validate_presence_of :api_key } - it { should validate_presence_of :user_key } - it { should validate_presence_of :priority } - end - end - - describe 'Execute' do - let(:pushover) { PushoverService.new } - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } - - let(:api_key) { 'verySecret' } - let(:user_key) { 'verySecret' } - let(:device) { 'myDevice' } - let(:priority) { 0 } - let(:sound) { 'bike' } - let(:api_url) { 'https://api.pushover.net/1/messages.json' } - - before do - pushover.stub( - project: project, - project_id: project.id, - service_hook: true, - api_key: api_key, - user_key: user_key, - device: device, - priority: priority, - sound: sound - ) - - WebMock.stub_request(:post, api_url) - end - - it 'should call Pushover API' do - pushover.execute(sample_data) - - WebMock.should have_requested(:post, api_url).once - end - end -end diff --git a/spec/models/service_hook_spec.rb b/spec/models/service_hook_spec.rb deleted file mode 100644 index 6ec82438dfe..00000000000 --- a/spec/models/service_hook_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require "spec_helper" - -describe ServiceHook do - describe "Associations" do - it { should belong_to :service } - end -end diff --git a/spec/models/slack_message_spec.rb b/spec/models/slack_message_spec.rb deleted file mode 100644 index c530fad619b..00000000000 --- a/spec/models/slack_message_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'spec_helper' - -describe SlackMessage do - subject { SlackMessage.new(args) } - - let(:args) { - { - after: 'after', - before: 'before', - project_name: 'project_name', - ref: 'refs/heads/master', - user_name: 'user_name', - project_url: 'url' - } - } - - let(:color) { '#345' } - - context 'push' do - before do - args[:commits] = [ - { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } }, - { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } }, - ] - end - - it 'returns a message regarding pushes' do - subject.pretext.should == - 'user_name pushed to branch of '\ - ' ()' - subject.attachments.should == [ - { - text: ": message1 - author1\n"\ - ": message2 - author2", - color: color, - } - ] - end - end - - context 'new branch' do - before do - args[:before] = '000000' - end - - it 'returns a message regarding a new branch' do - subject.pretext.should == - 'user_name pushed new branch to '\ - '' - subject.attachments.should be_empty - end - end - - context 'removed branch' do - before do - args[:after] = '000000' - end - - it 'returns a message regarding a removed branch' do - subject.pretext.should == - 'user_name removed branch master from ' - subject.attachments.should be_empty - end - end -end diff --git a/spec/models/slack_service_spec.rb b/spec/models/slack_service_spec.rb deleted file mode 100644 index 34594072409..00000000000 --- a/spec/models/slack_service_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe SlackService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Validations" do - context "active" do - before do - subject.active = true - end - - it { should validate_presence_of :webhook } - end - end - - describe "Execute" do - let(:slack) { SlackService.new } - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } - let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } - - before do - slack.stub( - project: project, - project_id: project.id, - service_hook: true, - webhook: webhook_url - ) - - WebMock.stub_request(:post, webhook_url) - end - - it "should call Slack API" do - slack.execute(sample_data) - - WebMock.should have_requested(:post, webhook_url).once - end - end -end diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb deleted file mode 100644 index 8deb732de9c..00000000000 --- a/spec/models/system_hook_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require "spec_helper" - -describe SystemHook do - describe "execute" do - before(:each) do - @system_hook = create(:system_hook) - WebMock.stub_request(:post, @system_hook.url) - end - - it "project_create hook" do - Projects::CreateService.new(create(:user), name: 'empty').execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once - end - - it "project_destroy hook" do - user = create(:user) - project = create(:empty_project, namespace: user.namespace) - Projects::DestroyService.new(project, user, {}).execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once - end - - it "user_create hook" do - create(:user) - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once - end - - it "user_destroy hook" do - user = create(:user) - user.destroy - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once - end - - it "project_create hook" do - user = create(:user) - project = create(:project) - project.team << [user, :master] - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once - end - - it "project_destroy hook" do - user = create(:user) - project = create(:project) - project.team << [user, :master] - project.project_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once - end - - it 'group create hook' do - create(:group) - WebMock.should have_requested(:post, @system_hook.url).with( - body: /group_create/ - ).once - end - - it 'group destroy hook' do - group = create(:group) - group.destroy - WebMock.should have_requested(:post, @system_hook.url).with( - body: /group_destroy/ - ).once - end - - it 'group member create hook' do - group = create(:group) - user = create(:user) - group.add_user(user, Gitlab::Access::MASTER) - WebMock.should have_requested(:post, @system_hook.url).with( - body: /user_add_to_group/ - ).once - end - - it 'group member destroy hook' do - group = create(:group) - user = create(:user) - group.add_user(user, Gitlab::Access::MASTER) - group.group_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with( - body: /user_remove_from_group/ - ).once - end - - end -end diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb deleted file mode 100644 index e9c04ee89cb..00000000000 --- a/spec/models/web_hook_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require 'spec_helper' - -describe ProjectHook do - describe "Associations" do - it { should belong_to :project } - end - - describe "Mass assignment" do - end - - describe "Validations" do - it { should validate_presence_of(:url) } - - context "url format" do - it { should allow_value("http://example.com").for(:url) } - it { should allow_value("https://excample.com").for(:url) } - it { should allow_value("http://test.com/api").for(:url) } - it { should allow_value("http://test.com/api?key=abc").for(:url) } - it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) } - - it { should_not allow_value("example.com").for(:url) } - it { should_not allow_value("ftp://example.com").for(:url) } - it { should_not allow_value("herp-and-derp").for(:url) } - end - end - - describe "execute" do - before(:each) do - @project_hook = create(:project_hook) - @project = create(:project) - @project.hooks << [@project_hook] - @data = { before: 'oldrev', after: 'newrev', ref: 'ref'} - - WebMock.stub_request(:post, @project_hook.url) - end - - it "POSTs to the web hook URL" do - @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).once - end - - it "POSTs the data as JSON" do - json = @data.to_json - - @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).with(body: json).once - end - - it "catches exceptions" do - WebHook.should_receive(:post).and_raise("Some HTTP Post error") - - lambda { - @project_hook.execute(@data) - }.should raise_error - end - end -end -- cgit v1.2.1 From b4d9ceb26fc4bd9125cdbd6796a618415d8f6af7 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 29 Jul 2014 17:41:55 +0200 Subject: Add Asana service Also add ability to render "service.help" in markdown --- spec/models/asana_service_spec.rb | 62 +++++++++++++++++++++++++++++++++++++++ spec/models/project_spec.rb | 1 + 2 files changed, 63 insertions(+) create mode 100644 spec/models/asana_service_spec.rb (limited to 'spec/models') diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb new file mode 100644 index 00000000000..4d4968e80ff --- /dev/null +++ b/spec/models/asana_service_spec.rb @@ -0,0 +1,62 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe AsanaService, models: true do + describe 'Associations' do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe 'Validations' do + context 'active' do + before do + subject.active = true + end + + it { should validate_presence_of :api_key } + end + end + + describe 'Execute' do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @asana = AsanaService.new + @asana.stub( + project: project, + project_id: project.id, + service_hook: true, + api_key: 'verySecret' + ) + end + + it 'should call Asana service to created a story' do + Asana::Task.should_receive(:find).with('123456').once + # Asana::Task.should_receive(:create_story).with('pushed related to #123456').once + + @asana.check_commit('related to #123456', 'pushed') + end + + it 'should call Asana service to created a story and close a task' do + Asana::Task.should_receive(:find).with('456789').twice + # Asana::Task.should_receive(:create_story).with('pushed related to #456789').once + # Asana::Task.should_receive(:modify).with(completed: true).once + + @asana.check_commit('fix #456789', 'pushed') + end + end +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 092c02d552e..035fdab849e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -51,6 +51,7 @@ describe Project do it { should have_one(:forked_project_link).dependent(:destroy) } it { should have_one(:slack_service).dependent(:destroy) } it { should have_one(:pushover_service).dependent(:destroy) } + it { should have_one(:asana_service).dependent(:destroy) } end describe 'Mass assignment' do -- cgit v1.2.1 From 3cd1eda5a4f8e4ac95ebab558e8965724481dd97 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 16 Jan 2015 12:49:50 +0100 Subject: Add restrict_to_branch to service controller And add restrict_to_branch to spec --- spec/models/asana_service_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb index 4d4968e80ff..d5d3d6c7c1c 100644 --- a/spec/models/asana_service_spec.rb +++ b/spec/models/asana_service_spec.rb @@ -27,6 +27,7 @@ describe AsanaService, models: true do end it { should validate_presence_of :api_key } + it { should validate_presence_of :restrict_to_branch } end end @@ -40,7 +41,8 @@ describe AsanaService, models: true do project: project, project_id: project.id, service_hook: true, - api_key: 'verySecret' + api_key: 'verySecret', + restrict_to_branch: 'master' ) end -- cgit v1.2.1 From f79b6af18a29f8ddececb9c64de5ff6d456d1d29 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 25 Jan 2015 10:35:16 +0100 Subject: Fix HoundCI --- spec/models/asana_service_spec.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb index d5d3d6c7c1c..7cdf346db63 100644 --- a/spec/models/asana_service_spec.rb +++ b/spec/models/asana_service_spec.rb @@ -48,15 +48,12 @@ describe AsanaService, models: true do it 'should call Asana service to created a story' do Asana::Task.should_receive(:find).with('123456').once - # Asana::Task.should_receive(:create_story).with('pushed related to #123456').once @asana.check_commit('related to #123456', 'pushed') end it 'should call Asana service to created a story and close a task' do Asana::Task.should_receive(:find).with('456789').twice - # Asana::Task.should_receive(:create_story).with('pushed related to #456789').once - # Asana::Task.should_receive(:modify).with(completed: true).once @asana.check_commit('fix #456789', 'pushed') end -- cgit v1.2.1 From d56c2a9bc58091f906b8d0001600bad448847d4f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 27 Jan 2015 14:28:11 +0100 Subject: Fix test Related https://semaphoreapp.com/gitlabhq/gitlabhq/branches/pull-request-8580/builds/9 Asana service doesn't check if restrict_to_branch is defined since it can be undefined --- spec/models/asana_service_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb index 7cdf346db63..6bebb76f8c7 100644 --- a/spec/models/asana_service_spec.rb +++ b/spec/models/asana_service_spec.rb @@ -27,7 +27,6 @@ describe AsanaService, models: true do end it { should validate_presence_of :api_key } - it { should validate_presence_of :restrict_to_branch } end end -- cgit v1.2.1 From c0acb28c4ec710c90eb55dc996251a30001c8e79 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 2 Feb 2015 10:24:40 -0800 Subject: Annotate models --- spec/models/project_services/jira_service_spec.rb | 14 ++++++++++++++ spec/models/project_spec.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 0c73a68c924..99ca04eff6e 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + require 'spec_helper' describe JiraService do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 092c02d552e..4669a9fd87d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -14,7 +14,7 @@ # merge_requests_enabled :boolean default(TRUE), not null # wiki_enabled :boolean default(TRUE), not null # namespace_id :integer -# issues_tracker :string(255) default('gitlab'), not null +# issues_tracker :string(255) default("gitlab"), not null # issues_tracker_id :string(255) # snippets_enabled :boolean default(TRUE), not null # last_activity_at :datetime -- cgit v1.2.1 From c5be267e40c0ba05c2a7de6a71d154f1b5161160 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 5 Feb 2015 20:21:21 -0800 Subject: Refactor issuable sorting a bit --- spec/models/user_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 83341e516a5..629d51b960d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -474,7 +474,7 @@ describe User do @user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha' @user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega' end - + it "sorts users as recently_signed_in" do User.sort('recent_sign_in').first.should == @user end @@ -484,11 +484,11 @@ describe User do end it "sorts users as recently_created" do - User.sort('recently_created').first.should == @user + User.sort('created_desc').first.should == @user end it "sorts users as late_created" do - User.sort('late_created').first.should == @user1 + User.sort('created_asc').first.should == @user1 end it "sorts users by name when nil is passed" do -- cgit v1.2.1 From b3f944a3983db179fdaee0a1f0618c94600be823 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 11 Feb 2015 18:08:53 -0800 Subject: Annotate services. Add a link to service template. --- spec/models/service_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index c96f2b20529..10cbafebd95 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -5,11 +5,12 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# project_id :integer not null +# project_id :integer # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null # properties :text +# template :boolean default(FALSE) # require 'spec_helper' -- cgit v1.2.1 From 0c4a70a306b871899bf87ce4673918abfee4d95f Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Thu, 12 Feb 2015 19:17:35 +0100 Subject: Updated rspec to rspec 3.x syntax Signed-off-by: Jeroen van Baarsen --- spec/models/application_setting_spec.rb | 2 +- spec/models/asana_service_spec.rb | 10 +- spec/models/broadcast_message_spec.rb | 8 +- spec/models/commit_spec.rb | 42 +-- spec/models/concerns/issuable_spec.rb | 46 ++-- spec/models/concerns/mentionable_spec.rb | 4 +- spec/models/deploy_key_spec.rb | 4 +- spec/models/deploy_keys_project_spec.rb | 8 +- spec/models/event_spec.rb | 24 +- spec/models/forked_project_link_spec.rb | 10 +- spec/models/group_spec.rb | 30 +-- spec/models/hooks/service_hook_spec.rb | 2 +- spec/models/hooks/system_hook_spec.rb | 20 +- spec/models/hooks/web_hook_spec.rb | 30 +-- spec/models/issue_spec.rb | 10 +- spec/models/key_spec.rb | 28 +- spec/models/label_link_spec.rb | 6 +- spec/models/label_spec.rb | 30 +-- spec/models/members/group_member_spec.rb | 6 +- spec/models/members/project_member_spec.rb | 26 +- spec/models/members_spec.rb | 12 +- spec/models/merge_request_spec.rb | 32 +-- spec/models/milestone_spec.rb | 42 +-- spec/models/namespace_spec.rb | 30 +-- spec/models/note_spec.rb | 291 +++++++++++++++------ spec/models/project_security_spec.rb | 18 +- .../project_services/assembla_service_spec.rb | 6 +- .../project_services/buildbox_service_spec.rb | 18 +- .../project_services/flowdock_service_spec.rb | 6 +- .../project_services/gemnasium_service_spec.rb | 6 +- .../project_services/gitlab_ci_service_spec.rb | 8 +- spec/models/project_services/jira_service_spec.rb | 12 +- .../project_services/pushover_service_spec.rb | 12 +- spec/models/project_services/slack_message_spec.rb | 17 +- spec/models/project_services/slack_service_spec.rb | 8 +- spec/models/project_snippet_spec.rb | 4 +- spec/models/project_spec.rb | 130 ++++----- spec/models/project_team_spec.rb | 44 ++-- spec/models/project_wiki_spec.rb | 80 +++--- spec/models/protected_branch_spec.rb | 6 +- spec/models/repository_spec.rb | 8 +- spec/models/service_spec.rb | 8 +- spec/models/snippet_spec.rb | 16 +- spec/models/user_spec.rb | 196 +++++++------- spec/models/wiki_page_spec.rb | 30 +-- 45 files changed, 758 insertions(+), 628 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index cd6d03e6c1a..cb43fdb7fc7 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -17,5 +17,5 @@ require 'spec_helper' describe ApplicationSetting, models: true do - it { ApplicationSetting.create_from_defaults.should be_valid } + it { expect(ApplicationSetting.create_from_defaults).to be_valid } end diff --git a/spec/models/asana_service_spec.rb b/spec/models/asana_service_spec.rb index 6bebb76f8c7..83e39f87f33 100644 --- a/spec/models/asana_service_spec.rb +++ b/spec/models/asana_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe AsanaService, models: true do describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe 'Validations' do @@ -26,7 +26,7 @@ describe AsanaService, models: true do subject.active = true end - it { should validate_presence_of :api_key } + it { is_expected.to validate_presence_of :api_key } end end @@ -46,13 +46,13 @@ describe AsanaService, models: true do end it 'should call Asana service to created a story' do - Asana::Task.should_receive(:find).with('123456').once + expect(Asana::Task).to receive(:find).with('123456').once @asana.check_commit('related to #123456', 'pushed') end it 'should call Asana service to created a story and close a task' do - Asana::Task.should_receive(:find).with('456789').twice + expect(Asana::Task).to receive(:find).with('456789').twice @asana.check_commit('fix #456789', 'pushed') end diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 0f31c407c90..8ab72151a69 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -18,22 +18,22 @@ require 'spec_helper' describe BroadcastMessage do subject { create(:broadcast_message) } - it { should be_valid } + it { is_expected.to be_valid } describe :current do it "should return last message if time match" do broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow) - BroadcastMessage.current.should == broadcast_message + expect(BroadcastMessage.current).to eq(broadcast_message) end it "should return nil if time not come" do broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) - BroadcastMessage.current.should be_nil + expect(BroadcastMessage.current).to be_nil end it "should return nil if time has passed" do broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) - BroadcastMessage.current.should be_nil + expect(BroadcastMessage.current).to be_nil end end end diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 7a2a7a4ce9b..8b3d88640da 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -6,22 +6,22 @@ describe Commit do describe '#title' do it "returns no_commit_message when safe_message is blank" do - commit.stub(:safe_message).and_return('') - commit.title.should == "--no commit message" + allow(commit).to receive(:safe_message).and_return('') + expect(commit.title).to eq("--no commit message") end it "truncates a message without a newline at 80 characters" do message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.' - commit.stub(:safe_message).and_return(message) - commit.title.should == "#{message[0..79]}…" + allow(commit).to receive(:safe_message).and_return(message) + expect(commit.title).to eq("#{message[0..79]}…") end it "truncates a message with a newline before 80 characters at the newline" do message = commit.safe_message.split(" ").first - commit.stub(:safe_message).and_return(message + "\n" + message) - commit.title.should == message + allow(commit).to receive(:safe_message).and_return(message + "\n" + message) + expect(commit.title).to eq(message) end it "does not truncates a message with a newline after 80 but less 100 characters" do @@ -30,25 +30,25 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis Vivamus egestas lacinia lacus, sed rutrum mauris. eos - commit.stub(:safe_message).and_return(message) - commit.title.should == message.split("\n").first + allow(commit).to receive(:safe_message).and_return(message) + expect(commit.title).to eq(message.split("\n").first) end end describe "delegation" do subject { commit } - it { should respond_to(:message) } - it { should respond_to(:authored_date) } - it { should respond_to(:committed_date) } - it { should respond_to(:committer_email) } - it { should respond_to(:author_email) } - it { should respond_to(:parents) } - it { should respond_to(:date) } - it { should respond_to(:diffs) } - it { should respond_to(:tree) } - it { should respond_to(:id) } - it { should respond_to(:to_patch) } + it { is_expected.to respond_to(:message) } + it { is_expected.to respond_to(:authored_date) } + it { is_expected.to respond_to(:committed_date) } + it { is_expected.to respond_to(:committer_email) } + it { is_expected.to respond_to(:author_email) } + it { is_expected.to respond_to(:parents) } + it { is_expected.to respond_to(:date) } + it { is_expected.to respond_to(:diffs) } + it { is_expected.to respond_to(:tree) } + it { is_expected.to respond_to(:id) } + it { is_expected.to respond_to(:to_patch) } end describe '#closes_issues' do @@ -58,13 +58,13 @@ eos it 'detects issues that this commit is marked as closing' do commit.stub(safe_message: "Fixes ##{issue.iid}") - commit.closes_issues(project).should == [issue] + expect(commit.closes_issues(project)).to eq([issue]) end it 'does not detect issues from other projects' do ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}" commit.stub(safe_message: "Fixes #{ext_ref}") - commit.closes_issues(project).should be_empty + expect(commit.closes_issues(project)).to be_empty end end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 9cbc8990676..557c71b4d2c 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -4,63 +4,63 @@ describe Issue, "Issuable" do let(:issue) { create(:issue) } describe "Associations" do - it { should belong_to(:project) } - it { should belong_to(:author) } - it { should belong_to(:assignee) } - it { should have_many(:notes).dependent(:destroy) } + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:author) } + it { is_expected.to belong_to(:assignee) } + it { is_expected.to have_many(:notes).dependent(:destroy) } end describe "Validation" do before { subject.stub(set_iid: false) } - it { should validate_presence_of(:project) } - it { should validate_presence_of(:iid) } - it { should validate_presence_of(:author) } - it { should validate_presence_of(:title) } - it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) } + it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:iid) } + it { is_expected.to validate_presence_of(:author) } + it { is_expected.to validate_presence_of(:title) } + it { is_expected.to ensure_length_of(:title).is_at_least(0).is_at_most(255) } end describe "Scope" do - it { described_class.should respond_to(:opened) } - it { described_class.should respond_to(:closed) } - it { described_class.should respond_to(:assigned) } + it { expect(described_class).to respond_to(:opened) } + it { expect(described_class).to respond_to(:closed) } + it { expect(described_class).to respond_to(:assigned) } end describe ".search" do let!(:searchable_issue) { create(:issue, title: "Searchable issue") } it "matches by title" do - described_class.search('able').should == [searchable_issue] + expect(described_class.search('able')).to eq([searchable_issue]) end end describe "#today?" do it "returns true when created today" do # Avoid timezone differences and just return exactly what we want - Date.stub(:today).and_return(issue.created_at.to_date) - issue.today?.should be_true + allow(Date).to receive(:today).and_return(issue.created_at.to_date) + expect(issue.today?).to be_truthy end it "returns false when not created today" do - Date.stub(:today).and_return(Date.yesterday) - issue.today?.should be_false + allow(Date).to receive(:today).and_return(Date.yesterday) + expect(issue.today?).to be_falsey end end describe "#new?" do it "returns true when created today and record hasn't been updated" do - issue.stub(:today?).and_return(true) - issue.new?.should be_true + allow(issue).to receive(:today?).and_return(true) + expect(issue.new?).to be_truthy end it "returns false when not created today" do - issue.stub(:today?).and_return(false) - issue.new?.should be_false + allow(issue).to receive(:today?).and_return(false) + expect(issue.new?).to be_falsey end it "returns false when record has been updated" do - issue.stub(:today?).and_return(true) + allow(issue).to receive(:today?).and_return(true) issue.touch - issue.new?.should be_false + expect(issue.new?).to be_falsey end end end diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index ca6f11b2a4d..eadb941a3fa 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -8,7 +8,7 @@ describe Issue, "Mentionable" do subject { issue.mentioned_users } - it { should include(user) } - it { should_not include(user2) } + it { is_expected.to include(user) } + it { is_expected.not_to include(user2) } end end diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb index adbbbac875f..b32be8d7a7c 100644 --- a/spec/models/deploy_key_spec.rb +++ b/spec/models/deploy_key_spec.rb @@ -19,7 +19,7 @@ describe DeployKey do let(:deploy_key) { create(:deploy_key, projects: [project]) } describe "Associations" do - it { should have_many(:deploy_keys_projects) } - it { should have_many(:projects) } + it { is_expected.to have_many(:deploy_keys_projects) } + it { is_expected.to have_many(:projects) } end end diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb index 3e0e25ee39a..aacd9bf38bf 100644 --- a/spec/models/deploy_keys_project_spec.rb +++ b/spec/models/deploy_keys_project_spec.rb @@ -13,12 +13,12 @@ require 'spec_helper' describe DeployKeysProject do describe "Associations" do - it { should belong_to(:deploy_key) } - it { should belong_to(:project) } + it { is_expected.to belong_to(:deploy_key) } + it { is_expected.to belong_to(:project) } end describe "Validation" do - it { should validate_presence_of(:project_id) } - it { should validate_presence_of(:deploy_key_id) } + it { is_expected.to validate_presence_of(:project_id) } + it { is_expected.to validate_presence_of(:deploy_key_id) } end end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 204ae9da704..0f32f162a10 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -18,16 +18,16 @@ require 'spec_helper' describe Event do describe "Associations" do - it { should belong_to(:project) } - it { should belong_to(:target) } + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:target) } end describe "Respond to" do - it { should respond_to(:author_name) } - it { should respond_to(:author_email) } - it { should respond_to(:issue_title) } - it { should respond_to(:merge_request_title) } - it { should respond_to(:commits) } + it { is_expected.to respond_to(:author_name) } + it { is_expected.to respond_to(:author_email) } + it { is_expected.to respond_to(:issue_title) } + it { is_expected.to respond_to(:merge_request_title) } + it { is_expected.to respond_to(:commits) } end describe "Push event" do @@ -58,10 +58,10 @@ describe Event do ) end - it { @event.push?.should be_true } - it { @event.proper?.should be_true } - it { @event.tag?.should be_false } - it { @event.branch_name.should == "master" } - it { @event.author.should == @user } + it { expect(@event.push?).to be_truthy } + it { expect(@event.proper?).to be_truthy } + it { expect(@event.tag?).to be_falsey } + it { expect(@event.branch_name).to eq("master") } + it { expect(@event.author).to eq(@user) } end end diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 1845c6103f5..7d0ad44a92c 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -21,11 +21,11 @@ describe ForkedProjectLink, "add link on fork" do end it "project_to should know it is forked" do - @project_to.forked?.should be_true + expect(@project_to.forked?).to be_truthy end it "project should know who it is forked from" do - @project_to.forked_from_project.should == project_from + expect(@project_to.forked_from_project).to eq(project_from) end end @@ -43,15 +43,15 @@ describe :forked_from_project do it "project_to should know it is forked" do - project_to.forked?.should be_true + expect(project_to.forked?).to be_truthy end it "project_from should not be forked" do - project_from.forked?.should be_false + expect(project_from.forked?).to be_falsey end it "project_to.destroy should destroy fork_link" do - forked_project_link.should_receive(:destroy) + expect(forked_project_link).to receive(:destroy) project_to.destroy end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 1d4ba8a2b85..9428224a64f 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -19,29 +19,29 @@ describe Group do let!(:group) { create(:group) } describe "Associations" do - it { should have_many :projects } - it { should have_many :group_members } + it { is_expected.to have_many :projects } + it { is_expected.to have_many :group_members } end - it { should validate_presence_of :name } - it { should validate_uniqueness_of(:name) } - it { should validate_presence_of :path } - it { should validate_uniqueness_of(:path) } - it { should_not validate_presence_of :owner } + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_uniqueness_of(:name) } + it { is_expected.to validate_presence_of :path } + it { is_expected.to validate_uniqueness_of(:path) } + it { is_expected.not_to validate_presence_of :owner } describe :users do - it { group.users.should == group.owners } + it { expect(group.users).to eq(group.owners) } end describe :human_name do - it { group.human_name.should == group.name } + it { expect(group.human_name).to eq(group.name) } end describe :add_users do let(:user) { create(:user) } before { group.add_user(user, GroupMember::MASTER) } - it { group.group_members.masters.map(&:user).should include(user) } + it { expect(group.group_members.masters.map(&:user)).to include(user) } end describe :add_users do @@ -49,10 +49,10 @@ describe Group do before { group.add_users([user.id], GroupMember::GUEST) } it "should update the group permission" do - group.group_members.guests.map(&:user).should include(user) + expect(group.group_members.guests.map(&:user)).to include(user) group.add_users([user.id], GroupMember::DEVELOPER) - group.group_members.developers.map(&:user).should include(user) - group.group_members.guests.map(&:user).should_not include(user) + expect(group.group_members.developers.map(&:user)).to include(user) + expect(group.group_members.guests.map(&:user)).not_to include(user) end end @@ -62,12 +62,12 @@ describe Group do it "should be true if avatar is image" do group.update_attribute(:avatar, 'uploads/avatar.png') - group.avatar_type.should be_true + expect(group.avatar_type).to be_truthy end it "should be false if avatar is html page" do group.update_attribute(:avatar, 'uploads/avatar.html') - group.avatar_type.should == ["only images allowed"] + expect(group.avatar_type).to eq(["only images allowed"]) end end end diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb index 6ec82438dfe..96bf74d45da 100644 --- a/spec/models/hooks/service_hook_spec.rb +++ b/spec/models/hooks/service_hook_spec.rb @@ -19,6 +19,6 @@ require "spec_helper" describe ServiceHook do describe "Associations" do - it { should belong_to :service } + it { is_expected.to belong_to :service } end end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 8deb732de9c..810b311a40b 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -26,32 +26,32 @@ describe SystemHook do it "project_create hook" do Projects::CreateService.new(create(:user), name: 'empty').execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_create/).once end it "project_destroy hook" do user = create(:user) project = create(:empty_project, namespace: user.namespace) Projects::DestroyService.new(project, user, {}).execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_destroy/).once end it "user_create hook" do create(:user) - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_create/).once end it "user_destroy hook" do user = create(:user) user.destroy - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_destroy/).once end it "project_create hook" do user = create(:user) project = create(:project) project.team << [user, :master] - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once end it "project_destroy hook" do @@ -59,12 +59,12 @@ describe SystemHook do project = create(:project) project.team << [user, :master] project.project_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once + expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once end it 'group create hook' do create(:group) - WebMock.should have_requested(:post, @system_hook.url).with( + expect(WebMock).to have_requested(:post, @system_hook.url).with( body: /group_create/ ).once end @@ -72,7 +72,7 @@ describe SystemHook do it 'group destroy hook' do group = create(:group) group.destroy - WebMock.should have_requested(:post, @system_hook.url).with( + expect(WebMock).to have_requested(:post, @system_hook.url).with( body: /group_destroy/ ).once end @@ -81,7 +81,7 @@ describe SystemHook do group = create(:group) user = create(:user) group.add_user(user, Gitlab::Access::MASTER) - WebMock.should have_requested(:post, @system_hook.url).with( + expect(WebMock).to have_requested(:post, @system_hook.url).with( body: /user_add_to_group/ ).once end @@ -91,7 +91,7 @@ describe SystemHook do user = create(:user) group.add_user(user, Gitlab::Access::MASTER) group.group_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with( + expect(WebMock).to have_requested(:post, @system_hook.url).with( body: /user_remove_from_group/ ).once end diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb index e9c04ee89cb..67ec9193ad7 100644 --- a/spec/models/hooks/web_hook_spec.rb +++ b/spec/models/hooks/web_hook_spec.rb @@ -19,25 +19,25 @@ require 'spec_helper' describe ProjectHook do describe "Associations" do - it { should belong_to :project } + it { is_expected.to belong_to :project } end describe "Mass assignment" do end describe "Validations" do - it { should validate_presence_of(:url) } + it { is_expected.to validate_presence_of(:url) } context "url format" do - it { should allow_value("http://example.com").for(:url) } - it { should allow_value("https://excample.com").for(:url) } - it { should allow_value("http://test.com/api").for(:url) } - it { should allow_value("http://test.com/api?key=abc").for(:url) } - it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) } + it { is_expected.to allow_value("http://example.com").for(:url) } + it { is_expected.to allow_value("https://excample.com").for(:url) } + it { is_expected.to allow_value("http://test.com/api").for(:url) } + it { is_expected.to allow_value("http://test.com/api?key=abc").for(:url) } + it { is_expected.to allow_value("http://test.com/api?key=abc&type=def").for(:url) } - it { should_not allow_value("example.com").for(:url) } - it { should_not allow_value("ftp://example.com").for(:url) } - it { should_not allow_value("herp-and-derp").for(:url) } + it { is_expected.not_to allow_value("example.com").for(:url) } + it { is_expected.not_to allow_value("ftp://example.com").for(:url) } + it { is_expected.not_to allow_value("herp-and-derp").for(:url) } end end @@ -53,22 +53,22 @@ describe ProjectHook do it "POSTs to the web hook URL" do @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).once + expect(WebMock).to have_requested(:post, @project_hook.url).once end it "POSTs the data as JSON" do json = @data.to_json @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).with(body: json).once + expect(WebMock).to have_requested(:post, @project_hook.url).with(body: json).once end it "catches exceptions" do - WebHook.should_receive(:post).and_raise("Some HTTP Post error") + expect(WebHook).to receive(:post).and_raise("Some HTTP Post error") - lambda { + expect { @project_hook.execute(@data) - }.should raise_error + }.to raise_error end end end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 6b6efe832e5..087e40c3d84 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -21,14 +21,14 @@ require 'spec_helper' describe Issue do describe "Associations" do - it { should belong_to(:milestone) } + it { is_expected.to belong_to(:milestone) } end describe "Mass assignment" do end describe 'modules' do - it { should include_module(Issuable) } + it { is_expected.to include_module(Issuable) } end subject { create(:issue) } @@ -36,10 +36,10 @@ describe Issue do describe '#is_being_reassigned?' do it 'returns true if the issue assignee has changed' do subject.assignee = create(:user) - subject.is_being_reassigned?.should be_true + expect(subject.is_being_reassigned?).to be_truthy end it 'returns false if the issue assignee has not changed' do - subject.is_being_reassigned?.should be_false + expect(subject.is_being_reassigned?).to be_falsey end end @@ -51,7 +51,7 @@ describe Issue do issue = create :issue, assignee: user end - Issue.open_for(user).count.should eq 2 + expect(Issue.open_for(user).count).to eq 2 end end diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 95c0aed0ffe..a212b95a7d6 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -16,67 +16,67 @@ require 'spec_helper' describe Key do describe "Associations" do - it { should belong_to(:user) } + it { is_expected.to belong_to(:user) } end describe "Mass assignment" do end describe "Validation" do - it { should validate_presence_of(:title) } - it { should validate_presence_of(:key) } - it { should ensure_length_of(:title).is_within(0..255) } - it { should ensure_length_of(:key).is_within(0..5000) } + it { is_expected.to validate_presence_of(:title) } + it { is_expected.to validate_presence_of(:key) } + it { is_expected.to ensure_length_of(:title).is_within(0..255) } + it { is_expected.to ensure_length_of(:key).is_within(0..5000) } end describe "Methods" do - it { should respond_to :projects } + it { is_expected.to respond_to :projects } end context "validation of uniqueness" do let(:user) { create(:user) } it "accepts the key once" do - build(:key, user: user).should be_valid + expect(build(:key, user: user)).to be_valid end it "does not accept the exact same key twice" do create(:key, user: user) - build(:key, user: user).should_not be_valid + expect(build(:key, user: user)).not_to be_valid end it "does not accept a duplicate key with a different comment" do create(:key, user: user) duplicate = build(:key, user: user) duplicate.key << ' extra comment' - duplicate.should_not be_valid + expect(duplicate).not_to be_valid end end context "validate it is a fingerprintable key" do it "accepts the fingerprintable key" do - build(:key).should be_valid + expect(build(:key)).to be_valid end it "rejects the unfingerprintable key (contains space in middle)" do - build(:key_with_a_space_in_the_middle).should_not be_valid + expect(build(:key_with_a_space_in_the_middle)).not_to be_valid end it "rejects the unfingerprintable key (not a key)" do - build(:invalid_key).should_not be_valid + expect(build(:invalid_key)).not_to be_valid end end context 'callbacks' do it 'should add new key to authorized_file' do @key = build(:personal_key, id: 7) - GitlabShellWorker.should_receive(:perform_async).with(:add_key, @key.shell_id, @key.key) + expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, @key.shell_id, @key.key) @key.save end it 'should remove key from authorized_file' do @key = create(:personal_key) - GitlabShellWorker.should_receive(:perform_async).with(:remove_key, @key.shell_id, @key.key) + expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, @key.shell_id, @key.key) @key.destroy end end diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb index 0db60432ad3..8c240826582 100644 --- a/spec/models/label_link_spec.rb +++ b/spec/models/label_link_spec.rb @@ -14,8 +14,8 @@ require 'spec_helper' describe LabelLink do let(:label) { create(:label_link) } - it { label.should be_valid } + it { expect(label).to be_valid } - it { should belong_to(:label) } - it { should belong_to(:target) } + it { is_expected.to belong_to(:label) } + it { is_expected.to belong_to(:target) } end diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 31634648f04..8644ac46605 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -14,30 +14,30 @@ require 'spec_helper' describe Label do let(:label) { create(:label) } - it { label.should be_valid } + it { expect(label).to be_valid } - it { should belong_to(:project) } + it { is_expected.to belong_to(:project) } describe 'Validation' do it 'should validate color code' do - build(:label, color: 'G-ITLAB').should_not be_valid - build(:label, color: 'AABBCC').should_not be_valid - build(:label, color: '#AABBCCEE').should_not be_valid - build(:label, color: '#GGHHII').should_not be_valid - build(:label, color: '#').should_not be_valid - build(:label, color: '').should_not be_valid + expect(build(:label, color: 'G-ITLAB')).not_to be_valid + expect(build(:label, color: 'AABBCC')).not_to be_valid + expect(build(:label, color: '#AABBCCEE')).not_to be_valid + expect(build(:label, color: '#GGHHII')).not_to be_valid + expect(build(:label, color: '#')).not_to be_valid + expect(build(:label, color: '')).not_to be_valid - build(:label, color: '#AABBCC').should be_valid + expect(build(:label, color: '#AABBCC')).to be_valid end it 'should validate title' do - build(:label, title: 'G,ITLAB').should_not be_valid - build(:label, title: 'G?ITLAB').should_not be_valid - build(:label, title: 'G&ITLAB').should_not be_valid - build(:label, title: '').should_not be_valid + expect(build(:label, title: 'G,ITLAB')).not_to be_valid + expect(build(:label, title: 'G?ITLAB')).not_to be_valid + expect(build(:label, title: 'G&ITLAB')).not_to be_valid + expect(build(:label, title: '')).not_to be_valid - build(:label, title: 'GITLAB').should be_valid - build(:label, title: 'gitlab').should be_valid + expect(build(:label, title: 'GITLAB')).to be_valid + expect(build(:label, title: 'gitlab')).to be_valid end end end diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb index 38657de6793..e04f1741b24 100644 --- a/spec/models/members/group_member_spec.rb +++ b/spec/models/members/group_member_spec.rb @@ -21,7 +21,7 @@ describe GroupMember do it "should send email to user" do membership = build(:group_member) membership.stub(notification_service: double('NotificationService').as_null_object) - membership.should_receive(:notification_service) + expect(membership).to receive(:notification_service) membership.save end end @@ -33,12 +33,12 @@ describe GroupMember do end it "should send email to user" do - @membership.should_receive(:notification_service) + expect(@membership).to receive(:notification_service) @membership.update_attribute(:access_level, GroupMember::MASTER) end it "does not send an email when the access level has not changed" do - @membership.should_not_receive(:notification_service) + expect(@membership).not_to receive(:notification_service) @membership.update_attribute(:access_level, GroupMember::OWNER) end end diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 9b5f89b6d7d..521721f3577 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -33,19 +33,19 @@ describe ProjectMember do @status = @project_2.team.import(@project_1) end - it { @status.should be_true } + it { expect(@status).to be_truthy } describe 'project 2 should get user 1 as developer. user_2 should not be changed' do - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } + it { expect(@project_2.users).to include(@user_1) } + it { expect(@project_2.users).to include(@user_2) } - it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true } - it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true } + it { expect(@abilities.allowed?(@user_1, :write_project, @project_2)).to be_truthy } + it { expect(@abilities.allowed?(@user_2, :read_project, @project_2)).to be_truthy } end describe 'project 1 should not be changed' do - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should_not include(@user_2) } + it { expect(@project_1.users).to include(@user_1) } + it { expect(@project_1.users).not_to include(@user_2) } end end @@ -64,12 +64,12 @@ describe ProjectMember do ) end - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should include(@user_2) } + it { expect(@project_1.users).to include(@user_1) } + it { expect(@project_1.users).to include(@user_2) } - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } + it { expect(@project_2.users).to include(@user_1) } + it { expect(@project_2.users).to include(@user_2) } end describe :truncate_teams do @@ -86,7 +86,7 @@ describe ProjectMember do ProjectMember.truncate_teams([@project_1.id, @project_2.id]) end - it { @project_1.users.should be_empty } - it { @project_2.users.should be_empty } + it { expect(@project_1.users).to be_empty } + it { expect(@project_2.users).to be_empty } end end diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb index cea653ec285..dfd3f7feb6b 100644 --- a/spec/models/members_spec.rb +++ b/spec/models/members_spec.rb @@ -2,19 +2,19 @@ require 'spec_helper' describe Member do describe "Associations" do - it { should belong_to(:user) } + it { is_expected.to belong_to(:user) } end describe "Validation" do subject { Member.new(access_level: Member::GUEST) } - it { should validate_presence_of(:user) } - it { should validate_presence_of(:source) } - it { should validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } + it { is_expected.to validate_presence_of(:user) } + it { is_expected.to validate_presence_of(:source) } + it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } end describe "Delegate methods" do - it { should respond_to(:user_name) } - it { should respond_to(:user_email) } + it { is_expected.to respond_to(:user_name) } + it { is_expected.to respond_to(:user_email) } end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 9585cf09768..d40503d791c 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -25,35 +25,35 @@ require 'spec_helper' describe MergeRequest do describe "Validation" do - it { should validate_presence_of(:target_branch) } - it { should validate_presence_of(:source_branch) } + it { is_expected.to validate_presence_of(:target_branch) } + it { is_expected.to validate_presence_of(:source_branch) } end describe "Mass assignment" do end describe "Respond to" do - it { should respond_to(:unchecked?) } - it { should respond_to(:can_be_merged?) } - it { should respond_to(:cannot_be_merged?) } + it { is_expected.to respond_to(:unchecked?) } + it { is_expected.to respond_to(:can_be_merged?) } + it { is_expected.to respond_to(:cannot_be_merged?) } end describe 'modules' do - it { should include_module(Issuable) } + it { is_expected.to include_module(Issuable) } end describe "#mr_and_commit_notes" do let!(:merge_request) { create(:merge_request) } before do - merge_request.stub(:commits) { [merge_request.source_project.repository.commit] } + allow(merge_request).to receive(:commits) { [merge_request.source_project.repository.commit] } create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit', project: merge_request.project) create(:note, noteable: merge_request, project: merge_request.project) end it "should include notes for commits" do - merge_request.commits.should_not be_empty - merge_request.mr_and_commit_notes.count.should == 2 + expect(merge_request.commits).not_to be_empty + expect(merge_request.mr_and_commit_notes.count).to eq(2) end end @@ -62,10 +62,10 @@ describe MergeRequest do describe '#is_being_reassigned?' do it 'returns true if the merge_request assignee has changed' do subject.assignee = create(:user) - subject.is_being_reassigned?.should be_true + expect(subject.is_being_reassigned?).to be_truthy end it 'returns false if the merge request assignee has not changed' do - subject.is_being_reassigned?.should be_false + expect(subject.is_being_reassigned?).to be_falsey end end @@ -74,11 +74,11 @@ describe MergeRequest do subject.source_project = create(:project, namespace: create(:group)) subject.target_project = create(:project, namespace: create(:group)) - subject.for_fork?.should be_true + expect(subject.for_fork?).to be_truthy end it 'returns false if is not for a fork' do - subject.for_fork?.should be_false + expect(subject.for_fork?).to be_falsey end end @@ -96,14 +96,14 @@ describe MergeRequest do it 'accesses the set of issues that will be closed on acceptance' do subject.project.stub(default_branch: subject.target_branch) - subject.closes_issues.should == [issue0, issue1].sort_by(&:id) + expect(subject.closes_issues).to eq([issue0, issue1].sort_by(&:id)) end it 'only lists issues as to be closed if it targets the default branch' do subject.project.stub(default_branch: 'master') subject.target_branch = 'something-else' - subject.closes_issues.should be_empty + expect(subject.closes_issues).to be_empty end it 'detects issues mentioned in the description' do @@ -111,7 +111,7 @@ describe MergeRequest do subject.description = "Closes ##{issue2.iid}" subject.project.stub(default_branch: subject.target_branch) - subject.closes_issues.should include(issue2) + expect(subject.closes_issues).to include(issue2) end end diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index a3071c3251a..45171e1bf64 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -17,8 +17,8 @@ require 'spec_helper' describe Milestone do describe "Associations" do - it { should belong_to(:project) } - it { should have_many(:issues) } + it { is_expected.to belong_to(:project) } + it { is_expected.to have_many(:issues) } end describe "Mass assignment" do @@ -26,8 +26,8 @@ describe Milestone do describe "Validation" do before { subject.stub(set_iid: false) } - it { should validate_presence_of(:title) } - it { should validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:title) } + it { is_expected.to validate_presence_of(:project) } end let(:milestone) { create(:milestone) } @@ -36,30 +36,30 @@ describe Milestone do describe "#percent_complete" do it "should not count open issues" do milestone.issues << issue - milestone.percent_complete.should == 0 + expect(milestone.percent_complete).to eq(0) end it "should count closed issues" do issue.close milestone.issues << issue - milestone.percent_complete.should == 100 + expect(milestone.percent_complete).to eq(100) end it "should recover from dividing by zero" do - milestone.issues.should_receive(:count).and_return(0) - milestone.percent_complete.should == 100 + expect(milestone.issues).to receive(:count).and_return(0) + expect(milestone.percent_complete).to eq(100) end end describe "#expires_at" do it "should be nil when due_date is unset" do milestone.update_attributes(due_date: nil) - milestone.expires_at.should be_nil + expect(milestone.expires_at).to be_nil end it "should not be nil when due_date is set" do milestone.update_attributes(due_date: Date.tomorrow) - milestone.expires_at.should be_present + expect(milestone.expires_at).to be_present end end @@ -69,7 +69,7 @@ describe Milestone do milestone.stub(due_date: Date.today.prev_year) end - it { milestone.expired?.should be_true } + it { expect(milestone.expired?).to be_truthy } end context "not expired" do @@ -77,7 +77,7 @@ describe Milestone do milestone.stub(due_date: Date.today.next_year) end - it { milestone.expired?.should be_false } + it { expect(milestone.expired?).to be_falsey } end end @@ -89,7 +89,7 @@ describe Milestone do ) end - it { milestone.percent_complete.should == 75 } + it { expect(milestone.percent_complete).to eq(75) } end describe :items_count do @@ -99,14 +99,14 @@ describe Milestone do milestone.merge_requests << create(:merge_request) end - it { milestone.closed_items_count.should == 1 } - it { milestone.open_items_count.should == 2 } - it { milestone.total_items_count.should == 3 } - it { milestone.is_empty?.should be_false } + it { expect(milestone.closed_items_count).to eq(1) } + it { expect(milestone.open_items_count).to eq(2) } + it { expect(milestone.total_items_count).to eq(3) } + it { expect(milestone.is_empty?).to be_falsey } end describe :can_be_closed? do - it { milestone.can_be_closed?.should be_true } + it { expect(milestone.can_be_closed?).to be_truthy } end describe :is_empty? do @@ -116,7 +116,7 @@ describe Milestone do end it 'Should return total count of issues and merge requests assigned to milestone' do - milestone.total_items_count.should eq 2 + expect(milestone.total_items_count).to eq 2 end end @@ -129,14 +129,14 @@ describe Milestone do end it 'should be true if milestone active and all nested issues closed' do - milestone.can_be_closed?.should be_true + expect(milestone.can_be_closed?).to be_truthy end it 'should be false if milestone active and not all nested issues closed' do issue.milestone = milestone issue.save - milestone.can_be_closed?.should be_false + expect(milestone.can_be_closed?).to be_falsey end end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 3562ebed1ff..4e268f8d8fa 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -18,29 +18,29 @@ require 'spec_helper' describe Namespace do let!(:namespace) { create(:namespace) } - it { should have_many :projects } - it { should validate_presence_of :name } - it { should validate_uniqueness_of(:name) } - it { should validate_presence_of :path } - it { should validate_uniqueness_of(:path) } - it { should validate_presence_of :owner } + it { is_expected.to have_many :projects } + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_uniqueness_of(:name) } + it { is_expected.to validate_presence_of :path } + it { is_expected.to validate_uniqueness_of(:path) } + it { is_expected.to validate_presence_of :owner } describe "Mass assignment" do end describe "Respond to" do - it { should respond_to(:human_name) } - it { should respond_to(:to_param) } + it { is_expected.to respond_to(:human_name) } + it { is_expected.to respond_to(:to_param) } end - it { Namespace.global_id.should == 'GLN' } + it { expect(Namespace.global_id).to eq('GLN') } describe :to_param do - it { namespace.to_param.should == namespace.path } + it { expect(namespace.to_param).to eq(namespace.path) } end describe :human_name do - it { namespace.human_name.should == namespace.owner_name } + it { expect(namespace.human_name).to eq(namespace.owner_name) } end describe :search do @@ -48,8 +48,8 @@ describe Namespace do @namespace = create :namespace end - it { Namespace.search(@namespace.path).should == [@namespace] } - it { Namespace.search('unknown').should == [] } + it { expect(Namespace.search(@namespace.path)).to eq([@namespace]) } + it { expect(Namespace.search('unknown')).to eq([]) } end describe :move_dir do @@ -66,13 +66,13 @@ describe Namespace do new_path = @namespace.path + "_new" @namespace.stub(path_was: @namespace.path) @namespace.stub(path: new_path) - @namespace.move_dir.should be_true + expect(@namespace.move_dir).to be_truthy end end describe :rm_dir do it "should remove dir" do - namespace.rm_dir.should be_true + expect(namespace.rm_dir).to be_truthy end end end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 6ab7162c15c..17cb439c90e 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -21,17 +21,17 @@ require 'spec_helper' describe Note do describe "Associations" do - it { should belong_to(:project) } - it { should belong_to(:noteable) } - it { should belong_to(:author).class_name('User') } + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:noteable) } + it { is_expected.to belong_to(:author).class_name('User') } end describe "Mass assignment" do end describe "Validation" do - it { should validate_presence_of(:note) } - it { should validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:note) } + it { is_expected.to validate_presence_of(:project) } end describe "Voting score" do @@ -39,44 +39,44 @@ describe Note do it "recognizes a neutral note" do note = create(:votable_note, note: "This is not a +1 note") - note.should_not be_upvote - note.should_not be_downvote + expect(note).not_to be_upvote + expect(note).not_to be_downvote end it "recognizes a neutral emoji note" do note = build(:votable_note, note: "I would :+1: this, but I don't want to") - note.should_not be_upvote - note.should_not be_downvote + expect(note).not_to be_upvote + expect(note).not_to be_downvote end it "recognizes a +1 note" do note = create(:votable_note, note: "+1 for this") - note.should be_upvote + expect(note).to be_upvote end it "recognizes a +1 emoji as a vote" do note = build(:votable_note, note: ":+1: for this") - note.should be_upvote + expect(note).to be_upvote end it "recognizes a thumbsup emoji as a vote" do note = build(:votable_note, note: ":thumbsup: for this") - note.should be_upvote + expect(note).to be_upvote end it "recognizes a -1 note" do note = create(:votable_note, note: "-1 for this") - note.should be_downvote + expect(note).to be_downvote end it "recognizes a -1 emoji as a vote" do note = build(:votable_note, note: ":-1: for this") - note.should be_downvote + expect(note).to be_downvote end it "recognizes a thumbsdown emoji as a vote" do note = build(:votable_note, note: ":thumbsdown: for this") - note.should be_downvote + expect(note).to be_downvote end end @@ -87,22 +87,22 @@ describe Note do let!(:commit) { note.noteable } it "should be accessible through #noteable" do - note.commit_id.should == commit.id - note.noteable.should be_a(Commit) - note.noteable.should == commit + expect(note.commit_id).to eq(commit.id) + expect(note.noteable).to be_a(Commit) + expect(note.noteable).to eq(commit) end it "should save a valid note" do - note.commit_id.should == commit.id + expect(note.commit_id).to eq(commit.id) note.noteable == commit end it "should be recognized by #for_commit?" do - note.should be_for_commit + expect(note).to be_for_commit end it "should not be votable" do - note.should_not be_votable + expect(note).not_to be_votable end end @@ -111,20 +111,20 @@ describe Note do let!(:commit) { note.noteable } it "should save a valid note" do - note.commit_id.should == commit.id - note.noteable.id.should == commit.id + expect(note.commit_id).to eq(commit.id) + expect(note.noteable.id).to eq(commit.id) end it "should be recognized by #for_diff_line?" do - note.should be_for_diff_line + expect(note).to be_for_diff_line end it "should be recognized by #for_commit_diff_line?" do - note.should be_for_commit_diff_line + expect(note).to be_for_commit_diff_line end it "should not be votable" do - note.should_not be_votable + expect(note).not_to be_votable end end @@ -132,7 +132,7 @@ describe Note do let!(:note) { create(:note_on_issue, note: "+1 from me") } it "should not be votable" do - note.should be_votable + expect(note).to be_votable end end @@ -140,7 +140,7 @@ describe Note do let!(:note) { create(:note_on_merge_request, note: "+1 from me") } it "should be votable" do - note.should be_votable + expect(note).to be_votable end end @@ -148,7 +148,7 @@ describe Note do let!(:note) { create(:note_on_merge_request_diff, note: "+1 from me") } it "should not be votable" do - note.should_not be_votable + expect(note).not_to be_votable end end @@ -161,20 +161,35 @@ describe Note do subject { Note.create_status_change_note(thing, project, author, status, nil) } it 'creates and saves a Note' do - should be_a Note - subject.id.should_not be_nil + is_expected.to be_a Note + expect(subject.id).not_to be_nil end - its(:noteable) { should == thing } - its(:project) { should == thing.project } - its(:author) { should == author } - its(:note) { should =~ /Status changed to #{status}/ } + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(thing) } + end + + describe '#project' do + subject { super().project } + it { is_expected.to eq(thing.project) } + end + + describe '#author' do + subject { super().author } + it { is_expected.to eq(author) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to match(/Status changed to #{status}/) } + end it 'appends a back-reference if a closing mentionable is supplied' do commit = double('commit', gfm_reference: 'commit 123456') n = Note.create_status_change_note(thing, project, author, status, commit) - n.note.should =~ /Status changed to #{status} by commit 123456/ + expect(n.note).to match(/Status changed to #{status} by commit 123456/) end end @@ -187,19 +202,41 @@ describe Note do subject { Note.create_assignee_change_note(thing, project, author, assignee) } context 'creates and saves a Note' do - it { should be_a Note } - its(:id) { should_not be_nil } + it { is_expected.to be_a Note } + + describe '#id' do + subject { super().id } + it { is_expected.not_to be_nil } + end + end + + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(thing) } end - its(:noteable) { should == thing } - its(:project) { should == thing.project } - its(:author) { should == author } - its(:note) { should =~ /Reassigned to @#{assignee.username}/ } + describe '#project' do + subject { super().project } + it { is_expected.to eq(thing.project) } + end + + describe '#author' do + subject { super().author } + it { is_expected.to eq(author) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to match(/Reassigned to @#{assignee.username}/) } + end context 'assignee is removed' do let(:assignee) { nil } - its(:note) { should =~ /Assignee removed/ } + describe '#note' do + subject { super().note } + it { is_expected.to match(/Assignee removed/) } + end end end @@ -216,64 +253,144 @@ describe Note do context 'issue from a merge request' do subject { Note.create_cross_reference_note(issue, mergereq, author, project) } - it { should be_valid } - its(:noteable) { should == issue } - its(:project) { should == issue.project } - its(:author) { should == author } - its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } + it { is_expected.to be_valid } + + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(issue) } + end + + describe '#project' do + subject { super().project } + it { is_expected.to eq(issue.project) } + end + + describe '#author' do + subject { super().author } + it { is_expected.to eq(author) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") } + end end context 'issue from a commit' do subject { Note.create_cross_reference_note(issue, commit, author, project) } - it { should be_valid } - its(:noteable) { should == issue } - its(:note) { should == "_mentioned in commit #{commit.sha}_" } + it { is_expected.to be_valid } + + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(issue) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in commit #{commit.sha}_") } + end end context 'merge request from an issue' do subject { Note.create_cross_reference_note(mergereq, issue, author, project) } - it { should be_valid } - its(:noteable) { should == mergereq } - its(:project) { should == mergereq.project } - its(:note) { should == "_mentioned in issue ##{issue.iid}_" } + it { is_expected.to be_valid } + + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(mergereq) } + end + + describe '#project' do + subject { super().project } + it { is_expected.to eq(mergereq.project) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") } + end end context 'commit from a merge request' do subject { Note.create_cross_reference_note(commit, mergereq, author, project) } - it { should be_valid } - its(:noteable) { should == commit } - its(:project) { should == project } - its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } + it { is_expected.to be_valid } + + describe '#noteable' do + subject { super().noteable } + it { is_expected.to eq(commit) } + end + + describe '#project' do + subject { super().project } + it { is_expected.to eq(project) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in merge request !#{mergereq.iid}_") } + end end context 'commit contained in a merge request' do subject { Note.create_cross_reference_note(mergereq.commits.first, mergereq, author, project) } - it { should be_nil } + it { is_expected.to be_nil } end context 'commit from issue' do subject { Note.create_cross_reference_note(commit, issue, author, project) } - it { should be_valid } - its(:noteable_type) { should == "Commit" } - its(:noteable_id) { should be_nil } - its(:commit_id) { should == commit.id } - its(:note) { should == "_mentioned in issue ##{issue.iid}_" } + it { is_expected.to be_valid } + + describe '#noteable_type' do + subject { super().noteable_type } + it { is_expected.to eq("Commit") } + end + + describe '#noteable_id' do + subject { super().noteable_id } + it { is_expected.to be_nil } + end + + describe '#commit_id' do + subject { super().commit_id } + it { is_expected.to eq(commit.id) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in issue ##{issue.iid}_") } + end end context 'commit from commit' do let(:parent_commit) { commit.parents.first } subject { Note.create_cross_reference_note(commit, parent_commit, author, project) } - it { should be_valid } - its(:noteable_type) { should == "Commit" } - its(:noteable_id) { should be_nil } - its(:commit_id) { should == commit.id } - its(:note) { should == "_mentioned in commit #{parent_commit.id}_" } + it { is_expected.to be_valid } + + describe '#noteable_type' do + subject { super().noteable_type } + it { is_expected.to eq("Commit") } + end + + describe '#noteable_id' do + subject { super().noteable_id } + it { is_expected.to be_nil } + end + + describe '#commit_id' do + subject { super().commit_id } + it { is_expected.to eq(commit.id) } + end + + describe '#note' do + subject { super().note } + it { is_expected.to eq("_mentioned in commit #{parent_commit.id}_") } + end end end @@ -289,11 +406,11 @@ describe Note do end it 'detects if a mentionable has already been mentioned' do - Note.cross_reference_exists?(issue, commit0).should be_true + expect(Note.cross_reference_exists?(issue, commit0)).to be_truthy end it 'detects if a mentionable has not already been mentioned' do - Note.cross_reference_exists?(issue, commit1).should be_false + expect(Note.cross_reference_exists?(issue, commit1)).to be_falsey end context 'commit on commit' do @@ -301,8 +418,8 @@ describe Note do Note.create_cross_reference_note(commit0, commit1, author, project) end - it { Note.cross_reference_exists?(commit0, commit1).should be_true } - it { Note.cross_reference_exists?(commit1, commit0).should be_false } + it { expect(Note.cross_reference_exists?(commit0, commit1)).to be_truthy } + it { expect(Note.cross_reference_exists?(commit1, commit0)).to be_falsey } end end @@ -315,22 +432,22 @@ describe Note do it 'should recognize user-supplied notes as non-system' do @note = create(:note_on_issue) - @note.should_not be_system + expect(@note).not_to be_system end it 'should identify status-change notes as system notes' do @note = Note.create_status_change_note(issue, project, author, 'closed', nil) - @note.should be_system + expect(@note).to be_system end it 'should identify cross-reference notes as system notes' do @note = Note.create_cross_reference_note(issue, other, author, project) - @note.should be_system + expect(@note).to be_system end it 'should identify assignee-change notes as system notes' do @note = Note.create_assignee_change_note(issue, project, author, assignee) - @note.should be_system + expect(@note).to be_system end end @@ -351,9 +468,9 @@ describe Note do @p2.project_members.create(user: @u3, access_level: ProjectMember::GUEST) end - it { @abilities.allowed?(@u1, :read_note, @p1).should be_false } - it { @abilities.allowed?(@u2, :read_note, @p1).should be_true } - it { @abilities.allowed?(@u3, :read_note, @p1).should be_false } + it { expect(@abilities.allowed?(@u1, :read_note, @p1)).to be_falsey } + it { expect(@abilities.allowed?(@u2, :read_note, @p1)).to be_truthy } + it { expect(@abilities.allowed?(@u3, :read_note, @p1)).to be_falsey } end describe :write do @@ -362,9 +479,9 @@ describe Note do @p2.project_members.create(user: @u3, access_level: ProjectMember::DEVELOPER) end - it { @abilities.allowed?(@u1, :write_note, @p1).should be_false } - it { @abilities.allowed?(@u2, :write_note, @p1).should be_true } - it { @abilities.allowed?(@u3, :write_note, @p1).should be_false } + it { expect(@abilities.allowed?(@u1, :write_note, @p1)).to be_falsey } + it { expect(@abilities.allowed?(@u2, :write_note, @p1)).to be_truthy } + it { expect(@abilities.allowed?(@u3, :write_note, @p1)).to be_falsey } end describe :admin do @@ -374,9 +491,9 @@ describe Note do @p2.project_members.create(user: @u3, access_level: ProjectMember::MASTER) end - it { @abilities.allowed?(@u1, :admin_note, @p1).should be_false } - it { @abilities.allowed?(@u2, :admin_note, @p1).should be_true } - it { @abilities.allowed?(@u3, :admin_note, @p1).should be_false } + it { expect(@abilities.allowed?(@u1, :admin_note, @p1)).to be_falsey } + it { expect(@abilities.allowed?(@u2, :admin_note, @p1)).to be_truthy } + it { expect(@abilities.allowed?(@u3, :admin_note, @p1)).to be_falsey } end end diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb index 5c8d1e7438b..1ee19003543 100644 --- a/spec/models/project_security_spec.rb +++ b/spec/models/project_security_spec.rb @@ -23,7 +23,7 @@ describe Project do describe "Non member rules" do it "should deny for non-project users any actions" do admin_actions.each do |action| - @abilities.allowed?(@u1, action, @p1).should be_false + expect(@abilities.allowed?(@u1, action, @p1)).to be_falsey end end end @@ -35,7 +35,7 @@ describe Project do it "should allow for project user any guest actions" do guest_actions.each do |action| - @abilities.allowed?(@u2, action, @p1).should be_true + expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy end end end @@ -47,7 +47,7 @@ describe Project do it "should allow for project user any report actions" do report_actions.each do |action| - @abilities.allowed?(@u2, action, @p1).should be_true + expect(@abilities.allowed?(@u2, action, @p1)).to be_truthy end end end @@ -60,13 +60,13 @@ describe Project do it "should deny for developer master-specific actions" do [dev_actions - report_actions].each do |action| - @abilities.allowed?(@u2, action, @p1).should be_false + expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey end end it "should allow for project user any dev actions" do dev_actions.each do |action| - @abilities.allowed?(@u3, action, @p1).should be_true + expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy end end end @@ -79,13 +79,13 @@ describe Project do it "should deny for developer master-specific actions" do [master_actions - dev_actions].each do |action| - @abilities.allowed?(@u2, action, @p1).should be_false + expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey end end it "should allow for project user any master actions" do master_actions.each do |action| - @abilities.allowed?(@u3, action, @p1).should be_true + expect(@abilities.allowed?(@u3, action, @p1)).to be_truthy end end end @@ -98,13 +98,13 @@ describe Project do it "should deny for masters admin-specific actions" do [admin_actions - master_actions].each do |action| - @abilities.allowed?(@u2, action, @p1).should be_false + expect(@abilities.allowed?(@u2, action, @p1)).to be_falsey end end it "should allow for project owner any admin actions" do admin_actions.each do |action| - @abilities.allowed?(@u4, action, @p1).should be_true + expect(@abilities.allowed?(@u4, action, @p1)).to be_truthy end end end diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb index 005dd41fea9..ee7f780c8f6 100644 --- a/spec/models/project_services/assembla_service_spec.rb +++ b/spec/models/project_services/assembla_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe AssemblaService, models: true do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Execute" do @@ -40,7 +40,7 @@ describe AssemblaService, models: true do it "should call Assembla API" do @assembla_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( + expect(WebMock).to have_requested(:post, @api_url).with( body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ ).once end diff --git a/spec/models/project_services/buildbox_service_spec.rb b/spec/models/project_services/buildbox_service_spec.rb index 1d9ca51be16..050363e14c7 100644 --- a/spec/models/project_services/buildbox_service_spec.rb +++ b/spec/models/project_services/buildbox_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe BuildboxService do describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe 'commits methods' do @@ -38,35 +38,39 @@ describe BuildboxService do describe :webhook_url do it 'returns the webhook url' do - @service.webhook_url.should == + expect(@service.webhook_url).to eq( 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token' + ) end end describe :commit_status_path do it 'returns the correct status page' do - @service.commit_status_path('2ab7834c').should == + expect(@service.commit_status_path('2ab7834c')).to eq( 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c' + ) end end describe :build_page do it 'returns the correct build page' do - @service.build_page('2ab7834c').should == + expect(@service.build_page('2ab7834c')).to eq( 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c' + ) end end describe :builds_page do it 'returns the correct path to the builds page' do - @service.builds_path.should == + expect(@service.builds_path).to eq( 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho' + ) end end describe :status_img_path do it 'returns the correct path to the status image' do - @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg' + expect(@service.status_img_path).to eq('https://badge.buildbox.io/secret-sauce-status-token.svg') end end end diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb index ac156719b43..b34e36bc940 100644 --- a/spec/models/project_services/flowdock_service_spec.rb +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe FlowdockService do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Execute" do @@ -39,7 +39,7 @@ describe FlowdockService do it "should call FlowDock API" do @flowdock_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( + expect(WebMock).to have_requested(:post, @api_url).with( body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ ).once end diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb index 2c560c11dac..fe5d62b2f53 100644 --- a/spec/models/project_services/gemnasium_service_spec.rb +++ b/spec/models/project_services/gemnasium_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe GemnasiumService do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Execute" do @@ -36,7 +36,7 @@ describe GemnasiumService do @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) end it "should call Gemnasium service" do - Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once + expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once @gemnasium_service.execute(@sample_data) end end diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb index 83277058fbb..0cd255f08ea 100644 --- a/spec/models/project_services/gitlab_ci_service_spec.rb +++ b/spec/models/project_services/gitlab_ci_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe GitlabCiService do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Mass assignment" do @@ -34,11 +34,11 @@ describe GitlabCiService do end describe :commit_status_path do - it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} + it { expect(@service.commit_status_path("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret")} end describe :build_page do - it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} + it { expect(@service.build_page("2ab7834c")).to eq("http://ci.gitlab.org/projects/2/commits/2ab7834c")} end end end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 99ca04eff6e..6ef4d036c3f 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe JiraService do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Validations" do @@ -26,9 +26,9 @@ describe JiraService do subject.active = true end - it { should validate_presence_of :project_url } - it { should validate_presence_of :issues_url } - it { should validate_presence_of :new_issue_url } + it { is_expected.to validate_presence_of :project_url } + it { is_expected.to validate_presence_of :issues_url } + it { is_expected.to validate_presence_of :new_issue_url } end end @@ -79,7 +79,7 @@ describe JiraService do "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" } } - Gitlab.config.stub(:issues_tracker).and_return(settings) + allow(Gitlab.config).to receive(:issues_tracker).and_return(settings) @service = project.create_jira_service(active: true) end diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb index f2813d66c7d..188626a7a27 100644 --- a/spec/models/project_services/pushover_service_spec.rb +++ b/spec/models/project_services/pushover_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe PushoverService do describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe 'Validations' do @@ -26,9 +26,9 @@ describe PushoverService do subject.active = true end - it { should validate_presence_of :api_key } - it { should validate_presence_of :user_key } - it { should validate_presence_of :priority } + it { is_expected.to validate_presence_of :api_key } + it { is_expected.to validate_presence_of :user_key } + it { is_expected.to validate_presence_of :priority } end end @@ -63,7 +63,7 @@ describe PushoverService do it 'should call Pushover API' do pushover.execute(sample_data) - WebMock.should have_requested(:post, api_url).once + expect(WebMock).to have_requested(:post, api_url).once end end end diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb index c530fad619b..7197a94e53f 100644 --- a/spec/models/project_services/slack_message_spec.rb +++ b/spec/models/project_services/slack_message_spec.rb @@ -25,16 +25,17 @@ describe SlackMessage do end it 'returns a message regarding pushes' do - subject.pretext.should == + expect(subject.pretext).to eq( 'user_name pushed to branch of '\ ' ()' - subject.attachments.should == [ + ) + expect(subject.attachments).to eq([ { text: ": message1 - author1\n"\ ": message2 - author2", color: color, } - ] + ]) end end @@ -44,10 +45,11 @@ describe SlackMessage do end it 'returns a message regarding a new branch' do - subject.pretext.should == + expect(subject.pretext).to eq( 'user_name pushed new branch to '\ '' - subject.attachments.should be_empty + ) + expect(subject.attachments).to be_empty end end @@ -57,9 +59,10 @@ describe SlackMessage do end it 'returns a message regarding a removed branch' do - subject.pretext.should == + expect(subject.pretext).to eq( 'user_name removed branch master from ' - subject.attachments.should be_empty + ) + expect(subject.attachments).to be_empty end end end diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb index 34594072409..90b385423f1 100644 --- a/spec/models/project_services/slack_service_spec.rb +++ b/spec/models/project_services/slack_service_spec.rb @@ -16,8 +16,8 @@ require 'spec_helper' describe SlackService do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Validations" do @@ -26,7 +26,7 @@ describe SlackService do subject.active = true end - it { should validate_presence_of :webhook } + it { is_expected.to validate_presence_of :webhook } end end @@ -51,7 +51,7 @@ describe SlackService do it "should call Slack API" do slack.execute(sample_data) - WebMock.should have_requested(:post, webhook_url).once + expect(WebMock).to have_requested(:post, webhook_url).once end end end diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb index a6e1d9eef50..3e8f106d27f 100644 --- a/spec/models/project_snippet_spec.rb +++ b/spec/models/project_snippet_spec.rb @@ -19,13 +19,13 @@ require 'spec_helper' describe ProjectSnippet do describe "Associations" do - it { should belong_to(:project) } + it { is_expected.to belong_to(:project) } end describe "Mass assignment" do end describe "Validation" do - it { should validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:project) } end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e2197420018..ad7a0f0a1e3 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -33,25 +33,25 @@ require 'spec_helper' describe Project do describe 'Associations' do - it { should belong_to(:group) } - it { should belong_to(:namespace) } - it { should belong_to(:creator).class_name('User') } - it { should have_many(:users) } - it { should have_many(:events).dependent(:destroy) } - it { should have_many(:merge_requests).dependent(:destroy) } - it { should have_many(:issues).dependent(:destroy) } - it { should have_many(:milestones).dependent(:destroy) } - it { should have_many(:project_members).dependent(:destroy) } - it { should have_many(:notes).dependent(:destroy) } - it { should have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) } - it { should have_many(:deploy_keys_projects).dependent(:destroy) } - it { should have_many(:deploy_keys) } - it { should have_many(:hooks).dependent(:destroy) } - it { should have_many(:protected_branches).dependent(:destroy) } - it { should have_one(:forked_project_link).dependent(:destroy) } - it { should have_one(:slack_service).dependent(:destroy) } - it { should have_one(:pushover_service).dependent(:destroy) } - it { should have_one(:asana_service).dependent(:destroy) } + it { is_expected.to belong_to(:group) } + it { is_expected.to belong_to(:namespace) } + it { is_expected.to belong_to(:creator).class_name('User') } + it { is_expected.to have_many(:users) } + it { is_expected.to have_many(:events).dependent(:destroy) } + it { is_expected.to have_many(:merge_requests).dependent(:destroy) } + it { is_expected.to have_many(:issues).dependent(:destroy) } + it { is_expected.to have_many(:milestones).dependent(:destroy) } + it { is_expected.to have_many(:project_members).dependent(:destroy) } + it { is_expected.to have_many(:notes).dependent(:destroy) } + it { is_expected.to have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) } + it { is_expected.to have_many(:deploy_keys_projects).dependent(:destroy) } + it { is_expected.to have_many(:deploy_keys) } + it { is_expected.to have_many(:hooks).dependent(:destroy) } + it { is_expected.to have_many(:protected_branches).dependent(:destroy) } + it { is_expected.to have_one(:forked_project_link).dependent(:destroy) } + it { is_expected.to have_one(:slack_service).dependent(:destroy) } + it { is_expected.to have_one(:pushover_service).dependent(:destroy) } + it { is_expected.to have_one(:asana_service).dependent(:destroy) } end describe 'Mass assignment' do @@ -60,50 +60,50 @@ describe Project do describe 'Validation' do let!(:project) { create(:project) } - it { should validate_presence_of(:name) } - it { should validate_uniqueness_of(:name).scoped_to(:namespace_id) } - it { should ensure_length_of(:name).is_within(0..255) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to(:namespace_id) } + it { is_expected.to ensure_length_of(:name).is_within(0..255) } - it { should validate_presence_of(:path) } - it { should validate_uniqueness_of(:path).scoped_to(:namespace_id) } - it { should ensure_length_of(:path).is_within(0..255) } - it { should ensure_length_of(:description).is_within(0..2000) } - it { should validate_presence_of(:creator) } - it { should ensure_length_of(:issues_tracker_id).is_within(0..255) } - it { should validate_presence_of(:namespace) } + it { is_expected.to validate_presence_of(:path) } + it { is_expected.to validate_uniqueness_of(:path).scoped_to(:namespace_id) } + it { is_expected.to ensure_length_of(:path).is_within(0..255) } + it { is_expected.to ensure_length_of(:description).is_within(0..2000) } + it { is_expected.to validate_presence_of(:creator) } + it { is_expected.to ensure_length_of(:issues_tracker_id).is_within(0..255) } + it { is_expected.to validate_presence_of(:namespace) } it 'should not allow new projects beyond user limits' do project2 = build(:project) - project2.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object) - project2.should_not be_valid - project2.errors[:limit_reached].first.should match(/Your project limit is 0/) + allow(project2).to receive(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object) + expect(project2).not_to be_valid + expect(project2.errors[:limit_reached].first).to match(/Your project limit is 0/) end end describe 'Respond to' do - it { should respond_to(:url_to_repo) } - it { should respond_to(:repo_exists?) } - it { should respond_to(:satellite) } - it { should respond_to(:update_merge_requests) } - it { should respond_to(:execute_hooks) } - it { should respond_to(:name_with_namespace) } - it { should respond_to(:owner) } - it { should respond_to(:path_with_namespace) } + it { is_expected.to respond_to(:url_to_repo) } + it { is_expected.to respond_to(:repo_exists?) } + it { is_expected.to respond_to(:satellite) } + it { is_expected.to respond_to(:update_merge_requests) } + it { is_expected.to respond_to(:execute_hooks) } + it { is_expected.to respond_to(:name_with_namespace) } + it { is_expected.to respond_to(:owner) } + it { is_expected.to respond_to(:path_with_namespace) } end it 'should return valid url to repo' do project = Project.new(path: 'somewhere') - project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git' + expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git') end it 'returns the full web URL for this repo' do project = Project.new(path: 'somewhere') - project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere" + expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/somewhere") end it 'returns the web URL without the protocol for this repo' do project = Project.new(path: 'somewhere') - project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere" + expect(project.web_url_without_protocol).to eq("#{Gitlab.config.gitlab.url.split('://')[1]}/somewhere") end describe 'last_activity methods' do @@ -113,18 +113,18 @@ describe Project do describe 'last_activity' do it 'should alias last_activity to last_event' do project.stub(last_event: last_event) - project.last_activity.should == last_event + expect(project.last_activity).to eq(last_event) end end describe 'last_activity_date' do it 'returns the creation date of the project\'s last event if present' do last_activity_event = create(:event, project: project) - project.last_activity_at.to_i.should == last_event.created_at.to_i + expect(project.last_activity_at.to_i).to eq(last_event.created_at.to_i) end it 'returns the project\'s last update date if it has no events' do - project.last_activity_date.should == project.updated_at + expect(project.last_activity_date).to eq(project.updated_at) end end end @@ -139,13 +139,13 @@ describe Project do it 'should close merge request if last commit from source branch was pushed to target branch' do project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user) merge_request.reload - merge_request.merged?.should be_true + expect(merge_request.merged?).to be_truthy end it 'should update merge request commits with new one if pushed to source branch' do project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user) merge_request.reload - merge_request.last_commit.id.should == commit_id + expect(merge_request.last_commit.id).to eq(commit_id) end end @@ -156,8 +156,8 @@ describe Project do @project = create(:project, name: 'gitlabhq', namespace: @group) end - it { Project.find_with_namespace('gitlab/gitlabhq').should == @project } - it { Project.find_with_namespace('gitlab-ci').should be_nil } + it { expect(Project.find_with_namespace('gitlab/gitlabhq')).to eq(@project) } + it { expect(Project.find_with_namespace('gitlab-ci')).to be_nil } end end @@ -168,7 +168,7 @@ describe Project do @project = create(:project, name: 'gitlabhq', namespace: @group) end - it { @project.to_param.should == 'gitlab/gitlabhq' } + it { expect(@project.to_param).to eq('gitlab/gitlabhq') } end end @@ -176,7 +176,7 @@ describe Project do let(:project) { create(:project) } it 'should return valid repo' do - project.repository.should be_kind_of(Repository) + expect(project.repository).to be_kind_of(Repository) end end @@ -187,15 +187,15 @@ describe Project do let(:ext_project) { create(:redmine_project) } it 'should be true or if used internal tracker and issue exists' do - project.issue_exists?(existed_issue.iid).should be_true + expect(project.issue_exists?(existed_issue.iid)).to be_truthy end it 'should be false or if used internal tracker and issue not exists' do - project.issue_exists?(not_existed_issue.iid).should be_false + expect(project.issue_exists?(not_existed_issue.iid)).to be_falsey end it 'should always be true if used other tracker' do - ext_project.issue_exists?(rand(100)).should be_true + expect(ext_project.issue_exists?(rand(100))).to be_truthy end end @@ -204,11 +204,11 @@ describe Project do let(:ext_project) { create(:redmine_project) } it "should be true if used internal tracker" do - project.default_issues_tracker?.should be_true + expect(project.default_issues_tracker?).to be_truthy end it "should be false if used other tracker" do - ext_project.default_issues_tracker?.should be_false + expect(ext_project.default_issues_tracker?).to be_falsey end end @@ -217,19 +217,19 @@ describe Project do let(:ext_project) { create(:redmine_project) } it 'should be true for projects with external issues tracker if issues enabled' do - ext_project.can_have_issues_tracker_id?.should be_true + expect(ext_project.can_have_issues_tracker_id?).to be_truthy end it 'should be false for projects with internal issue tracker if issues enabled' do - project.can_have_issues_tracker_id?.should be_false + expect(project.can_have_issues_tracker_id?).to be_falsey end it 'should be always false if issues disabled' do project.issues_enabled = false ext_project.issues_enabled = false - project.can_have_issues_tracker_id?.should be_false - ext_project.can_have_issues_tracker_id?.should be_false + expect(project.can_have_issues_tracker_id?).to be_falsey + expect(ext_project.can_have_issues_tracker_id?).to be_falsey end end @@ -240,8 +240,8 @@ describe Project do project.protected_branches.create(name: 'master') end - it { project.open_branches.map(&:name).should include('feature') } - it { project.open_branches.map(&:name).should_not include('master') } + it { expect(project.open_branches.map(&:name)).to include('feature') } + it { expect(project.open_branches.map(&:name)).not_to include('master') } end describe '#star_count' do @@ -318,12 +318,12 @@ describe Project do it 'should be true if avatar is image' do project.update_attribute(:avatar, 'uploads/avatar.png') - project.avatar_type.should be_true + expect(project.avatar_type).to be_truthy end it 'should be false if avatar is html page' do project.update_attribute(:avatar, 'uploads/avatar.html') - project.avatar_type.should == ['only images allowed'] + expect(project.avatar_type).to eq(['only images allowed']) end end end diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index bbf50b654f4..19201cc15a7 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -16,19 +16,19 @@ describe ProjectTeam do end describe 'members collection' do - it { project.team.masters.should include(master) } - it { project.team.masters.should_not include(guest) } - it { project.team.masters.should_not include(reporter) } - it { project.team.masters.should_not include(nonmember) } + it { expect(project.team.masters).to include(master) } + it { expect(project.team.masters).not_to include(guest) } + it { expect(project.team.masters).not_to include(reporter) } + it { expect(project.team.masters).not_to include(nonmember) } end describe 'access methods' do - it { project.team.master?(master).should be_true } - it { project.team.master?(guest).should be_false } - it { project.team.master?(reporter).should be_false } - it { project.team.master?(nonmember).should be_false } - it { project.team.member?(nonmember).should be_false } - it { project.team.member?(guest).should be_true } + it { expect(project.team.master?(master)).to be_truthy } + it { expect(project.team.master?(guest)).to be_falsey } + it { expect(project.team.master?(reporter)).to be_falsey } + it { expect(project.team.master?(nonmember)).to be_falsey } + it { expect(project.team.member?(nonmember)).to be_falsey } + it { expect(project.team.member?(guest)).to be_truthy } end end @@ -49,21 +49,21 @@ describe ProjectTeam do end describe 'members collection' do - it { project.team.reporters.should include(reporter) } - it { project.team.masters.should include(master) } - it { project.team.masters.should include(guest) } - it { project.team.masters.should_not include(reporter) } - it { project.team.masters.should_not include(nonmember) } + it { expect(project.team.reporters).to include(reporter) } + it { expect(project.team.masters).to include(master) } + it { expect(project.team.masters).to include(guest) } + it { expect(project.team.masters).not_to include(reporter) } + it { expect(project.team.masters).not_to include(nonmember) } end describe 'access methods' do - it { project.team.reporter?(reporter).should be_true } - it { project.team.master?(master).should be_true } - it { project.team.master?(guest).should be_true } - it { project.team.master?(reporter).should be_false } - it { project.team.master?(nonmember).should be_false } - it { project.team.member?(nonmember).should be_false } - it { project.team.member?(guest).should be_true } + it { expect(project.team.reporter?(reporter)).to be_truthy } + it { expect(project.team.master?(master)).to be_truthy } + it { expect(project.team.master?(guest)).to be_truthy } + it { expect(project.team.master?(reporter)).to be_falsey } + it { expect(project.team.master?(nonmember)).to be_falsey } + it { expect(project.team.member?(nonmember)).to be_falsey } + it { expect(project.team.member?(guest)).to be_truthy } end end end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index e4ee2fc5b13..2acdb7dfddc 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -12,19 +12,19 @@ describe ProjectWiki do describe "#path_with_namespace" do it "returns the project path with namespace with the .wiki extension" do - subject.path_with_namespace.should == project.path_with_namespace + ".wiki" + expect(subject.path_with_namespace).to eq(project.path_with_namespace + ".wiki") end end describe "#url_to_repo" do it "returns the correct ssh url to the repo" do - subject.url_to_repo.should == gitlab_shell.url_to_repo(subject.path_with_namespace) + expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.path_with_namespace)) end end describe "#ssh_url_to_repo" do it "equals #url_to_repo" do - subject.ssh_url_to_repo.should == subject.url_to_repo + expect(subject.ssh_url_to_repo).to eq(subject.url_to_repo) end end @@ -32,21 +32,21 @@ describe ProjectWiki do it "provides the full http url to the repo" do gitlab_url = Gitlab.config.gitlab.url repo_http_url = "#{gitlab_url}/#{subject.path_with_namespace}.git" - subject.http_url_to_repo.should == repo_http_url + expect(subject.http_url_to_repo).to eq(repo_http_url) end end describe "#wiki" do it "contains a Gollum::Wiki instance" do - subject.wiki.should be_a Gollum::Wiki + expect(subject.wiki).to be_a Gollum::Wiki end it "creates a new wiki repo if one does not yet exist" do - project_wiki.create_page("index", "test content").should be_true + expect(project_wiki.create_page("index", "test content")).to be_truthy end it "raises CouldNotCreateWikiError if it can't create the wiki repository" do - project_wiki.stub(:init_repo).and_return(false) + allow(project_wiki).to receive(:init_repo).and_return(false) expect { project_wiki.send(:create_repo!) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError) end end @@ -54,21 +54,27 @@ describe ProjectWiki do describe "#empty?" do context "when the wiki repository is empty" do before do - Gitlab::Shell.any_instance.stub(:add_repository) do + allow_any_instance_of(Gitlab::Shell).to receive(:add_repository) do create_temp_repo("#{Rails.root}/tmp/test-git-base-path/non-existant.wiki.git") end - project.stub(:path_with_namespace).and_return("non-existant") + allow(project).to receive(:path_with_namespace).and_return("non-existant") end - its(:empty?) { should be_true } + describe '#empty?' do + subject { super().empty? } + it { is_expected.to be_truthy } + end end context "when the wiki has pages" do before do - create_page("index", "This is an awesome new Gollum Wiki") + project_wiki.create_page("index", "This is an awesome new Gollum Wiki") end - its(:empty?) { should be_false } + describe '#empty?' do + subject { super().empty? } + it { is_expected.to be_falsey } + end end end @@ -83,11 +89,11 @@ describe ProjectWiki do end it "returns an array of WikiPage instances" do - @pages.first.should be_a WikiPage + expect(@pages.first).to be_a WikiPage end it "returns the correct number of pages" do - @pages.count.should == 1 + expect(@pages.count).to eq(1) end end @@ -102,55 +108,55 @@ describe ProjectWiki do it "returns the latest version of the page if it exists" do page = subject.find_page("index page") - page.title.should == "index page" + expect(page.title).to eq("index page") end it "returns nil if the page does not exist" do - subject.find_page("non-existant").should == nil + expect(subject.find_page("non-existant")).to eq(nil) end it "can find a page by slug" do page = subject.find_page("index-page") - page.title.should == "index page" + expect(page.title).to eq("index page") end it "returns a WikiPage instance" do page = subject.find_page("index page") - page.should be_a WikiPage + expect(page).to be_a WikiPage end end describe '#find_file' do before do file = Gollum::File.new(subject.wiki) - Gollum::Wiki.any_instance. - stub(:file).with('image.jpg', 'master', true). + allow_any_instance_of(Gollum::Wiki). + to receive(:file).with('image.jpg', 'master', true). and_return(file) - Gollum::File.any_instance. - stub(:mime_type). + allow_any_instance_of(Gollum::File). + to receive(:mime_type). and_return('image/jpeg') - Gollum::Wiki.any_instance. - stub(:file).with('non-existant', 'master', true). + allow_any_instance_of(Gollum::Wiki). + to receive(:file).with('non-existant', 'master', true). and_return(nil) end after do - Gollum::Wiki.any_instance.unstub(:file) - Gollum::File.any_instance.unstub(:mime_type) + allow_any_instance_of(Gollum::Wiki).to receive(:file).and_call_original + allow_any_instance_of(Gollum::File).to receive(:mime_type).and_call_original end it 'returns the latest version of the file if it exists' do file = subject.find_file('image.jpg') - file.mime_type.should == 'image/jpeg' + expect(file.mime_type).to eq('image/jpeg') end it 'returns nil if the page does not exist' do - subject.find_file('non-existant').should == nil + expect(subject.find_file('non-existant')).to eq(nil) end it 'returns a Gollum::File instance' do file = subject.find_file('image.jpg') - file.should be_a Gollum::File + expect(file).to be_a Gollum::File end end @@ -160,23 +166,23 @@ describe ProjectWiki do end it "creates a new wiki page" do - subject.create_page("test page", "this is content").should_not == false - subject.pages.count.should == 1 + expect(subject.create_page("test page", "this is content")).not_to eq(false) + expect(subject.pages.count).to eq(1) end it "returns false when a duplicate page exists" do subject.create_page("test page", "content") - subject.create_page("test page", "content").should == false + expect(subject.create_page("test page", "content")).to eq(false) end it "stores an error message when a duplicate page exists" do 2.times { subject.create_page("test page", "content") } - subject.error_message.should =~ /Duplicate page:/ + expect(subject.error_message).to match(/Duplicate page:/) end it "sets the correct commit message" do subject.create_page("test page", "some content", :markdown, "commit message") - subject.pages.first.page.version.message.should == "commit message" + expect(subject.pages.first.page.version.message).to eq("commit message") end end @@ -193,11 +199,11 @@ describe ProjectWiki do end it "updates the content of the page" do - @page.raw_data.should == "some other content" + expect(@page.raw_data).to eq("some other content") end it "sets the correct commit message" do - @page.version.message.should == "updated page" + expect(@page.version.message).to eq("updated page") end end @@ -209,7 +215,7 @@ describe ProjectWiki do it "deletes the page" do subject.delete_page(@page) - subject.pages.count.should == 0 + expect(subject.pages.count).to eq(0) end end diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index b0f57e8a206..1e6937b536c 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -14,14 +14,14 @@ require 'spec_helper' describe ProtectedBranch do describe 'Associations' do - it { should belong_to(:project) } + it { is_expected.to belong_to(:project) } end describe "Mass assignment" do end describe 'Validation' do - it { should validate_presence_of(:project) } - it { should validate_presence_of(:name) } + it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:name) } end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 6c3e221f343..eeb0f3d9ee0 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -8,14 +8,14 @@ describe Repository do describe :branch_names_contains do subject { repository.branch_names_contains(sample_commit.id) } - it { should include('master') } - it { should_not include('feature') } - it { should_not include('fix') } + it { is_expected.to include('master') } + it { is_expected.not_to include('feature') } + it { is_expected.not_to include('fix') } end describe :last_commit_for_path do subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id } - it { should eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } + it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } end end diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index c96f2b20529..1129bd1c76d 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -17,8 +17,8 @@ require 'spec_helper' describe Service do describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe "Mass assignment" do @@ -40,7 +40,7 @@ describe Service do end describe :can_test do - it { @testable.should == true } + it { expect(@testable).to eq(true) } end end @@ -55,7 +55,7 @@ describe Service do end describe :can_test do - it { @testable.should == true } + it { expect(@testable).to eq(true) } end end end diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 1ef2c512c1f..e37dcc75230 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -19,22 +19,22 @@ require 'spec_helper' describe Snippet do describe "Associations" do - it { should belong_to(:author).class_name('User') } - it { should have_many(:notes).dependent(:destroy) } + it { is_expected.to belong_to(:author).class_name('User') } + it { is_expected.to have_many(:notes).dependent(:destroy) } end describe "Mass assignment" do end describe "Validation" do - it { should validate_presence_of(:author) } + it { is_expected.to validate_presence_of(:author) } - it { should validate_presence_of(:title) } - it { should ensure_length_of(:title).is_within(0..255) } + it { is_expected.to validate_presence_of(:title) } + it { is_expected.to ensure_length_of(:title).is_within(0..255) } - it { should validate_presence_of(:file_name) } - it { should ensure_length_of(:title).is_within(0..255) } + it { is_expected.to validate_presence_of(:file_name) } + it { is_expected.to ensure_length_of(:title).is_within(0..255) } - it { should validate_presence_of(:content) } + it { is_expected.to validate_presence_of(:content) } end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 629d51b960d..e853262e00f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -49,32 +49,32 @@ require 'spec_helper' describe User do describe "Associations" do - it { should have_one(:namespace) } - it { should have_many(:snippets).class_name('Snippet').dependent(:destroy) } - it { should have_many(:project_members).dependent(:destroy) } - it { should have_many(:groups) } - it { should have_many(:keys).dependent(:destroy) } - it { should have_many(:events).class_name('Event').dependent(:destroy) } - it { should have_many(:recent_events).class_name('Event') } - it { should have_many(:issues).dependent(:destroy) } - it { should have_many(:notes).dependent(:destroy) } - it { should have_many(:assigned_issues).dependent(:destroy) } - it { should have_many(:merge_requests).dependent(:destroy) } - it { should have_many(:assigned_merge_requests).dependent(:destroy) } - it { should have_many(:identities).dependent(:destroy) } + it { is_expected.to have_one(:namespace) } + it { is_expected.to have_many(:snippets).class_name('Snippet').dependent(:destroy) } + it { is_expected.to have_many(:project_members).dependent(:destroy) } + it { is_expected.to have_many(:groups) } + it { is_expected.to have_many(:keys).dependent(:destroy) } + it { is_expected.to have_many(:events).class_name('Event').dependent(:destroy) } + it { is_expected.to have_many(:recent_events).class_name('Event') } + it { is_expected.to have_many(:issues).dependent(:destroy) } + it { is_expected.to have_many(:notes).dependent(:destroy) } + it { is_expected.to have_many(:assigned_issues).dependent(:destroy) } + it { is_expected.to have_many(:merge_requests).dependent(:destroy) } + it { is_expected.to have_many(:assigned_merge_requests).dependent(:destroy) } + it { is_expected.to have_many(:identities).dependent(:destroy) } end describe "Mass assignment" do end describe 'validations' do - it { should validate_presence_of(:username) } - it { should validate_presence_of(:projects_limit) } - it { should validate_numericality_of(:projects_limit) } - it { should allow_value(0).for(:projects_limit) } - it { should_not allow_value(-1).for(:projects_limit) } + it { is_expected.to validate_presence_of(:username) } + it { is_expected.to validate_presence_of(:projects_limit) } + it { is_expected.to validate_numericality_of(:projects_limit) } + it { is_expected.to allow_value(0).for(:projects_limit) } + it { is_expected.not_to allow_value(-1).for(:projects_limit) } - it { should ensure_length_of(:bio).is_within(0..255) } + it { is_expected.to ensure_length_of(:bio).is_within(0..255) } describe 'email' do it 'accepts info@example.com' do @@ -110,34 +110,34 @@ describe User do end describe "Respond to" do - it { should respond_to(:is_admin?) } - it { should respond_to(:name) } - it { should respond_to(:private_token) } + it { is_expected.to respond_to(:is_admin?) } + it { is_expected.to respond_to(:name) } + it { is_expected.to respond_to(:private_token) } end describe '#generate_password' do it "should execute callback when force_random_password specified" do user = build(:user, force_random_password: true) - user.should_receive(:generate_password) + expect(user).to receive(:generate_password) user.save end it "should not generate password by default" do user = create(:user, password: 'abcdefghe') - user.password.should == 'abcdefghe' + expect(user.password).to eq('abcdefghe') end it "should generate password when forcing random password" do - Devise.stub(:friendly_token).and_return('123456789') + allow(Devise).to receive(:friendly_token).and_return('123456789') user = create(:user, password: 'abcdefg', force_random_password: true) - user.password.should == '12345678' + expect(user.password).to eq('12345678') end end describe 'authentication token' do it "should have authentication token" do user = create(:user) - user.authentication_token.should_not be_blank + expect(user.authentication_token).not_to be_blank end end @@ -152,15 +152,15 @@ describe User do @project_3.team << [@user, :developer] end - it { @user.authorized_projects.should include(@project) } - it { @user.authorized_projects.should include(@project_2) } - it { @user.authorized_projects.should include(@project_3) } - it { @user.owned_projects.should include(@project) } - it { @user.owned_projects.should_not include(@project_2) } - it { @user.owned_projects.should_not include(@project_3) } - it { @user.personal_projects.should include(@project) } - it { @user.personal_projects.should_not include(@project_2) } - it { @user.personal_projects.should_not include(@project_3) } + it { expect(@user.authorized_projects).to include(@project) } + it { expect(@user.authorized_projects).to include(@project_2) } + it { expect(@user.authorized_projects).to include(@project_3) } + it { expect(@user.owned_projects).to include(@project) } + it { expect(@user.owned_projects).not_to include(@project_2) } + it { expect(@user.owned_projects).not_to include(@project_3) } + it { expect(@user.personal_projects).to include(@project) } + it { expect(@user.personal_projects).not_to include(@project_2) } + it { expect(@user.personal_projects).not_to include(@project_3) } end describe 'groups' do @@ -170,9 +170,9 @@ describe User do @group.add_owner(@user) end - it { @user.several_namespaces?.should be_true } - it { @user.authorized_groups.should == [@group] } - it { @user.owned_groups.should == [@group] } + it { expect(@user.several_namespaces?).to be_truthy } + it { expect(@user.authorized_groups).to eq([@group]) } + it { expect(@user.owned_groups).to eq([@group]) } end describe 'group multiple owners' do @@ -185,7 +185,7 @@ describe User do @group.add_user(@user2, GroupMember::OWNER) end - it { @user2.several_namespaces?.should be_true } + it { expect(@user2.several_namespaces?).to be_truthy } end describe 'namespaced' do @@ -194,7 +194,7 @@ describe User do @project = create :project, namespace: @user.namespace end - it { @user.several_namespaces?.should be_false } + it { expect(@user.several_namespaces?).to be_falsey } end describe 'blocking user' do @@ -202,7 +202,7 @@ describe User do it "should block user" do user.block - user.blocked?.should be_true + expect(user.blocked?).to be_truthy end end @@ -214,10 +214,10 @@ describe User do @blocked = create :user, state: :blocked end - it { User.filter("admins").should == [@admin] } - it { User.filter("blocked").should == [@blocked] } - it { User.filter("wop").should include(@user, @admin, @blocked) } - it { User.filter(nil).should include(@user, @admin) } + it { expect(User.filter("admins")).to eq([@admin]) } + it { expect(User.filter("blocked")).to eq([@blocked]) } + it { expect(User.filter("wop")).to include(@user, @admin, @blocked) } + it { expect(User.filter(nil)).to include(@user, @admin) } end describe :not_in_project do @@ -227,27 +227,27 @@ describe User do @project = create :project end - it { User.not_in_project(@project).should include(@user, @project.owner) } + it { expect(User.not_in_project(@project)).to include(@user, @project.owner) } end describe 'user creation' do describe 'normal user' do let(:user) { create(:user, name: 'John Smith') } - it { user.is_admin?.should be_false } - it { user.require_ssh_key?.should be_true } - it { user.can_create_group?.should be_true } - it { user.can_create_project?.should be_true } - it { user.first_name.should == 'John' } + it { expect(user.is_admin?).to be_falsey } + it { expect(user.require_ssh_key?).to be_truthy } + it { expect(user.can_create_group?).to be_truthy } + it { expect(user.can_create_project?).to be_truthy } + it { expect(user.first_name).to eq('John') } end describe 'with defaults' do let(:user) { User.new } it "should apply defaults to user" do - user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit - user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group - user.theme_id.should == Gitlab.config.gitlab.default_theme + expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) + expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group) + expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) end end @@ -255,9 +255,9 @@ describe User do let(:user) { User.new(projects_limit: 123, can_create_group: false, can_create_team: true, theme_id: Gitlab::Theme::BASIC) } it "should apply defaults to user" do - user.projects_limit.should == 123 - user.can_create_group.should be_false - user.theme_id.should == Gitlab::Theme::BASIC + expect(user.projects_limit).to eq(123) + expect(user.can_create_group).to be_falsey + expect(user.theme_id).to eq(Gitlab::Theme::BASIC) end end end @@ -267,12 +267,12 @@ describe User do let(:user2) { create(:user, username: 'jameson', email: 'jameson@example.com') } it "should be case insensitive" do - User.search(user1.username.upcase).to_a.should == [user1] - User.search(user1.username.downcase).to_a.should == [user1] - User.search(user2.username.upcase).to_a.should == [user2] - User.search(user2.username.downcase).to_a.should == [user2] - User.search(user1.username.downcase).to_a.count.should == 2 - User.search(user2.username.downcase).to_a.count.should == 1 + expect(User.search(user1.username.upcase).to_a).to eq([user1]) + expect(User.search(user1.username.downcase).to_a).to eq([user1]) + expect(User.search(user2.username.upcase).to_a).to eq([user2]) + expect(User.search(user2.username.downcase).to_a).to eq([user2]) + expect(User.search(user1.username.downcase).to_a.count).to eq(2) + expect(User.search(user2.username.downcase).to_a.count).to eq(1) end end @@ -280,10 +280,10 @@ describe User do let(:user1) { create(:user, username: 'foo') } it "should get the correct user" do - User.by_username_or_id(user1.id).should == user1 - User.by_username_or_id('foo').should == user1 - User.by_username_or_id(-1).should be_nil - User.by_username_or_id('bar').should be_nil + expect(User.by_username_or_id(user1.id)).to eq(user1) + expect(User.by_username_or_id('foo')).to eq(user1) + expect(User.by_username_or_id(-1)).to be_nil + expect(User.by_username_or_id('bar')).to be_nil end end @@ -302,13 +302,13 @@ describe User do end describe 'all_ssh_keys' do - it { should have_many(:keys).dependent(:destroy) } + it { is_expected.to have_many(:keys).dependent(:destroy) } it "should have all ssh keys" do user = create :user key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id - user.all_ssh_keys.should include(key.key) + expect(user.all_ssh_keys).to include(key.key) end end @@ -317,12 +317,12 @@ describe User do it "should be true if avatar is image" do user.update_attribute(:avatar, 'uploads/avatar.png') - user.avatar_type.should be_true + expect(user.avatar_type).to be_truthy end it "should be false if avatar is html page" do user.update_attribute(:avatar, 'uploads/avatar.html') - user.avatar_type.should == ["only images allowed"] + expect(user.avatar_type).to eq(["only images allowed"]) end end @@ -333,7 +333,7 @@ describe User do # Create a condition which would otherwise cause 'true' to be returned user.stub(ldap_user?: true) user.last_credential_check_at = nil - expect(user.requires_ldap_check?).to be_false + expect(user.requires_ldap_check?).to be_falsey end context 'when LDAP is enabled' do @@ -341,7 +341,7 @@ describe User do it 'is false for non-LDAP users' do user.stub(ldap_user?: false) - expect(user.requires_ldap_check?).to be_false + expect(user.requires_ldap_check?).to be_falsey end context 'and when the user is an LDAP user' do @@ -349,12 +349,12 @@ describe User do it 'is true when the user has never had an LDAP check before' do user.last_credential_check_at = nil - expect(user.requires_ldap_check?).to be_true + expect(user.requires_ldap_check?).to be_truthy end it 'is true when the last LDAP check happened over 1 hour ago' do user.last_credential_check_at = 2.hours.ago - expect(user.requires_ldap_check?).to be_true + expect(user.requires_ldap_check?).to be_truthy end end end @@ -363,24 +363,24 @@ describe User do describe :ldap_user? do it "is true if provider name starts with ldap" do user = create(:omniauth_user, provider: 'ldapmain') - expect( user.ldap_user? ).to be_true + expect( user.ldap_user? ).to be_truthy end it "is false for other providers" do user = create(:omniauth_user, provider: 'other-provider') - expect( user.ldap_user? ).to be_false + expect( user.ldap_user? ).to be_falsey end it "is false if no extern_uid is provided" do user = create(:omniauth_user, extern_uid: nil) - expect( user.ldap_user? ).to be_false + expect( user.ldap_user? ).to be_falsey end end describe :ldap_identity do it "returns ldap identity" do user = create :omniauth_user - user.ldap_identity.provider.should_not be_empty + expect(user.ldap_identity.provider).not_to be_empty end end @@ -434,24 +434,24 @@ describe User do project1 = create :project, :public project2 = create :project, :public - expect(user.starred?(project1)).to be_false - expect(user.starred?(project2)).to be_false + expect(user.starred?(project1)).to be_falsey + expect(user.starred?(project2)).to be_falsey star1 = UsersStarProject.create!(project: project1, user: user) - expect(user.starred?(project1)).to be_true - expect(user.starred?(project2)).to be_false + expect(user.starred?(project1)).to be_truthy + expect(user.starred?(project2)).to be_falsey star2 = UsersStarProject.create!(project: project2, user: user) - expect(user.starred?(project1)).to be_true - expect(user.starred?(project2)).to be_true + expect(user.starred?(project1)).to be_truthy + expect(user.starred?(project2)).to be_truthy star1.destroy - expect(user.starred?(project1)).to be_false - expect(user.starred?(project2)).to be_true + expect(user.starred?(project1)).to be_falsey + expect(user.starred?(project2)).to be_truthy star2.destroy - expect(user.starred?(project1)).to be_false - expect(user.starred?(project2)).to be_false + expect(user.starred?(project1)).to be_falsey + expect(user.starred?(project2)).to be_falsey end end @@ -460,11 +460,11 @@ describe User do user = create :user project = create :project, :public - expect(user.starred?(project)).to be_false + expect(user.starred?(project)).to be_falsey user.toggle_star(project) - expect(user.starred?(project)).to be_true + expect(user.starred?(project)).to be_truthy user.toggle_star(project) - expect(user.starred?(project)).to be_false + expect(user.starred?(project)).to be_falsey end end @@ -476,23 +476,23 @@ describe User do end it "sorts users as recently_signed_in" do - User.sort('recent_sign_in').first.should == @user + expect(User.sort('recent_sign_in').first).to eq(@user) end it "sorts users as late_signed_in" do - User.sort('oldest_sign_in').first.should == @user1 + expect(User.sort('oldest_sign_in').first).to eq(@user1) end it "sorts users as recently_created" do - User.sort('created_desc').first.should == @user + expect(User.sort('created_desc').first).to eq(@user) end it "sorts users as late_created" do - User.sort('created_asc').first.should == @user1 + expect(User.sort('created_asc').first).to eq(@user1) end it "sorts users by name when nil is passed" do - User.sort(nil).first.should == @user + expect(User.sort(nil).first).to eq(@user) end end end diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 78877db61b7..f3fd805783f 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -16,27 +16,27 @@ describe WikiPage do end it "sets the slug attribute" do - @wiki_page.slug.should == "test-page" + expect(@wiki_page.slug).to eq("test-page") end it "sets the title attribute" do - @wiki_page.title.should == "test page" + expect(@wiki_page.title).to eq("test page") end it "sets the formatted content attribute" do - @wiki_page.content.should == "test content" + expect(@wiki_page.content).to eq("test content") end it "sets the format attribute" do - @wiki_page.format.should == :markdown + expect(@wiki_page.format).to eq(:markdown) end it "sets the message attribute" do - @wiki_page.message.should == "test commit" + expect(@wiki_page.message).to eq("test commit") end it "sets the version attribute" do - @wiki_page.version.should be_a Gollum::Git::Commit + expect(@wiki_page.version).to be_a Gollum::Git::Commit end end end @@ -48,12 +48,12 @@ describe WikiPage do it "validates presence of title" do subject.attributes.delete(:title) - subject.valid?.should be_false + expect(subject.valid?).to be_falsey end it "validates presence of content" do subject.attributes.delete(:content) - subject.valid?.should be_false + expect(subject.valid?).to be_falsey end end @@ -69,11 +69,11 @@ describe WikiPage do context "with valid attributes" do it "saves the wiki page" do subject.create(@wiki_attr) - wiki.find_page("Index").should_not be_nil + expect(wiki.find_page("Index")).not_to be_nil end it "returns true" do - subject.create(@wiki_attr).should == true + expect(subject.create(@wiki_attr)).to eq(true) end end end @@ -95,7 +95,7 @@ describe WikiPage do end it "returns true" do - @page.update("more content").should be_true + expect(@page.update("more content")).to be_truthy end end end @@ -108,11 +108,11 @@ describe WikiPage do it "should delete the page" do @page.delete - wiki.pages.should be_empty + expect(wiki.pages).to be_empty end it "should return true" do - @page.delete.should == true + expect(@page.delete).to eq(true) end end @@ -128,7 +128,7 @@ describe WikiPage do it "returns an array of all commits for the page" do 3.times { |i| @page.update("content #{i}") } - @page.versions.count.should == 4 + expect(@page.versions.count).to eq(4) end end @@ -144,7 +144,7 @@ describe WikiPage do it "should be replace a hyphen to a space" do @page.title = "Import-existing-repositories-into-GitLab" - @page.title.should == "Import existing repositories into GitLab" + expect(@page.title).to eq("Import existing repositories into GitLab") end end -- cgit v1.2.1 From 378520bd8be0a23510c9beea5987e10343194fb5 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 12 Feb 2015 10:53:01 -0800 Subject: Add a test for service template. --- spec/models/service_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spec/models') diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 10cbafebd95..1df34f56cf1 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -60,4 +60,29 @@ describe Service do end end end + + describe "Template" do + describe "for pushover service" do + let(:service_template) { + PushoverService.create(template: true, properties: {device: 'MyDevice', sound: 'mic', priority: 4, api_key: '123456789'}) + } + let(:project) { create(:project) } + + describe 'should be prefilled for projects pushover service' do + before do + service_template + project.build_missing_services + end + + it "should have all fields prefilled" do + service = project.pushover_service + expect(service.template).to eq(false) + expect(service.device).to eq('MyDevice') + expect(service.sound).to eq('mic') + expect(service.priority).to eq(4) + expect(service.api_key).to eq('123456789') + end + end + end + end end -- cgit v1.2.1 From 6685661b549cdece3b93131af168b5174bc0403f Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 11 Feb 2015 14:12:43 +0100 Subject: Clean username acquired from OAuth/LDAP. Fixes #1967. --- spec/models/user_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 629d51b960d..7473054f481 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -301,6 +301,16 @@ describe User do end end + describe ".clean_username" do + + let!(:user1) { create(:user, username: "johngitlab-etc") } + let!(:user2) { create(:user, username: "JohnGitLab-etc1") } + + it "cleans a username and makes sure it's available" do + expect(User.clean_username("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") + end + end + describe 'all_ssh_keys' do it { should have_many(:keys).dependent(:destroy) } -- cgit v1.2.1 From 161d15541a65ba167830f9a9bf5d181d0c5f4d77 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 13 Feb 2015 12:39:11 +0100 Subject: Prevent autogenerated OAuth username to clash with existing namespace. --- spec/models/user_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6102b2e30be..c015a1d2687 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -303,8 +303,8 @@ describe User do describe ".clean_username" do - let!(:user1) { create(:user, username: "johngitlab-etc") } - let!(:user2) { create(:user, username: "JohnGitLab-etc1") } + let!(:user) { create(:user, username: "johngitlab-etc") } + let!(:namespace) { create(:namespace, path: "JohnGitLab-etc1") } it "cleans a username and makes sure it's available" do expect(User.clean_username("-john+gitlab-ETC%.git@gmail.com")).to eq("johngitlab-ETC2") -- cgit v1.2.1 From 76aad9b76ed756ca9ba2cbcdb399c815e542b3ae Mon Sep 17 00:00:00 2001 From: Vinnie Okada Date: Sat, 24 Jan 2015 11:02:58 -0700 Subject: Upgrade to Rails 4.1.9 Make the following changes to deal with new behavior in Rails 4.1.2: * Use nested resources to avoid slashes in arguments to path helpers. --- spec/models/project_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ad7a0f0a1e3..a9df6f137b7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -168,7 +168,7 @@ describe Project do @project = create(:project, name: 'gitlabhq', namespace: @group) end - it { expect(@project.to_param).to eq('gitlab/gitlabhq') } + it { expect(@project.to_param).to eq('gitlabhq') } end end -- cgit v1.2.1 From b0dfe434c60da7d04ddf23f7a3e85af97d377568 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Feb 2015 12:38:30 -0800 Subject: Using gitlab url to build links for gitlab issue tracker and add a spec. Fix rubocop warnings in path. --- .../gitlab_issue_tracker_service_spec.rb | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spec/models/project_services/gitlab_issue_tracker_service_spec.rb (limited to 'spec/models') diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb new file mode 100644 index 00000000000..c474f4a2d95 --- /dev/null +++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb @@ -0,0 +1,60 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# template :boolean default(FALSE) +# +require 'spec_helper' + +describe GitlabIssueTrackerService do + describe "Associations" do + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } + end + + + describe 'project and issue urls' do + let(:project) { create(:project) } + + context 'with absolute urls' do + before do + @service = project.create_gitlab_issue_tracker_service(active: true) + end + + after do + @service.destroy! + end + + it 'should give the correct path' do + expect(@service.project_url).to eq("/#{project.path_with_namespace}/issues") + expect(@service.new_issue_url).to eq("/#{project.path_with_namespace}/issues/new") + expect(@service.issue_url(432)).to eq("/#{project.path_with_namespace}/issues/432") + end + end + + context 'with enabled relative urls' do + before do + Settings.gitlab.stub(:relative_url_root).and_return("/gitlab/root") + @service = project.create_gitlab_issue_tracker_service(active: true) + end + + after do + @service.destroy! + end + + it 'should give the correct path' do + expect(@service.project_url).to eq("/gitlab/root/#{project.path_with_namespace}/issues") + expect(@service.new_issue_url).to eq("/gitlab/root/#{project.path_with_namespace}/issues/new") + expect(@service.issue_url(432)).to eq("/gitlab/root/#{project.path_with_namespace}/issues/432") + end + end + end +end -- cgit v1.2.1 From 804a2488cfd6704726c0dc7e6b0facc7e2ff7ce3 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 27 Feb 2015 10:47:37 +0100 Subject: Fix and test User#contributed_projects_ids. --- spec/models/user_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c015a1d2687..29d0c24e87e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -505,4 +505,32 @@ describe User do expect(User.sort(nil).first).to eq(@user) end end + + describe "#contributed_projects_ids" do + + subject { create(:user) } + let!(:project1) { create(:project) } + let!(:project2) { create(:project, forked_from_project: project3) } + let!(:project3) { create(:project) } + let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) } + let!(:push_event) { create(:event, action: Event::PUSHED, project: project1, target: project1, author: subject) } + let!(:merge_event) { create(:event, action: Event::CREATED, project: project3, target: merge_request, author: subject) } + + before do + project1.team << [subject, :master] + project2.team << [subject, :master] + end + + it "includes IDs for projects the user has pushed to" do + expect(subject.contributed_projects_ids).to include(project1.id) + end + + it "includes IDs for projects the user has had merge requests merged into" do + expect(subject.contributed_projects_ids).to include(project3.id) + end + + it "doesn't include IDs for unrelated projects" do + expect(subject.contributed_projects_ids).not_to include(project2.id) + end + end end -- cgit v1.2.1