debian-mirror-gitlab/spec/models/timelog_spec.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
RSpec.describe Timelog do
2017-08-17 22:00:37 +05:30
subject { build(:timelog) }
2019-12-21 20:55:43 +05:30
2017-08-17 22:00:37 +05:30
let(:issue) { create(:issue) }
let(:merge_request) { create(:merge_request) }
2018-11-08 19:23:39 +05:30
it { is_expected.to belong_to(:issue).touch(true) }
it { is_expected.to belong_to(:merge_request).touch(true) }
2017-08-17 22:00:37 +05:30
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:time_spent) }
it { is_expected.to validate_presence_of(:user) }
describe 'Issuable validation' do
it 'is invalid if issue_id and merge_request_id are missing' do
subject.attributes = { issue: nil, merge_request: nil }
expect(subject).to be_invalid
end
it 'is invalid if issue_id and merge_request_id are set' do
subject.attributes = { issue: issue, merge_request: merge_request }
expect(subject).to be_invalid
end
it 'is valid if only issue_id is set' do
subject.attributes = { issue: issue, merge_request: nil }
expect(subject).to be_valid
end
it 'is valid if only merge_request_id is set' do
subject.attributes = { merge_request: merge_request, issue: nil }
expect(subject).to be_valid
end
end
end