0
0
Fork 0

Test embedded_view related code in a helper (#2282)

The two methods `StreamEntriesHelper#stream_link_target` and
`StreamEntriesHelper#acct` are based on checking whether we are running
in an embedded view.

This adds some test helper code to make the testing easier. We extracted
some "magic strings" to constants to lower the coupling in the specs.
This commit is contained in:
Joël Quenneville 2017-04-23 00:05:52 -04:00 committed by Eugen
parent 0c2fe22bc1
commit 1cf9e14a41
2 changed files with 72 additions and 2 deletions

View file

@ -1,6 +1,9 @@
# frozen_string_literal: true
module StreamEntriesHelper
EMBEDDED_CONTROLLER = 'stream_entries'.freeze
EMBEDDED_ACTION = 'embed'.freeze
def display_name(account)
account.display_name.presence || account.username
end
@ -10,7 +13,11 @@ module StreamEntriesHelper
end
def acct(account)
"@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
if embedded_view? && account.local?
"@#{account.acct}@#{Rails.configuration.x.local_domain}"
else
"@#{account.acct}"
end
end
def style_classes(status, is_predecessor, is_successor, include_threads)
@ -58,6 +65,6 @@ module StreamEntriesHelper
end
def embedded_view?
params[:controller] == 'stream_entries' && params[:action] == 'embed'
params[:controller] == EMBEDDED_CONTROLLER && params[:action] == EMBEDDED_ACTION
end
end