cirandas.net

ref: master

plugins/custom_routes/test/unit/route_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'test_helper'

class RouteTest < ActiveSupport::TestCase

  should 'not create a route without source or target url' do
    route = CustomRoutesPlugin::Route.new(source_url: '/source')
    refute route.valid?

    route = CustomRoutesPlugin::Route.new(target_url: '/')
    refute route.valid?
  end

  should 'not create a route if target or source url are not relative' do
    route = CustomRoutesPlugin::Route.new(source_url: '/source',
                                         target_url: 'https://not.relative')
    refute route.valid?

    route = CustomRoutesPlugin::Route.new(source_url: 'https://not.relative',
                                         target_url: '/')
    refute route.valid?
  end

  should 'not create a route if target or source urls are invalid uris' do
    route = CustomRoutesPlugin::Route.new(source_url: '/source',
                                         target_url: '/not valid')
    refute route.valid?

    route = CustomRoutesPlugin::Route.new(source_url: '/not valid',
                                         target_url: '/target')
    refute route.valid?
  end

  should 'create a route and reload the mappings' do
    CustomRoutesPlugin::CustomRoutes.expects(:reload).returns(true).once
    route = CustomRoutesPlugin::Route.create(
      source_url: '/source',
      target_url: '/',
      environment_id: Environment.default.id
    )
    assert route.valid?
  end

end