debian-mirror-gitlab/spec/models/concerns/issuable_spec.rb

117 lines
3.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe Issue, "Issuable" do
let(:issue) { create(:issue) }
2015-09-25 12:07:36 +05:30
let(:user) { create(:user) }
2014-09-02 18:07:02 +05:30
describe "Associations" do
2015-04-26 12:48:37 +05:30
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) }
2014-09-02 18:07:02 +05:30
end
describe "Validation" do
2015-09-11 14:41:01 +05:30
before do
allow(subject).to receive(:set_iid).and_return(false)
end
2015-04-26 12:48:37 +05:30
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) }
2015-09-11 14:41:01 +05:30
it { is_expected.to validate_length_of(:title).is_at_least(0).is_at_most(255) }
2014-09-02 18:07:02 +05:30
end
describe "Scope" do
2015-04-26 12:48:37 +05:30
it { expect(described_class).to respond_to(:opened) }
it { expect(described_class).to respond_to(:closed) }
it { expect(described_class).to respond_to(:assigned) }
2014-09-02 18:07:02 +05:30
end
describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
it "matches by title" do
2015-04-26 12:48:37 +05:30
expect(described_class.search('able')).to eq([searchable_issue])
2014-09-02 18:07:02 +05:30
end
end
describe "#today?" do
it "returns true when created today" do
# Avoid timezone differences and just return exactly what we want
2015-04-26 12:48:37 +05:30
allow(Date).to receive(:today).and_return(issue.created_at.to_date)
expect(issue.today?).to be_truthy
2014-09-02 18:07:02 +05:30
end
it "returns false when not created today" do
2015-04-26 12:48:37 +05:30
allow(Date).to receive(:today).and_return(Date.yesterday)
expect(issue.today?).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
describe "#new?" do
it "returns true when created today and record hasn't been updated" do
2015-04-26 12:48:37 +05:30
allow(issue).to receive(:today?).and_return(true)
expect(issue.new?).to be_truthy
2014-09-02 18:07:02 +05:30
end
it "returns false when not created today" do
2015-04-26 12:48:37 +05:30
allow(issue).to receive(:today?).and_return(false)
expect(issue.new?).to be_falsey
2014-09-02 18:07:02 +05:30
end
it "returns false when record has been updated" do
2015-04-26 12:48:37 +05:30
allow(issue).to receive(:today?).and_return(true)
2014-09-02 18:07:02 +05:30
issue.touch
2015-04-26 12:48:37 +05:30
expect(issue.new?).to be_falsey
2014-09-02 18:07:02 +05:30
end
end
2015-09-25 12:07:36 +05:30
describe "#to_hook_data" do
let(:hook_data) { issue.to_hook_data(user) }
it "returns correct hook data" do
expect(hook_data[:object_kind]).to eq("issue")
expect(hook_data[:user]).to eq(user.hook_attrs)
expect(hook_data[:repository][:name]).to eq(issue.project.name)
expect(hook_data[:repository][:url]).to eq(issue.project.url_to_repo)
expect(hook_data[:repository][:description]).to eq(issue.project.description)
expect(hook_data[:repository][:homepage]).to eq(issue.project.web_url)
expect(hook_data[:object_attributes]).to eq(issue.hook_attrs)
end
end
describe '#card_attributes' do
it 'includes the author name' do
allow(issue).to receive(:author).and_return(double(name: 'Robert'))
allow(issue).to receive(:assignee).and_return(nil)
expect(issue.card_attributes).
to eq({ 'Author' => 'Robert', 'Assignee' => nil })
end
it 'includes the assignee name' do
allow(issue).to receive(:author).and_return(double(name: 'Robert'))
allow(issue).to receive(:assignee).and_return(double(name: 'Douwe'))
expect(issue.card_attributes).
to eq({ 'Author' => 'Robert', 'Assignee' => 'Douwe' })
end
end
describe "votes" do
before do
author = create :user
project = create :empty_project
issue.notes.awards.create!(note: "thumbsup", author: author, project: project)
issue.notes.awards.create!(note: "thumbsdown", author: author, project: project)
end
it "returns correct values" do
expect(issue.upvotes).to eq(1)
expect(issue.downvotes).to eq(1)
end
end
2014-09-02 18:07:02 +05:30
end