summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/timelog_helper.rb12
-rw-r--r--app/models/enumeration.rb2
-rw-r--r--app/models/project.rb20
-rw-r--r--test/unit/helpers/timelog_helper_test.rb56
-rw-r--r--test/unit/project_test.rb47
5 files changed, 133 insertions, 4 deletions
diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb
index 0c3e7e6b6..178929161 100644
--- a/app/helpers/timelog_helper.rb
+++ b/app/helpers/timelog_helper.rb
@@ -29,10 +29,16 @@ module TimelogHelper
# Returns a collection of activities for a select field. time_entry
# is optional and will be used to check if the selected TimeEntryActivity
# is active.
- def activity_collection_for_select_options(time_entry=nil)
- activities = TimeEntryActivity.active
+ def activity_collection_for_select_options(time_entry=nil, project=nil)
+ project ||= @project
+ if project.nil?
+ activities = TimeEntryActivity.active
+ else
+ activities = project.activities
+ end
+
collection = []
- if time_entry && !time_entry.activity.active?
+ if time_entry && time_entry.activity && !time_entry.activity.active?
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ]
else
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 2d27d2f86..bdb6ddd25 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -62,7 +62,7 @@ class Enumeration < ActiveRecord::Base
named_scope :active, lambda {
{
- :conditions => {:active => true},
+ :conditions => {:active => true, :project_id => nil},
:order => 'position'
}
}
diff --git a/app/models/project.rb b/app/models/project.rb
index f9030bdf2..6e397b776 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -20,6 +20,7 @@ class Project < ActiveRecord::Base
STATUS_ACTIVE = 1
STATUS_ARCHIVED = 9
+ has_many :time_entry_activities, :conditions => {:active => true } # Specific overidden Activities
has_many :members, :include => :user, :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
has_many :member_principals, :class_name => 'Member',
:include => :principal,
@@ -155,6 +156,17 @@ class Project < ActiveRecord::Base
statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
end
+ # Returns all the Systemwide and project specific activities
+ def activities
+ overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
+
+ if overridden_activity_ids.empty?
+ return TimeEntryActivity.active
+ else
+ return system_activities_and_project_overrides
+ end
+ end
+
# Returns a :conditions SQL string that can be used to find the issues associated with this project.
#
# Examples:
@@ -446,4 +458,12 @@ private
def allowed_actions
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
end
+
+ # Returns the systemwide activities merged with the project specific overrides
+ def system_activities_and_project_overrides
+ return TimeEntryActivity.active.
+ find(:all,
+ :conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) +
+ self.time_entry_activities
+ end
end
diff --git a/test/unit/helpers/timelog_helper_test.rb b/test/unit/helpers/timelog_helper_test.rb
new file mode 100644
index 000000000..0056a0d92
--- /dev/null
+++ b/test/unit/helpers/timelog_helper_test.rb
@@ -0,0 +1,56 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class TimelogHelperTest < HelperTestCase
+ include TimelogHelper
+ include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::DateHelper
+
+ fixtures :projects, :roles, :enabled_modules, :users,
+ :repositories, :changesets,
+ :trackers, :issue_statuses, :issues, :versions, :documents,
+ :wikis, :wiki_pages, :wiki_contents,
+ :boards, :messages,
+ :attachments,
+ :enumerations
+
+ def setup
+ super
+ end
+
+ def test_activities_collection_for_select_options_should_return_array_of_activity_names_and_ids
+ activities = activity_collection_for_select_options
+ assert activities.include?(["Design", 9])
+ assert activities.include?(["Development", 10])
+ end
+
+ def test_activities_collection_for_select_options_should_not_include_inactive_activities
+ activities = activity_collection_for_select_options
+ assert !activities.include?(["Inactive Activity", 14])
+ end
+
+ def test_activities_collection_for_select_options_should_use_the_projects_override
+ project = Project.find(1)
+ override_activity = TimeEntryActivity.create!({:name => "Design override", :parent => TimeEntryActivity.find_by_name("Design"), :project => project})
+
+ activities = activity_collection_for_select_options(nil, project)
+ assert !activities.include?(["Design", 9]), "System activity found in: " + activities.inspect
+ assert activities.include?(["Design override", override_activity.id]), "Override activity not found in: " + activities.inspect
+ end
+end
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index fa163cfad..7ac9bf382 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -313,6 +313,53 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal 1, copied_project.status
end
+ def test_activities_should_use_the_system_activities
+ project = Project.find(1)
+ assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} )
+ end
+
+
+ def test_activities_should_use_the_project_specific_activities
+ project = Project.find(1)
+ overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project})
+ assert overridden_activity.save!
+
+ assert project.activities.include?(overridden_activity), "Project specific Activity not found"
+ end
+
+ def test_activities_should_not_include_the_inactive_project_specific_activities
+ project = Project.find(1)
+ overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
+ assert overridden_activity.save!
+
+ assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
+ end
+
+ def test_activities_should_not_include_project_specific_activities_from_other_projects
+ project = Project.find(1)
+ overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)})
+ assert overridden_activity.save!
+
+ assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project"
+ end
+
+ def test_activities_should_handle_nils
+ TimeEntryActivity.delete_all
+
+ project = Project.find(1)
+ assert project.activities.empty?
+ end
+
+ def test_activities_should_override_system_activities_with_project_activities
+ project = Project.find(1)
+ parent_activity = TimeEntryActivity.find(:first)
+ overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
+ assert overridden_activity.save!
+
+ assert project.activities.include?(overridden_activity), "Project specific Activity not found"
+ assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden"
+ end
+
context "Project#copy" do
setup do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests