Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:21+00:00 2026-05-21T07:26:21+00:00

How can I fake the current_user method to stop my cucumber tests failing? Something

  • 0

How can I fake the current_user method to stop my cucumber tests failing?

Something like a Given /^I am logged in$/ step.

class ApplicationController < ActionController::Base
  protect_from_forgery

  helper_method :current_user

  def facebook_cookies
    @facebook_cookies ||= Koala::Facebook::OAuth.new.get_user_info_from_cookie(cookies)
  end

  def current_user
    @graph = Koala::Facebook::GraphAPI.new(facebook_cookies['access_token'])
    @current_user = User.find_by_fbid(@graph.get_object("me")["id"]) || User.create(:fbid => @graph.get_object("me")["id"]) 
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:26:21+00:00Added an answer on May 21, 2026 at 7:26 am

    I’m not familiar with Koala, but these are some ideas I’ve successfully used with other auth frameworks.

    1. Define current_user to behave differently in test mode. It’s a little ugly.

      class ApplicationController < ActionController::Base
        ...
        def current_user
          if Rails.env == 'test'
            User.create! :username => 'Tester'
          else
            # do normal stuff
          end
        end
        ..
      end
      
    2. Create a step that logs in a user for you, and just use it at the beginning of each scenario

      Given /^I am logged in$/ do
        passwd = 'realgoodpassword'
        user = User.create! :username => 'Tester', :password => passwd
        visit login_path
        fill_in 'Username', :with => user.username
        fill_in 'Password', :with => passwd
        click_button 'Sign in'
      end
      

    This assumes you are using Capybara to power Cucumber. Webrat might look different; take a look in features/step_definitions/web_steps.rb to get some ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I call an onTouch method programmatically by dispatching a fake touch event?
How can I fake a REST response in my model s.t. it does not
Is it possible? I want to do this so I can kinda fake the
How can I do this in Moq? Foo bar = new Foo(); Fake(bar.PrivateGetter).Return('whatever value')
Is it possible to load a class in Java and 'fake' the package name/canonical
i'm using an example in which i can fake the session. It's for use
I would like to know how can I extend JEditorPane (or any other swing
Just curious, Can you fake an uptime , for instance increase it to 10
I'm wondering if I can make fake sections in the popup menu: The rule
So I'm making a tile based game and I'd like to add some fake

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.