FIX: Use the quote generator in the example text

This way if a plugin customizes the quotes the example will match.
This commit is contained in:
Robin Ward 2019-10-16 13:40:05 -04:00
parent 48c1238492
commit a37dafdd4d
4 changed files with 13 additions and 4 deletions

View File

@ -124,7 +124,7 @@ en:
> :game_die: 3, 6
`@%{discobot_username} %{quote_trigger}`
> :left_speech_bubble: _Carry out a random act of kindness, with no expectation of reward, safe in the knowledge that one day someone might do the same for you_ — Princess Diana
%{quote_sample}
`@%{discobot_username} %{magic_8_ball_trigger}`
> :crystal_ball: You may rely on it

View File

@ -6,6 +6,10 @@ module DiscourseNarrativeBot
class QuoteGenerator
API_ENDPOINT = 'http://api.forismatic.com/api/1.0/'.freeze
def self.format_quote(quote, author)
I18n.t('discourse_narrative_bot.quote.results', quote: quote, author: author)
end
def self.generate(user)
quote, author =
if !user.effective_locale.start_with?('en')
@ -23,7 +27,7 @@ module DiscourseNarrativeBot
[response_body["quoteText"].strip, response_body["quoteAuthor"].strip]
end
I18n.t('discourse_narrative_bot.quote.results', quote: quote, author: author)
format_quote(quote, author)
end
end
end

View File

@ -178,6 +178,7 @@ module DiscourseNarrativeBot
discobot_username: discobot_username,
dice_trigger: self.class.dice_trigger,
quote_trigger: self.class.quote_trigger,
quote_sample: DiscourseNarrativeBot::QuoteGenerator.generate(@user),
magic_8_ball_trigger: self.class.magic_8_ball_trigger
)}"
end

View File

@ -14,6 +14,11 @@ describe DiscourseNarrativeBot::TrackSelector do
)
end
before do
stub_request(:get, "http://api.forismatic.com/api/1.0/?format=json&lang=en&method=getQuote").
to_return(status: 200, body: "{\"quoteText\":\"Be Like Water\",\"quoteAuthor\":\"Bruce Lee\"}")
end
let(:help_message) do
discobot_username = discobot_user.username
@ -30,6 +35,7 @@ describe DiscourseNarrativeBot::TrackSelector do
discobot_username: discobot_username,
dice_trigger: described_class.dice_trigger,
quote_trigger: described_class.quote_trigger,
quote_sample: DiscourseNarrativeBot::QuoteGenerator.format_quote('Be Like Water', 'Bruce Lee'),
magic_8_ball_trigger: described_class.magic_8_ball_trigger
)}
RAW
@ -577,8 +583,6 @@ describe DiscourseNarrativeBot::TrackSelector do
describe 'when a quote is requested' do
it 'should create the right reply' do
stub_request(:get, "http://api.forismatic.com/api/1.0/?format=json&lang=en&method=getQuote").
to_return(status: 200, body: "{\"quoteText\":\"Be Like Water\",\"quoteAuthor\":\"Bruce Lee\"}")
post.update!(raw: "@discobot quote")
described_class.new(:reply, user, post_id: post.id).select