diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/issue/metrics_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 3 |
2 files changed, 14 insertions, 14 deletions
diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb index 49c891c20da..6e3ef69017b 100644 --- a/spec/models/issue/metrics_spec.rb +++ b/spec/models/issue/metrics_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Issue::Metrics do end end - describe "when recording the default set of issue metrics on issue save" do + shared_examples "when recording the default set of issue metrics on issue save" do context "milestones" do it "records the first time an issue is associated with a milestone" do time = Time.current @@ -80,20 +80,21 @@ RSpec.describe Issue::Metrics do expect(metrics.first_added_to_board_at).to be_like_time(time) end 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) + context 'when upsert_issue_metrics is enabled' do + before do + stub_feature_flags(upsert_issue_metrics: true) + end - subject.update!(label_ids: additional_labels.map(&:id)) + it_behaves_like 'when recording the default set of issue metrics on issue save' + end - expect { Issue::Metrics.find_by(issue: subject).record! }.not_to exceed_query_limit(control_count) - end + context 'when upsert_issue_metrics is disabled' do + before do + stub_feature_flags(upsert_issue_metrics: false) end + + it_behaves_like 'when recording the default set of issue metrics on issue save' end end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 116bda7a18b..3ec28a3f72f 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -102,7 +102,7 @@ RSpec.describe Issue do end it 'records current metrics' do - expect_any_instance_of(Issue::Metrics).to receive(:record!) + expect(Issue::Metrics).to receive(:record!) create(:issue, project: reusable_project) end @@ -111,7 +111,6 @@ RSpec.describe Issue do before do subject.metrics.delete subject.reload - subject.metrics # make sure metrics association is cached (currently nil) end it 'creates the metrics record' do |