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
I’m not familiar with Koala, but these are some ideas I’ve successfully used with other auth frameworks.
Define current_user to behave differently in test mode. It’s a little ugly.
Create a step that logs in a user for you, and just use it at the beginning of each scenario
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.