summaryrefslogtreecommitdiff
path: root/spec/support/issuables_list_metadata_shared_examples.rb
blob: 3406e4c316137c14af8413e30954a7e0f293c151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
  before do
    @issuable_ids = []

    2.times do |n|
      issuable =
        if issuable_type == :issue
          create(issuable_type, project: project)
        else
          create(issuable_type, source_project: project, source_branch: "#{n}-feature")
        end

      @issuable_ids << issuable.id

      issuable.id.times       { create(:note, noteable: issuable, project: issuable.project) }
      (issuable.id + 1).times { create(:award_emoji, :downvote, awardable: issuable) }
      (issuable.id + 2).times { create(:award_emoji, :upvote, awardable: issuable) }
    end
  end

  it "creates indexed meta-data object for issuable notes and votes count" do
    if action
      get action
    else
      get :index, namespace_id: project.namespace, project_id: project
    end

    meta_data = assigns(:issuable_meta_data)

    @issuable_ids.each do |id|
      expect(meta_data[id].notes_count).to eq(id)
      expect(meta_data[id].downvotes).to eq(id + 1)
      expect(meta_data[id].upvotes).to eq(id + 2)
    end
  end

  describe "when given empty collection" do
    let(:project2) { create(:empty_project, :public) }

    it "doesn't execute any queries with false conditions" do
      get_action =
        if action
          proc { get action }
        else
          proc { get :index, namespace_id: project2.namespace, project_id: project2 }
        end

      expect(&get_action).not_to make_queries_matching(/WHERE (?:1=0|0=1)/)
    end
  end
end