routing_helper_spec.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RoutingHelper, type: :helper do
  4. describe '.full_asset_url' do
  5. around do |example|
  6. use_s3 = Rails.configuration.x.use_s3
  7. example.run
  8. Rails.configuration.x.use_s3 = use_s3
  9. end
  10. shared_examples 'returns full path URL' do
  11. it 'with host' do
  12. url = helper.full_asset_url('https://example.com/avatars/000/000/002/original/icon.png')
  13. expect(url).to eq 'https://example.com/avatars/000/000/002/original/icon.png'
  14. end
  15. it 'without host' do
  16. url = helper.full_asset_url('/avatars/original/missing.png', skip_pipeline: true)
  17. expect(url).to eq 'http://test.host/avatars/original/missing.png'
  18. end
  19. end
  20. context 'Do not use S3' do
  21. before do
  22. Rails.configuration.x.use_s3 = false
  23. end
  24. it_behaves_like 'returns full path URL'
  25. end
  26. context 'Use S3' do
  27. before do
  28. Rails.configuration.x.use_s3 = true
  29. end
  30. it_behaves_like 'returns full path URL'
  31. end
  32. end
  33. end