mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 16:29:32 +08:00
DEV: Fix failing chat spec and add unexpected failure indicator (#20299)
This commit fixes the UpdateUserLastRead spec which was checking for a message ID that did not exist -- this could fail at times since message ID 2 could exist. Better to create + destroy a message since then it's guaranteed we have a unique ID. This also attempts to clarify a step that we expect to fail which succeeds instead by adding another emoji next to the success tick and an explanation text. Also removes some uses of unless in Services::Base, we generally prefer to use alternatives, since unless can be hard to parse in a lot of cases. Co-authored-by: Loïc Guitaut <loic@discourse.org>
This commit is contained in:
@ -197,7 +197,7 @@ module Chat
|
||||
def call(instance, context)
|
||||
method = instance.method(method_name)
|
||||
args = {}
|
||||
args = context.to_h unless method.arity.zero?
|
||||
args = context.to_h if !method.arity.zero?
|
||||
context[result_key] = Context.build
|
||||
instance.instance_exec(**args, &method)
|
||||
end
|
||||
@ -217,7 +217,7 @@ module Chat
|
||||
class ModelStep < Step
|
||||
def call(instance, context)
|
||||
context[name] = super
|
||||
raise ArgumentError, "Model not found" unless context[name]
|
||||
raise ArgumentError, "Model not found" if !context[name]
|
||||
rescue ArgumentError => exception
|
||||
context[result_key].fail(exception: exception)
|
||||
context.fail!
|
||||
@ -227,7 +227,7 @@ module Chat
|
||||
# @!visibility private
|
||||
class PolicyStep < Step
|
||||
def call(instance, context)
|
||||
unless super
|
||||
if !super
|
||||
context[result_key].fail
|
||||
context.fail!
|
||||
end
|
||||
@ -250,7 +250,7 @@ module Chat
|
||||
contract = class_name.new(default_values.merge(context.to_h.slice(*attributes)))
|
||||
context[contract_name] = contract
|
||||
context[result_key] = Context.build
|
||||
unless contract.valid?
|
||||
if contract.invalid?
|
||||
context[result_key].fail(errors: contract.errors)
|
||||
context.fail!
|
||||
end
|
||||
@ -384,7 +384,7 @@ module Chat
|
||||
# private
|
||||
#
|
||||
# def save_channel(channel:, **)
|
||||
# fail!("something went wrong") unless channel.save
|
||||
# fail!("something went wrong") if !channel.save
|
||||
# end
|
||||
|
||||
# @!scope class
|
||||
|
Reference in New Issue
Block a user