Shane Mingins
2011-Aug-02 02:29 UTC
[rspec-users] Testing Routing Constraint => redirect example.com to www.example.com
Hi All With the following route constraints(:host => "example.com") do match "(*x)" => redirect { |params, request| URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s } end I am wondering how or where I would spec this? Ideally I would like to be able to write a routing spec, something like: get("http://example.com").should route_to(:controller => "home", :action => "index", :host => "www.example.com") Thanks in advance Shane Mingins -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110802/80902bf9/attachment.html>
Justin Ko
2011-Aug-02 09:37 UTC
[rspec-users] Testing Routing Constraint => redirect example.com to www.example.com
On Mon, Aug 1, 2011 at 8:29 PM, Shane Mingins <elc at mingins.com> wrote:> Hi All > > With the following route > > constraints(:host => "example.com") do > match "(*x)" => redirect { |params, request| > URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s > } > end > > > I am wondering how or where I would spec this? > > Ideally I would like to be able to write a routing spec, something like: > > get("http://example.com").should route_to(:controller => "home", :action > => "index", :host => "www.example.com") > > Thanks in advance > > Shane Mingins > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersHi, take a look at this: https://github.com/rspec/rspec-rails/issues/416 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110802/b9433940/attachment-0001.html>
Shane Mingins
2011-Aug-03 02:19 UTC
[rspec-users] Testing Routing Constraint => redirect example.com to www.example.com
Thanks for that Justin! I was not aware of request specs http://relishapp.com/rspec/rspec-rails/v/2-6/dir/request-specs/request-spec... could not find any reference to them in the rspec book (maybe I missed them). so adding spec/requests/routes_spec.rb with the following did the trick! require "spec_helper" describe "routes that redirect" do it "redirects http://example.com to http://www.example.com" do get "http://example.com" response.should redirect_to(''http://www.example.com'') end it "should not redirect https://secure.example.com" do get "https://secure.example.com" response.should_not be_redirect end end constraints(:host => /^example.com/) do match "(*x)" => redirect { |params, request| URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s } end On 2 August 2011 21:37, Justin Ko <jko170 at gmail.com> wrote:> > > On Mon, Aug 1, 2011 at 8:29 PM, Shane Mingins <elc at mingins.com> wrote: > >> Hi All >> >> With the following route >> >> constraints(:host => "example.com") do >> match "(*x)" => redirect { |params, request| >> URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s >> } >> end >> >> >> I am wondering how or where I would spec this? >> >> Ideally I would like to be able to write a routing spec, something like: >> >> get("http://example.com").should route_to(:controller => "home", :action >> => "index", :host => "www.example.com") >> >> Thanks in advance >> >> Shane Mingins >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Hi, take a look at this: > https://github.com/rspec/rspec-rails/issues/416 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110803/952f167b/attachment.html>
Justin Ko
2011-Aug-03 05:01 UTC
[rspec-users] Testing Routing Constraint => redirect example.com to www.example.com
On Tue, Aug 2, 2011 at 8:19 PM, Shane Mingins <elc at mingins.com> wrote:> Thanks for that Justin! > > I was not aware of request specs > http://relishapp.com/rspec/rspec-rails/v/2-6/dir/request-specs/request-spec... could not find any reference to them in the rspec book (maybe I missed > them). > > so adding spec/requests/routes_spec.rb with the following did the trick! > > > require "spec_helper" > > describe "routes that redirect" do > > it "redirects http://example.com to http://www.example.com" do > get "http://example.com" > response.should redirect_to(''http://www.example.com'') > end > > it "should not redirect https://secure.example.com" do > get "https://secure.example.com" > response.should_not be_redirect > end > > end > > > constraints(:host => /^example.com/) do > match "(*x)" => redirect { |params, request| > URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s > } > end > > > > On 2 August 2011 21:37, Justin Ko <jko170 at gmail.com> wrote: > >> >> >> On Mon, Aug 1, 2011 at 8:29 PM, Shane Mingins <elc at mingins.com> wrote: >> >>> Hi All >>> >>> With the following route >>> >>> constraints(:host => "example.com") do >>> match "(*x)" => redirect { |params, request| >>> URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s >>> } >>> end >>> >>> >>> I am wondering how or where I would spec this? >>> >>> Ideally I would like to be able to write a routing spec, something like: >>> >>> get("http://example.com").should route_to(:controller => "home", :action >>> => "index", :host => "www.example.com") >>> >>> Thanks in advance >>> >>> Shane Mingins >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> Hi, take a look at this: >> https://github.com/rspec/rspec-rails/issues/416 >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersAwesome, glad it worked out! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110802/1a052790/attachment-0001.html>