From 783b94ac86bb6addcb6f0e39a9226e8b177bed7d Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 20 Nov 2024 14:03:57 +0100 Subject: [PATCH] Enhance compatibility with Redmine 6 --- app/models/issues_organization.rb | 2 +- app/models/organization.rb | 2 +- app/models/organization_manager.rb | 2 +- app/models/organization_non_member_role.rb | 2 +- app/models/organization_notification.rb | 2 +- app/models/organization_role.rb | 2 +- app/models/organization_team_leader.rb | 2 +- .../patches/field_format_patch.rb | 2 +- .../patches/issue_patch.rb | 2 +- .../patches/project_patch.rb | 2 +- .../patches/role_patch.rb | 2 +- spec/controllers/admin_menu_patch_spec.rb | 2 -- spec/controllers/users_admin_patch_spec.rb | 2 -- spec/models/files_checksums_spec.rb | 4 +-- spec/models/issue_query_patch_spec.rb | 26 ++++++++++--------- 15 files changed, 27 insertions(+), 29 deletions(-) diff --git a/app/models/issues_organization.rb b/app/models/issues_organization.rb index b2fc485..2f03e82 100644 --- a/app/models/issues_organization.rb +++ b/app/models/issues_organization.rb @@ -1,4 +1,4 @@ -class IssuesOrganization < ActiveRecord::Base +class IssuesOrganization < ApplicationRecord belongs_to :issue belongs_to :organization diff --git a/app/models/organization.rb b/app/models/organization.rb index 3ba0cc8..5d15bff 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,4 +1,4 @@ -class Organization < ActiveRecord::Base +class Organization < ApplicationRecord include Redmine::SafeAttributes acts_as_nested_set diff --git a/app/models/organization_manager.rb b/app/models/organization_manager.rb index b5c77dc..84820ea 100644 --- a/app/models/organization_manager.rb +++ b/app/models/organization_manager.rb @@ -1,4 +1,4 @@ -class OrganizationManager < ActiveRecord::Base +class OrganizationManager < ApplicationRecord belongs_to :user belongs_to :organization diff --git a/app/models/organization_non_member_role.rb b/app/models/organization_non_member_role.rb index bb924bc..c6838b8 100644 --- a/app/models/organization_non_member_role.rb +++ b/app/models/organization_non_member_role.rb @@ -1,4 +1,4 @@ -class OrganizationNonMemberRole < ActiveRecord::Base +class OrganizationNonMemberRole < ApplicationRecord include Redmine::SafeAttributes belongs_to :project diff --git a/app/models/organization_notification.rb b/app/models/organization_notification.rb index 83d19a5..df87e98 100644 --- a/app/models/organization_notification.rb +++ b/app/models/organization_notification.rb @@ -1,4 +1,4 @@ -class OrganizationNotification < ActiveRecord::Base +class OrganizationNotification < ApplicationRecord belongs_to :project belongs_to :organization end diff --git a/app/models/organization_role.rb b/app/models/organization_role.rb index 08fd03a..2b651d2 100644 --- a/app/models/organization_role.rb +++ b/app/models/organization_role.rb @@ -1,4 +1,4 @@ -class OrganizationRole < ActiveRecord::Base +class OrganizationRole < ApplicationRecord include Redmine::SafeAttributes belongs_to :project diff --git a/app/models/organization_team_leader.rb b/app/models/organization_team_leader.rb index cd2f6d2..1f33ba4 100644 --- a/app/models/organization_team_leader.rb +++ b/app/models/organization_team_leader.rb @@ -1,4 +1,4 @@ -class OrganizationTeamLeader < ActiveRecord::Base +class OrganizationTeamLeader < ApplicationRecord belongs_to :user belongs_to :organization diff --git a/lib/redmine_organizations/patches/field_format_patch.rb b/lib/redmine_organizations/patches/field_format_patch.rb index 9bad73c..a377729 100644 --- a/lib/redmine_organizations/patches/field_format_patch.rb +++ b/lib/redmine_organizations/patches/field_format_patch.rb @@ -29,6 +29,6 @@ def possible_values_records(custom_field, object = nil) Redmine::FieldFormat.include RedmineOrganizations::Patches::FieldFormatPatch -class CustomField < ActiveRecord::Base +class CustomField safe_attributes('direction_only') end diff --git a/lib/redmine_organizations/patches/issue_patch.rb b/lib/redmine_organizations/patches/issue_patch.rb index b2dc55b..8842c36 100644 --- a/lib/redmine_organizations/patches/issue_patch.rb +++ b/lib/redmine_organizations/patches/issue_patch.rb @@ -1,6 +1,6 @@ require_dependency "issue" -class Issue < ActiveRecord::Base +class Issue has_many :issues_organizations, dependent: :destroy has_many :organizations, through: :issues_organizations diff --git a/lib/redmine_organizations/patches/project_patch.rb b/lib/redmine_organizations/patches/project_patch.rb index 29163e2..2753c01 100644 --- a/lib/redmine_organizations/patches/project_patch.rb +++ b/lib/redmine_organizations/patches/project_patch.rb @@ -2,7 +2,7 @@ require_dependency 'principal' require_dependency 'user' -class Project < ActiveRecord::Base +class Project has_many :organization_roles, :dependent => :destroy has_many :organization_notifications diff --git a/lib/redmine_organizations/patches/role_patch.rb b/lib/redmine_organizations/patches/role_patch.rb index bdd6371..f3646b0 100644 --- a/lib/redmine_organizations/patches/role_patch.rb +++ b/lib/redmine_organizations/patches/role_patch.rb @@ -4,7 +4,7 @@ module RedmineOrganizations::Patches::RolePatch end -class Role < ActiveRecord::Base +class Role has_many :organization_roles, :dependent => :destroy has_many :organization_non_member_roles, :dependent => :destroy end diff --git a/spec/controllers/admin_menu_patch_spec.rb b/spec/controllers/admin_menu_patch_spec.rb index bcf2b17..56d5742 100644 --- a/spec/controllers/admin_menu_patch_spec.rb +++ b/spec/controllers/admin_menu_patch_spec.rb @@ -8,8 +8,6 @@ before do @controller = AdminController.new - @request = ActionDispatch::TestRequest.create - @response = ActionDispatch::TestResponse.new User.current = nil @request.session[:user_id] = 1 # admin end diff --git a/spec/controllers/users_admin_patch_spec.rb b/spec/controllers/users_admin_patch_spec.rb index 5b4769f..5dd8d8e 100644 --- a/spec/controllers/users_admin_patch_spec.rb +++ b/spec/controllers/users_admin_patch_spec.rb @@ -4,8 +4,6 @@ render_views before do @controller = UsersController.new - @request = ActionDispatch::TestRequest.create - @response = ActionDispatch::TestResponse.new User.current = nil @request.session[:user_id] = 1 # admin end diff --git a/spec/models/files_checksums_spec.rb b/spec/models/files_checksums_spec.rb index 6afa60d..4b84cd3 100644 --- a/spec/models/files_checksums_spec.rb +++ b/spec/models/files_checksums_spec.rb @@ -8,8 +8,8 @@ def assert_checksum(expected, filename) end it "should ensure project patch file is up to date" do - # 5.1.3 & 4.2.9 checksum (the self.allowed_to_condition method is completely overridden and should be reviewed if this test breaks) - assert_checksum %w(d3b53e9654bfdd6969c69d7ea7852cf8 b8ce67efe695bc2381e56db07a0a889e a11cce5462e20a51064f9a72834ac527), "app/models/project.rb" + # 6.0.1 & 5.1.4 checksum (the self.allowed_to_condition method is completely overridden and should be reviewed if this test breaks) + assert_checksum %w(40b18f67d953eda5041ac5c20233b784 d3b53e9654bfdd6969c69d7ea7852cf8 b8ce67efe695bc2381e56db07a0a889e a11cce5462e20a51064f9a72834ac527), "app/models/project.rb" end end diff --git a/spec/models/issue_query_patch_spec.rb b/spec/models/issue_query_patch_spec.rb index 7c3f097..fbf583e 100644 --- a/spec/models/issue_query_patch_spec.rb +++ b/spec/models/issue_query_patch_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require "rails_helper" describe "IssueQueryPatch" do fixtures :organizations, :users, :roles, :projects, :members, :trackers @@ -7,13 +7,15 @@ before do @org = Organization.create(:name => "Team C") @user = User.generate! + expect(@user).to be_present @user.update_attribute(:organization_id, @org.id) + User.current = User.anonymous end - def find_issues_with_query(query) + def find_issues_ids_with_query(query) Issue.joins(:status, :tracker, :project, :priority).where( query.statement - ).to_a + ).order(:id).pluck(:id) end it "Should have updated_by_organization in available_filters" do @@ -31,7 +33,7 @@ def find_issues_with_query(query) query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s] } } - expect(find_issues_with_query(query).map(&:id).sort).to include(2, 3) + expect(find_issues_ids_with_query(query)).to include(2, 3) end it "operator equal ! , one organization" do @@ -43,7 +45,7 @@ def find_issues_with_query(query) filter_name = "updated_by_organization" query.filters = { filter_name => { :operator => '!', :values => [@org.id.to_s] } } - expect(find_issues_with_query(query).map(&:id).sort).to_not include(2, 3) + expect(find_issues_ids_with_query(query)).to_not include(2, 3) end it "operator equal = , multi organizations" do @@ -59,7 +61,7 @@ def find_issues_with_query(query) filter_name = "updated_by_organization" query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s, org_test.id.to_s] } } - expect(find_issues_with_query(query).map(&:id).sort).to include(2, 3, 4) + expect(find_issues_ids_with_query(query)).to include(2, 3, 4) end it "operator equal ! , multi organizations" do @@ -75,23 +77,23 @@ def find_issues_with_query(query) filter_name = "updated_by_organization" query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s, org_test.id.to_s] } } - expect(find_issues_with_query(query).map(&:id).sort).to_not include([2, 3, 4]) + expect(find_issues_ids_with_query(query)).to_not include([2, 3, 4]) end - it "Should ignore private notes that are not visible" do + it "ignores private notes that are not visible" do Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes', :private_notes => true) Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes') query = IssueQuery.new(:name => '_') filter_name = "updated_by_organization" - query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s] } } - expect(find_issues_with_query(query).map(&:id).sort).to eq([2, 3]) + User.current = @user + query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s] } } + expect(find_issues_ids_with_query(query)).to eq([2, 3]) User.current = User.anonymous query.filters = { filter_name => { :operator => '=', :values => [@org.id.to_s] } } - - expect(find_issues_with_query(query).map(&:id).sort).to eq([3]) + expect(find_issues_ids_with_query(query)).to eq([3]) end end