Skip to content

Instantly share code, notes, and snippets.

@cdb
Created November 1, 2008 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdb/21546 to your computer and use it in GitHub Desktop.
Save cdb/21546 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Activity do
it_should_belong_to :goal
it_should_validate_presence_of :goal_id, :date
end
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe GoalsController do
describe "#index" do
before do
@goal = mock_model(Goal)
Goal.stub!(:find).and_return([@goal])
end
act { get :index }
it_should_be_success
it_should_render_template 'index'
it_should_assign(:goals) { [@goal] }
it_should_expect 'find all goals' do
Goal.should_receive(:find).with(:all).and_return([@goal])
end
end
describe "#show" do
before do
@goal = mock_model(Goal)
Goal.stub!(:find).and_return(@goal)
end
act { get :show, :id => "1" }
it_should_be_success
it_should_render_template 'show'
it_should_expect_to "find the goal requested" do
Goal.should_receive(:find).with("1").and_return(@goal)
end
it_should_assign :goal, @goal
end
describe "#new" do
before do
@goal = mock_model(Goal)
Goal.stub!(:new).and_return(@goal)
end
act { get :new }
it_should_be_success
it_should_render_template :new
it_should_assign :goal, @goal
it_should_expect_to "create a new goal" do
Goal.should_receive(:new).and_return(@goal)
end
it_should_expect_to "not save the new goal" do
@goal.should_not_receive(:save)
end
end
describe "#edit" do
before do
@goal = mock_model(Goal)
Goal.stub!(:find).and_return(@goal)
end
act { get :edit, :id => "1" }
it_should_be_success
it_should_render_template 'edit'
it_should_assign :goal, @goal
it_should_expect_to "find the goal requested" do
Goal.should_receive(:find).and_return(@goal)
end
end
describe "#create" do
before do
@goal = mock_model(Goal, :to_param => "1")
Goal.stub!(:new).and_return(@goal)
end
describe "with successful save" do
before { @goal.should_receive(:save).and_return(true) }
act { post :create, :goal => {} }
it_should_expect_to "create a new goal" do
Goal.should_receive(:new).with({}).and_return(@goal)
end
it_should_redirect_to { goal_url('1') }
end
describe "with failed save" do
before { @goal.should_receive(:save).and_return(false) }
act { post :create, :goal => {} }
it_should_render_template 'new'
end
end
describe "#update" do
before do
@goal = mock_model(Goal, :to_param => "1")
Goal.stub!(:find).and_return(@goal)
end
describe "with successful update" do
before { @goal.should_receive(:update_attributes).and_return(true) }
act { put :update, :id => "1" }
it_should_expect_to "find the goal requested" do
Goal.should_receive(:find).with("1").and_return(@goal)
end
it_should_assign :goal, @goal
it_should_redirect_to { goal_url('1') }
end
describe "with failed update" do
before { @goal.should_receive(:update_attributes).and_return(false) }
act { put :update, :id => "1" }
it_should_render_template 'edit'
end
end
describe "#destroy" do
before do
@goal = mock_model(Goal, :destroy => true)
Goal.stub!(:find).and_return(@goal)
end
act { delete :destroy, :id => "1" }
it_should_expect_to "find the goal requested" do
Goal.should_receive(:find).with("1").and_return(@goal)
end
it_should_expect_to "call destroy on the found goal" do
@goal.should_receive(:destroy).and_return(true)
end
it_should_redirect_to { goals_url }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment