Skip to content

Commit bebd2b1

Browse files
committed
Use have_queried_db_times matcher in lifecycle ordering tests
Replace manual SQL logger capture with the existing have_queried_db_times matcher for consistency with the rest of the test suite.
1 parent 9b6a491 commit bebd2b1

2 files changed

Lines changed: 8 additions & 22 deletions

File tree

spec/unit/models/runtime/buildpack_lifecycle_data_model_spec.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ module VCAP::CloudController
1414
describe 'buildpack_lifecycle_buildpacks association' do
1515
it 'orders by id via the default_order_by_id extension' do
1616
lifecycle_data.save
17-
lifecycle_data.reload
17+
lifecycle_data.reload # clear cached association
1818

19-
sqls = []
20-
logger = Logger.new(StringIO.new)
21-
logger.define_singleton_method(:info) { |msg| sqls << msg }
22-
BuildpackLifecycleDataModel.db.loggers << logger
23-
24-
lifecycle_data.buildpack_lifecycle_buildpacks
25-
26-
BuildpackLifecycleDataModel.db.loggers.delete(logger)
27-
sql = sqls.find { |s| s.include?('buildpack_lifecycle_buildpacks') }
28-
expect(sql).to match(/ORDER BY .id./)
19+
expect {
20+
lifecycle_data.buildpack_lifecycle_buildpacks
21+
}.to have_queried_db_times(/buildpack_lifecycle_buildpacks.*ORDER BY .id./i, 1)
2922
end
3023
end
3124

spec/unit/models/runtime/cnb_lifecycle_data_model_spec.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ module VCAP::CloudController
66

77
describe 'buildpack_lifecycle_buildpacks association' do
88
it 'orders by id via the default_order_by_id extension' do
9-
lifecycle_data.reload
9+
lifecycle_data.reload # clear cached association
1010

11-
sqls = []
12-
logger = Logger.new(StringIO.new)
13-
logger.define_singleton_method(:info) { |msg| sqls << msg }
14-
CNBLifecycleDataModel.db.loggers << logger
15-
16-
lifecycle_data.buildpack_lifecycle_buildpacks
17-
18-
CNBLifecycleDataModel.db.loggers.delete(logger)
19-
sql = sqls.find { |s| s.include?('buildpack_lifecycle_buildpacks') }
20-
expect(sql).to match(/ORDER BY .id./)
11+
expect {
12+
lifecycle_data.buildpack_lifecycle_buildpacks
13+
}.to have_queried_db_times(/buildpack_lifecycle_buildpacks.*ORDER BY .id./i, 1)
2114
end
2215
end
2316

0 commit comments

Comments
 (0)