mirror of
https://github.com/discourse/discourse.git
synced 2024-12-30 08:53:54 +08:00
ea5c3a3bdc
In AdminDashboardData we have a bunch of problem checks implemented as methods on that class. This PR absolves it of the responsibility by promoting each of those checks to a first class ProblemCheck. This way each of them can have their own priority and arbitrary functionality can be isolated in its own class. Think "extract class" refactoring over and over. Since they were all moved we can also get rid of the @@problem_syms class variable which was basically the old version of the registry now replaced by ProblemCheck.realtime. In addition AdminDashboardData::Problem value object has been entirely replaced with the new ProblemCheck::Problem (with compatible API). Lastly, I added some RSpec matchers to simplify testing of problem checks and provide helpful error messages when assertions fail.
46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec::Matchers.define :be_chill_about_it do
|
|
match { |service| expect(service.call).to be_empty }
|
|
end
|
|
|
|
RSpec::Matchers.define :have_a_problem do
|
|
chain :with_message do |message|
|
|
@message = message
|
|
end
|
|
|
|
chain :with_priority do |priority|
|
|
@priority = priority
|
|
end
|
|
|
|
match do |service|
|
|
@result = service.call
|
|
|
|
aggregate_failures do
|
|
expect(@result).to include(be_a(ProblemCheck::Problem))
|
|
expect(@result.first.priority).to(eq(@priority.to_s)) if @priority.present?
|
|
expect(@result.first.message).to(eq(@message)) if @message.present?
|
|
end
|
|
end
|
|
|
|
failure_message do |service|
|
|
if @result.empty?
|
|
"Expected check to have a problem, but it was chill about it."
|
|
elsif !@result.all?(ProblemCheck::Problem)
|
|
"Expected result to contain only instances of `Problem`."
|
|
elsif @priority.present? && @result.first.priority != @priority
|
|
"Expected problem to have priority `#{@priority}`, but got priority `#{@result.first.priority}`."
|
|
elsif @message.present? && @result.first.message != @message
|
|
<<~MESSAGE
|
|
Expected problem to have message:
|
|
|
|
> #{@message}
|
|
|
|
but got message:
|
|
|
|
> #{@result.first.message}
|
|
MESSAGE
|
|
end
|
|
end
|
|
end
|