Sha256: 6fbe18a5fd6cac72cedfc479b57a6ed4a0739c8bcd8418e10d47fe63176d4bff

Contents?: true

Size: 1.44 KB

Versions: 62

Compression:

Stored size: 1.44 KB

Contents

require 'test_helper'

module Workarea
  module Navigation
    class RedirectTest < TestCase
      def test_does_not_allow_duplicate_paths
        create_redirect(path: '/test')
        dup = Redirect.new(path: '/test')

        refute(dup.valid?)
        assert(dup.errors[:path].present?)
      end

      def test_finds_the_redirect_based_on_path
        path = '/test_path'
        redirect = create_redirect(path: path)

        assert_equal(redirect, Redirect.find_by_path(path))
      end

      def test_sanitizing_paths
        redirect = create_redirect(path: '/one/')

        %w(/one one/ /one/ one? one/?).each do |test|
          assert_equal(redirect, Redirect.find_by_path(test))
        end
      end

      def test_handle_invalid_path
        path = '/category/FoalBroodmare/Supplements-Mares & Foals/20552.html'
        encoded_path = URI.encode(path)
        redirect = Redirect.create(path: path, destination: '/')

        assert(redirect.valid?, redirect.errors.full_messages.to_sentence)
        assert_equal(encoded_path, redirect.path)

        new_redirect = Redirect.new(path: encoded_path, destination: '/')

        refute(new_redirect.valid?)
        assert(new_redirect.errors[:path].present?)

        assert_equal(redirect.reload.path, new_redirect.path)

        new_redirect = Redirect.new(path: path, destination: '/')

        refute(new_redirect.valid?)
        assert(new_redirect.errors[:path].present?)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.36 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.14 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.35 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.13 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.34 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.12 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.33 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.11 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.10 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.32 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.9 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.31 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.8 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.30 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.7 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.29 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.6 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.28 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.5 test/models/workarea/navigation/redirect_test.rb