Read about our upcoming Code of Conduct on this issue

issue_spec.rb 2.11 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
2
3
4
# == Schema Information
#
# Table name: issues
#
5
#  id           :integer          not null, primary key
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6
7
8
9
#  title        :string(255)
#  assignee_id  :integer
#  author_id    :integer
#  project_id   :integer
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10
11
#  created_at   :datetime
#  updated_at   :datetime
12
#  position     :integer          default(0)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13
14
15
#  branch_name  :string(255)
#  description  :text
#  milestone_id :integer
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
16
#  state        :string(255)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
17
#  iid          :integer
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18
19
#

gitlabhq's avatar
gitlabhq committed
20
21
22
23
require 'spec_helper'

describe Issue do
  describe "Associations" do
24
    it { is_expected.to belong_to(:milestone) }
gitlabhq's avatar
gitlabhq committed
25
26
  end

27
  describe 'modules' do
28
29
30
    subject { described_class }

    it { is_expected.to include_module(InternalId) }
31
    it { is_expected.to include_module(Issuable) }
32
33
34
    it { is_expected.to include_module(Referable) }
    it { is_expected.to include_module(Sortable) }
    it { is_expected.to include_module(Taskable) }
35
36
  end

37
  subject { create(:issue) }
38

39
40
41
42
43
44
45
46
47
48
49
50
  describe '#to_reference' do
    it 'returns a String reference to the object' do
      expect(subject.to_reference).to eq "##{subject.iid}"
    end

    it 'supports a cross-project reference' do
      cross = double('project')
      expect(subject.to_reference(cross)).
        to eq "#{subject.project.to_reference}##{subject.iid}"
    end
  end

51
52
  describe '#is_being_reassigned?' do
    it 'returns true if the issue assignee has changed' do
53
      subject.assignee = create(:user)
54
      expect(subject.is_being_reassigned?).to be_truthy
55
56
    end
    it 'returns false if the issue assignee has not changed' do
57
      expect(subject.is_being_reassigned?).to be_falsey
58
59
    end
  end
Andrew8xx8's avatar
Andrew8xx8 committed
60
61

  describe '#is_being_reassigned?' do
Johannes Schleifenbaum's avatar
Johannes Schleifenbaum committed
62
    it 'returns issues assigned to user' do
Andrew8xx8's avatar
Andrew8xx8 committed
63
64
65
66
67
68
      user = create :user

      2.times do
        issue = create :issue, assignee: user
      end

69
      expect(Issue.open_for(user).count).to eq 2
Andrew8xx8's avatar
Andrew8xx8 committed
70
71
    end
  end
72
73

  it_behaves_like 'an editable mentionable' do
74
75
    subject { create(:issue, project: project) }

76
77
78
    let(:backref_text) { "issue ##{subject.iid}" }
    let(:set_mentionable_text) { ->(txt){ subject.description = txt } }
  end
Vinnie Okada's avatar
Vinnie Okada committed
79
80
81
82

  it_behaves_like 'a Taskable' do
    let(:subject) { create :issue }
  end
gitlabhq's avatar
gitlabhq committed
83
end