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.4.27 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.4 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.26 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.3 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.25 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.2 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.24 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.1 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.23 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.22 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.0 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.21 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.20 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.19 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.18 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.17 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.16 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.15 test/models/workarea/navigation/redirect_test.rb
workarea-core-3.4.14 test/models/workarea/navigation/redirect_test.rb