]> source.dussan.org Git - redmine.git/commitdiff
Merged r14179 (#19569).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:40:46 +0000 (07:40 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:40:46 +0000 (07:40 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14210 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/member.rb
test/unit/issue_test.rb
test/unit/member_test.rb
test/unit/user_test.rb

index b76e37dbd5f472935cb155c73d369dcfc51a366b..72a92db536ffec713d1f740510e9cb164550dc13 100644 (file)
@@ -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, lambda {uniq}, :through => :member_roles
   belongs_to :project
 
   validates_presence_of :principal, :project
index 61b24c10d388420d8f94238cf2d4d472d61eb293..70a22ab77f3e414201a269e717a411f0a9891ad1 100644 (file)
@@ -958,6 +958,27 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal %w(done_ratio start_date), issue.read_only_attribute_names(user).sort
   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?
index 97ba590794a9cd11b5664177791c2c2964616a2f..2ed65543b1b42c40a15b3a726c6526d5cec2f997 100644 (file)
@@ -133,6 +133,16 @@ class MemberTest < ActiveSupport::TestCase
     Member._destroy_callbacks.delete(: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.ids
+  end
+
   def test_sort_without_roles
     a = Member.new(:roles => [Role.first])
     b = Member.new
index 429f2908b2360e3bdaf7382b0301b433370ddbcd..831ff577dc0bf327304cd9d0f8844f956de6b262 100644 (file)
@@ -907,6 +907,18 @@ class UserTest < ActiveSupport::TestCase
     assert_equal [], roles.map(&:name).sort
   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