Created
April 24, 2013 17:15
-
-
Save burtlo/5453806 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ApplicationController do | |
describe "#require_login" do | |
context "when the user is logged in" do | |
it "does nothing" do | |
end | |
end | |
context "when the user is not logged in" do | |
before do | |
controller.stub(:logged_in?).and_return(false) | |
end | |
it "redirect to the login path" do | |
controller.should_receive(:redirect_to).with(login_path) | |
controller.send(:require_login) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'ostruct' | |
describe ArticlesController do | |
describe '#index' do | |
it "assigns articles" do | |
# Article.stub(:all).and_return([ :article1, :article2 ]) | |
# Article.should_receive(:all). | |
get :index | |
expect(assigns(:articles)).to_not be_nil | |
# expect(assigns(:articles)).to eq([ :article1, :article2 ]) | |
end | |
end | |
context "when the user logged in" do | |
before do | |
controller.stub(:require_login).and_return(true) | |
end | |
describe "#create" do | |
context "when the article params are valid" do | |
it "creates the article" do | |
post :create, article: { title: "title", body: "body" } | |
# asserts | |
expect(response).to redirect_to(article_path(Article.last)) | |
end | |
it "redirects to the show page for the article" | |
end | |
context "when the article params are invalid" do | |
it "renders new" do | |
fake_article = stub('Fake Article',valid?: false) | |
Article.stub(:create).and_return(fake_article) | |
post :create | |
expect(response).to render_template(:new) | |
end | |
end | |
context "when the article does exist" | |
context "when the article is not valid" | |
end | |
end | |
context "when the user is not logged in" do | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment