summaryrefslogtreecommitdiff
path: root/spec/models/timelog_spec.rb
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-01-25 19:16:09 -0600
committerRuben Davila <rdavila84@gmail.com>2017-02-07 10:41:44 -0500
commitbdc932245088b3a7ae5d633e81175352d5599083 (patch)
treef98c8d57c6f7d1f9e1d6a2a2eda8835fd9c2f0be /spec/models/timelog_spec.rb
parent8abdabdb3ad9e4b87893f24042de077cd4a7d791 (diff)
downloadgitlab-ce-bdc932245088b3a7ae5d633e81175352d5599083.tar.gz
Use normal associations instead of polymorphic.
We can't properly use foreign keys on columns that are configured for polymorphic associations which has disadvantages related to data integrity and storage. Given we only use time tracking for Issues and Merge Requests we're moving to the usage of regular associations.
Diffstat (limited to 'spec/models/timelog_spec.rb')
-rw-r--r--spec/models/timelog_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/models/timelog_spec.rb b/spec/models/timelog_spec.rb
index f08935b6425..ebc694213b6 100644
--- a/spec/models/timelog_spec.rb
+++ b/spec/models/timelog_spec.rb
@@ -2,9 +2,37 @@ require 'rails_helper'
RSpec.describe Timelog, type: :model do
subject { build(:timelog) }
+ let(:issue) { create(:issue) }
+ let(:merge_request) { create(:merge_request) }
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