ruby on rails - how to set user agent in rspec route assertions -


i trying use rails-rpec route specs test different routing based on different user agents, , cannot find correct method or object stub.

my method looks this:

require "spec_helper"  describe "articles routing"   describe "/articles/#slug"      "routes articles#show"       get("/articles/fancy-slug").should route_to(controller: "articles",                                                     action:     "show",                                                     id:         "fancy-slug")     end      describe "when have iphone user agent"       before(:each)         # magical happens along lines of line below         # request.user_agent = "mozilla/5.0 (iphone; cpu iphone os 6_1_3 mac os x) applewebkit/536.26 (khtml, gecko) version/6.0 mobile/10b329 safari/8536.25"       end        "routes mobile::articles#show"         expect(get: "/articles/fancy-slug").to route_to(controller: "mobile_articles",                                                       action:     "show",                                                       id:         "fancy-slug")       end     end    end end 

but life of me, cannot figure out how stub request, or controller, or whatever. of available documentation seems refer old/outdated version of get syntax.

i'm not sure work, here's try:

if @ source routetomatcher, parses controller/action pair (given hash or in controller#action format) , other parameters given along them , delegates actiondispatch::assertions::routingassertions#assert_recognizes. method builds request object parameters pass in argument route_to. there's no easy way access request object spec. however, build dummy request, calls

actioncontroller::testrequest.new

so might try

actioncontroller::testrequest.any_instance.stub(:user_agent).   and_return "mozilla/5.0 (iphone; cpu iphone os 6_1_3 mac os x) applewebkit/536.26 (khtml, gecko) version/6.0 mobile/10b329 safari/8536.25" 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -