Created
March 16, 2009 21:57
-
-
Save brookr/80112 to your computer and use it in GitHub Desktop.
This file contains 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 File.dirname(__FILE__) + '/../test_helper' | |
class SurveysControllerTest < ActionController::TestCase | |
context 'GET to index' do | |
setup do | |
@staff = Factory(:staff) | |
session['staff'] = @staff.id | |
get :index | |
end | |
should_respond_with :success | |
should_render_template :index | |
end | |
context 'GET to new' do | |
setup do | |
@staff = Factory(:staff) | |
session['staff'] = @staff.id | |
get :new | |
end | |
should_respond_with :success | |
should_render_template :new | |
should_assign_to :survey | |
end | |
context 'POST to create with valid parameters' do | |
setup do | |
post :create, :survey => Factory.attributes_for(:survey) | |
@survey = Survey.find(:all).last | |
end | |
should_change 'Survey.count', :by => 1 | |
should_set_the_flash_to /created/i | |
should_redirect_to( 'survey_path(@survey)' ) {} | |
end | |
context 'GET to show for existing survey' do | |
setup do | |
@survey = Factory(:survey) | |
@staff = Factory(:staff) | |
get :show, :id => @survey.to_param | |
end | |
should_respond_with :success | |
should_render_template :show | |
should_assign_to( :survey ) { @survey } | |
end | |
context 'GET to edit for existing survey' do | |
setup do | |
@survey = Factory(:survey) | |
@staff = Factory(:staff) | |
get :edit, :id => @survey.survey_link.to_param | |
end | |
should_respond_with :success | |
should_render_template :edit | |
should_assign_to (:survey) { @survey } | |
end | |
context 'PUT to update for existing survey' do | |
setup do | |
@survey = Factory(:survey) | |
@staff = Factory(:staff) | |
put :update, :id => @survey.to_param, | |
:survey => Factory.attributes_for(:survey) | |
end | |
should_set_the_flash_to /updated/i | |
should_redirect_to( 'survey_path(@survey)' ) {} | |
end | |
context 'given a survey' do | |
setup do | |
@survey = Factory(:survey) | |
end | |
context 'DELETE to destroy' do | |
setup do | |
delete :destroy, :id => @survey.to_param | |
end | |
should_change 'Survey.count', :from => 1, :to => 0 | |
should_set_the_flash_to /deleted/i | |
should_redirect_to( 'surveys_path' ) {} | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment