Rails вызывает действие контроллера из консоли - PullRequest
5 голосов
/ 09 декабря 2010

У меня есть контроллер сессий, который может создавать сессию.Я хотел бы вызвать его из консоли, как controller.create.Вот действие:



  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 

1 Ответ

13 голосов
/ 10 декабря 2010

с консоли:


   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

Из 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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...