summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-06-08 16:37:31 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-06-08 16:37:31 +0000
commitabaaad67605b446871beb42fa5413d64f2a1c76d (patch)
treecf4836aad9afb38693ac5389b50797bcc9daaeb6 /spec
parentae7fc2e12bfe5fdbd23f8c184166f3ac80bded7c (diff)
parent83e1274145792fbfb09557a2a202843129edf483 (diff)
downloadgitlab-ce-abaaad67605b446871beb42fa5413d64f2a1c76d.tar.gz
Merge branch '17960-issues-api-endpoint-performs-poorly' into 'master'
Optimize issuable APIs interaction with notes See merge request !4471
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/issuable_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index dd03d64f750..efbcbf72f76 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -10,6 +10,16 @@ describe Issue, "Issuable" do
it { is_expected.to belong_to(:assignee) }
it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:todos).dependent(:destroy) }
+
+ context 'Notes' do
+ let!(:note) { create(:note, noteable: issue, project: issue.project) }
+ let(:scoped_issue) { Issue.includes(notes: :author).find(issue.id) }
+
+ it 'indicates if the notes have their authors loaded' do
+ expect(issue.notes).not_to be_authors_loaded
+ expect(scoped_issue.notes).to be_authors_loaded
+ end
+ end
end
describe 'Included modules' do
@@ -245,6 +255,22 @@ describe Issue, "Issuable" do
end
end
+ describe '#user_notes_count' do
+ let(:project) { create(:project) }
+ let(:issue1) { create(:issue, project: project) }
+ let(:issue2) { create(:issue, project: project) }
+
+ before do
+ create_list(:note, 3, noteable: issue1, project: project)
+ create_list(:note, 6, noteable: issue2, project: project)
+ end
+
+ it 'counts the user notes' do
+ expect(issue1.user_notes_count).to be(3)
+ expect(issue2.user_notes_count).to be(6)
+ end
+ end
+
describe "votes" do
let(:project) { issue.project }