diff options
Diffstat (limited to 'spec/models/issue/metrics_spec.rb')
-rw-r--r-- | spec/models/issue/metrics_spec.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb index 18b0a46c928..49c891c20da 100644 --- a/spec/models/issue/metrics_spec.rb +++ b/spec/models/issue/metrics_spec.rb @@ -80,5 +80,20 @@ RSpec.describe Issue::Metrics do expect(metrics.first_added_to_board_at).to be_like_time(time) end end + + describe "#record!" do + it "does not cause an N+1 query" do + label = create(:label) + subject.update!(label_ids: [label.id]) + + control_count = ActiveRecord::QueryRecorder.new { Issue::Metrics.find_by(issue: subject).record! }.count + + additional_labels = create_list(:label, 4) + + subject.update!(label_ids: additional_labels.map(&:id)) + + expect { Issue::Metrics.find_by(issue: subject).record! }.not_to exceed_query_limit(control_count) + end + end end end |