Gab Social. All are welcome.
This commit is contained in:
55
spec/helpers/admin/account_moderation_notes_helper_spec.rb
Normal file
55
spec/helpers/admin/account_moderation_notes_helper_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
|
||||
include StreamEntriesHelper
|
||||
|
||||
describe '#admin_account_link_to' do
|
||||
context 'account is nil' do
|
||||
let(:account) { nil }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(helper.admin_account_link_to(account)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with account' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'calls #link_to' do
|
||||
expect(helper).to receive(:link_to).with(
|
||||
admin_account_path(account.id),
|
||||
class: name_tag_classes(account),
|
||||
title: account.acct
|
||||
)
|
||||
|
||||
helper.admin_account_link_to(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#admin_account_inline_link_to' do
|
||||
context 'account is nil' do
|
||||
let(:account) { nil }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(helper.admin_account_inline_link_to(account)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with account' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'calls #link_to' do
|
||||
expect(helper).to receive(:link_to).with(
|
||||
admin_account_path(account.id),
|
||||
class: name_tag_classes(account, true),
|
||||
title: account.acct
|
||||
)
|
||||
|
||||
helper.admin_account_inline_link_to(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
272
spec/helpers/admin/action_log_helper_spec.rb
Normal file
272
spec/helpers/admin/action_log_helper_spec.rb
Normal file
@@ -0,0 +1,272 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::ActionLogsHelper, type: :helper do
|
||||
klass = Class.new do
|
||||
include ActionView::Helpers
|
||||
include Admin::ActionLogsHelper
|
||||
end
|
||||
|
||||
let(:hoge) { klass.new }
|
||||
|
||||
describe '#log_target' do
|
||||
after do
|
||||
hoge.log_target(log)
|
||||
end
|
||||
|
||||
context 'log.target' do
|
||||
let(:log) { double(target: true) }
|
||||
|
||||
it 'calls linkable_log_target' do
|
||||
expect(hoge).to receive(:linkable_log_target).with(log.target)
|
||||
end
|
||||
end
|
||||
|
||||
context '!log.target' do
|
||||
let(:log) { double(target: false, target_type: :type, recorded_changes: :change) }
|
||||
|
||||
it 'calls log_target_from_history' do
|
||||
expect(hoge).to receive(:log_target_from_history).with(log.target_type, log.recorded_changes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#relevant_log_changes' do
|
||||
let(:log) { double(target_type: target_type, action: log_action, recorded_changes: recorded_changes) }
|
||||
let(:recorded_changes) { double }
|
||||
|
||||
after do
|
||||
hoge.relevant_log_changes(log)
|
||||
end
|
||||
|
||||
context "log.target_type == 'CustomEmoji' && [:enable, :disable, :destroy].include?(log.action)" do
|
||||
let(:target_type) { 'CustomEmoji' }
|
||||
let(:log_action) { :enable }
|
||||
|
||||
it "calls log.recorded_changes.slice('domain')" do
|
||||
expect(recorded_changes).to receive(:slice).with('domain')
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'CustomEmoji' && log.action == :update" do
|
||||
let(:target_type) { 'CustomEmoji' }
|
||||
let(:log_action) { :update }
|
||||
|
||||
it "calls log.recorded_changes.slice('domain', 'visible_in_picker')" do
|
||||
expect(recorded_changes).to receive(:slice).with('domain', 'visible_in_picker')
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'User' && [:promote, :demote].include?(log.action)" do
|
||||
let(:target_type) { 'User' }
|
||||
let(:log_action) { :promote }
|
||||
|
||||
it "calls log.recorded_changes.slice('moderator', 'admin')" do
|
||||
expect(recorded_changes).to receive(:slice).with('moderator', 'admin')
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'User' && [:change_email].include?(log.action)" do
|
||||
let(:target_type) { 'User' }
|
||||
let(:log_action) { :change_email }
|
||||
|
||||
it "calls log.recorded_changes.slice('email', 'unconfirmed_email')" do
|
||||
expect(recorded_changes).to receive(:slice).with('email', 'unconfirmed_email')
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'DomainBlock'" do
|
||||
let(:target_type) { 'DomainBlock' }
|
||||
let(:log_action) { nil }
|
||||
|
||||
it "calls log.recorded_changes.slice('severity', 'reject_media')" do
|
||||
expect(recorded_changes).to receive(:slice).with('severity', 'reject_media')
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'Status' && log.action == :update" do
|
||||
let(:target_type) { 'Status' }
|
||||
let(:log_action) { :update }
|
||||
|
||||
it "log.recorded_changes.slice('sensitive')" do
|
||||
expect(recorded_changes).to receive(:slice).with('sensitive')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#log_extra_attributes' do
|
||||
after do
|
||||
hoge.log_extra_attributes(hoge: 'hoge')
|
||||
end
|
||||
|
||||
it "calls content_tag(:span, key, class: 'diff-key')" do
|
||||
allow(hoge).to receive(:log_change).with(anything)
|
||||
expect(hoge).to receive(:content_tag).with(:span, :hoge, class: 'diff-key')
|
||||
end
|
||||
|
||||
it 'calls safe_join twice' do
|
||||
expect(hoge).to receive(:safe_join).with(
|
||||
['<span class="diff-key">hoge</span>',
|
||||
'=',
|
||||
'<span class="diff-neutral">hoge</span>']
|
||||
)
|
||||
|
||||
expect(hoge).to receive(:safe_join).with([nil], ' ')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#log_change' do
|
||||
after do
|
||||
hoge.log_change(val)
|
||||
end
|
||||
|
||||
context '!val.is_a?(Array)' do
|
||||
let(:val) { 'hoge' }
|
||||
|
||||
it "calls content_tag(:span, val, class: 'diff-neutral')" do
|
||||
expect(hoge).to receive(:content_tag).with(:span, val, class: 'diff-neutral')
|
||||
end
|
||||
end
|
||||
|
||||
context 'val.is_a?(Array)' do
|
||||
let(:val) { %w(foo bar) }
|
||||
|
||||
it 'calls #content_tag twice and #safe_join' do
|
||||
expect(hoge).to receive(:content_tag).with(:span, 'foo', class: 'diff-old')
|
||||
expect(hoge).to receive(:content_tag).with(:span, 'bar', class: 'diff-new')
|
||||
expect(hoge).to receive(:safe_join).with([nil, nil], '→')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#icon_for_log' do
|
||||
subject { hoge.icon_for_log(log) }
|
||||
|
||||
context "log.target_type == 'Account'" do
|
||||
let(:log) { double(target_type: 'Account') }
|
||||
|
||||
it 'returns "user"' do
|
||||
expect(subject).to be 'user'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'User'" do
|
||||
let(:log) { double(target_type: 'User') }
|
||||
|
||||
it 'returns "user"' do
|
||||
expect(subject).to be 'user'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'CustomEmoji'" do
|
||||
let(:log) { double(target_type: 'CustomEmoji') }
|
||||
|
||||
it 'returns "file"' do
|
||||
expect(subject).to be 'file'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'Report'" do
|
||||
let(:log) { double(target_type: 'Report') }
|
||||
|
||||
it 'returns "flag"' do
|
||||
expect(subject).to be 'flag'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'DomainBlock'" do
|
||||
let(:log) { double(target_type: 'DomainBlock') }
|
||||
|
||||
it 'returns "lock"' do
|
||||
expect(subject).to be 'lock'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'EmailDomainBlock'" do
|
||||
let(:log) { double(target_type: 'EmailDomainBlock') }
|
||||
|
||||
it 'returns "envelope"' do
|
||||
expect(subject).to be 'envelope'
|
||||
end
|
||||
end
|
||||
|
||||
context "log.target_type == 'Status'" do
|
||||
let(:log) { double(target_type: 'Status') }
|
||||
|
||||
it 'returns "pencil"' do
|
||||
expect(subject).to be 'pencil'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#class_for_log_icon' do
|
||||
subject { hoge.class_for_log_icon(log) }
|
||||
|
||||
%i(enable unsuspend unsilence confirm promote resolve).each do |action|
|
||||
context "log.action == #{action}" do
|
||||
let(:log) { double(action: action) }
|
||||
|
||||
it 'returns "positive"' do
|
||||
expect(subject).to be 'positive'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'log.action == :create' do
|
||||
context 'opposite_verbs?(log)' do
|
||||
let(:log) { double(action: :create, target_type: 'DomainBlock') }
|
||||
|
||||
it 'returns "negative"' do
|
||||
expect(subject).to be 'negative'
|
||||
end
|
||||
end
|
||||
|
||||
context '!opposite_verbs?(log)' do
|
||||
let(:log) { double(action: :create, target_type: '') }
|
||||
|
||||
it 'returns "positive"' do
|
||||
expect(subject).to be 'positive'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%i(update reset_password disable_2fa memorialize change_email).each do |action|
|
||||
context "log.action == #{action}" do
|
||||
let(:log) { double(action: action) }
|
||||
|
||||
it 'returns "neutral"' do
|
||||
expect(subject).to be 'neutral'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%i(demote silence disable suspend remove_avatar remove_header reopen).each do |action|
|
||||
context "log.action == #{action}" do
|
||||
let(:log) { double(action: action) }
|
||||
|
||||
it 'returns "negative"' do
|
||||
expect(subject).to be 'negative'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'log.action == :destroy' do
|
||||
context 'opposite_verbs?(log)' do
|
||||
let(:log) { double(action: :destroy, target_type: 'DomainBlock') }
|
||||
|
||||
it 'returns "positive"' do
|
||||
expect(subject).to be 'positive'
|
||||
end
|
||||
end
|
||||
|
||||
context '!opposite_verbs?(log)' do
|
||||
let(:log) { double(action: :destroy, target_type: '') }
|
||||
|
||||
it 'returns "negative"' do
|
||||
expect(subject).to be 'negative'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
spec/helpers/admin/filter_helper_spec.rb
Normal file
20
spec/helpers/admin/filter_helper_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::FilterHelper do
|
||||
it 'Uses filter_link_to to create filter links' do
|
||||
params = ActionController::Parameters.new(
|
||||
{ test: 'test' }
|
||||
)
|
||||
allow(helper).to receive(:params).and_return(params)
|
||||
allow(helper).to receive(:url_for).and_return('/test')
|
||||
result = helper.filter_link_to('text', { resolved: true })
|
||||
|
||||
expect(result).to match(/text/)
|
||||
end
|
||||
|
||||
it 'Uses table_link_to to create icon links' do
|
||||
result = helper.table_link_to 'icon', 'text', 'path'
|
||||
|
||||
expect(result).to match(/text/)
|
||||
end
|
||||
end
|
||||
129
spec/helpers/application_helper_spec.rb
Normal file
129
spec/helpers/application_helper_spec.rb
Normal file
@@ -0,0 +1,129 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ApplicationHelper do
|
||||
describe 'active_nav_class' do
|
||||
it 'returns active when on the current page' do
|
||||
allow(helper).to receive(:current_page?).and_return(true)
|
||||
|
||||
result = helper.active_nav_class("/test")
|
||||
expect(result).to eq "active"
|
||||
end
|
||||
|
||||
it 'returns active when on a current page' do
|
||||
allow(helper).to receive(:current_page?).with('/foo').and_return(false)
|
||||
allow(helper).to receive(:current_page?).with('/test').and_return(true)
|
||||
|
||||
result = helper.active_nav_class('/foo', '/test')
|
||||
expect(result).to eq "active"
|
||||
end
|
||||
|
||||
it 'returns empty string when not on current page' do
|
||||
allow(helper).to receive(:current_page?).and_return(false)
|
||||
|
||||
result = helper.active_nav_class("/test")
|
||||
expect(result).to eq ""
|
||||
end
|
||||
end
|
||||
|
||||
describe 'locale_direction' do
|
||||
around do |example|
|
||||
current_locale = I18n.locale
|
||||
example.run
|
||||
I18n.locale = current_locale
|
||||
end
|
||||
|
||||
it 'adds rtl body class if locale is Arabic' do
|
||||
I18n.locale = :ar
|
||||
expect(helper.locale_direction).to eq 'rtl'
|
||||
end
|
||||
|
||||
it 'adds rtl body class if locale is Farsi' do
|
||||
I18n.locale = :fa
|
||||
expect(helper.locale_direction).to eq 'rtl'
|
||||
end
|
||||
|
||||
it 'adds rtl if locale is Hebrew' do
|
||||
I18n.locale = :he
|
||||
expect(helper.locale_direction).to eq 'rtl'
|
||||
end
|
||||
|
||||
it 'does not add rtl if locale is Thai' do
|
||||
I18n.locale = :th
|
||||
expect(helper.locale_direction).to_not eq 'rtl'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'fa_icon' do
|
||||
it 'returns a tag of fixed-width cog' do
|
||||
expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'favicon_path' do
|
||||
it 'returns /favicon.ico on production enviromnent' do
|
||||
expect(Rails.env).to receive(:production?).and_return(true)
|
||||
expect(helper.favicon_path).to eq '/favicon.ico'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'open_registrations?' do
|
||||
it 'returns true when open for registrations' do
|
||||
without_partial_double_verification do
|
||||
expect(Setting).to receive(:registrations_mode).and_return('open')
|
||||
end
|
||||
|
||||
expect(helper.open_registrations?).to eq true
|
||||
end
|
||||
|
||||
it 'returns false when closed for registrations' do
|
||||
without_partial_double_verification do
|
||||
expect(Setting).to receive(:registrations_mode).and_return('none')
|
||||
end
|
||||
|
||||
expect(helper.open_registrations?).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'show_landing_strip?', without_verify_partial_doubles: true do
|
||||
describe 'when signed in' do
|
||||
before do
|
||||
allow(helper).to receive(:user_signed_in?).and_return(true)
|
||||
end
|
||||
it 'does not show landing strip' do
|
||||
expect(helper.show_landing_strip?).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
before do
|
||||
allow(helper).to receive(:user_signed_in?).and_return(false)
|
||||
end
|
||||
|
||||
it 'does not show landing strip on single user instance' do
|
||||
allow(helper).to receive(:single_user_mode?).and_return(true)
|
||||
|
||||
expect(helper.show_landing_strip?).to eq false
|
||||
end
|
||||
|
||||
it 'shows landing strip on multi user instance' do
|
||||
allow(helper).to receive(:single_user_mode?).and_return(false)
|
||||
|
||||
expect(helper.show_landing_strip?).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'title' do
|
||||
around do |example|
|
||||
site_title = Setting.site_title
|
||||
example.run
|
||||
Setting.site_title = site_title
|
||||
end
|
||||
|
||||
it 'returns site title on production enviroment' do
|
||||
Setting.site_title = 'site title'
|
||||
expect(Rails.env).to receive(:production?).and_return(true)
|
||||
expect(helper.title).to eq 'site title'
|
||||
end
|
||||
end
|
||||
end
|
||||
19
spec/helpers/flashes_helper_spec.rb
Normal file
19
spec/helpers/flashes_helper_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe FlashesHelper, type: :helper do
|
||||
describe 'user_facing_flashes' do
|
||||
it 'returns user facing flashes' do
|
||||
flash[:alert] = 'an alert'
|
||||
flash[:error] = 'an error'
|
||||
flash[:notice] = 'a notice'
|
||||
flash[:success] = 'a success'
|
||||
flash[:not_user_facing] = 'a not user facing flash'
|
||||
expect(helper.user_facing_flashes).to eq 'alert' => 'an alert',
|
||||
'error' => 'an error',
|
||||
'notice' => 'a notice',
|
||||
'success' => 'a success'
|
||||
end
|
||||
end
|
||||
end
|
||||
9
spec/helpers/home_helper_spec.rb
Normal file
9
spec/helpers/home_helper_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe HomeHelper, type: :helper do
|
||||
describe 'default_props' do
|
||||
it 'returns default properties according to the context' do
|
||||
expect(helper.default_props).to eq locale: I18n.locale
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/helpers/instance_helper_spec.rb
Normal file
33
spec/helpers/instance_helper_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe InstanceHelper do
|
||||
describe 'site_title' do
|
||||
around do |example|
|
||||
site_title = Setting.site_title
|
||||
example.run
|
||||
Setting.site_title = site_title
|
||||
end
|
||||
|
||||
it 'Uses the Setting.site_title value when it exists' do
|
||||
Setting.site_title = 'New site title'
|
||||
|
||||
expect(helper.site_title).to eq 'New site title'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'site_hostname' do
|
||||
around(:each) do |example|
|
||||
before = Rails.configuration.x.local_domain
|
||||
example.run
|
||||
Rails.configuration.x.local_domain = before
|
||||
end
|
||||
|
||||
it 'returns the local domain value' do
|
||||
Rails.configuration.x.local_domain = 'example.com'
|
||||
|
||||
expect(helper.site_hostname).to eq 'example.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
92
spec/helpers/jsonld_helper_spec.rb
Normal file
92
spec/helpers/jsonld_helper_spec.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe JsonLdHelper do
|
||||
describe '#equals_or_includes?' do
|
||||
it 'returns true when value equals' do
|
||||
expect(helper.equals_or_includes?('foo', 'foo')).to be true
|
||||
end
|
||||
|
||||
it 'returns false when value does not equal' do
|
||||
expect(helper.equals_or_includes?('foo', 'bar')).to be false
|
||||
end
|
||||
|
||||
it 'returns true when value is included' do
|
||||
expect(helper.equals_or_includes?(%w(foo baz), 'foo')).to be true
|
||||
end
|
||||
|
||||
it 'returns false when value is not included' do
|
||||
expect(helper.equals_or_includes?(%w(foo baz), 'bar')).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#first_of_value' do
|
||||
context 'value.is_a?(Array)' do
|
||||
it 'returns value.first' do
|
||||
value = ['a']
|
||||
expect(helper.first_of_value(value)).to be 'a'
|
||||
end
|
||||
end
|
||||
|
||||
context '!value.is_a?(Array)' do
|
||||
it 'returns value' do
|
||||
value = 'a'
|
||||
expect(helper.first_of_value(value)).to be 'a'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#supported_context?' do
|
||||
context "!json.nil? && equals_or_includes?(json['@context'], ActivityPub::TagManager::CONTEXT)" do
|
||||
it 'returns true' do
|
||||
json = { '@context' => ActivityPub::TagManager::CONTEXT }.as_json
|
||||
expect(helper.supported_context?(json)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'else' do
|
||||
it 'returns false' do
|
||||
json = nil
|
||||
expect(helper.supported_context?(json)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch_resource' do
|
||||
context 'when the second argument is false' do
|
||||
it 'returns resource even if the retrieved ID and the given URI does not match' do
|
||||
stub_request(:get, 'https://bob.test/').to_return body: '{"id": "https://alice.test/"}'
|
||||
stub_request(:get, 'https://alice.test/').to_return body: '{"id": "https://alice.test/"}'
|
||||
|
||||
expect(fetch_resource('https://bob.test/', false)).to eq({ 'id' => 'https://alice.test/' })
|
||||
end
|
||||
|
||||
it 'returns nil if the object identified by the given URI and the object identified by the retrieved ID does not match' do
|
||||
stub_request(:get, 'https://mallory.test/').to_return body: '{"id": "https://marvin.test/"}'
|
||||
stub_request(:get, 'https://marvin.test/').to_return body: '{"id": "https://alice.test/"}'
|
||||
|
||||
expect(fetch_resource('https://mallory.test/', false)).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the second argument is true' do
|
||||
it 'returns nil if the retrieved ID and the given URI does not match' do
|
||||
stub_request(:get, 'https://mallory.test/').to_return body: '{"id": "https://alice.test/"}'
|
||||
expect(fetch_resource('https://mallory.test/', true)).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch_resource_without_id_validation' do
|
||||
it 'returns nil if the status code is not 200' do
|
||||
stub_request(:get, 'https://host.test/').to_return status: 400, body: '{}'
|
||||
expect(fetch_resource_without_id_validation('https://host.test/')).to eq nil
|
||||
end
|
||||
|
||||
it 'returns hash' do
|
||||
stub_request(:get, 'https://host.test/').to_return status: 200, body: '{}'
|
||||
expect(fetch_resource_without_id_validation('https://host.test/')).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
43
spec/helpers/routing_helper_spec.rb
Normal file
43
spec/helpers/routing_helper_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RoutingHelper, type: :helper do
|
||||
describe '.full_asset_url' do
|
||||
around do |example|
|
||||
use_s3 = Rails.configuration.x.use_s3
|
||||
example.run
|
||||
Rails.configuration.x.use_s3 = use_s3
|
||||
end
|
||||
|
||||
shared_examples 'returns full path URL' do
|
||||
it 'with host' do
|
||||
url = helper.full_asset_url('https://example.com/avatars/000/000/002/original/icon.png')
|
||||
|
||||
expect(url).to eq 'https://example.com/avatars/000/000/002/original/icon.png'
|
||||
end
|
||||
|
||||
it 'without host' do
|
||||
url = helper.full_asset_url('/avatars/original/missing.png', skip_pipeline: true)
|
||||
|
||||
expect(url).to eq 'http://test.host/avatars/original/missing.png'
|
||||
end
|
||||
end
|
||||
|
||||
context 'Do not use S3' do
|
||||
before do
|
||||
Rails.configuration.x.use_s3 = false
|
||||
end
|
||||
|
||||
it_behaves_like 'returns full path URL'
|
||||
end
|
||||
|
||||
context 'Use S3' do
|
||||
before do
|
||||
Rails.configuration.x.use_s3 = true
|
||||
end
|
||||
|
||||
it_behaves_like 'returns full path URL'
|
||||
end
|
||||
end
|
||||
end
|
||||
22
spec/helpers/settings_helper_spec.rb
Normal file
22
spec/helpers/settings_helper_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SettingsHelper do
|
||||
describe 'the HUMAN_LOCALES constant' do
|
||||
it 'includes all I18n locales' do
|
||||
options = I18n.available_locales
|
||||
|
||||
expect(described_class::HUMAN_LOCALES.keys).to include(*options)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'human_locale' do
|
||||
it 'finds the human readable local description from a key' do
|
||||
# Ensure the value is as we expect
|
||||
expect(described_class::HUMAN_LOCALES[:en]).to eq('English')
|
||||
|
||||
expect(helper.human_locale(:en)).to eq('English')
|
||||
end
|
||||
end
|
||||
end
|
||||
224
spec/helpers/stream_entries_helper_spec.rb
Normal file
224
spec/helpers/stream_entries_helper_spec.rb
Normal file
@@ -0,0 +1,224 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe StreamEntriesHelper, type: :helper do
|
||||
describe '#display_name' do
|
||||
it 'uses the display name when it exists' do
|
||||
account = Account.new(display_name: "Display", username: "Username")
|
||||
|
||||
expect(helper.display_name(account)).to eq "Display"
|
||||
end
|
||||
|
||||
it 'uses the username when display name is nil' do
|
||||
account = Account.new(display_name: nil, username: "Username")
|
||||
|
||||
expect(helper.display_name(account)).to eq "Username"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stream_link_target' do
|
||||
it 'returns nil if it is not an embedded view' do
|
||||
set_not_embedded_view
|
||||
|
||||
expect(helper.stream_link_target).to be_nil
|
||||
end
|
||||
|
||||
it 'returns _blank if it is an embedded view' do
|
||||
set_embedded_view
|
||||
|
||||
expect(helper.stream_link_target).to eq '_blank'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#acct' do
|
||||
it 'is fully qualified for embedded local accounts' do
|
||||
allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
|
||||
set_embedded_view
|
||||
account = Account.new(domain: nil, username: 'user')
|
||||
|
||||
acct = helper.acct(account)
|
||||
|
||||
expect(acct).to eq '@user@local_domain'
|
||||
end
|
||||
|
||||
it 'is fully qualified for embedded foreign accounts' do
|
||||
set_embedded_view
|
||||
account = Account.new(domain: 'foreign_server.com', username: 'user')
|
||||
|
||||
acct = helper.acct(account)
|
||||
|
||||
expect(acct).to eq '@user@foreign_server.com'
|
||||
end
|
||||
|
||||
it 'is fully qualified for non embedded foreign accounts' do
|
||||
set_not_embedded_view
|
||||
account = Account.new(domain: 'foreign_server.com', username: 'user')
|
||||
|
||||
acct = helper.acct(account)
|
||||
|
||||
expect(acct).to eq '@user@foreign_server.com'
|
||||
end
|
||||
|
||||
it 'is fully qualified for non embedded local accounts' do
|
||||
allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
|
||||
set_not_embedded_view
|
||||
account = Account.new(domain: nil, username: 'user')
|
||||
|
||||
acct = helper.acct(account)
|
||||
|
||||
expect(acct).to eq '@user@local_domain'
|
||||
end
|
||||
end
|
||||
|
||||
def set_not_embedded_view
|
||||
params[:controller] = "not_#{StreamEntriesHelper::EMBEDDED_CONTROLLER}"
|
||||
params[:action] = "not_#{StreamEntriesHelper::EMBEDDED_ACTION}"
|
||||
end
|
||||
|
||||
def set_embedded_view
|
||||
params[:controller] = StreamEntriesHelper::EMBEDDED_CONTROLLER
|
||||
params[:action] = StreamEntriesHelper::EMBEDDED_ACTION
|
||||
end
|
||||
|
||||
describe '#style_classes' do
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.style_classes(status, false, false, false)
|
||||
|
||||
expect(classes).to eq 'entry'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
classes = helper.style_classes(status, false, false, false)
|
||||
|
||||
expect(classes).to eq 'entry entry-reblog'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.style_classes(status, true, false, false)
|
||||
|
||||
expect(classes).to eq 'entry entry-predecessor'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.style_classes(status, false, true, false)
|
||||
|
||||
expect(classes).to eq 'entry entry-successor'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.style_classes(status, false, false, true)
|
||||
|
||||
expect(classes).to eq 'entry entry-center'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
classes = helper.style_classes(status, true, true, true)
|
||||
|
||||
expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#microformats_classes' do
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.microformats_classes(status, false, false)
|
||||
|
||||
expect(classes).to eq ''
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.microformats_classes(status, true, false)
|
||||
|
||||
expect(classes).to eq 'p-in-reply-to'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
classes = helper.microformats_classes(status, false, true)
|
||||
|
||||
expect(classes).to eq 'p-comment'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
classes = helper.microformats_classes(status, true, false)
|
||||
|
||||
expect(classes).to eq 'p-in-reply-to p-repost-of'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
classes = helper.microformats_classes(status, true, true)
|
||||
|
||||
expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#microformats_h_class' do
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
css_class = helper.microformats_h_class(status, false, false, false)
|
||||
|
||||
expect(css_class).to eq 'h-entry'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
css_class = helper.microformats_h_class(status, false, false, false)
|
||||
|
||||
expect(css_class).to eq 'h-cite'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
css_class = helper.microformats_h_class(status, true, false, false)
|
||||
|
||||
expect(css_class).to eq 'h-cite'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
css_class = helper.microformats_h_class(status, false, true, false)
|
||||
|
||||
expect(css_class).to eq 'h-cite'
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: false)
|
||||
css_class = helper.microformats_h_class(status, false, false, true)
|
||||
|
||||
expect(css_class).to eq ''
|
||||
end
|
||||
|
||||
it do
|
||||
status = double(reblog?: true)
|
||||
css_class = helper.microformats_h_class(status, true, true, true)
|
||||
|
||||
expect(css_class).to eq 'h-cite'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#rtl?' do
|
||||
it 'is false if text is empty' do
|
||||
expect(helper).not_to be_rtl ''
|
||||
end
|
||||
|
||||
it 'is false if there are no right to left characters' do
|
||||
expect(helper).not_to be_rtl 'hello world'
|
||||
end
|
||||
|
||||
it 'is false if right to left characters are fewer than 1/3 of total text' do
|
||||
expect(helper).not_to be_rtl 'hello ݟ world'
|
||||
end
|
||||
|
||||
it 'is true if right to left characters are greater than 1/3 of total text' do
|
||||
expect(helper).to be_rtl 'aaݟaaݟ'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user