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.27 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.26 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.45 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.25 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.23 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.44 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.22 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.43 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.21 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.42 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.20 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.41 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.19 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.40 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.18 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.39 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.17 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.38 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.16 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.37 test/models/workarea/navigation/redirect_test.rb