forked from amatsuda/traceroute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraceroute_with_engine_test.rb
95 lines (72 loc) · 2.34 KB
/
traceroute_with_engine_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true
require_relative 'test_helper'
module TestEngine
class Engine < ::Rails::Engine
isolate_namespace TestEngine
end
class TasksController < ApplicationController; end
end
module EngineTestsCondition
def setup
TestEngine::TasksController.class_eval { def index() end }
super
end
def teardown
super
TestEngine::TasksController.send :undef_method, :index
TestEngine::TasksController.clear_action_methods!
end
end
module TracerouteWithEngineTest
class BasicTest < Minitest::Test
prepend EngineTestsCondition
def setup
@traceroute = Traceroute.new Rails.application
end
def test_defined_action_methods
assert_defined_action_methods 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'test_engine/tasks#index', 'users#index', 'users#index2', 'users#show'
end
def test_routed_actions
assert_empty @traceroute.routed_actions
end
end
class RoutedActionsTest < Minitest::Test
prepend EngineTestsCondition
def setup
DummyApp::Application.routes.draw do
resources :posts, :only => [:index, :show, :new, :create]
end
@traceroute = Traceroute.new Rails.application
end
def teardown
DummyApp::Application.routes.clear!
end
def test_routed_actions
assert_routed_actions 'posts#index', 'posts#show', 'posts#new', 'posts#create'
end
end
class EngineTest < Minitest::Test
prepend EngineTestsCondition
def setup
TestEngine::Engine.routes.draw do
resources :tasks, only: :index
root to: redirect(path: '/tasks')
end
Rails.application.routes_reloader.route_sets << DummyApp::Application.routes
DummyApp::Application.routes.draw do
resources :posts, only: [:index, :show]
mount TestEngine::Engine => '/test_engine'
end
@traceroute = Traceroute.new Rails.application
end
def teardown
DummyApp::Application.routes.clear!
end
def test_defined_action_methods
assert_defined_action_methods 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'test_engine/tasks#index', 'users#index', 'users#index2', 'users#show'
end
def test_routed_actions
assert_routed_actions 'posts#index', 'posts#show', 'test_engine/tasks#index'
end
end
end