On Aug 25, 2010, at 5:15 PM, Cameron Caine wrote:
> How do I spec rails3 routing constraints?
> My Cucumber features pass whatever subdomain I pass in. Not sure where
> or how to spec the subdomain. Any help would be appreciated.
>
> I have something like the following:
>
> #features/create_account.feature
> Scenario:
> Given I visit subdomain "www"
> And I go to the new account page
>
> #accounts_controller_spec.rb
> describe AccountsController do
> describe "GET new" do
> before(:each) do
> get :new
> end
>
> it "should render new.html.haml" do
> response.should render_template(:new)
> end
> end
> end
>
> #routes.rb
> constraints Promotional do
> resource :account, :only => :new
> end
>
> #lib/promotional.rb
> class Promotional
> def self.matches?(request)
> request.subdomain.empty? || request.subdomain == "www"
> end
> end
There was a commit to rails [1] that got in a day or two before the rc2 release
that lets you pass a full URL to routing assertions. This means you can do this
in RSpec:
{ :get => "http://www.example.com/accounts/new" }.should route_to(:controller
=> "accounts", :action => "new")
{ :get => "http://foo.example.com/accounts/new" }.should_not be_routable
You need rails-3.0.0.rc2. Not sure what version of rspec-rails you need, but
you may as well grab rspec-rails-2.0.0.beta.20 (the latest).
HTH,
David
[1] https://rails.lighthouseapp.com/projects/8994/tickets/5005
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users