我在我的路由中有一個約束,只允許發送一個jjax請求。 如何用rspec測試這個? 特別是什麼測試會顯示/日程安排是可路由的,但僅限於AJAX。如何使用rspec/rails測試AJAX請求的路由
的routes.rb
class OnlyAjaxRequest
def matches?(request)
request.xhr?
end
end
resources :schedules, :constraints => OnlyAjaxRequest.new
我現在有測試以下通過區域表明,正常的GET請求是不可路由的,但我想知道如何測試一個AJAX GET請求是可路由的。
規格/路由/ schedules_routing_spec.rb
require 'spec_helper'
describe "GET /schedules" do
it "returns http failure to non AJAX request" do
{:get => '/schedules'}.should_not be_routable
end
end
你在問什麼?你是否建議這個測試應該失敗?你需要幫助寫其他測試?如果是這樣,你在尋求什麼樣的測試幫助? –
是的,對不起。我要求一個可以測試的測試。像某種'{:ajax_get =>'/schedules'}.should be_routable' – mazlix