reimplements a work_packages's relations for better readibiity

pull/243/head
Jens Ulferts 11 years ago
parent b0872f67ee
commit 6e00d55ad2
  1. 13
      app/controllers/work_packages_controller.rb
  2. 19
      app/models/work_package.rb
  3. 22
      spec/controllers/work_packages_controller_spec.rb

@ -185,12 +185,15 @@ class WorkPackagesController < ApplicationController
end
def relations
@relations ||= work_package.relations(:include => { :other_issue => [:status,
:priority,
:tracker,
{ :project => :enabled_modules }] })
@relations ||= work_package.relations.includes(:issue_from => [:status,
:priority,
:tracker,
{ :project => :enabled_modules }],
:issue_to => [:status,
:priority,
:tracker,
{ :project => :enabled_modules }])
.select{ |r| r.other_issue(work_package) && r.other_issue(work_package).visible? }
end
def priorities

@ -179,23 +179,8 @@ class WorkPackage < ActiveRecord::Base
!relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
end
def relations(options = {})
options_to = options.clone
options_from = options.clone
if options[:include]
if options[:include].is_a?(Hash) && options[:include][:other_issue]
options_to[:include] = options_to[:include].dup
options_from[:include] = options_from[:include].dup
options_to[:include][:issue_from] = options_to[:include].delete(:other_issue)
options_from[:include][:issue_to] = options_from[:include].delete(:other_issue)
elsif options[:include].is_a?(Array) && options[:include].include?(:other_issue)
options_to[:include] = options[:include].dup - [:other_issue] + [:issue_from]
options_from[:include] = options[:include].dup - [:other_issue] + [:issue_to]
end
end
(relations_from.all(options_from) + relations_to.all(options_to)).sort
def relations
IssueRelation.of_issue(self)
end
def relation(id)

@ -432,8 +432,26 @@ describe WorkPackagesController do
end
describe :relations do
it "should be empty" do
controller.relations.should be_empty
let(:relation) { FactoryGirl.build_stubbed(:issue_relation, :issue_from => stub_issue,
:issue_to => stub_planning_element) }
let(:relations) { [relation] }
before do
controller.stub!(:work_package).and_return(stub_issue)
stub_issue.stub(:relations).and_return(relations)
relations.stub!(:includes).and_return(relations)
end
it "should return all the work_packages's relations visible to the user" do
stub_planning_element.stub!(:visible?).and_return(true)
controller.relations.should == relations
end
it "should not return relations invisible to the user" do
stub_planning_element.stub!(:visible?).and_return(false)
controller.relations.should == []
end
end

Loading…
Cancel
Save