Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issuable_spec.rb « concerns « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9cbc899067689d4f92056367995f8e92d9cc92df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'spec_helper'

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) }
  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) }
  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) }
  end

  describe ".search" do
    let!(:searchable_issue) { create(:issue, title: "Searchable issue") }

    it "matches by title" do
      described_class.search('able').should == [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
    end

    it "returns false when not created today" do
      Date.stub(:today).and_return(Date.yesterday)
      issue.today?.should be_false
    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
    end

    it "returns false when not created today" do
      issue.stub(:today?).and_return(false)
      issue.new?.should be_false
    end

    it "returns false when record has been updated" do
      issue.stub(:today?).and_return(true)
      issue.touch
      issue.new?.should be_false
    end
  end
end