6

I have a controller sessions that can create session. I'd like to call it from the console, like controller.create. Here is the action:



  def create  
    #raise request.env["omniauth.auth"].to_yaml

    auth = request.env["omniauth.auth"]  
    user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)  
    user.create_or_update_profile(auth)
    session[:user_id] = user.id 

    if user.needs_to_create_profile?
      redirect_to new_profile_path, :notice => "Signed in!. We just need your contact e-mail"
    else
      redirect_to root_url, :notice => "Signed in!"  
    end
  end 
daniel
  • 9,732
  • 7
  • 42
  • 57
  • 1
    Answered/Duplicate of http://stackoverflow.com/questions/151030/how-do-i-call-controller-view-methods-from-the-console-in-rails/1161163#1161163 – Edward M Smith Dec 09 '10 at 17:04
  • Seems to be a duplicate of: http://stackoverflow.com/questions/151030/how-do-i-call-controller-view-methods-from-the-console-in-rails – Brian Dec 09 '10 at 17:04

1 Answers1

14

From the console:


   include ActionController::TestProcess
   @request = ActionController::TestRequest.new
   @response = ActionController::TestResponse.new
   @controller = SomeController.new

   @request.env["omniauth.auth"] = {'provider' => "twitter", 'uid' => "1234", 'user_info' => {'name' => "foo"}}

   app.get "/signup" etc

From rspec:



it "should allow login" do
    request.env["omniauth.auth"] = {'provider' => "twitter", 'uid' => "1234", 'user_info' => {'name' => "foo"}}
    post :create
    puts @current_user.name
    assigns(@current_user).should_not be_nil
  end

daniel
  • 9,732
  • 7
  • 42
  • 57