diff --git a/app/controllers/deliverables_controller.rb b/app/controllers/deliverables_controller.rb index ee47cfa..260f90f 100644 --- a/app/controllers/deliverables_controller.rb +++ b/app/controllers/deliverables_controller.rb @@ -4,7 +4,7 @@ class DeliverablesController < ApplicationController before_filter :find_project, :authorize, :get_settings def index - @deliverables = Deliverable.find(:all) + @deliverables = Deliverable.find_all_by_project_id(@project.id) end private diff --git a/spec/controllers/deliverables_controller_spec.rb b/spec/controllers/deliverables_controller_spec.rb index 1a9b6df..01e0253 100644 --- a/spec/controllers/deliverables_controller_spec.rb +++ b/spec/controllers/deliverables_controller_spec.rb @@ -8,3 +8,27 @@ describe DeliverablesController do end end + +describe DeliverablesController,"#index when logged in" do + before(:each) do + @project = mock_model(Project) + Deliverable.stub!(:find_all_by_project_id).and_return([]) + Project.should_receive(:find).with(@project.to_param).and_return(@project) + controller.stub!(:authorize).and_return(true) + end + + it "should be successful" do + get :index, :id => @project.id + response.should be_success + end + + it "should set @deliverables for the view" do + get :index, :id => @project.id + assigns[:deliverables].should_not be_nil + end + + it "should only show the deliverables for the current project only" do + Deliverable.should_receive(:find_all_by_project_id).with(@project.id) + get :index, :id => @project.id + end +end