0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/spec/support/matchers/problem_check_matcher.rb
Martin Brennan f36388234b
FIX: Upcoming change problem check not respecting should_display? (#41955)
Our UpcomingChangeStableOptedOut problem check was showing
problems on brand new sites, when it should only show a
problem after admin has opted out of a stable upcoming change.

This was happening because on some sites a plugin might be disabled
or not configurable, so it would return false when calling
`SiteSetting.send(change_name)`, but crucially we weren't filtering
out upcoming changes that shouldn't display on the site.

This commit fixes the issue by returning no problem if the upcoming
change is not configured to display on the site.
2026-07-23 10:22:00 +10:00

56 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec::Matchers.define :be_chill_about_it do
match { |service| expect(service.call).to be_blank }
failure_message do |service|
"Expected check to be chill about it, but it had a problem: #{service.call.inspect}"
end
end
RSpec::Matchers.define :have_a_problem do
chain :with_message do |message|
@message = message
end
chain :with_priority do |priority|
@priority = priority
end
chain :with_target do |target|
@target = target
end
match do |service|
@result = service.call
aggregate_failures do
expect(@result).to be_a(ProblemCheck::Problem)
expect(@result.priority).to(eq(@priority.to_s)) if @priority.present?
expect(@result.message).to(eq(@message)) if @message.present?
expect(@result.target).to(eq(@target)) if @target.present?
end
end
failure_message do |service|
if @result.blank?
"Expected check to have a problem, but it was chill about it."
elsif !@result.is_a?(ProblemCheck::Problem)
"Expected result to must be an instance of `Problem`."
elsif @priority.present? && @result.priority != @priority
"Expected problem to have priority `#{@priority}`, but got priority `#{@result.priority}`."
elsif @message.present? && @result.message != @message
<<~MESSAGE
Expected problem to have message:
> #{@message}
but got message:
> #{@result.message}
MESSAGE
elsif @target.present? && @result.target != @target
"Expected problem to have target `#{@target}`, but got target `#{@result.target}`."
end
end
end