blairanderson
4/24/2013 - 4:38 PM

stubs with controller tests

stubs with controller tests

context "using OpenStruct to stub" do 
  fake_article = OpenStruct.new(valid?:true)
  Article.stub(:create).and_return(fake_article)
  post :create
end

context "stubbing some shit" do 
# after you test the before_filter, it can be stubbed for future tests 
  before do 
    controller.stub(:require_login).and_return(true)
  end
      
  Order.stub(:all).and_return([:a1,:a2,])
  Order.should_receive(:all).and_return([ ])
  
  expect(response).to redirect_to(article_path)
end

describe Application controller do 
  describe "#require_login" do 
    it "should work" do 
      #response = ActionDispatch::TestResponse.new
      #controller.response = response
      controller.stub(:logged_in?).and_return(false)
      controller.should_receive(:redirect_to).with(login_path)
      controller.send(:require_login)
    end
  end
end