Created
May 25, 2011 19:21
-
-
Save marcelloma/991687 to your computer and use it in GitHub Desktop.
Job Symbols Controller Spec
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 'spec_helper' | |
describe JobSymbolsController do | |
before do | |
JobSymbol.stub!(:new).and_return(@job_symbol = mock_model(JobSymbol)) | |
JobSymbol.stub!(:search).and_return(@search = []) | |
@search.stub!(:paginate).and_return(@job_symbols = []) | |
@request_params = { :search => Hash.new, :page => 10, :job_symbol => {} } | |
@job_symbol.stub!(:attributes=) | |
end | |
it { should_expose(:job_symbol).as(@job_symbol) } | |
it { should_expose(:job_symbols).as(@job_symbols) } | |
it { should_expose(:search).as(@search) } | |
describe 'handling POST requests' do | |
context 'with a valid job symbol' do | |
before do | |
@job_symbol.stub!(:save).and_return(true) | |
post :create, @request_params | |
end | |
specify { response.should redirect_to(job_symbols_url) } | |
end | |
context 'with an invalid job symbol' do | |
before do | |
@job_symbol.stub!(:save).and_return(false) | |
post :create, @request_params | |
end | |
specify { response.should render_template('new') } | |
end | |
end | |
describe 'handling PUT requests' do | |
before do | |
@put_request_params = @request_params.merge({ :id => 1 }) | |
JobSymbol.stub!(:find).with(1).and_return(@job_symbol) | |
end | |
context 'with a valid job symbol' do | |
before do | |
@job_symbol.stub!(:update_attributes).with(@put_request_params[:job_symbol]).and_return(true) | |
put :update, @put_request_params | |
end | |
specify { response.should redirect_to(job_symbols_url) } | |
end | |
context 'with an invalid job symbol' do | |
before do | |
@job_symbol.stub!(:update_attributes).with(@put_request_params[:job_symbol]).and_return(false) | |
put :update, @put_request_params | |
end | |
specify { response.should render_template('edit') } | |
end | |
end | |
describe 'handling DELETE requests' do | |
before do | |
@delete_request_params = @request_params.merge({ :id => 1 }) | |
JobSymbol.stub!(:find).with(1).and_return(@job_symbol) | |
@job_symbol.stub!(:destroy) | |
delete :destroy, @delete_request_params | |
end | |
specify { @job_symbol.should_receive(:destroy).with(no_args()) } | |
specify { response.should redirect_to(job_symbols_url) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment