132 lines
4.8 KiB
Ruby
132 lines
4.8 KiB
Ruby
|
require 'spec_helper'
|
||
|
|
||
|
describe MashTournamentsController do
|
||
|
|
||
|
def mock_mash_tournament(stubs={})
|
||
|
@mock_mash_tournament ||= mock_model(MashTournament, stubs)
|
||
|
end
|
||
|
|
||
|
describe "GET index" do
|
||
|
it "assigns all mash_tournaments as @mash_tournaments" do
|
||
|
MashTournament.stub(:find).with(:all).and_return([mock_mash_tournament])
|
||
|
get :index
|
||
|
assigns[:mash_tournaments].should == [mock_mash_tournament]
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "GET show" do
|
||
|
it "assigns the requested mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:find).with("37").and_return(mock_mash_tournament)
|
||
|
get :show, :id => "37"
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "GET new" do
|
||
|
it "assigns a new mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:new).and_return(mock_mash_tournament)
|
||
|
get :new
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "GET edit" do
|
||
|
it "assigns the requested mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:find).with("37").and_return(mock_mash_tournament)
|
||
|
get :edit, :id => "37"
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "POST create" do
|
||
|
|
||
|
describe "with valid params" do
|
||
|
it "assigns a newly created mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:new).with({'these' => 'params'}).and_return(mock_mash_tournament(:save => true))
|
||
|
post :create, :mash_tournament => {:these => 'params'}
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
|
||
|
it "redirects to the created mash_tournament" do
|
||
|
MashTournament.stub(:new).and_return(mock_mash_tournament(:save => true))
|
||
|
post :create, :mash_tournament => {}
|
||
|
response.should redirect_to(mash_tournament_url(mock_mash_tournament))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "with invalid params" do
|
||
|
it "assigns a newly created but unsaved mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:new).with({'these' => 'params'}).and_return(mock_mash_tournament(:save => false))
|
||
|
post :create, :mash_tournament => {:these => 'params'}
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
|
||
|
it "re-renders the 'new' template" do
|
||
|
MashTournament.stub(:new).and_return(mock_mash_tournament(:save => false))
|
||
|
post :create, :mash_tournament => {}
|
||
|
response.should render_template('new')
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
describe "PUT update" do
|
||
|
|
||
|
describe "with valid params" do
|
||
|
it "updates the requested mash_tournament" do
|
||
|
MashTournament.should_receive(:find).with("37").and_return(mock_mash_tournament)
|
||
|
mock_mash_tournament.should_receive(:update_attributes).with({'these' => 'params'})
|
||
|
put :update, :id => "37", :mash_tournament => {:these => 'params'}
|
||
|
end
|
||
|
|
||
|
it "assigns the requested mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:find).and_return(mock_mash_tournament(:update_attributes => true))
|
||
|
put :update, :id => "1"
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
|
||
|
it "redirects to the mash_tournament" do
|
||
|
MashTournament.stub(:find).and_return(mock_mash_tournament(:update_attributes => true))
|
||
|
put :update, :id => "1"
|
||
|
response.should redirect_to(mash_tournament_url(mock_mash_tournament))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "with invalid params" do
|
||
|
it "updates the requested mash_tournament" do
|
||
|
MashTournament.should_receive(:find).with("37").and_return(mock_mash_tournament)
|
||
|
mock_mash_tournament.should_receive(:update_attributes).with({'these' => 'params'})
|
||
|
put :update, :id => "37", :mash_tournament => {:these => 'params'}
|
||
|
end
|
||
|
|
||
|
it "assigns the mash_tournament as @mash_tournament" do
|
||
|
MashTournament.stub(:find).and_return(mock_mash_tournament(:update_attributes => false))
|
||
|
put :update, :id => "1"
|
||
|
assigns[:mash_tournament].should equal(mock_mash_tournament)
|
||
|
end
|
||
|
|
||
|
it "re-renders the 'edit' template" do
|
||
|
MashTournament.stub(:find).and_return(mock_mash_tournament(:update_attributes => false))
|
||
|
put :update, :id => "1"
|
||
|
response.should render_template('edit')
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
describe "DELETE destroy" do
|
||
|
it "destroys the requested mash_tournament" do
|
||
|
MashTournament.should_receive(:find).with("37").and_return(mock_mash_tournament)
|
||
|
mock_mash_tournament.should_receive(:destroy)
|
||
|
delete :destroy, :id => "37"
|
||
|
end
|
||
|
|
||
|
it "redirects to the mash_tournaments list" do
|
||
|
MashTournament.stub(:find).and_return(mock_mash_tournament(:destroy => true))
|
||
|
delete :destroy, :id => "1"
|
||
|
response.should redirect_to(mash_tournaments_url)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|