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

G
gitlabhq 已提交
20 21 22 23
require 'spec_helper'

describe Issue do
  describe "Associations" do
24
    it { is_expected.to belong_to(:milestone) }
G
gitlabhq 已提交
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
A
Andrew8xx8 已提交
60 61

  describe '#is_being_reassigned?' do
J
Johannes Schleifenbaum 已提交
62
    it 'returns issues assigned to user' do
R
Robert Speicher 已提交
63 64
      user = create(:user)
      create_list(:issue, 2, assignee: user)
A
Andrew8xx8 已提交
65

66
      expect(Issue.open_for(user).count).to eq 2
A
Andrew8xx8 已提交
67 68
    end
  end
69 70

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

73 74 75
    let(:backref_text) { "issue ##{subject.iid}" }
    let(:set_mentionable_text) { ->(txt){ subject.description = txt } }
  end
V
Vinnie Okada 已提交
76 77 78 79

  it_behaves_like 'a Taskable' do
    let(:subject) { create :issue }
  end
G
gitlabhq 已提交
80
end