How to specify https protocol in routing specification using rspec?

In the routes file I have:

resources :subscription, :only => [:show], :constraints => {:protocol => "https"} 

I am trying to add a specification for this route as follows:

 it "recognizes and generates #show" do { :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show") end 

However, the specification still does not work. If I remove :protocol => 'https' , the specification also fails:

  ActionController :: RoutingError:    
   No route matches "/ subscription" 
+6
source share
3 answers

The solution (undocumented?) Is to simply include the entire dummy URL, for example:

 it "recognizes and generates #show" do { :get => "https://test.host/subscription" }.should route_to(:controller => "subscriptions", :action => "show") end 

I understood this from this ticket and this set of changes .

+4
source

I'm not sure, but I think routes should be declared as multiple - see Rails Routing from Outside In . So it will be

 resources :subscriptions 

and in spec

 {:get => '/subscriptions', :protocol => 'https'} 

Try it if it goes without :protocol . If so, skip the specification using HTTPS. This should not be tested at the unit test level, but in the integration test.

-1
source

Does this pass if you change the specification to this ?:

 {:get => '/subscription'}.should_not route_to(:controller => …) 

This will at least give you confidence that HTTP is not routed.

-1
source

Source: https://habr.com/ru/post/896698/


All Articles