Controller:
class SessionsController < ApplicationController layout 'login' def create user = login(params[:username], params[:password]) if user redirect_back_or_to root_url else flash.now.alert = "Username or password was invalid" render :new end end end
Test:
require 'spec_helper' describe SessionsController do describe "POST create" do before(:each) { Fabricate(:school) } it "Should log me in" do post(:create, {'password' => 'Secret', 'username' => 'director'}) response.should redirect_to('/') end end end
Fabricate(:school) has a callback that generates the first user. I want to reorganize this code so that it does not use database calls at all. I want to mute the login, so that it will return true.
How can I stub the login method? It comes from Magic.
https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller.rb#L31
source share