Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix broken tests

Christophe Bliard86ce8c41140a
diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb
index b2932328870..cb910d6e685 100644
--- a/app/helpers/tabs_helper.rb
+++ b/app/helpers/tabs_helper.rb
@@ -43,7 +43,7 @@ module TabsHelper
# Render tabs from the ui/extensible tabs manager
def render_extensible_tabs(key, params = {})
- tabs = ::OpenProject::Ui::ExtensibleTabs.enabled_tabs(key, params).map do |tab|
+ tabs = ::OpenProject::Ui::ExtensibleTabs.enabled_tabs(key, params.reverse_merge(current_user:)).map do |tab|
path = tab[:path].respond_to?(:call) ? instance_exec(params, &tab[:path]) : tab[:path]
tab.dup.merge(path:)
end
diff --git a/lib/open_project/ui/extensible_tabs.rb b/lib/open_project/ui/extensible_tabs.rb
index 40855c41cb2..5e1ad85ed62 100644
--- a/lib/open_project/ui/extensible_tabs.rb
+++ b/lib/open_project/ui/extensible_tabs.rb
@@ -63,7 +63,7 @@ module OpenProject
path: ->(params) { edit_user_path(params[:user], tab: :general) },
label: :label_general,
only_if: ->(context) {
- Users::UpdateContract.new(context[:user], User.current).allowed_to_update?
+ Users::UpdateContract.new(context[:user], context[:current_user]).allowed_to_update?
}
},
{
diff --git a/spec/helpers/tabs_helper_spec.rb b/spec/helpers/tabs_helper_spec.rb
index 73884ffe456..25ca4e8115c 100644
--- a/spec/helpers/tabs_helper_spec.rb
+++ b/spec/helpers/tabs_helper_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
RSpec.describe TabsHelper do
- include TabsHelper
+ include described_class
let(:given_tab) do
{ name: 'avatar',
@@ -46,6 +46,9 @@ RSpec.describe TabsHelper do
end
describe 'render_extensible_tabs' do
+ let(:current_user) { build(:user) }
+ let(:user) { build(:user, id: 2) }
+
before do
allow_any_instance_of(TabsHelper)
.to receive(:render_tabs)
@@ -54,16 +57,14 @@ RSpec.describe TabsHelper do
allow(OpenProject::Ui::ExtensibleTabs)
.to receive(:enabled_tabs)
- .with(:user)
+ .with(:user, a_hash_including(user:, current_user:))
.and_return [given_tab]
-
- user = build(:user, id: 2)
- @tabs = render_extensible_tabs(:user, user:)
end
it "returns an evaluated path" do
- expect(response.status).to eq 200
- expect(@tabs).to eq([expected_tab])
+ tabs = render_extensible_tabs(:user, user:)
+ expect(response).to have_http_status :ok
+ expect(tabs).to eq([expected_tab])
end
end
end
diff --git a/spec/views/users/edit.html.erb_spec.rb b/spec/views/users/edit.html.erb_spec.rb
index 7ec285015b0..b20872bc491 100644
--- a/spec/views/users/edit.html.erb_spec.rb
+++ b/spec/views/users/edit.html.erb_spec.rb
@@ -84,8 +84,8 @@ RSpec.describe 'users/edit' do
end
end
- context 'for a non-admin' do
- let(:non_admin) { create(:user) }
+ context 'for a non-admin with manage_user global permission' do
+ let(:non_admin) { create(:user, global_permissions: [:manage_user]) }
before do
allow(view).to receive(:current_user).and_return(non_admin)