In my routes file I have:
resources :subscription, :only => [:show], :constraints => {:protocol => "https"}
I'm trying to add a spec for this route like this:
it "recognizes and generates #show" do
{ :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show")
end
However, the spec still fails.
If I remove the :protocol => 'https'
, the spec also fails:
ActionController::RoutingError: No route matches "/subscription"
Does it pass if you change to spec to this?:
That would at least give you the confidence that HTTP is not routed.
I'm not sure, but I think routes should be declared as plural — see Rails Routing from the Outside In. So it would be
and in the spec
Try if that passes without
:protocol
. If it does, skip the spec with HTTPS. That should not be tested on a unit-test level, but in an integration test.The (undocumented?) solution is to simply include an entire dummy url, like so:
I figured it out from this ticket and this changeset.