I have a constraint in my routes to only allow ajax requests to be routed. How do I test this with rspec? Specifically what test would show that /schedules is routable, but only from AJAX.
routes.rb
class OnlyAjaxRequest
def matches?(request)
request.xhr?
end
end
resources :schedules, :constraints => OnlyAjaxRequest.new
I currently have the following passing part of the test to show that a normal GET request is not routable, but I want to know how to test that an AJAX GET request is routable.
spec/routing/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