Doing the right thing when changing trackers

pull/6827/head
Gregor Schmidt 13 years ago
parent 2956391fbc
commit 7be0997cd9
  1. 18
      lib/redmine_backlogs/patches/issue_patch.rb
  2. 75
      spec/models/issue_position_spec.rb

@ -17,7 +17,7 @@ module RedmineBacklogs::Patches::IssuePatch
end
# add new items to top of list automatically
after_create :insert_at, :if => :in_backlogs_tracker?
after_create :insert_at, :if => :is_story?
# reorder list, if issue is removed from sprint
before_update :fix_other_issues_positions
@ -30,6 +30,12 @@ module RedmineBacklogs::Patches::IssuePatch
def fix_other_issues_positions
if changes.slice('project_id', 'tracker_id', 'fixed_version_id').present?
if changes.slice('project_id', 'fixed_version_id').blank? and
Story.trackers.include?(tracker_id.to_i) and
Story.trackers.include?(tracker_id_was.to_i)
return
end
if fixed_version_id_changed?
restore_version_id = true
new_version_id = fixed_version_id
@ -50,7 +56,7 @@ module RedmineBacklogs::Patches::IssuePatch
self.project = Project.find(project_id_was)
end
remove_from_list if in_backlogs_tracker?
remove_from_list if is_story?
if restore_project_id
self.project = new_project
@ -68,7 +74,13 @@ module RedmineBacklogs::Patches::IssuePatch
def fix_own_issue_position
if changes.slice('project_id', 'tracker_id', 'fixed_version_id').present?
if in_backlogs_tracker? and fixed_version.present?
if changes.slice('project_id', 'fixed_version_id').blank? and
Story.trackers.include?(tracker_id.to_i) and
Story.trackers.include?(tracker_id_was.to_i)
return
end
if is_story? and fixed_version.present?
insert_at(1)
else
assume_not_in_list

@ -36,6 +36,12 @@ describe Issue do
let(:issue_b) { create_issue(:subject => 'Issue b', :fixed_version_id => sprint_2.id) }
let(:issue_c) { create_issue(:subject => 'Issue c', :fixed_version_id => sprint_2.id) }
let(:feedback_1) { create_issue(:subject => 'Feedback 1', :fixed_version_id => sprint_1.id,
:tracker_id => other_tracker.id) }
let(:task_1) { create_issue(:subject => 'Task 1', :fixed_version_id => sprint_1.id,
:tracker_id => task_tracker.id) }
before do
# had problems while writing these specs, that some elements kept creaping
# around between tests. This should be fast enough to not harm anybody
@ -55,7 +61,7 @@ describe Issue do
Issue.instance_variable_set(:@backlogs_trackers, nil)
project.trackers = [story_tracker, task_tracker, other_tracker]
project.trackers = [story_tracker, epic_tracker, task_tracker, other_tracker]
sprint_1
sprint_2
@ -122,27 +128,76 @@ describe Issue do
describe '- Changing the tracker' do
describe 'by moving a story to another story tracker' do
it 'keeps all positions in the sprint in tact'
it 'keeps all positions in the sprint in tact' do
issue_3.tracker = epic_tracker
issue_3.save!
[issue_1, issue_2, issue_3, issue_4, issue_5].each(&:reload).map(&:position).should == [1, 2, 3, 4, 5]
end
end
describe 'by moving a story to a non-backlogs tracker' do
it 'removes it from any list'
it 'reorders the remaining stories'
it 'removes it from any list' do
issue_3.tracker = other_tracker
issue_3.save!
issue_3.should_not be_in_list
end
it 'reorders the remaining stories' do
issue_3.tracker = other_tracker
issue_3.save!
[issue_1, issue_2, issue_4, issue_5].each(&:reload).map(&:position).should == [1, 2, 3, 4]
end
end
describe 'by moving a story to the task tracker' do
it 'removes it from any list'
it 'reorders the remaining stories'
it 'removes it from any list' do
issue_3.tracker = task_tracker
issue_3.save!
issue_3.should_not be_in_list
end
it 'reorders the remaining stories' do
issue_3.tracker = task_tracker
issue_3.save!
[issue_1, issue_2, issue_4, issue_5].each(&:reload).map(&:position).should == [1, 2, 3, 4]
end
end
describe 'by moving a task to the story tracker' do
it 'adds it to the top of the list'
it 'reorders the existing stories'
it 'adds it to the top of the list' do
task_1.tracker = story_tracker
task_1.save!
task_1.should be_first
end
it 'reorders the existing stories' do
task_1.tracker = story_tracker
task_1.save!
[task_1, issue_1, issue_2, issue_3, issue_4, issue_5].each(&:reload).map(&:position).should == [1, 2, 3, 4, 5, 6]
end
end
describe 'by moving a non-backlogs issue to a story tracker' do
it 'adds it to the top of the list'
it 'reorders the existing stories'
it 'adds it to the top of the list' do
feedback_1.tracker = story_tracker
feedback_1.save!
feedback_1.should be_first
end
it 'reorders the existing stories' do
feedback_1.tracker = story_tracker
feedback_1.save!
[feedback_1, issue_1, issue_2, issue_3, issue_4, issue_5].each(&:reload).map(&:position).should == [1, 2, 3, 4, 5, 6]
end
end
end

Loading…
Cancel
Save