Skip to content

Instantly share code, notes, and snippets.

@Sutto
Created June 1, 2009 05:26
Show Gist options
  • Select an option

  • Save Sutto/121245 to your computer and use it in GitHub Desktop.

Select an option

Save Sutto/121245 to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
Spec::Runner.configure do |config|
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
end
require 'factory_girl'
require File.join(File.dirname(__FILE__), "default_factories")
module AuthenticationSpecHelper
def stub_current_user(*args)
opts = args.extract_options!
type = opts.delete(:type) || :user
object = case self
when Spec::Rails::Example::ViewExampleGroup : template
when Spec::Rails::Example::HelperExampleGroup : helper
when Spec::Rails::Example::ControllerExampleGroup : controller
end
args << opts
user = Factory(type, *args)
object.stub!(:current_user).and_return(user)
object.stub!(:logged_in?).and_return(true)
return user
end
def openid_auth_params(openid_url = "http://railsrumble.com/awesome/", mode = :successful, opts = {})
mode = mode.to_sym
normalized_url = OpenIdAuthentication.normalize_url(openid_url)
result = OpenIdAuthentication::Result[mode]
data = {"email" => "[email protected]"}.merge(opts)
sreg = (mode == :successful ? OpenID::SReg::Response.new(data, "http://openid.net/extensions/sreg/1.1") : nil)
return result, normalized_url, sreg
end
def stub_openid_auth(openid_url = "http://railsrumble.com/awesome", mode = :successful, opts = {})
controller.stub!(:authenticate_with_open_id).and_yield(*openid_auth_params(openid_url, mode, opts))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment