Refactor `search_answer` to be dynamically inserted so it can be changed

This commit is contained in:
Robin Ward 2019-10-16 14:36:54 -04:00
parent 5ef49692e0
commit 74207ef03a
3 changed files with 10 additions and 6 deletions

View File

@ -293,7 +293,7 @@ en:
<img src="%{base_uri}/plugins/discourse-narrative-bot/images/capybara-eating.gif"/> <img src="%{base_uri}/plugins/discourse-narrative-bot/images/capybara-eating.gif"/>
Did you notice youre now back at the beginning? Feed this poor hungry capybara by **replying with the `:herb:` emoji** and youll be automatically taken to the end. Did you notice youre now back at the beginning? Feed this poor hungry capybara by **replying with the `%{search_answer}` emoji** and youll be automatically taken to the end.
reply: |- reply: |-
Yay you found it :tada: Yay you found it :tada:

View File

@ -117,7 +117,9 @@ module DiscourseNarrativeBot
} }
} }
SEARCH_ANSWER = ':herb:'.freeze def self.search_answer
':herb:'
end
def self.reset_trigger def self.reset_trigger
I18n.t('discourse_narrative_bot.new_user_narrative.reset_trigger') I18n.t('discourse_narrative_bot.new_user_narrative.reset_trigger')
@ -152,7 +154,7 @@ module DiscourseNarrativeBot
raw = <<~RAW raw = <<~RAW
#{post.raw} #{post.raw}
#{I18n.t("#{I18N_KEY}.search.hidden_message", i18n_post_args)} #{I18n.t("#{I18N_KEY}.search.hidden_message", i18n_post_args.merge(search_answer: NewUserNarrative.search_answer))}
RAW RAW
PostRevisor.new(post, topic).revise!( PostRevisor.new(post, topic).revise!(
@ -495,7 +497,7 @@ module DiscourseNarrativeBot
post_topic_id = @post.topic_id post_topic_id = @post.topic_id
return unless valid_topic?(post_topic_id) return unless valid_topic?(post_topic_id)
if @post.raw.match(/#{SEARCH_ANSWER}/) if @post.raw.match(/#{NewUserNarrative.search_answer}/)
fake_delay fake_delay
reply_to(@post, I18n.t("#{I18N_KEY}.search.reply", i18n_post_args(search_url: url_helpers(:search_url)))) reply_to(@post, I18n.t("#{I18N_KEY}.search.reply", i18n_post_args(search_url: url_helpers(:search_url))))
else else

View File

@ -946,7 +946,9 @@ describe DiscourseNarrativeBot::NewUserNarrative do
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_search) expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_search)
expect(post.reload.topic.first_post.raw).to include(I18n.t( expect(post.reload.topic.first_post.raw).to include(I18n.t(
"discourse_narrative_bot.new_user_narrative.search.hidden_message", base_uri: '' "discourse_narrative_bot.new_user_narrative.search.hidden_message",
base_uri: '',
search_answer: described_class.search_answer
)) ))
end end
@ -963,7 +965,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
it 'should create the right reply' do it 'should create the right reply' do
post.update!( post.update!(
raw: "#{described_class::SEARCH_ANSWER} this is a capybara" raw: "#{described_class.search_answer} this is a capybara"
) )
expect do expect do