Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: Delete request in capybara, bug or my mistake?
    primarykey
    data
    text
    <p>In <a href="http://ruby.railstutorial.org/book/ruby-on-rails-tutorial" rel="nofollow">Michael Hartl's Rails Tutorial (Rails 3.2)</a>, in Listing 9.52:</p> <pre><code> describe "when signing in again" do before do delete signout_path print page.html &lt;---- Insert this here visit signin_path print page.html &lt;---- Insert here again fill_in "Email", with: user.email fill_in "Password", with: user.password click_button "Sign in" end it "should render the default (profile) page" do page.should have_selector('title', text: user.name) end end </code></pre> <p>I inserted those two prints. And, surprisingly I got the printout of the same page (which shouldn't be, It was supposed to bring you back to the root url after sending the <code>DELETE</code> request). After this happens, since <code>visit signin_path</code> takes me back to the sign in page, the sign in procedure succeeds and so does the test case. However, the second <code>print page.html</code> gave me the header of a user whom is still signed in.</p> <p>When I changed <code>delete signout_path</code> to <code>click_link "Sign out"</code>, it worked.</p> <p>Did I miss something in my code or it's a Capybara bug? (Cause I'm pretty sure I followed everything just right..)</p> <p><strong>UPDATE:</strong> If I change <code>delete signout_path</code> to <code>Capybara.current_session.driver.delete signout_path</code> it also works just fine. (Meaning capybara signs out the user correctly)</p> <p><strong>UPDATE</strong></p> <p>These are the files (sessions controller and helper):</p> <p>sessions_controller.rb</p> <pre><code>class SessionsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:session][:email].downcase) if user &amp;&amp; user.authenticate(params[:session][:password]) sign_in user redirect_back_or user else flash.now[:error] = 'Invalid email/password combination' render 'new' end end def destroy sign_out redirect_to root_url end end </code></pre> <p>sessions_helper.rb</p> <pre><code>module SessionsHelper def sign_in(user) cookies.permanent[:remember_token] = user.remember_token self.current_user = user end def signed_in? !current_user.nil? end def current_user=(user) @current_user = user end def current_user?(user) user == current_user end def signed_in_user unless signed_in? store_location redirect_to signin_url, notice: "Please sign in." end end def current_user @current_user ||= User.find_by_remember_token(cookies[:remember_token]) end def sign_out self.current_user = nil cookies.delete(:remember_token) end def redirect_back_or(default) redirect_to(session[:return_to] || default) session.delete(:return_to) end def store_location session[:return_to] = request.url end end </code></pre> <p>routes.rb</p> <pre><code>DemoApp::Application.routes.draw do ... root to: 'static_pages#home' match '/signup', to: 'users#new' match '/signin', to: 'sessions#new' match '/signout', to: 'sessions#destroy', via: :delete resources :sessions, only: [:new, :create, :destroy] ... end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload