Как протестировать after_sign_in_path_for (ресурс)?

Я разработал аутентификацию и регистрацию, настроенную в моем приложении Rails.Я использую after_sign_in_path_for () , чтобы настроить перенаправление при входе пользователя в систему на основе различных сценариев.

Я спрашиваю, как протестировать этот метод? Кажется трудно изолировать, так как Devise автоматически вызывает это, когда пользователь входит в систему. Я хочу сделать что-то вроде этого:

describe ApplicationController do
  describe "after_sign_in_path_for" do
    before :each do
      @user = Factory :user
      @listing = Factory :listing
      sign_in @user
    end

    describe "with listing_id on the session" do
      before :each do
        session[:listing_id] = @listing.id
      end

      describe "and a user in one team" do
        it "should save the listing from the session" do
          expect {
            ApplicationController.new.after_sign_in_path_for(@user)
          }.to change(ListingStore, :count).by(1)
        end

        it "should return the path to the users team page" do
          ApplicationController.new.after_sign_in_path_for(@user).should eq team_path(@user.team)
        end
      end
    end
  end
end

но, очевидно, это не способ сделать это, потому что я просто получаю сообщение об ошибке:

 Failure/Error: ApplicationController.new.after_sign_in_path_for(@user)
 RuntimeError:
   ActionController::Metal#session delegated to @_request.session, but @_request is nil: #<ApplicationController:0x00000104581c68 @_routes=nil, @_action_has_layout=true, @_view_context_class=nil, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_request=nil, @_response=nil>

Итак, как я могу протестировать этот метод?

17
задан David Tuite 12 July 2011 в 00:26
поделиться