Question

I get this error on my tests from the Hartl tutorial section 9.2.3

1) Authentication signin with valid information 
 Failure/Error: click_button 'Sign in'
 ArgumentError:
   wrong number of arguments (0 for 1)
 # ./app/helpers/sessions_helper.rb:34:in `redirect_back_or'
 # ./app/controllers/sessions_controller.rb:11:in `create'
 # (eval):2:in `click_button'
 # ./spec/requests/authentication_pages_spec.rb:37:in `block (4 levels) in <top (required)>'

It comes from this method in the Sessions Controller:

app/controllers/sesssions_controllers.rb

def create
  user = User.find_by_email(params[:session][:email])
  if user && user.authenticate(params[:session][:password])
  sign_in user
  redirect_back_or user
  else
  flash.now[:error] = "Invalid email/password combination"
  render 'new'
end 

The 'redirect_back_or' method comes from the session helper: app/helpers/sessions_helper.rb

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  session.delete.(:return_to)
end 

Prior to this the Session Controller create method would...

redirect_to user

Changing it to redirect_back_or fails almost all my tests. Using redirect_to user has most of the tests passing.

Here are the relevant tests: spec/requests/authentication_pages_spec.rb

describe "Authorization" do

describe "for non signed in users" do                    
  let(:user) {FactoryGirl.create(:user) }                

  describe "when attempting to visit a protected page" do
    before do
      visit edit_user_path(user)                         
      fill_in "Email", with: user.email                  
      fill_in "Password", with: user.password            
      click_button "Sign in"                             
    end                                                  
    describe "after signing in" do                       
      it "should render the desired protected page" do   
        page.should have_selector('title', text: "Edit user")
      end
    end
  end
end

I'm not sure what to do about this. Why am I getting the wrong number of arguments error?

I've gone back over the code but I'm not sure where to go. I feel like I double checked all the code from the book... but I still get this error. Thanks for being another set of eyes. Help me out with this problem thanks.

Was it helpful?

Solution

You have an extra dot in this line:

session.delete.(:return_to)

Change it to:

session.delete(:return_to)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top