test: cover ApplicationNPlusOneTest, teardown
This commit is contained in:
1 parent
99bbae8099
commit
5f2b55b35d
3 files changed
+175
No files matched your search
@@ -8,11 +8,16 @@ class ResourceApp < Prism::Application
|
||||
root(to: 'welcome#show')
|
||||
|
||||
resources :routing_posts, only: %i[index show create]
|
||||
resources :routing_comments, only: %i[destroy]
|
||||
|
||||
get '/whoami' do
|
||||
json(path: url_for(:routing_post, id: 5))
|
||||
end
|
||||
|
||||
get '/destroy-link' do
|
||||
json(path: url_for(:routing_comment, id: 7))
|
||||
end
|
||||
|
||||
get '/write-flash' do
|
||||
flash[:notice] = 'saved!'
|
||||
redirect '/after-flash'
|
||||
@@ -43,6 +48,12 @@ class RoutingPostsController < Prism::Controller
|
||||
end
|
||||
end
|
||||
|
||||
class RoutingCommentsController < Prism::Controller
|
||||
def destroy
|
||||
json(action: 'destroy', id: params['id'])
|
||||
end
|
||||
end
|
||||
|
||||
class ApplicationRoutingTest < Minitest::Test
|
||||
include TestSupport
|
||||
|
||||
@@ -81,6 +92,20 @@ class ApplicationRoutingTest < Minitest::Test
|
||||
assert_equal '/routing_posts/5', JSON.parse(body.join)['path']
|
||||
end
|
||||
|
||||
def test_resources_destroy_dispatches
|
||||
_, _, body = call('DELETE', '/routing_comments/3')
|
||||
assert_equal({ 'action' => 'destroy', 'id' => '3' }, JSON.parse(body.join))
|
||||
end
|
||||
|
||||
# Regression: add_resource_route used to skip `as:` for :destroy, so a
|
||||
# resource declared with only: [:destroy] (no :show alongside it) had no
|
||||
# named route at all - url_for/link_to/button_to for a delete link had no
|
||||
# path to build from.
|
||||
def test_url_for_named_resource_route_for_destroy_only_resource
|
||||
_, _, body = call('GET', '/destroy-link')
|
||||
assert_equal '/routing_comments/7', JSON.parse(body.join)['path']
|
||||
end
|
||||
|
||||
def test_flash_survives_a_redirect
|
||||
status, headers, = call('GET', '/write-flash')
|
||||
assert_equal 302, status
|
||||
@@ -97,4 +122,19 @@ class ApplicationRoutingTest < Minitest::Test
|
||||
_, _, body = call('GET', '/after-flash', cookies: cookie2)
|
||||
assert_nil JSON.parse(body.join)['notice']
|
||||
end
|
||||
|
||||
def test_controller_dispatch_enriches_process_action_payload
|
||||
events = []
|
||||
subscriber = Prism::Instrumentation.subscribe('process_action.prism') { |event| events << event }
|
||||
begin
|
||||
call('GET', '/routing_posts/9')
|
||||
ensure
|
||||
Prism::Instrumentation.unsubscribe(subscriber)
|
||||
end
|
||||
|
||||
assert_equal 1, events.size
|
||||
assert_equal 'routing_posts', events.first.payload[:controller]
|
||||
assert_equal 'show', events.first.payload[:action]
|
||||
assert_equal 200, events.first.payload[:status]
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user