Cameron Caine
2010-Aug-25 22:15 UTC
[rspec-users] Rails3 subdomain constraints with Cucumber and RSpec2
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
--
Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Aug-26 00:05 UTC
[rspec-users] Rails3 subdomain constraints with Cucumber and RSpec2
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 > endThere 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
Cameron Caine
2010-Aug-26 13:22 UTC
[rspec-users] Rails3 subdomain constraints with Cucumber and RSpec2
I updated to rc2 and RSpec beta.20 but still get an error:
Failure/Error: { :get => "http://foo.example.com/account/new"
}.should_not be_routable
expected {:get=>"http://foo.example.com/account/new"} not to
be
routable, but it routes to {:controller=>"accounts",
:action=>"new"}
Is this a bug? Any advice?
Many thanks
Cameron
--
Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Aug-26 13:27 UTC
[rspec-users] Rails3 subdomain constraints with Cucumber and RSpec2
On Aug 26, 2010, at 8:22 AM, Cameron Caine wrote:> I updated to rc2 and RSpec beta.20 but still get an error: > > Failure/Error: { :get => "http://foo.example.com/account/new" > }.should_not be_routable > expected {:get=>"http://foo.example.com/account/new"} not to be > routable, but it routes to {:controller=>"accounts", :action=>"new"}Please quote all the relevant parts of the thread in each email so we don''t have to go searching through the thread for context.> Is this a bug? Any advice? > > Many thanks > > Cameron