2012-08-29 01:52:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-01-03 02:12:24 -05:00
|
|
|
describe Issue, "Issuable" do
|
2012-08-29 01:52:19 -04:00
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
|
|
|
describe "Associations" do
|
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 belong_to(:assignee) }
|
|
|
|
it { is_expected.to have_many(:notes).dependent(:destroy) }
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2013-08-20 09:56:05 -04:00
|
|
|
before { subject.stub(set_iid: false) }
|
2015-02-12 13:17:35 -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 ensure_length_of(:title).is_at_least(0).is_at_most(255) }
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Scope" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(described_class).to respond_to(:opened) }
|
|
|
|
it { expect(described_class).to respond_to(:closed) }
|
|
|
|
it { expect(described_class).to respond_to(:assigned) }
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".search" do
|
|
|
|
let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
|
|
|
|
|
|
|
|
it "matches by title" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(described_class.search('able')).to eq([searchable_issue])
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
2012-08-29 01:52:19 -04:00
|
|
|
issue.touch
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issue.new?).to be_falsey
|
2012-08-29 01:52:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|