diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-04-25 07:44:57 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-04-25 07:44:57 +0000 |
commit | 232ddd07567969b4c0d4c7d523e804c74c5af97d (patch) | |
tree | a1043c111f99c735a88ef3660a5d9c822909afa2 | |
parent | fea9353152f4588ee0aaa860be9d21937add2792 (diff) | |
download | redmine-232ddd07567969b4c0d4c7d523e804c74c5af97d.tar.gz redmine-232ddd07567969b4c0d4c7d523e804c74c5af97d.zip |
Backported r14179 (#19569).
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14211 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/member.rb | 2 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 21 | ||||
-rw-r--r-- | test/unit/member_test.rb | 10 | ||||
-rw-r--r-- | test/unit/user_test.rb | 12 |
4 files changed, 44 insertions, 1 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 1d44adb46..a73f269be 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -19,7 +19,7 @@ class Member < ActiveRecord::Base belongs_to :user belongs_to :principal, :foreign_key => 'user_id' has_many :member_roles, :dependent => :destroy - has_many :roles, :through => :member_roles + has_many :roles, :through => :member_roles, :uniq => true belongs_to :project validates_presence_of :principal, :project diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index b04907c5e..a5804af72 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -925,6 +925,27 @@ class IssueTest < ActiveSupport::TestCase assert_equal [field.id.to_s], issue.read_only_attribute_names(user) end + def test_workflow_rules_should_work_for_member_with_duplicate_role + WorkflowPermission.delete_all + WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, + :role_id => 1, :field_name => 'due_date', + :rule => 'required') + WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, + :role_id => 1, :field_name => 'start_date', + :rule => 'readonly') + + user = User.generate! + m = Member.new(:user_id => user.id, :project_id => 1) + m.member_roles.build(:role_id => 1) + m.member_roles.build(:role_id => 1) + m.save! + + issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) + + assert_equal %w(due_date), issue.required_attribute_names(user) + assert_equal %w(start_date), issue.read_only_attribute_names(user) + end + def test_copy issue = Issue.new.copy_from(1) assert issue.copy? diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb index 6ea204e91..174fb7ec8 100644 --- a/test/unit/member_test.rb +++ b/test/unit/member_test.rb @@ -134,6 +134,16 @@ class MemberTest < ActiveSupport::TestCase Member._destroy_callbacks.reject! {|c| c.filter==:destroy_test_callback} end + def test_roles_should_be_unique + m = Member.new(:user_id => 1, :project_id => 1) + m.member_roles.build(:role_id => 1) + m.member_roles.build(:role_id => 1) + m.save! + m.reload + assert_equal 1, m.roles.count + assert_equal [1], m.roles.map(&:id) + end + def test_sort_without_roles a = Member.new(:roles => [Role.first]) b = Member.new diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 4ca0fccf4..9ebdde9cc 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -876,6 +876,18 @@ class UserTest < ActiveSupport::TestCase assert_equal [], roles.map(&:name) end + def test_roles_for_project_should_be_unique + m = Member.new(:user_id => 1, :project_id => 1) + m.member_roles.build(:role_id => 1) + m.member_roles.build(:role_id => 1) + m.save! + + user = User.find(1) + project = Project.find(1) + assert_equal 1, user.roles_for_project(project).size + assert_equal [1], user.roles_for_project(project).map(&:id) + end + def test_projects_by_role_for_user_with_role user = User.find(2) assert_kind_of Hash, user.projects_by_role |