calling tracker method from within acts_as_list scope

pull/6827/head
Jens Ulferts 14 years ago
parent 81c0d3de36
commit 9d87bd473d
  1. 2
      app/models/impediment.rb
  2. 2
      app/models/story.rb
  3. 2
      features/product_owner.feature
  4. 4
      features/step_definitions/_then_steps.rb
  5. 26
      lib/backlogs_list.rb
  6. 5
      spec/models/backlog_spec.rb
  7. 10
      spec/models/impediment_spec.rb
  8. 4
      spec/models/tasks_spec.rb

@ -4,7 +4,7 @@ class Impediment < Task
unloadable unloadable
include Backlogs::List include Backlogs::List
acts_as_backlogs_list(Setting.plugin_redmine_backlogs[:task_tracker]) acts_as_backlogs_list(:tracker)
after_save :update_blocks_list after_save :update_blocks_list

@ -4,7 +4,7 @@ class Story < Issue
unloadable unloadable
include Backlogs::List include Backlogs::List
acts_as_backlogs_list(Setting.plugin_redmine_backlogs[:story_trackers]) acts_as_backlogs_list(:trackers)
def self.condition(project_id, sprint_id, extras=[]) def self.condition(project_id, sprint_id, extras=[])
if sprint_id.nil? if sprint_id.nil?

@ -56,7 +56,7 @@ Feature: Product Owner
And I set the subject of the story to A Whole New Story And I set the subject of the story to A Whole New Story
And I create the story And I create the story
Then the 1st story in the "Product Backlog" should be "A Whole New Story" Then the 1st story in the "Product Backlog" should be "A Whole New Story"
And all positions should be unique And all positions should be unique within versions
Scenario: Update a story Scenario: Update a story
Given I am on the master backlog Given I am on the master backlog

@ -90,8 +90,8 @@ Then /^the (\d+)(?:st|nd|rd|th) story in (?:the )"(.+?)" should be "(.+)"$/ do |
story.subject.should == subject story.subject.should == subject
end end
Then /^all positions should be unique$/ do Then /^all positions should be unique within versions$/ do
Story.find_by_sql("select project_id, position, count(*) as dups from issues where not position is NULL group by project_id, position having count(*) > 1").length.should == 0 Story.find_by_sql("select project_id, fixed_version_id, position, count(*) as dups from issues where not position is NULL group by project_id, fixed_version_id, position having count(*) > 1").length.should == 0
end end
Then /^the (\d+)(?:st|nd|rd|th) task for (.+) should be (.+)$/ do |position, story_subject, task_subject| Then /^the (\d+)(?:st|nd|rd|th) task for (.+) should be (.+)$/ do |position, story_subject, task_subject|

@ -8,10 +8,26 @@ module Backlogs
end end
module ClassMethods module ClassMethods
def acts_as_backlogs_list(trackers) def acts_as_backlogs_list(tracker_method)
self.class_eval do scope_string = 'project_id = #{self.project_id}' +
acts_as_list :scope => :project #TODO: consider changing the scope to project, version and tracker ' AND fixed_version_id = #{self.fixed_version_id}' +
@trackers = trackers ' AND tracker_id in (#{self.class.trackers_in_scope})'
trackers_method = "def self.trackers_method() \"#{tracker_method}\" end"
class_eval <<-EOV
acts_as_list :scope => scope_string
#{ trackers_method }
EOV
end
def trackers_in_scope
trackers = self.send(self.trackers_method().to_sym)
if trackers.is_a?(Array)
trackers.join(', ')
else
trackers
end end
end end
end end
@ -47,7 +63,7 @@ module Backlogs
private private
def set_default_prev_positions_silently(prev) def set_default_prev_positions_silently(prev)
stories = self.class.find(:all, :conditions => {:fixed_version_id => self.fixed_version_id, :tracker_id => @trackers}) stories = self.class.find(:all, :conditions => {:fixed_version_id => self.fixed_version_id, :tracker_id => self.class.trackers_in_scope})
self.class.record_timestamps = false #temporarily turn off column updates self.class.record_timestamps = false #temporarily turn off column updates

@ -5,6 +5,11 @@ describe Backlog do
before(:each) do before(:each) do
@feature = Factory.create(:tracker_feature) @feature = Factory.create(:tracker_feature)
Setting.plugin_redmine_backlogs = {:points_burn_direction => "down",
:wiki_template => "",
:card_spec => "Sattleford VM-5040",
:story_trackers => [@feature.id.to_s],
:task_tracker => "0"}
@status = Factory.create(:issue_status) @status = Factory.create(:issue_status)
end end

@ -43,11 +43,11 @@ describe Impediment do
:status => issue_status1)} :status => issue_status1)}
before(:each) do before(:each) do
Setting.plugin_redmine_backlogs = {:points_burn_direction => "down", Setting.plugin_redmine_backlogs = {:points_burn_direction => "down",
:wiki_template => "", :wiki_template => "",
:card_spec => "Sattleford VM-5040", :card_spec => "Sattleford VM-5040",
:story_trackers => [tracker_feature.id.to_s], :story_trackers => [tracker_feature.id.to_s],
:task_tracker => tracker_task.id.to_s } :task_tracker => tracker_task.id.to_s }
User.current = user User.current = user
issue_priority.save issue_priority.save

@ -23,8 +23,8 @@ describe Task do
Setting.plugin_redmine_backlogs = {"points_burn_direction" => "down", Setting.plugin_redmine_backlogs = {"points_burn_direction" => "down",
"wiki_template" => "", "wiki_template" => "",
"card_spec" => "Sattleford VM-5040", "card_spec" => "Sattleford VM-5040",
"story_trackers" => [tracker_feature.id.to_s], :story_trackers => [tracker_feature.id.to_s],
"task_tracker" => tracker_task.id.to_s } :task_tracker => tracker_task.id.to_s }
end end
describe "Instance Methods" do describe "Instance Methods" do

Loading…
Cancel
Save