Rails calling a controller action from the console

前端 未结 1 1493
感动是毒
感动是毒 2021-01-13 11:32

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  
            


        
相关标签:
1条回答
  • 2021-01-13 12:01

    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
    
    
    0 讨论(0)
提交回复
热议问题