1 module OAuthControllerSpecHelper
3 controller.stub!(:local_request?).and_return(true)
4 @user = mock_model(User)
5 controller.stub!(:current_user).and_return(@user)
7 @tokens.stub!(:find).and_return(@tokens)
8 @user.stub!(:tokens).and_return(@tokens)
9 User.stub!(:find_by_id).and_return(@user)
12 def login_as_application_owner
14 @client_application = mock_model(ClientApplication)
15 @client_applications = [@client_application]
17 @user.stub!(:client_applications).and_return(@client_applications)
18 @client_applications.stub!(:find).and_return(@client_application)
22 controller.stub!(:local_request?).and_return(true)
23 @user||=mock_model(User)
25 User.stub!(:find_by_id).and_return(@user)
27 @server = OAuth::Server.new "http://test.host"
28 @consumer = OAuth::Consumer.new('key', 'secret',{:site => "http://test.host"})
30 @client_application = mock_model(ClientApplication)
31 controller.stub!(:current_client_application).and_return(@client_application)
32 ClientApplication.stub!(:find_by_key).and_return(@client_application)
33 @client_application.stub!(:key).and_return(@consumer.key)
34 @client_application.stub!(:secret).and_return(@consumer.secret)
35 @client_application.stub!(:name).and_return("Client Application name")
36 @client_application.stub!(:callback_url).and_return("http://application/callback")
37 @request_token = mock_model(RequestToken, :token => 'request_token', :client_application => @client_application, :secret => "request_secret", :user => @user)
38 @request_token.stub!(:invalidated?).and_return(false)
39 ClientApplication.stub!(:find_token).and_return(@request_token)
41 @request_token_string = "oauth_token = request_token&oauth_token_secret = request_secret"
42 @request_token.stub!(:to_query).and_return(@request_token_string)
44 @access_token = mock_model(AccessToken, :token => 'access_token', :client_application => @client_application, :secret => "access_secret", :user => @user)
45 @access_token.stub!(:invalidated?).and_return(false)
46 @access_token.stub!(:authorized?).and_return(true)
47 @access_token_string = "oauth_token = access_token&oauth_token_secret = access_secret"
48 @access_token.stub!(:to_query).and_return(@access_token_string)
50 @client_application.stub!(:authorize_request?).and_return(true)
51 # @client_application.stub!(:sign_request_with_oauth_token).and_return(@request_token)
52 @client_application.stub!(:exchange_for_access_token).and_return(@access_token)
55 def setup_oauth_for_user
58 @tokens = [@request_token]
59 @tokens.stub!(:find).and_return(@tokens)
60 @tokens.stub!(:find_by_token).and_return(@request_token)
61 @user.stub!(:tokens).and_return(@tokens)
64 def sign_request_with_oauth(token = nil)
65 ActionController::TestRequest.use_oauth = true
66 @request.configure_oauth(@consumer,token)
69 def setup_to_authorize_request
71 OauthToken.stub!(:find_by_token).with( @access_token.token).and_return(@access_token)
72 @access_token.stub!(:is_a?).and_return(true)