Created
February 3, 2012 20:01
-
-
Save sskirby/1732097 to your computer and use it in GitHub Desktop.
Sample controller spec
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 EventTypesController do | |
login_user | |
let(:m) {mock_model(EventType)} | |
describe "GET index" do | |
it "assigns all event_types as @event_types" do | |
EventType.should_receive(:all).and_return m | |
get :index | |
response.should be_success | |
assigns(:event_types).should == m | |
end | |
end | |
describe "GET show" do | |
it "assigns the requested event_type as @event_type" do | |
EventType.should_receive(:find).with('1').and_return m | |
get :show, :id => 1 | |
response.should be_success | |
assigns(:event_type).should == m | |
end | |
end | |
describe "GET new" do | |
it "assigns a new event_type as @event_type" do | |
EventType.should_receive(:new).and_return m | |
get :new | |
response.should be_success | |
assigns(:event_type).should == m | |
end | |
end | |
describe "GET edit" do | |
it "assigns the requested event_type as @event_type" do | |
EventType.should_receive(:find).with('1').and_return m | |
get :edit, :id => '1' | |
response.should be_success | |
assigns(:event_type).should eq(m) | |
end | |
end | |
describe "POST create" do | |
describe "with valid params" do | |
it "creates a new EventType" do | |
EventType.should_receive(:new).with("key" => "value").and_return m | |
m.should_receive(:save).and_return true | |
post :create, :event_type => {'key' => 'value'} | |
response.should be_redirect | |
assigns(:event_type).should == m | |
response.should redirect_to(m) | |
end | |
end | |
describe "with invalid params" do | |
it "assigns a newly created but unsaved event_type as @event_type" do | |
EventType.should_receive(:new).and_return m | |
m.should_receive(:save).and_return false | |
post :create, :event_type => {} | |
assigns(:event_type).should == m | |
response.should render_template("new") | |
end | |
end | |
end | |
describe "PUT update" do | |
describe "with valid params" do | |
it "updates the requested event_type" do | |
EventType.should_receive(:find).with('1').and_return m | |
m.should_receive(:update_attributes).with('these' => 'params').and_return true | |
put :update, :id => '1', :event_type => {'these' => 'params'} | |
assigns(:event_type).should eq(m) | |
response.should redirect_to(m) | |
end | |
end | |
describe "with invalid params" do | |
it "assigns the event_type as @event_type" do | |
EventType.should_receive(:find).with('1').and_return m | |
m.should_receive(:update_attributes).and_return false | |
put :update, :id => '1', :event_type => {} | |
assigns(:event_type).should eq(m) | |
response.should render_template("edit") | |
end | |
end | |
end | |
describe "DELETE destroy" do | |
it "redirects to the event_types list" do | |
EventType.should_receive(:find).with('1').and_return m | |
m.should_receive(:destroy) | |
delete :destroy, :id => 1 | |
response.should redirect_to(event_types_url) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment