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