Skip to content

Instantly share code, notes, and snippets.

@neotericdesign
Created July 2, 2012 22:57
Show Gist options
  • Save neotericdesign/3036238 to your computer and use it in GitHub Desktop.
Save neotericdesign/3036238 to your computer and use it in GitHub Desktop.
require 'active_record'
unless defined?(Page)
class Page < ActiveRecord::Base; end
end
unless defined?(ApplicationController)
class ApplicationController; end
end
require 'ostruct'
require './app/helpers/pages_helper'
require './app/controllers/pages_controller'
describe PagesController do
let(:request) do
OpenStruct.new(:path => '/hello/world')
end
let(:page) { stub }
let(:controller) { PagesController.new }
before :each do
controller.stub(:request) { request }
controller.stub(:render)
controller.stub(:top_ancestor_for) { page }
page.stub_chain(:children, :visible) { [] }
end
describe "GET show" do
it "finds the page by slug from the path" do
Page.should_receive(:where)
.with(:slug => 'world')
.and_return([page])
page.stub(:drafted? => false)
controller.send(:show)
end
it "returns 404 for pages that are drafted" do
Page.stub(:where) { [page] }
page.stub(:drafted? => true)
controller.should_receive(:render)
.with(:template => 'pages/error_404',
:status => 404)
controller.send(:show)
end
it "returns 404 for pages that are not found" do
Page.stub(:where) { [] }
controller.should_receive(:render)
.with(:template => 'pages/error_404',
:status => 404)
controller.send(:show)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment