Commit 981bb3ba authored by jplang's avatar jplang

Default status per tracker (#5991).

git-svn-id: https://svn.redmine.org/redmine/trunk@13535 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e9b00b60
......@@ -24,7 +24,6 @@ class IssuesController < ApplicationController
before_filter :find_project, :only => [:new, :create, :update_form]
before_filter :authorize, :except => [:index]
before_filter :find_optional_project, :only => [:index]
before_filter :check_for_default_issue_status, :only => [:new, :create]
before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
accept_rss_auth :index, :show
accept_api_auth :index, :show, :create, :update, :destroy
......@@ -234,7 +233,8 @@ class IssuesController < ApplicationController
target_projects ||= @projects
if @copy
@available_statuses = [IssueStatus.default]
# Copied issues will get their default statuses
@available_statuses = []
else
@available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
end
......@@ -425,12 +425,21 @@ class IssuesController < ApplicationController
@issue = @project.issues.visible.find(params[:id])
end
@issue.safe_attributes = params[:issue]
if attrs = params[:issue].deep_dup
if params[:was_default_status] == attrs[:status_id]
attrs.delete(:status_id)
end
@issue.safe_attributes = attrs
end
@issue.tracker ||= @project.trackers.first
if @issue.tracker.nil?
render_error l(:error_no_tracker_in_project)
return false
end
if @issue.status.nil?
render_error l(:error_no_default_issue_status)
return false
end
@priorities = IssuePriority.active
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
......@@ -440,13 +449,6 @@ class IssuesController < ApplicationController
end
end
def check_for_default_issue_status
if IssueStatus.default.nil?
render_error l(:error_no_default_issue_status)
return false
end
end
def parse_params_for_bulk_issue_attributes(params)
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
......
......@@ -162,7 +162,6 @@ class Issue < ActiveRecord::Base
super
if new_record?
# set default values for new records only
self.status ||= IssueStatus.default
self.priority ||= IssuePriority.default
self.watcher_user_ids = []
end
......@@ -273,11 +272,19 @@ class Issue < ActiveRecord::Base
issue.save ? issue : false
end
def status_id=(sid)
self.status = nil
result = write_attribute(:status_id, sid)
@workflow_rule_by_attribute = nil
result
def status_id=(status_id)
if status_id.to_s != self.status_id.to_s
self.status = (status_id.present? ? IssueStatus.find_by_id(status_id) : nil)
end
self.status_id
end
# Sets the status.
def self.status=(status)
if status != self.status
@workflow_rule_by_attribute = nil
end
association(:status).writer(status)
end
def priority_id=(pid)
......@@ -302,12 +309,24 @@ class Issue < ActiveRecord::Base
self.tracker_id
end
# Sets the tracker.
# This will set the status to the default status of the new tracker if:
# * the status was the default for the previous tracker
# * or if the status was not part of the new tracker statuses
# * or the status was nil
def tracker=(tracker)
if tracker != self.tracker
if status == default_status
self.status = nil
elsif status && tracker && !tracker.issue_status_ids.include?(status.id)
self.status = nil
end
@custom_field_values = nil
@workflow_rule_by_attribute = nil
end
association(:tracker).writer(tracker)
self.status ||= default_status
self.tracker
end
def project_id=(project_id)
......@@ -317,6 +336,14 @@ class Issue < ActiveRecord::Base
self.project_id
end
# Sets the project.
# Unless keep_tracker argument is set to true, this will change the tracker
# to the first tracker of the new project if the previous tracker is not part
# of the new project trackers.
# This will clear the fixed_version is it's no longer valid for the new project.
# This will clear the parent issue if it's no longer valid for the new project.
# This will set the category to the category with the same name in the new
# project if it exists, or clear it if it doesn't.
def project=(project, keep_tracker=false)
project_was = self.project
association(:project).writer(project)
......@@ -339,7 +366,9 @@ class Issue < ActiveRecord::Base
self.parent_issue_id = nil
end
@custom_field_values = nil
@workflow_rule_by_attribute = nil
end
self.project
end
def description=(arg)
......@@ -776,14 +805,28 @@ class Issue < ActiveRecord::Base
!relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
end
# Returns the default status of the issue based on its tracker
# Returns nil if tracker is nil
def default_status
tracker.try(:default_status)
end
# Returns an array of statuses that user is able to apply
def new_statuses_allowed_to(user=User.current, include_default=false)
if new_record? && @copied_from
[IssueStatus.default, @copied_from.status].compact.uniq.sort
[default_status, @copied_from.status].compact.uniq.sort
else
initial_status = nil
if new_record?
initial_status = IssueStatus.default
initial_status = default_status
elsif tracker_id_changed?
if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any?
initial_status = default_status
elsif tracker.issue_status_ids.include?(status_id_was)
initial_status = IssueStatus.find_by_id(status_id_was)
else
initial_status = default_status
end
else
initial_status = status_was
end
......@@ -802,7 +845,7 @@ class Issue < ActiveRecord::Base
)
end
statuses << initial_status unless statuses.empty?
statuses << IssueStatus.default if include_default
statuses << default_status if include_default
statuses = statuses.compact.uniq.sort
if blocked?
statuses.reject!(&:is_closed?)
......
......@@ -22,7 +22,6 @@ class IssueStatus < ActiveRecord::Base
acts_as_list
before_destroy :delete_workflow_rules
after_save :update_default
validates_presence_of :name
validates_uniqueness_of :name
......@@ -33,15 +32,6 @@ class IssueStatus < ActiveRecord::Base
scope :sorted, lambda { order(:position) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
def update_default
IssueStatus.where(['id <> ?', id]).update_all({:is_default => false}) if self.is_default?
end
# Returns the default status for new issues
def self.default
where(:is_default => true).first
end
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
def self.update_issue_done_ratios
if Issue.use_status_for_done_ratio?
......@@ -100,7 +90,11 @@ class IssueStatus < ActiveRecord::Base
private
def check_integrity
raise "Can't delete status" if Issue.where(:status_id => id).any?
if Issue.where(:status_id => id).any?
raise "This status is used by some issues"
elsif Tracker.where(:default_status_id => id).any?
raise "This status is used as the default status by some trackers"
end
end
# Deletes associated workflows
......
......@@ -24,6 +24,7 @@ class Tracker < ActiveRecord::Base
CORE_FIELDS_ALL = (CORE_FIELDS_UNDISABLABLE + CORE_FIELDS).freeze
before_destroy :check_integrity
belongs_to :default_status, :class_name => 'IssueStatus'
has_many :issues
has_many :workflow_rules, :dependent => :delete_all do
def copy(source_tracker)
......@@ -37,6 +38,7 @@ class Tracker < ActiveRecord::Base
attr_protected :fields_bits
validates_presence_of :default_status
validates_presence_of :name
validates_uniqueness_of :name
validates_length_of :name, :maximum => 30
......@@ -53,14 +55,15 @@ class Tracker < ActiveRecord::Base
# Returns an array of IssueStatus that are used
# in the tracker's workflows
def issue_statuses
if @issue_statuses
return @issue_statuses
elsif new_record?
return []
end
@issue_statuses ||= IssueStatus.where(:id => issue_status_ids).to_a.sort
end
status_ids = WorkflowTransition.where(:tracker_id => id).uniq.pluck(:old_status_id, :new_status_id).flatten.uniq
@issue_statuses = IssueStatus.where(:id => status_ids).to_a.sort
def issue_status_ids
if new_record?
[]
else
@issue_status_ids ||= WorkflowTransition.where(:tracker_id => id).uniq.pluck(:old_status_id, :new_status_id).flatten.uniq
end
end
def disabled_core_fields
......
......@@ -6,7 +6,6 @@
<p><%= f.select :default_done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }), :include_blank => true, :label => :field_done_ratio %></p>
<% end %>
<p><%= f.check_box :is_closed %></p>
<p><%= f.check_box :is_default %></p>
<%= call_hook(:view_issue_statuses_form, :issue_status => @issue_status) %>
</div>
......@@ -3,7 +3,6 @@ api.array :issue_statuses do
api.issue_status do
api.id status.id
api.name status.name
api.is_default status.is_default
api.is_closed status.is_closed
end
end
......
......@@ -11,7 +11,6 @@
<% if Issue.use_status_for_done_ratio? %>
<th><%=l(:field_done_ratio)%></th>
<% end %>
<th><%=l(:field_is_default)%></th>
<th><%=l(:field_is_closed)%></th>
<th><%=l(:button_sort)%></th>
<th></th>
......@@ -23,7 +22,6 @@
<% if Issue.use_status_for_done_ratio? %>
<td><%= h status.default_done_ratio %></td>
<% end %>
<td><%= checked_image status.is_default? %></td>
<td><%= checked_image status.is_closed? %></td>
<td class="reorder"><%= reorder_links('issue_status', {:action => 'update', :id => status}, :put) %></td>
<td class="buttons">
......
......@@ -5,9 +5,9 @@
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
:onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %></p>
<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %>
<% else %>
<p><label><%= l(:field_status) %></label> <%= h(@issue.status.name) %></p>
<p><label><%= l(:field_status) %></label> <%= @issue.status %></p>
<% end %>
<% if @issue.safe_attribute? 'priority_id' %>
......
......@@ -4,8 +4,12 @@
<div class="box tabular">
<!--[form:tracker]-->
<p><%= f.text_field :name, :required => true %></p>
<p><%= f.select :default_status_id,
IssueStatus.sorted.map {|s| [s.name, s.id]},
:include_blank => @tracker.default_status.nil?,
:required => true %>
</p>
<p><%= f.check_box :is_in_roadmap %></p>
<p>
<label><%= l(:field_core_fields) %></label>
<% Tracker::CORE_FIELDS.each do |field| %>
......
......@@ -3,6 +3,7 @@ api.array :trackers do
api.tracker do
api.id tracker.id
api.name tracker.name
api.default_status(:id => tracker.default_status.id, :name => tracker.default_status.name) unless tracker.default_status.nil?
end
end
end
......@@ -337,6 +337,7 @@ en:
field_inherit_members: Inherit members
field_generate_password: Generate password
field_must_change_passwd: Must change password at next logon
field_default_status: Default status
setting_app_title: Application title
setting_app_subtitle: Application subtitle
......
......@@ -357,6 +357,7 @@ fr:
field_inherit_members: Hériter les membres
field_generate_password: Générer un mot de passe
field_must_change_passwd: Doit changer de mot de passe à la prochaine connexion
field_default_status: Statut par défaut
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
......
class AddTrackersDefaultStatusId < ActiveRecord::Migration
def up
add_column :trackers, :default_status_id, :integer
status_id = IssueStatus.where(:is_default => true).pluck(:id).first
status_id ||= IssueStatus.order(:position).pluck(:id).first
if status_id
Tracker.update_all :default_status_id => status_id
end
end
def down
remove_column :trackers, :default_status_id
end
end
class RemoveIssueStatusesIsDefault < ActiveRecord::Migration
def up
remove_column :issue_statuses, :is_default
end
def down
add_column :issue_statuses, :is_default, :boolean, :null => false, :default => false
# Restores the first status as default
default_status_id = IssueStatus.order("position").first.pluck(:id)
IssueStatus.where(:id => default_status_id).update_all(:is_default => true)
end
end
......@@ -125,18 +125,18 @@ module Redmine
:browse_repository,
:view_changesets]
# Trackers
Tracker.create!(:name => l(:default_tracker_bug), :is_in_chlog => true, :is_in_roadmap => false, :position => 1)
Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true, :is_in_roadmap => true, :position => 2)
Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3)
# Issue statuses
new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1)
in_progress = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :is_default => false, :position => 2)
resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :is_default => false, :position => 3)
feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4)
closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5)
rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6)
new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :position => 1)
in_progress = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :position => 2)
resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :position => 3)
feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :position => 4)
closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :position => 5)
rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :position => 6)
# Trackers
Tracker.create!(:name => l(:default_tracker_bug), :default_status_id => new.id, :is_in_chlog => true, :is_in_roadmap => false, :position => 1)
Tracker.create!(:name => l(:default_tracker_feature), :default_status_id => new.id, :is_in_chlog => true, :is_in_roadmap => true, :position => 2)
Tracker.create!(:name => l(:default_tracker_support), :default_status_id => new.id, :is_in_chlog => false, :is_in_roadmap => false, :position => 3)
# Workflow
Tracker.all.each { |t|
......
......@@ -25,15 +25,15 @@ task :migrate_from_mantis => :environment do
module MantisMigrate
DEFAULT_STATUS = IssueStatus.default
new_status = IssueStatus.find_by_position(1)
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
STATUS_MAPPING = {10 => new_status, # new
20 => feedback_status, # feedback
30 => DEFAULT_STATUS, # acknowledged
40 => DEFAULT_STATUS, # confirmed
30 => new_status, # acknowledged
40 => new_status, # confirmed
50 => assigned_status, # assigned
80 => resolved_status, # resolved
90 => closed_status # closed
......@@ -317,8 +317,8 @@ task :migrate_from_mantis => :environment do
i.author = User.find_by_id(users_map[bug.reporter_id])
i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
i.status = STATUS_MAPPING[bug.status] || i.status
i.id = bug.id if keep_bug_ids
next unless i.save
issues_map[bug.id] = i.id
......
......@@ -25,12 +25,12 @@ namespace :redmine do
module TracMigrate
TICKET_MAP = []
DEFAULT_STATUS = IssueStatus.default
new_status = IssueStatus.find_by_position(1)
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {'new' => DEFAULT_STATUS,
STATUS_MAPPING = {'new' => new_status,
'reopened' => feedback_status,
'assigned' => assigned_status,
'closed' => closed_status
......@@ -476,8 +476,8 @@ namespace :redmine do
i.author = find_or_create_user(ticket.reporter)
i.category = issues_category_map[ticket.component] unless ticket.component.blank?
i.fixed_version = version_map[ticket.milestone] unless ticket.milestone.blank?
i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
i.status = STATUS_MAPPING[ticket.status] || i.default_status
i.id = ticket.id unless Issue.exists?(ticket.id)
next unless Time.fake(ticket.changetime) { i.save }
TICKET_MAP[ticket.id] = i.id
......
......@@ -2,36 +2,30 @@
issue_statuses_001:
id: 1
name: New
is_default: true
is_closed: false
position: 1
issue_statuses_002:
id: 2
name: Assigned
is_default: false
is_closed: false
position: 2
issue_statuses_003:
id: 3
name: Resolved
is_default: false
is_closed: false
position: 3
issue_statuses_004:
name: Feedback
id: 4
is_default: false
is_closed: false
position: 4
issue_statuses_005:
id: 5
name: Closed
is_default: false
is_closed: true
position: 5
issue_statuses_006:
id: 6
name: Rejected
is_default: false
is_closed: true
position: 6
......@@ -3,14 +3,17 @@ trackers_001:
name: Bug
id: 1
is_in_chlog: true
default_status_id: 1
position: 1
trackers_002:
name: Feature request
id: 2
is_in_chlog: true
default_status_id: 1
position: 2
trackers_003:
name: Support request
id: 3
is_in_chlog: false
default_status_id: 1
position: 3
......@@ -86,7 +86,8 @@ class IssueStatusesControllerTest < ActionController::TestCase
end
def test_destroy
Issue.delete_all("status_id = 1")
Issue.where(:status_id => 1).delete_all
Tracker.where(:default_status_id => 1).delete_all
assert_difference 'IssueStatus.count', -1 do
delete :destroy, :id => '1'
......@@ -96,7 +97,19 @@ class IssueStatusesControllerTest < ActionController::TestCase
end
def test_destroy_should_block_if_status_in_use
assert_not_nil Issue.find_by_status_id(1)
assert Issue.where(:status_id => 1).any?
Tracker.where(:default_status_id => 1).delete_all
assert_no_difference 'IssueStatus.count' do
delete :destroy, :id => '1'
end
assert_redirected_to :action => 'index'
assert_not_nil IssueStatus.find_by_id(1)
end
def test_destroy_should_block_if_status_in_use
Issue.where(:status_id => 1).delete_all
assert Tracker.where(:default_status_id => 1).any?
assert_no_difference 'IssueStatus.count' do
delete :destroy, :id => '1'
......
......@@ -1511,6 +1511,30 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_new_should_select_default_status
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'issue[status_id]' do
assert_select 'option[value=1][selected=selected]'
end
assert_select 'input[name=was_default_status][value=1]'
end
def test_new_should_select_default_status
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'issue[status_id]' do
assert_select 'option[value=1][selected=selected]'
end
assert_select 'input[name=was_default_status][value=1]'
end
def test_get_new_with_list_custom_field
@request.session[:user_id] = 2
get :new, :project_id => 1, :tracker_id => 1
......@@ -1731,6 +1755,20 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
end
def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals
@request.session[:user_id] = 2
tracker = Tracker.find(2)
tracker.update! :default_status_id => 2
tracker.generate_transitions! 2, 1, :clear => true
xhr :post, :update_form, :project_id => 1,
:issue => {:tracker_id => 2,
:status_id => 1},
:was_default_status => 1
assert_equal 2, assigns(:issue).status_id
end
def test_post_create
@request.session[:user_id] = 2
assert_difference 'Issue.count' do
......@@ -2266,13 +2304,17 @@ class IssuesControllerTest < ActionController::TestCase
get :new, :project_id => 1
assert_response :success
assert_template 'new'
issue = assigns(:issue)
assert_not_nil issue.default_status
assert_select 'select[name=?]', 'issue[status_id]' do
assert_select 'option', 1
assert_select 'option[value=?]', IssueStatus.default.id.to_s
assert_select 'option[value=?]', issue.default_status.id.to_s
end
end
test "without workflow privilege #new should accept default status" do
test "without workflow privilege #create should accept default status" do
setup_without_workflow_privilege
assert_difference 'Issue.count' do
post :create, :project_id => 1,
......@@ -2281,10 +2323,11 @@ class IssuesControllerTest < ActionController::TestCase
:status_id => 1}
end
issue = Issue.order('id').last
assert_equal IssueStatus.default, issue.status
assert_not_nil issue.default_status
assert_equal issue.default_status, issue.status
end
test "without workflow privilege #new should ignore unauthorized status" do
test "without workflow privilege #create should ignore unauthorized status" do
setup_without_workflow_privilege
assert_difference 'Issue.count' do
post :create, :project_id => 1,
......@@ -2293,7 +2336,8 @@ class IssuesControllerTest < ActionController::TestCase
:status_id => 3}
end
issue = Issue.order('id').last
assert_equal IssueStatus.default, issue.status
assert_not_nil issue.default_status
assert_equal issue.default_status, issue.status
end
test "without workflow privilege #update should ignore status change" do
......
......@@ -18,7 +18,7 @@
require File.expand_path('../../test_helper', __FILE__)
class TrackersControllerTest < ActionController::TestCase
fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields, :issue_statuses
def setup
User.current = nil
......@@ -51,7 +51,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_create
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
post :create, :tracker => { :name => 'New tracker', :default_status_id => 1, :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
end
assert_redirected_to :action => 'index'
tracker = Tracker.order('id DESC').first
......@@ -62,9 +62,9 @@ class TrackersControllerTest < ActionController::TestCase
assert_equal 0, tracker.workflow_rules.count
end
def create_with_disabled_core_fields
def test_create_with_disabled_core_fields
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker', :core_fields => ['assigned_to_id', 'fixed_version_id', ''] }
post :create, :tracker => { :name => 'New tracker', :default_status_id => 1, :core_fields => ['assigned_to_id', 'fixed_version_id', ''] }
end
assert_redirected_to :action => 'index'
tracker = Tracker.order('id DESC').first
......@@ -74,7 +74,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_create_new_with_workflow_copy
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
post :create, :tracker => { :name => 'New tracker', :default_status_id => 1 }, :copy_workflow_from => 1
end
assert_redirected_to :action => 'index'
tracker = Tracker.find_by_name('New tracker')
......@@ -164,7 +164,7 @@ class TrackersControllerTest < ActionController::TestCase
end
def test_destroy
tracker = Tracker.create!(:name => 'Destroyable')
tracker = Tracker.generate!(:name => 'Destroyable')
assert_difference 'Tracker.count', -1 do
delete :destroy, :id => tracker.id
end
......
......@@ -45,11 +45,22 @@ module ObjectHelpers
project
end
def IssueStatus.generate!(attributes={})
@generated_status_name ||= 'Status 0'
@generated_status_name.succ!
status = IssueStatus.new(attributes)
status.name = @generated_status_name.dup if status.name.blank?
yield status if block_given?
status.save!
status
end
def Tracker.generate!(attributes={})
@generated_tracker_name ||= 'Tracker 0'
@generated_tracker_name.succ!
tracker = Tracker.new(attributes)
tracker.name = @generated_tracker_name.dup if tracker.name.blank?
tracker.default_status ||= IssueStatus.order('position').first || IssueStatus.generate!
yield tracker if block_given?
tracker.save!
tracker
......@@ -188,6 +199,27 @@ module ObjectHelpers
end
end
module TrackerObjectHelpers
def generate_transitions!(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
if args.size == 1