Forum: RSpec RSpec 2, Rails 3, and SSL routes

390d2e69569ba48d2335312717ff2d38?d=identicon&s=25 Brian Ploetz (bploetz)
on 2010-12-09 21:38
(Received via mailing list)
Hi all,

This is probably a stupid question, but I can't figure out how to do
this.....

If I have some routes which require SSL, how do I test that with
RSpec? For example:

# routes.rb
scope :constraints => { :protocol => "https" } do
  match '/foos.(:format)' => 'foos#index', :via => :get, :constraints
=> { :format => /(json|xml)/ }
end


In my routing spec, I've tried the following variants with no luck:

describe "routing to foos" do
  it "routes /foos.json to foos#index" do
    { :get => "/foos.json", :protocol => "https" }.should route_to(
      :controller => "foos",
      :action => "index",
      :format => "json"
    )
  end


describe "routing to foos" do
  it "routes /foos.json to foos#index" do
    { :get => "/foos.json" }.should route_to(
      :controller => "foos",
      :action => "index",
      :format => "json",
      :protocol => "https"
    )
  end


Thanks in advance for any help.
BP
390d2e69569ba48d2335312717ff2d38?d=identicon&s=25 Brian Ploetz (bploetz)
on 2010-12-13 15:06
(Received via mailing list)
Anybody?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2010-12-13 15:41
(Received via mailing list)
On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote:

>>
>>     { :get => "/foos.json", :protocol => "https" }.should route_to(
>>       :action => "index",
>>       :format => "json",
>>       :protocol => "https"
>>     )
>>   end
>>
>> Thanks in advance for any help.


There is an open issue in the Rails tracker about this [1].
assert_recognizes, to which "should route_to" delegates, does not yet
support constraints. Sadly, this means there is no good way to do this
at the moment.

[1]
https://rails.lighthouseapp.com/projects/8994/tick...
for more info.
390d2e69569ba48d2335312717ff2d38?d=identicon&s=25 Brian Ploetz (bploetz)
on 2010-12-13 16:31
(Received via mailing list)
OK, cool. I'll avoid banging my head against the wall in the mean
time. :-)

Thanks alot David.
BP
390d2e69569ba48d2335312717ff2d38?d=identicon&s=25 Brian Ploetz (bploetz)
on 2010-12-13 18:22
(Received via mailing list)
Actually, Rails seems to correctly support *some* routing constraints
in tests (:format being one), but not others (:protocol being one).
I'm coming up with a failing test which I'll attach to that Rails
ticket, but just noting it here as an FYI to others...
3bc7b6532e1537ca139c02f091636d3b?d=identicon&s=25 Aashish Kiran (aashishkiran)
on 2013-06-04 13:01
I too came across same situation (i.e., testing ssl request in rails
with specs).
Thinking there should be a solution.

Thanks,
Aashish
This topic is locked and can not be replied to.