Created
September 21, 2010 19:50
-
-
Save clarkware/590398 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
class EventsController < ApplicationController | |
def create | |
@event = Event.new(params[:event]) | |
if @event.save | |
flash[:notice] = 'Event was successfully created.' | |
redirect_to :action => :index | |
else | |
render :action => :new | |
end | |
end | |
end | |
# ============================================ | |
def setup | |
@attributes = { | |
'name' => "Valid Event", | |
'description' => "Example description" | |
} | |
@event = flexmock(Event.new) | |
flexmock(Event).should_receive(:new). | |
with(@attributes). | |
once.and_return(@event) | |
end | |
test "create with valid event should assign event and redirect" do | |
@event.should_receive(:save).with(). | |
once.and_return(true) | |
post :create, :event => @attributes | |
assert_equal @event, assigns(:event) | |
assert_not_nil flash[:notice] | |
assert_redirected_to events_url | |
end | |
test "create with invalid event should show new form" do | |
@event.should_receive(:save).with(). | |
once.and_return(false) | |
post :create, :event => @attributes | |
assert_equal @event, assigns(:event) | |
assert_nil flash[:notice] | |
assert_response :success | |
assert_template 'new' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment