From 2fa395101602ef746065a37d2e74411ce586f3c9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2024 09:31:53 +0100 Subject: [PATCH] Make the plugin compatible with Redmine 6 --- .github/workflows/{5_1_3.yml => 5_1_5.yml} | 4 +-- .github/workflows/{4_2_11.yml => 6_0_2.yml} | 9 ++---- .github/workflows/master.yml | 4 +-- README.md | 10 +++--- init.rb | 9 +++++- lib/redmine_comments/issue_patch.rb | 5 +-- lib/redmine_comments/journal_patch.rb | 2 +- spec/system/comments_spec.rb | 34 ++++++++++++--------- 8 files changed, 43 insertions(+), 34 deletions(-) rename .github/workflows/{5_1_3.yml => 5_1_5.yml} (99%) rename .github/workflows/{4_2_11.yml => 6_0_2.yml} (93%) diff --git a/.github/workflows/5_1_3.yml b/.github/workflows/5_1_5.yml similarity index 99% rename from .github/workflows/5_1_3.yml rename to .github/workflows/5_1_5.yml index c895a45..4d79938 100644 --- a/.github/workflows/5_1_3.yml +++ b/.github/workflows/5_1_5.yml @@ -1,8 +1,8 @@ -name: Tests 5.1.3 +name: Tests 5.1.5 env: PLUGIN_NAME: redmine_comments - REDMINE_VERSION: 5.1.3 + REDMINE_VERSION: 5.1.5 RAILS_ENV: test on: diff --git a/.github/workflows/4_2_11.yml b/.github/workflows/6_0_2.yml similarity index 93% rename from .github/workflows/4_2_11.yml rename to .github/workflows/6_0_2.yml index a86bccb..6be724e 100644 --- a/.github/workflows/4_2_11.yml +++ b/.github/workflows/6_0_2.yml @@ -1,8 +1,8 @@ -name: Tests 4.2.11 +name: Tests 6.0.2 env: PLUGIN_NAME: redmine_comments - REDMINE_VERSION: 4.2.11 + REDMINE_VERSION: 6.0.2 RAILS_ENV: test on: @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['2.7'] + ruby: ['3.3'] db: ['postgres'] fail-fast: false @@ -88,12 +88,9 @@ jobs: - name: Prepare Redmine source working-directory: redmine run: | - # TODO Remove the following line when https://www.redmine.org/issues/40551 is fixed - sed -i -e 's/.*mocha.*/ gem "mocha", "2.1.0"/' Gemfile # Fix core tests not compatible with Mocha 2.2.0 sed -i '/rubocop/d' Gemfile rm -f .rubocop* cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml - echo 'gem "builder", "~> 3.2.4"' >> Gemfile - name: Install Ruby dependencies working-directory: redmine diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 4a0f058..17caeb3 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['3.2'] + ruby: ['3.3'] db: ['postgres'] fail-fast: false @@ -88,8 +88,6 @@ jobs: - name: Prepare Redmine source working-directory: redmine run: | - # TODO Remove the following line when https://www.redmine.org/issues/40551 is fixed - sed -i -e 's/.*mocha.*/ gem "mocha", "2.1.0"/' Gemfile # Fix core tests not compatible with Mocha 2.2.0 sed -i '/rubocop/d' Gemfile rm -f .rubocop* cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml diff --git a/README.md b/README.md index 510858f..4cc45a3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Redmine Comments plugin This plugin improves private notes in Redmine issues. You can manage private notes visibility through roles and permissions. -A typical usage for an tech organization is to allow staff users to see/edit comments, but not lambda users. +A typical usage for a tech organization is to allow staff users to see/edit comments, but not lambda users. The plugin requires Redmine version 2.5.0 or higher. @@ -21,11 +21,11 @@ Test status |Plugin branch| Redmine Version | Test Status | |-------------|-----------------|-------------------| -|master | 4.2.11 | [![4.2.11][1]][5] | -|master | 5.1.3 | [![5.1.3][2]][5] | +|master | 6.0.2 | [![6.0.2][1]][5] | +|master | 5.1.5 | [![5.1.5][2]][5] | |master | master | [![master][4]][5] | -[1]: https://github.com/jbbarth/redmine_comments/actions/workflows/4_2_11.yml/badge.svg -[2]: https://github.com/jbbarth/redmine_comments/actions/workflows/5_1_3.yml/badge.svg +[1]: https://github.com/jbbarth/redmine_comments/actions/workflows/6_0_2.yml/badge.svg +[2]: https://github.com/jbbarth/redmine_comments/actions/workflows/5_1_5.yml/badge.svg [4]: https://github.com/jbbarth/redmine_comments/actions/workflows/master.yml/badge.svg [5]: https://github.com/jbbarth/redmine_comments/actions diff --git a/init.rb b/init.rb index f2db9f9..a348977 100644 --- a/init.rb +++ b/init.rb @@ -6,7 +6,7 @@ description 'Better private notes in issues for staff users' author 'Jean-Baptiste BARTH' author_url 'mailto:jeanbaptiste.barth@gmail.com' - version '0.0.2' + version '6.0.2' url 'https://github.com/jbbarth/redmine_comments' requires_redmine :version_or_higher => '2.5.0' requires_redmine_plugin :redmine_base_deface, :version_or_higher => '0.0.1' @@ -16,3 +16,10 @@ permission :view_private_notes_from_role_or_function, {}, :read => true, :require => :member end end + +# Support for Redmine 5 +if Redmine::VERSION::MAJOR < 6 + class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true + end +end diff --git a/lib/redmine_comments/issue_patch.rb b/lib/redmine_comments/issue_patch.rb index f76b24f..5c939e3 100644 --- a/lib/redmine_comments/issue_patch.rb +++ b/lib/redmine_comments/issue_patch.rb @@ -4,8 +4,9 @@ module RedmineComments::IssuePatch # Returns the journals that are visible to user with their index # Used to display the issue history def visible_journals_with_index(user = User.current) - result = journals. - includes(:functions, :roles). + result = journals + result = result.includes(:functions) if Redmine::Plugin.installed?(:redmine_limited_visibility) + result = result.includes(:roles). preload(:details). preload(:user => :email_address). reorder(:created_on, :id).to_a diff --git a/lib/redmine_comments/journal_patch.rb b/lib/redmine_comments/journal_patch.rb index 20a9cad..de3f146 100644 --- a/lib/redmine_comments/journal_patch.rb +++ b/lib/redmine_comments/journal_patch.rb @@ -4,7 +4,7 @@ module RedmineComments::JournalPatch end -class Journal < ActiveRecord::Base +class Journal < ApplicationRecord include RedmineComments::JournalPatch acts_as_attachable diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index d238255..c5c76d6 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -14,7 +14,7 @@ def log_user(login, password) fill_in 'password', with: password find('input[name=login]').click end - expect(current_path).to eq '/my/page' + expect(page).to have_current_path('/my/page', wait: true) end describe "creating new comments", type: :system do @@ -48,15 +48,19 @@ def log_user(login, password) expect { visit '/issues/1' click_on "Comment", match: :first + + expect(page).to have_css('form#add_issue_comment_form') # Waiting for the form to disappear + within 'form#add_issue_comment_form' do expect(page).to have_selector(".info", text: "Private comments are only visible with specific roles.") expect(page).to_not have_selector(".comment_role") fill_in 'journal[notes]', with: 'Here is a quick note' click_on 'Add' end - }.to change(issue.journals, :size).by(1) + expect(page).to have_no_css('form#add_issue_comment_form') # Waiting for the form to disappear + }.to change { issue.journals.reload.size }.by(1) - journal = issue.journals.last + journal = issue.journals.reload.last expect(journal.private_notes).to be_truthy expect(journal.notes).to eq 'Here is a quick note' expect(journal.roles).to be_empty if Redmine::Plugin.installed?(:redmine_limited_visibility) @@ -82,7 +86,7 @@ def log_user(login, password) page.find('.comment_role', text: 'function2').click click_on 'Add' end - }.to change(issue.journals, :size).by(1) + }.to change { issue.journals.reload.size }.by(1) journal = issue.journals.last expect(journal.private_notes).to be_truthy @@ -99,9 +103,9 @@ def log_user(login, password) journal_ids = [] 3.times do |i| journal = Journal.create(:journalized => issue, - :user => user_jsmith, - :notes => "test#{i + 1}", - :private_notes => true) + :user => user_jsmith, + :notes => "test#{i + 1}", + :private_notes => true) # set for journal[0] (function1), journal[1] (function2), journal[2] (function3) journal.function_ids = [i + 1] @@ -111,7 +115,7 @@ def log_user(login, password) visit '/issues/1?tab=notes' 3.times do |i| - click_link('Edit', :href =>"/journals/#{journal_ids.reverse[i]}/edit") + click_link('Edit', :href => "/journals/#{journal_ids.reverse[i]}/edit") end # set for the third journal (function1,function2), set for the second journal (function3), set for the first journal (function3, function4) @@ -140,20 +144,20 @@ def log_user(login, password) end end - it "should add new comment by right click on the comment link to open the form in a new tab" do - + it "allows to add a new comment from the form in a new tab" do expect { visit 'issue_comments/new?issue_id=1' fill_in 'journal[notes]', with: 'test comment in a new tab' click_button 'commit' - }.to change(issue.journals, :size).by(1) + expect(page).to have_current_path('/issues/1', wait: true) + }.to change { issue.journals.reload.size }.by(1) end - it "Should edit comment by rigth click on the comment link to open the form in a new tab" do + it "allows to right click on the comment link to open the form in a new tab" do Role.find(1).add_permission!(:edit_issue_notes) - editnote_text = 'test edit comme' + editnote_text = 'test edit comment' visit 'journals/1/edit' within 'form#journal-1-form' do @@ -161,7 +165,9 @@ def log_user(login, password) end click_button 'commit' - expect(journals.find(1).first.notes).to eq editnote_text + expect(page).to have_current_path('/issues/1', wait: true) + + expect(Journal.find(1).notes).to eq editnote_text end end