summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-06-02 13:17:54 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-06-02 21:43:01 +0200
commit078ba8c090dd30cb4cad7ef6dc5380e2036e2e6a (patch)
tree41b146393a7f41ed0ce026a2a6a05550d58aaf63 /spec
parent7deb21b6261c1e8f55617dd4f5ae75c10b0ab047 (diff)
downloadgitlab-ce-078ba8c090dd30cb4cad7ef6dc5380e2036e2e6a.tar.gz
issuable#labels_array explicitly load the labels
This will be useful when you want to ask for the number of items and later iterate over them, without needing to ask if the association is load or not. So you avoid extra database queries
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/issuable_spec.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index fb20578d8d3..e9f827e9f50 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -227,6 +227,20 @@ describe Issue, "Issuable" do
end
end
+ describe '#labels_array' do
+ let(:project) { create(:project) }
+ let(:bug) { create(:label, project: project, title: 'bug') }
+ let(:issue) { create(:issue, project: project) }
+
+ before(:each) do
+ issue.labels << bug
+ end
+
+ it 'loads the association and returns it as an array' do
+ expect(issue.reload.labels_array).to eq([bug])
+ end
+ end
+
describe "votes" do
let(:project) { issue.project }