Forum: RSpec Routing error with webrat

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Juanma C. (Guest)
on 2008-12-23 11:04
Hello

I am starting using cucumber with an app using restful_authentication.
I am having an error that is driving me mad.

I am using this step

Given /^que he hecho login en la aplicación$/ do
  user = User.create!(
      :login => "mi_login",
      :name => "mi_nombre",
      :email => "removed_email_address@domain.invalid",
      :password => 'supersecret',
      :password_confirmation => 'supersecret' )

  User.find_by_login("mi_login").should_not be_nil

  visit login_path
  fill_in :login, :with => user.login
  fill_in :password, :with => 'supersecret'
  click_button "Log in"
  response.body.should =~ /Logged/m
end

The problem is with the sentence click_button "Log in",
I have the standar new.html.erb template created by the
restful_authentication plugin

==== new.html.erb ===========
<h1>Log In</h1>

<% form_tag session_path do -%>
<p><%= label_tag 'login' %><br />
<%= text_field_tag 'login', @login %></p>

<p><%= label_tag 'password' %><br/>
<%= password_field_tag 'password', nil %></p>

<p><%= submit_tag 'Log in' %></p>
<% end -%>

===========================


Everything in routes.rb is standar

  map.logout '/logout', :controller => 'sessions', :action => 'destroy'
  map.login '/login', :controller => 'sessions', :action => 'new'
  map.register '/register', :controller => 'users', :action => 'create'
  map.signup '/signup', :controller => 'users', :action => 'new'
  map.resources :users
  map.resource :session


An the error says something about routing:

  No route matches "/" with {:method=>:get}
(ActionController::RoutingError)

that occurs when clicking the button.

I have put the error here, in http://pastie.org/345420.

Can somebody give me some light.

Thanks.
Matt W. (Guest)
on 2008-12-23 12:10
(Received via mailing list)
On 23 Dec 2008, at 09:04, Juanma C. wrote:

>      :name => "mi_nombre",
>  response.body.should =~ /Logged/m
> <p><%= label_tag 'login' %><br />
>
> An the error says something about routing:
>
>  No route matches "/" with {:method=>:get}
> (ActionController::RoutingError)
>
> that occurs when clicking the button.
>
> I have put the error here, in http://pastie.org/345420.
>
> Can somebody give me some light.

The error you're getting seems to suggest that rails can't find a
route defined for a GET request to "/" which is the homepage of your
app. I assume this is where the resful authentication plugin wants to
redirect you after logging you in.

When you set up your routes, did you remember to put in a route for
the homepage?

e.g. map.root :controller => "home", :action => "index"

HTH,

Matt W.
http://blog.mattwynne.net
http://www.songkick.com
Juanma C. (Guest)
on 2008-12-23 14:43
Thanks Matt.
You were right,
I have modified routes.rb with mapping root url but I did't understand
why this is needed.

The create action in sessions controller is completely standar.
The sentence that is causing the error
  redirect_back_or_default('/')

is not using thr root_url.
I think this is a bug, but I don't know.

Cheers and many thanks.
Juanma C..
Juanma C. (Guest)
on 2008-12-23 16:35
> I think this is a bug, but I don't know.
Well, I see all more clear now.
I thought it was a bug because I thought it was failing only when
running the feature, and it worked without problem hitting the
application with the browser.
But this was not true.
It worked because I had index.html in /public folder , when I removed
it, I has the same error.

Juanma C.
This topic is locked and can not be replied to.