[#4177] Scope the finders on ContractsController to use the current project.

This commit is contained in:
Eric Davis
2010-06-17 16:02:31 -07:00
parent 736f315b36
commit 793fe165c1
3 changed files with 32 additions and 10 deletions

View File

@@ -6,6 +6,12 @@ class ContractsController < InheritedResources::Base
before_filter :find_project
before_filter :authorize
protected
def begin_of_association_chain
@project
end
private
def find_project

View File

@@ -14,10 +14,10 @@
<tbody>
<% collection.each do |contract| %>
<% content_tag_for(:tr, contract) do %>
<td><%= h contract.id %></td>
<td><%= h contract.name %></td>
<td><%= h contract.account_executive.name %></td>
<td><%= h format_date(contract.end_date) %></td>
<td class="id"><%= h contract.id %></td>
<td class="name"><%= h contract.name %></td>
<td class="account-executive"><%= h contract.account_executive.name %></td>
<td class="end-date"><%= h format_date(contract.end_date) %></td>
<% end %>
<% end %>
</tbody>

View File

@@ -4,9 +4,18 @@ class ContractsListTest < ActionController::IntegrationTest
include Redmine::I18n
def setup
@project = Project.generate!
@project = Project.generate!(:identifier => 'main')
@contract = Contract.generate!(:project => @project)
@contract2 = Contract.generate!(:project => @project)
@other_project = Project.generate!(:identifier => 'other')
@other_contract = Contract.generate!(:project => @other_project)
[@project,
@other_project,
@contract,
@contract2,
@other_contract
].map {|c| c.reload }
end
should "allow any user to list the contracts on a project" do
@@ -18,15 +27,22 @@ class ContractsListTest < ActionController::IntegrationTest
assert_select "table#contracts" do
[@contract, @contract2].each do |contract|
assert_select "td", :text => /#{contract.id}/
assert_select "td", :text => /#{contract.name}/
assert_select "td", :text => /#{contract.account_executive.name}/
assert_select "td", :text => /#{format_date(contract.end_date)}/
assert_select "td.id", :text => /#{contract.id}/
assert_select "td.name", :text => /#{contract.name}/
assert_select "td.account-executive", :text => /#{contract.account_executive.name}/
assert_select "td.end-date", :text => /#{format_date(contract.end_date)}/
end
end
end
should "not list contracts from other projects"
should "not list contracts from other projects" do
visit_contracts_for_project(@project)
assert_select "table#contracts" do
assert_select "td", :text => /#{@other_contract.name}/, :count => 0
end
end
end