From a53ceb280438b6b17f2b93f46f7a7a40111945ba Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 11 Nov 2009 13:16:00 -0800 Subject: [PATCH] [#3294] Expand the new form if the project doesn't have any deliverables yet. --- app/controllers/deliverables_controller.rb | 2 +- spec/controllers/deliverables_controller_spec.rb | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/deliverables_controller.rb b/app/controllers/deliverables_controller.rb index ec46a3b..8b532a9 100644 --- a/app/controllers/deliverables_controller.rb +++ b/app/controllers/deliverables_controller.rb @@ -27,7 +27,7 @@ class DeliverablesController < ApplicationController @budget = Budget.new(@project.id) - @display_form = params[:new].present? + @display_form = params[:new].present? || @deliverables.empty? respond_to do |format| format.html { render :action => 'index', :layout => !request.xhr? } diff --git a/spec/controllers/deliverables_controller_spec.rb b/spec/controllers/deliverables_controller_spec.rb index 9c7839a..3da4dbe 100644 --- a/spec/controllers/deliverables_controller_spec.rb +++ b/spec/controllers/deliverables_controller_spec.rb @@ -12,9 +12,10 @@ end describe DeliverablesController,"#index when logged in" do before(:each) do @project = mock_model(Project) + @deliverable = mock_model(Deliverable) - Deliverable.stub!(:count).and_return(0) - Deliverable.stub!(:find).and_return([]) + Deliverable.stub!(:count).and_return(1) + Deliverable.stub!(:find).and_return([@deliverable]) Project.should_receive(:find).with(@project.to_param).and_return(@project) Project.should_receive(:find).with(@project.id).and_return(@project) @@ -36,6 +37,15 @@ describe DeliverablesController,"#index when logged in" do assigns[:display_form].should eql(false) end + it "should set @display_form to true if there are no deliverables" do + Deliverable.should_receive(:count).and_return(0) + Deliverable.should_receive(:find).and_return([]) + + get :index, :id => @project.id + + assigns[:display_form].should eql(true) + end + it "should set @display_form to true if the 'new' parameter is used" do get :index, :id => @project.id, :new => 'true' assigns[:display_form].should eql(true)