2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-08-29 01:52:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
describe Issuable do
|
|
|
|
let(:issuable_class) { Issue }
|
2017-09-15 13:08:27 -04:00
|
|
|
let(:issue) { create(:issue, title: 'An issue', description: 'A description') }
|
2015-09-10 23:42:14 -04:00
|
|
|
let(:user) { create(:user) }
|
2012-08-29 01:52:19 -04:00
|
|
|
|
|
|
|
describe "Associations" do
|
2017-04-25 08:28:55 -04:00
|
|
|
subject { build(:issue) }
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to belong_to(:author) }
|
|
|
|
it { is_expected.to have_many(:notes).dependent(:destroy) }
|
2016-03-23 22:14:02 -04:00
|
|
|
it { is_expected.to have_many(:todos).dependent(:destroy) }
|
2018-06-01 11:09:08 -04:00
|
|
|
it { is_expected.to have_many(:labels) }
|
2016-06-06 16:19:39 -04:00
|
|
|
|
|
|
|
context 'Notes' do
|
|
|
|
let!(:note) { create(:note, noteable: issue, project: issue.project) }
|
|
|
|
let(:scoped_issue) { Issue.includes(notes: :author).find(issue.id) }
|
|
|
|
|
|
|
|
it 'indicates if the notes have their authors loaded' do
|
|
|
|
expect(issue.notes).not_to be_authors_loaded
|
|
|
|
expect(scoped_issue.notes).to be_authors_loaded
|
|
|
|
end
|
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
2016-04-25 14:10:20 -04:00
|
|
|
describe 'Included modules' do
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:described_class) { issuable_class }
|
|
|
|
|
2016-04-25 14:10:20 -04:00
|
|
|
it { is_expected.to include_module(Awardable) }
|
|
|
|
end
|
|
|
|
|
2012-08-29 01:52:19 -04:00
|
|
|
describe "Validation" do
|
2019-01-14 05:46:39 -05:00
|
|
|
context 'general validations' do
|
|
|
|
subject { build(:issue) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(InternalId).to receive(:generate_next).and_return(nil)
|
|
|
|
end
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
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 validate_length_of(:title).is_at_most(255) }
|
2015-05-21 17:49:06 -04:00
|
|
|
end
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
describe 'milestone' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:milestone_id) { create(:milestone, project: project).id }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
title: 'something',
|
|
|
|
project: project,
|
|
|
|
author: build(:user),
|
|
|
|
milestone_id: milestone_id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { issuable_class.new(params) }
|
|
|
|
|
|
|
|
context 'with correct params' do
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with empty string milestone' do
|
|
|
|
let(:milestone_id) { '' }
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with nil milestone id' do
|
|
|
|
let(:milestone_id) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a milestone id from another project' do
|
|
|
|
let(:milestone_id) { create(:milestone).id }
|
|
|
|
|
|
|
|
it { is_expected.to be_invalid }
|
|
|
|
end
|
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Scope" do
|
2017-04-25 08:28:55 -04:00
|
|
|
subject { build(:issue) }
|
|
|
|
|
|
|
|
it { expect(issuable_class).to respond_to(:opened) }
|
|
|
|
it { expect(issuable_class).to respond_to(:closed) }
|
|
|
|
it { expect(issuable_class).to respond_to(:assigned) }
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
2017-03-17 14:48:01 -04:00
|
|
|
describe 'author_name' do
|
|
|
|
it 'is delegated to author' do
|
|
|
|
expect(issue.author_name).to eq issue.author.name
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when author is nil' do
|
|
|
|
issue.author_id = nil
|
|
|
|
issue.save(validate: false)
|
|
|
|
|
|
|
|
expect(issue.author_name).to eq nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
describe '#milestone_available?' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
def build_issuable(milestone_id)
|
|
|
|
issuable_class.new(project: project, milestone_id: milestone_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with a milestone from the issue project' do
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
|
|
|
|
expect(build_issuable(milestone.id).milestone_available?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with a milestone from the issue project group' do
|
|
|
|
milestone = create(:milestone, group: group)
|
|
|
|
|
|
|
|
expect(build_issuable(milestone.id).milestone_available?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with a milestone from the the parent of the issue project group', :nested_groups do
|
|
|
|
parent = create(:group)
|
|
|
|
group.update(parent: parent)
|
|
|
|
milestone = create(:milestone, group: parent)
|
|
|
|
|
|
|
|
expect(build_issuable(milestone.id).milestone_available?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false with a milestone from another project' do
|
|
|
|
milestone = create(:milestone)
|
|
|
|
|
|
|
|
expect(build_issuable(milestone.id).milestone_available?).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false with a milestone from another group' do
|
|
|
|
milestone = create(:milestone, group: create(:group))
|
|
|
|
|
|
|
|
expect(build_issuable(milestone.id).milestone_available?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-29 01:52:19 -04:00
|
|
|
describe ".search" do
|
2017-08-23 06:54:14 -04:00
|
|
|
let!(:searchable_issue) { create(:issue, title: "Searchable awesome issue") }
|
2017-11-24 06:24:24 -05:00
|
|
|
let!(:searchable_issue2) { create(:issue, title: 'Aw') }
|
2012-08-29 01:52:19 -04:00
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a matching title' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.search(searchable_issue.title))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a partially matching title' do
|
2017-04-25 08:28:55 -04:00
|
|
|
expect(issuable_class.search('able')).to eq([searchable_issue])
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
2016-03-01 10:59:36 -05:00
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a matching title regardless of the casing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.search(searchable_issue.title.upcase))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
2017-08-23 06:54:14 -04:00
|
|
|
|
|
|
|
it 'returns issues with a fuzzy matching title' do
|
|
|
|
expect(issuable_class.search('searchable issue')).to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
2017-11-24 06:24:24 -05:00
|
|
|
it 'returns issues with a matching title for a query shorter than 3 chars' do
|
|
|
|
expect(issuable_class.search(searchable_issue2.title.downcase)).to eq([searchable_issue2])
|
2017-08-23 06:54:14 -04:00
|
|
|
end
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".full_search" do
|
|
|
|
let!(:searchable_issue) do
|
2017-08-23 06:54:14 -04:00
|
|
|
create(:issue, title: "Searchable awesome issue", description: 'Many cute kittens')
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
2017-11-24 06:24:24 -05:00
|
|
|
let!(:searchable_issue2) { create(:issue, title: "Aw", description: "Cu") }
|
2016-03-01 10:59:36 -05:00
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a matching title' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.full_search(searchable_issue.title))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a partially matching title' do
|
2017-04-25 08:28:55 -04:00
|
|
|
expect(issuable_class.full_search('able')).to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a matching title regardless of the casing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.full_search(searchable_issue.title.upcase))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a fuzzy matching title' do
|
|
|
|
expect(issuable_class.full_search('searchable issue')).to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues with a matching description' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.full_search(searchable_issue.description))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a partially matching description' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.full_search(searchable_issue.description))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 06:54:14 -04:00
|
|
|
it 'returns issues with a matching description regardless of the casing' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(issuable_class.full_search(searchable_issue.description.upcase))
|
|
|
|
.to eq([searchable_issue])
|
2016-03-01 10:59:36 -05:00
|
|
|
end
|
2017-08-23 06:54:14 -04:00
|
|
|
|
|
|
|
it 'returns issues with a fuzzy matching description' do
|
|
|
|
expect(issuable_class.full_search('many kittens')).to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
2017-11-24 06:24:24 -05:00
|
|
|
it 'returns issues with a matching description for a query shorter than 3 chars' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue2.description.downcase)).to eq([searchable_issue2])
|
2017-08-23 06:54:14 -04:00
|
|
|
end
|
2019-01-13 11:24:31 -05:00
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is "title"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title'))
|
|
|
|
.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is "description"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns no issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'description'))
|
|
|
|
.to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'description'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is "title,description"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title,description'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title,description'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is nil"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: nil))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: nil))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is "invalid"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'invalid'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'invalid'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 03:32:27 -05:00
|
|
|
context 'when matching columns is "title,invalid"' do
|
2019-01-13 11:24:31 -05:00
|
|
|
it 'returns issues with a matching title' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title,invalid'))
|
|
|
|
.to eq([searchable_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no issues with a matching description' do
|
|
|
|
expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title,invalid'))
|
|
|
|
.to be_empty
|
|
|
|
end
|
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
2016-10-26 13:34:06 -04:00
|
|
|
describe '.to_ability_name' do
|
|
|
|
it { expect(Issue.to_ability_name).to eq("issue") }
|
|
|
|
it { expect(MergeRequest.to_ability_name).to eq("merge_request") }
|
|
|
|
end
|
|
|
|
|
2012-08-29 01:52:19 -04:00
|
|
|
describe "#today?" do
|
|
|
|
it "returns true when created today" do
|
|
|
|
# Avoid timezone differences and just return exactly what we want
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(Date).to receive(:today).and_return(issue.created_at.to_date)
|
|
|
|
expect(issue.today?).to be_truthy
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when not created today" do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(Date).to receive(:today).and_return(Date.yesterday)
|
|
|
|
expect(issue.today?).to be_falsey
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#new?" do
|
|
|
|
it "returns true when created today and record hasn't been updated" do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(issue).to receive(:today?).and_return(true)
|
|
|
|
expect(issue.new?).to be_truthy
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when not created today" do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(issue).to receive(:today?).and_return(false)
|
|
|
|
expect(issue.new?).to be_falsey
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when record has been updated" do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(issue).to receive(:today?).and_return(true)
|
2017-12-01 08:52:16 -05:00
|
|
|
issue.update_attribute(:updated_at, 1.hour.ago)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.new?).to be_falsey
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-10 23:42:14 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
describe "#sort_by_attribute" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-05-05 15:23:51 -04:00
|
|
|
|
|
|
|
context "by milestone due date" do
|
2016-05-31 18:33:46 -04:00
|
|
|
# Correct order is:
|
|
|
|
# Issues/MRs with milestones ordered by date
|
|
|
|
# Issues/MRs with milestones without dates
|
|
|
|
# Issues/MRs without milestones
|
2016-04-27 11:35:30 -04:00
|
|
|
|
2016-05-05 15:23:51 -04:00
|
|
|
let!(:issue) { create(:issue, project: project) }
|
|
|
|
let!(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) }
|
|
|
|
let!(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) }
|
|
|
|
let!(:issue1) { create(:issue, project: project, milestone: early_milestone) }
|
|
|
|
let!(:issue2) { create(:issue, project: project, milestone: late_milestone) }
|
|
|
|
let!(:issue3) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
it "sorts desc" do
|
2018-04-04 05:19:47 -04:00
|
|
|
issues = project.issues.sort_by_attribute('milestone_due_desc')
|
2016-05-05 15:23:51 -04:00
|
|
|
expect(issues).to match_array([issue2, issue1, issue, issue3])
|
|
|
|
end
|
2016-04-27 11:35:30 -04:00
|
|
|
|
2016-05-05 15:23:51 -04:00
|
|
|
it "sorts asc" do
|
2018-04-04 05:19:47 -04:00
|
|
|
issues = project.issues.sort_by_attribute('milestone_due_asc')
|
2016-05-05 15:23:51 -04:00
|
|
|
expect(issues).to match_array([issue1, issue2, issue, issue3])
|
2016-04-27 11:35:30 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-23 09:15:46 -04:00
|
|
|
|
|
|
|
context 'when all of the results are level on the sort key' do
|
|
|
|
let!(:issues) do
|
|
|
|
10.times { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no duplicates across pages' do
|
|
|
|
sorted_issue_ids = 1.upto(10).map do |i|
|
2018-04-04 05:19:47 -04:00
|
|
|
project.issues.sort_by_attribute('milestone_due_desc').page(i).per(1).first.id
|
2016-06-23 09:15:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(sorted_issue_ids).to eq(sorted_issue_ids.uniq)
|
|
|
|
end
|
|
|
|
end
|
2016-04-27 11:35:30 -04:00
|
|
|
end
|
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
describe '#subscribed?' do
|
2016-10-31 22:14:53 -04:00
|
|
|
let(:project) { issue.project }
|
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
context 'user is not a participant in the issue' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
allow(issue).to receive(:participants).with(user).and_return([])
|
|
|
|
end
|
2016-03-01 11:33:13 -05:00
|
|
|
|
|
|
|
it 'returns false when no subcription exists' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_falsey
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when a subcription exists and subscribed is true' do
|
2016-10-31 22:14:53 -04:00
|
|
|
issue.subscriptions.create(user: user, project: project, subscribed: true)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_truthy
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when a subcription exists and subscribed is false' do
|
2016-10-31 22:14:53 -04:00
|
|
|
issue.subscriptions.create(user: user, project: project, subscribed: false)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_falsey
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is a participant in the issue' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
allow(issue).to receive(:participants).with(user).and_return([user])
|
|
|
|
end
|
2016-03-01 11:33:13 -05:00
|
|
|
|
|
|
|
it 'returns false when no subcription exists' do
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_truthy
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when a subcription exists and subscribed is true' do
|
2016-10-31 22:14:53 -04:00
|
|
|
issue.subscriptions.create(user: user, project: project, subscribed: true)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_truthy
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when a subcription exists and subscribed is false' do
|
2016-10-31 22:14:53 -04:00
|
|
|
issue.subscriptions.create(user: user, project: project, subscribed: false)
|
2016-03-01 11:33:13 -05:00
|
|
|
|
2016-11-04 14:19:08 -04:00
|
|
|
expect(issue.subscribed?(user, project)).to be_falsey
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-15 06:40:17 -04:00
|
|
|
describe '#time_estimate=' do
|
|
|
|
it 'coerces the value below Gitlab::Database::MAX_INT_VALUE' do
|
|
|
|
expect { issue.time_estimate = 100 }.to change { issue.time_estimate }.to(100)
|
|
|
|
expect { issue.time_estimate = Gitlab::Database::MAX_INT_VALUE + 100 }.to change { issue.time_estimate }.to(Gitlab::Database::MAX_INT_VALUE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips coercion for not Integer values' do
|
|
|
|
expect { issue.time_estimate = nil }.to change { issue.time_estimate }.to(nil)
|
2018-06-01 11:09:08 -04:00
|
|
|
expect { issue.time_estimate = 'invalid time' }.not_to raise_error
|
|
|
|
expect { issue.time_estimate = 22.33 }.not_to raise_error
|
2018-05-15 06:40:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 13:23:15 -04:00
|
|
|
describe '#to_hook_data' do
|
2017-11-14 12:55:00 -05:00
|
|
|
let(:builder) { double }
|
|
|
|
|
2017-09-19 13:23:15 -04:00
|
|
|
context 'labels are updated' do
|
|
|
|
let(:labels) { create_list(:label, 2) }
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
2017-09-19 13:23:15 -04:00
|
|
|
before do
|
|
|
|
issue.update(labels: [labels[1]])
|
2017-11-14 12:55:00 -05:00
|
|
|
expect(Gitlab::HookData::IssuableBuilder)
|
|
|
|
.to receive(:new).with(issue).and_return(builder)
|
2017-09-19 13:23:15 -04:00
|
|
|
end
|
|
|
|
|
2017-10-05 13:02:50 -04:00
|
|
|
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
|
2017-11-14 12:55:00 -05:00
|
|
|
expect(builder).to receive(:build).with(
|
|
|
|
user: user,
|
|
|
|
changes: hash_including(
|
|
|
|
'labels' => [[labels[0].hook_attrs], [labels[1].hook_attrs]]
|
|
|
|
))
|
2017-10-05 13:02:50 -04:00
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
issue.to_hook_data(user, old_associations: { labels: [labels[0]] })
|
2017-11-14 12:55:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'total_time_spent is updated' do
|
|
|
|
before do
|
2017-12-14 14:32:55 -05:00
|
|
|
issue.spend_time(duration: 2, user_id: user.id, spent_at: Time.now)
|
2017-11-14 12:55:00 -05:00
|
|
|
issue.save
|
2017-10-05 13:02:50 -04:00
|
|
|
expect(Gitlab::HookData::IssuableBuilder)
|
|
|
|
.to receive(:new).with(issue).and_return(builder)
|
2017-11-14 12:55:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
|
2017-10-05 13:02:50 -04:00
|
|
|
expect(builder).to receive(:build).with(
|
|
|
|
user: user,
|
|
|
|
changes: hash_including(
|
2017-11-14 12:55:00 -05:00
|
|
|
'total_time_spent' => [1, 2]
|
2017-10-05 13:02:50 -04:00
|
|
|
))
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
issue.to_hook_data(user, old_associations: { total_time_spent: 1 })
|
2017-09-19 13:23:15 -04:00
|
|
|
end
|
2015-10-17 18:11:36 -04:00
|
|
|
end
|
|
|
|
|
2017-09-19 13:23:15 -04:00
|
|
|
context 'issue is assigned' do
|
|
|
|
let(:user2) { create(:user) }
|
2017-09-15 13:08:27 -04:00
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-09-19 13:23:15 -04:00
|
|
|
issue.assignees << user << user2
|
2017-11-14 12:55:00 -05:00
|
|
|
expect(Gitlab::HookData::IssuableBuilder)
|
|
|
|
.to receive(:new).with(issue).and_return(builder)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2017-10-05 13:02:50 -04:00
|
|
|
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
|
|
|
|
expect(builder).to receive(:build).with(
|
|
|
|
user: user,
|
|
|
|
changes: hash_including(
|
|
|
|
'assignees' => [[user.hook_attrs], [user.hook_attrs, user2.hook_attrs]]
|
|
|
|
))
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
issue.to_hook_data(user, old_associations: { assignees: [user] })
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 13:23:15 -04:00
|
|
|
context 'merge_request is assigned' do
|
2017-05-04 08:11:15 -04:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
2017-09-19 13:23:15 -04:00
|
|
|
let(:user2) { create(:user) }
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
before do
|
2019-04-07 14:35:16 -04:00
|
|
|
merge_request.update(assignees: [user])
|
|
|
|
merge_request.update(assignees: [user, user2])
|
2017-11-14 12:55:00 -05:00
|
|
|
expect(Gitlab::HookData::IssuableBuilder)
|
|
|
|
.to receive(:new).with(merge_request).and_return(builder)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
2015-10-17 18:11:36 -04:00
|
|
|
|
2017-10-05 13:02:50 -04:00
|
|
|
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
|
|
|
|
expect(builder).to receive(:build).with(
|
|
|
|
user: user,
|
|
|
|
changes: hash_including(
|
2019-04-07 14:35:16 -04:00
|
|
|
'assignees' => [[user.hook_attrs], [user.hook_attrs, user2.hook_attrs]]
|
2017-10-05 13:02:50 -04:00
|
|
|
))
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
merge_request.to_hook_data(user, old_associations: { assignees: [user] })
|
2015-10-17 18:11:36 -04:00
|
|
|
end
|
2015-09-10 23:42:14 -04:00
|
|
|
end
|
|
|
|
end
|
2015-12-24 17:03:54 -05:00
|
|
|
|
2016-06-02 07:17:54 -04:00
|
|
|
describe '#labels_array' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-06-02 07:17:54 -04:00
|
|
|
let(:bug) { create(:label, project: project, title: 'bug') }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2016-06-02 07:17:54 -04:00
|
|
|
issue.labels << bug
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'loads the association and returns it as an array' do
|
|
|
|
expect(issue.reload.labels_array).to eq([bug])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 16:19:39 -04:00
|
|
|
describe '#user_notes_count' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-06-06 16:19:39 -04:00
|
|
|
let(:issue1) { create(:issue, project: project) }
|
|
|
|
let(:issue2) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_list(:note, 3, noteable: issue1, project: project)
|
|
|
|
create_list(:note, 6, noteable: issue2, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'counts the user notes' do
|
|
|
|
expect(issue1.user_notes_count).to be(3)
|
|
|
|
expect(issue2.user_notes_count).to be(6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-25 11:13:55 -05:00
|
|
|
describe "votes" do
|
2016-05-04 05:17:16 -04:00
|
|
|
let(:project) { issue.project }
|
|
|
|
|
2015-12-25 11:13:55 -05:00
|
|
|
before do
|
2016-05-11 16:43:58 -04:00
|
|
|
create(:award_emoji, :upvote, awardable: issue)
|
|
|
|
create(:award_emoji, :downvote, awardable: issue)
|
2015-12-25 11:13:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns correct values" do
|
|
|
|
expect(issue.upvotes).to eq(1)
|
|
|
|
expect(issue.downvotes).to eq(1)
|
2017-03-10 06:10:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.order_due_date_and_labels_priority' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-03-10 06:10:48 -05:00
|
|
|
|
|
|
|
def create_issue(milestone, labels)
|
|
|
|
create(:labeled_issue, milestone: milestone, labels: labels, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts issues in order of milestone due date, then label priority' do
|
|
|
|
first_priority = create(:label, project: project, priority: 1)
|
|
|
|
second_priority = create(:label, project: project, priority: 2)
|
|
|
|
no_priority = create(:label, project: project)
|
|
|
|
|
|
|
|
first_milestone = create(:milestone, project: project, due_date: Time.now)
|
|
|
|
second_milestone = create(:milestone, project: project, due_date: Time.now + 1.month)
|
|
|
|
third_milestone = create(:milestone, project: project)
|
|
|
|
|
|
|
|
# The issues here are ordered by label priority, to ensure that we don't
|
|
|
|
# accidentally just sort by creation date.
|
|
|
|
second_milestone_first_priority = create_issue(second_milestone, [first_priority, second_priority, no_priority])
|
|
|
|
third_milestone_first_priority = create_issue(third_milestone, [first_priority, second_priority, no_priority])
|
|
|
|
first_milestone_second_priority = create_issue(first_milestone, [second_priority, no_priority])
|
|
|
|
second_milestone_second_priority = create_issue(second_milestone, [second_priority, no_priority])
|
|
|
|
no_milestone_second_priority = create_issue(nil, [second_priority, no_priority])
|
|
|
|
first_milestone_no_priority = create_issue(first_milestone, [no_priority])
|
|
|
|
second_milestone_no_labels = create_issue(second_milestone, [])
|
|
|
|
third_milestone_no_priority = create_issue(third_milestone, [no_priority])
|
|
|
|
|
|
|
|
result = Issue.order_due_date_and_labels_priority
|
|
|
|
|
|
|
|
expect(result).to eq([first_milestone_second_priority,
|
|
|
|
first_milestone_no_priority,
|
|
|
|
second_milestone_first_priority,
|
|
|
|
second_milestone_second_priority,
|
|
|
|
second_milestone_no_labels,
|
|
|
|
third_milestone_first_priority,
|
|
|
|
no_milestone_second_priority,
|
|
|
|
third_milestone_no_priority])
|
2015-12-25 11:13:55 -05:00
|
|
|
end
|
|
|
|
end
|
2016-05-12 03:23:21 -04:00
|
|
|
|
2016-10-27 20:26:56 -04:00
|
|
|
describe '.order_labels_priority' do
|
|
|
|
let(:label_1) { create(:label, title: 'label_1', project: issue.project, priority: 1) }
|
|
|
|
let(:label_2) { create(:label, title: 'label_2', project: issue.project, priority: 2) }
|
|
|
|
|
|
|
|
subject { Issue.order_labels_priority(excluded_labels: ['label_1']).first.highest_priority }
|
|
|
|
|
|
|
|
before do
|
|
|
|
issue.labels << label_1
|
|
|
|
issue.labels << label_2
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(2) }
|
|
|
|
end
|
|
|
|
|
2016-05-12 03:23:21 -04:00
|
|
|
describe ".with_label" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2016-05-12 03:23:21 -04:00
|
|
|
let(:bug) { create(:label, project: project, title: 'bug') }
|
|
|
|
let(:feature) { create(:label, project: project, title: 'feature') }
|
|
|
|
let(:enhancement) { create(:label, project: project, title: 'enhancement') }
|
|
|
|
let(:issue1) { create(:issue, title: "Bugfix1", project: project) }
|
|
|
|
let(:issue2) { create(:issue, title: "Bugfix2", project: project) }
|
|
|
|
let(:issue3) { create(:issue, title: "Feature1", project: project) }
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2016-05-12 03:23:21 -04:00
|
|
|
issue1.labels << bug
|
|
|
|
issue1.labels << feature
|
|
|
|
issue2.labels << bug
|
|
|
|
issue2.labels << enhancement
|
|
|
|
issue3.labels << feature
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds the correct issue containing just enhancement label' do
|
|
|
|
expect(Issue.with_label(enhancement.title)).to match_array([issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds the correct issues containing the same label' do
|
|
|
|
expect(Issue.with_label(bug.title)).to match_array([issue1, issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds the correct issues containing only both labels' do
|
|
|
|
expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2])
|
|
|
|
end
|
|
|
|
end
|
2016-10-12 08:01:34 -04:00
|
|
|
|
2016-12-23 00:44:02 -05:00
|
|
|
describe '#spend_time' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
|
|
|
def spend_time(seconds)
|
2017-12-14 14:32:55 -05:00
|
|
|
issue.spend_time(duration: seconds, user_id: user.id)
|
2016-12-23 00:44:02 -05:00
|
|
|
issue.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'adding time' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'updates the total time spent' do
|
2016-12-23 00:44:02 -05:00
|
|
|
spend_time(1800)
|
|
|
|
|
|
|
|
expect(issue.total_time_spent).to eq(1800)
|
|
|
|
end
|
2018-05-08 11:00:51 -04:00
|
|
|
|
|
|
|
it 'updates issues updated_at' do
|
|
|
|
issue
|
|
|
|
|
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect { spend_time(1800) }.to change { issue.updated_at }
|
|
|
|
end
|
|
|
|
end
|
2016-12-23 00:44:02 -05:00
|
|
|
end
|
|
|
|
|
2018-10-30 06:53:01 -04:00
|
|
|
context 'subtracting time' do
|
2016-12-23 00:44:02 -05:00
|
|
|
before do
|
|
|
|
spend_time(1800)
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'updates the total time spent' do
|
2016-12-23 00:44:02 -05:00
|
|
|
spend_time(-900)
|
|
|
|
|
|
|
|
expect(issue.total_time_spent).to eq(900)
|
|
|
|
end
|
|
|
|
|
2018-10-30 06:53:01 -04:00
|
|
|
context 'when time to subtract exceeds the total time spent' do
|
2017-01-18 11:48:16 -05:00
|
|
|
it 'raise a validation error' do
|
2018-05-08 11:00:51 -04:00
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect do
|
|
|
|
expect do
|
|
|
|
spend_time(-3600)
|
|
|
|
end.to raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
end.not_to change { issue.updated_at }
|
|
|
|
end
|
2016-12-23 00:44:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-29 11:04:42 -04:00
|
|
|
|
|
|
|
describe '#first_contribution?' do
|
|
|
|
let(:group) { create(:group) }
|
2017-08-15 12:18:02 -04:00
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
let(:other_project) { create(:project) }
|
2017-07-29 11:04:42 -04:00
|
|
|
let(:owner) { create(:owner) }
|
2018-07-11 10:36:08 -04:00
|
|
|
let(:maintainer) { create(:user) }
|
2017-07-29 11:04:42 -04:00
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:guest) { create(:user) }
|
|
|
|
|
|
|
|
let(:contributor) { create(:user) }
|
|
|
|
let(:first_time_contributor) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(owner)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
2017-08-02 10:06:28 -04:00
|
|
|
project.add_reporter(reporter)
|
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_guest(contributor)
|
|
|
|
project.add_guest(first_time_contributor)
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
2017-08-29 09:46:40 -04:00
|
|
|
|
2017-07-29 11:04:42 -04:00
|
|
|
let(:merged_mr) { create(:merge_request, :merged, author: contributor, target_project: project, source_project: project) }
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:open_mr) { create(:merge_request, author: first_time_contributor, target_project: project, source_project: project) }
|
2017-07-29 11:04:42 -04:00
|
|
|
let(:merged_mr_other_project) { create(:merge_request, :merged, author: first_time_contributor, target_project: other_project, source_project: other_project) }
|
|
|
|
|
|
|
|
context "for merge requests" do
|
2018-07-11 10:36:08 -04:00
|
|
|
it "is false for MAINTAINER" do
|
|
|
|
mr = create(:merge_request, author: maintainer, target_project: project, source_project: project)
|
2017-08-02 10:06:28 -04:00
|
|
|
|
|
|
|
expect(mr).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is false for OWNER" do
|
|
|
|
mr = create(:merge_request, author: owner, target_project: project, source_project: project)
|
2017-08-29 09:46:40 -04:00
|
|
|
|
2017-08-02 10:06:28 -04:00
|
|
|
expect(mr).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is false for REPORTER" do
|
|
|
|
mr = create(:merge_request, author: reporter, target_project: project, source_project: project)
|
2017-08-29 09:46:40 -04:00
|
|
|
|
2017-08-02 10:06:28 -04:00
|
|
|
expect(mr).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is true when you don't have any merged MR" do
|
2017-08-02 10:06:28 -04:00
|
|
|
expect(open_mr).to be_first_contribution
|
|
|
|
expect(merged_mr).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
|
2017-08-02 10:06:28 -04:00
|
|
|
it "handles multiple projects separately" do
|
|
|
|
expect(open_mr).to be_first_contribution
|
|
|
|
expect(merged_mr_other_project).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for issues" do
|
|
|
|
let(:contributor_issue) { create(:issue, author: contributor, project: project) }
|
|
|
|
let(:first_time_contributor_issue) { create(:issue, author: first_time_contributor, project: project) }
|
|
|
|
|
2017-08-15 09:21:27 -04:00
|
|
|
it "is false even without merged MR" do
|
2017-07-29 11:04:42 -04:00
|
|
|
expect(merged_mr).to be
|
2017-08-15 09:21:27 -04:00
|
|
|
expect(first_time_contributor_issue).not_to be_first_contribution
|
2017-08-02 10:06:28 -04:00
|
|
|
expect(contributor_issue).not_to be_first_contribution
|
2017-07-29 11:04:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|