Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "spec_helper"
- describe ProjectsController do
- # prepare params
- before(:all) do
- @user = Factory.build(:user)
- end
- describe "Projects request validation" do
- it "redirects to logon from index" do
- get :index
- response.should redirect_to(:controller => 'admin', :action => 'index')
- end
- it "redirects to logon from show" do
- get :show, :id => '1'
- response.should redirect_to(admin_path)
- end
- it "redirects to logon from edit" do
- get :edit, :id => '1'
- response.should redirect_to(admin_path)
- end
- it "redirects to logon from create" do
- put :create
- response.should redirect_to(admin_path)
- end
- it "redirects to logon from update" do
- put :update, :id => '1'
- response.should redirect_to(admin_path)
- end
- it "redirects to logon from destroy" do
- put :destroy, :id => '1'
- response.should redirect_to(admin_path)
- end
- end
- describe "Projects simple actions" do
- it "renders the index template" do
- session[:user] = @user
- get :index
- response.should render_template("index")
- end
- it "renders view_all template" do
- get :view_all
- response.should render_template('view_all')
- end
- end
- describe "Projects resources" do
- it "renders view templete" do
- Project.stub(:find).with("5") { mock_model(Project) }
- get :view, :id => '5'
- response.should render_template('view')
- end
- it "assigns new @project" do
- session[:user] = @user
- get :new
- flash[:notice].should be_nil
- response.should render_template('new')
- end
- it "assigns edit @project" do
- Project.stub(:find).with("5") { mock_model(Project) }
- session[:user] = @user
- get :edit, :id => '5'
- response.should render_template('edit')
- end
- it "creates @project" do
- session[:user] = @user
- post 'create', :project => { :name => 'New Project' }
- created_project = assigns[:project]
- created_project.should be_a(Project)
- flash[:notice].should_not be_nil
- flash[:error].should be_nil
- created_project.name.should eq('New Project')
- response.should redirect_to(
- :controller => 'projects',
- :action => 'show',
- :id => created_project.id
- )
- end
- it "updates @project" do
- Project.stub(:find).with("5") { mock_model( Project, :name => 'New Project', :update_attributes => true) }
- session[:user] = @user
- put :update, :id => "5"
- created_project = assigns[:project]
- flash[:notice].should_not be_nil
- flash[:error].should be_nil
- created_project.name.should eq('New Project')
- response.should redirect_to( projects_path )
- end
- it "destroy @project" do
- Project.stub(:find).with("5") { mock_model( Project, :name => 'New Project', :destroy => true) }
- session[:user] = @user
- delete :destroy, :id => "5"
- flash[:notice].should_not be_nil
- flash[:error].should be_nil
- response.should redirect_to( projects_path )
- end
- describe "simulates error on" do
- let(:project) { mock_model(Project) }
- before do
- Project.stub(:find).with("5"){ mock_model( Project, :id => '5', :destroy => false, :update_attributes => false) }
- Project.stub :new => project
- project.stub :save! => false
- end
- it "creates @project" do
- session[:user] = @user
- post 'create'
- created_project = assigns[:project]
- flash[:notice].should be_nil
- flash[:error].should_not be_nil
- response.should redirect_to(
- :controller => 'projects',
- :action => 'new'
- )
- end
- it "updates @project" do
- session[:user] = @user
- put :update, :id => "5"
- flash[:error].should_not be_nil
- flash[:notice].should be_nil
- response.should redirect_to(
- :controller => 'projects',
- :action => 'show',
- :id => '5'
- )
- end
- it "destroy @project" do
- session[:user] = @user
- delete :destroy, :id => "5"
- flash[:error].should_not be_nil
- flash[:notice].should be_nil
- response.should redirect_to( project_path(assigns[:project]) )
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment