From 1ffd1a305c51856da09dcac43781e7f2d1b6e633 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 30 Dec 2014 23:55:22 +0100 Subject: [PATCH] Section about testing xhr requests rails/rails#18305 --- guides/source/testing.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/guides/source/testing.md b/guides/source/testing.md index 21b0b37efa80f..308d744d710a5 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -528,6 +528,19 @@ All of request types have equivalent methods that you can use. In a typical C.R. NOTE: Functional tests do not verify whether the specified request type is accepted by the action, we're more concerned with the result. Request tests exist for this use case to make your tests more purposeful. +### Testing XHR (AJAX) requests + +`xhr` accepts method (listed in the section above), action name and parameters: + +```ruby +test "ajax request responds with no layout" do + xhr :get, :show, id: articles(:first).id + + assert_template :index + assert_template layout: nil +end +``` + ### The Four Hashes of the Apocalypse After a request has been made and processed, you will have 4 Hash objects ready for use: