discourse-chat-integration/spec/dummy_provider.rb

68 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.shared_context "with dummy provider" do
before(:each) do
module ::DiscourseChatIntegration::Provider::DummyProvider
PROVIDER_NAME = "dummy".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
2017-07-17 12:53:32 -04:00
CHANNEL_PARAMETERS = []
@@sent_messages = []
@@raise_exception = nil
def self.trigger_notification(post, channel, rule)
if @@raise_exception
raise @@raise_exception
end
2017-10-03 05:42:07 -04:00
@@sent_messages.push(post: post.id, channel: channel)
end
def self.sent_messages
@@sent_messages
end
def self.sent_to_channel_ids
2017-08-01 15:53:39 -04:00
@@sent_messages.map { |x| x[:channel].id }
end
def self.set_raise_exception(bool)
@@raise_exception = bool
end
end
end
after(:each) do
::DiscourseChatIntegration::Provider.send(:remove_const, :DummyProvider)
end
let(:provider) { ::DiscourseChatIntegration::Provider::DummyProvider }
end
RSpec.shared_context "with validated dummy provider" do
before(:each) do
module ::DiscourseChatIntegration::Provider::Dummy2Provider
PROVIDER_NAME = "dummy2".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
2017-07-17 12:53:32 -04:00
CHANNEL_PARAMETERS = [
2017-08-01 15:53:39 -04:00
{ key: "val", regex: '^\S+$', unique: true }
2017-07-17 12:53:32 -04:00
]
@@sent_messages = []
def self.trigger_notification(post, channel, rule)
@@sent_messages.push(post: post.id, channel: channel)
end
def self.sent_messages
@@sent_messages
end
end
2017-08-01 15:53:39 -04:00
end
after(:each) do
::DiscourseChatIntegration::Provider.send(:remove_const, :Dummy2Provider)
end
end