]> source.dussan.org Git - redmine.git/commitdiff
Add habtm relation between roles and queries_roles (#36416).
authorMarius Balteanu <marius.balteanu@zitec.com>
Mon, 28 Feb 2022 21:16:08 +0000 (21:16 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Mon, 28 Feb 2022 21:16:08 +0000 (21:16 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21444 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/role.rb
test/unit/role_test.rb

index 8a984bbba316c6d483f648c5e83eb9046f293314..790d09f271c97c19cf7e3498aefc5f41d508a8ec 100644 (file)
@@ -68,6 +68,8 @@ class Role < ActiveRecord::Base
     :join_table => "#{table_name_prefix}roles_managed_roles#{table_name_suffix}",
     :association_foreign_key => "managed_role_id"
 
+  has_and_belongs_to_many :queries, :join_table => "#{table_name_prefix}queries_roles#{table_name_suffix}", :foreign_key => "role_id"
+
   has_many :member_roles, :dependent => :destroy
   has_many :members, :through => :member_roles
   acts_as_positioned :scope => :builtin
index 78d95782147c3b856e9bc89a7278614c0647cbe3..8a1eb76d353d136f4143a3a5ae5f5620bb58d61b 100644 (file)
@@ -152,4 +152,17 @@ class RoleTest < ActiveSupport::TestCase
       assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
     end
   end
+
+  def test_destroy
+    role = Role.generate!
+
+    # generate some dependent objects
+    query = IssueQuery.generate!(:project => @ecookbook, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3, role.id]).to_a)
+
+    role.destroy
+
+    # make sure some related data was removed
+    assert_nil ActiveRecord::Base.connection.select_value("SELECT 1 FROM queries_roles WHERE role_id = #{role.id}")
+    assert [1, 3], query.roles
+  end
 end