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

Pass correct nil

Oliver Günther74fa859e5f60
diff --git a/.rubocop.yml b/.rubocop.yml
index d245164e264..addb52904d6 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -208,6 +208,8 @@ Rails/DynamicFindBy:
- 'spec/features/**/*.rb'
- 'spec/support/**/*.rb'
- 'modules/*/spec/features/**/*.rb'
+ Whitelist:
+ - find_by_login
# We have config.active_record.belongs_to_required_by_default = false ,
# which means, we do have to declare presence validators on belongs_to relations.
diff --git a/modules/auth_plugins/spec/views/base.html.erb_spec.rb b/modules/auth_plugins/spec/views/base.html.erb_spec.rb
index dff8b94e056..a7e45ad22b4 100644
--- a/modules/auth_plugins/spec/views/base.html.erb_spec.rb
+++ b/modules/auth_plugins/spec/views/base.html.erb_spec.rb
@@ -36,9 +36,8 @@ RSpec.describe "layouts/base" do
before do
without_partial_double_verification do
- allow(view).to receive(:current_menu_item).and_return("overview")
allow(view).to receive(:default_breadcrumb)
- allow(view).to receive(:current_user).and_return anonymous
+ allow(view).to receive_messages(current_menu_item: "overview", current_user: anonymous)
end
allow(OpenProject::Plugins::AuthPlugin).to receive(:providers).and_return([provider])
end
diff --git a/modules/costs/spec/lib/api/v3/costs_api_user_permission_check_spec.rb b/modules/costs/spec/lib/api/v3/costs_api_user_permission_check_spec.rb
index 5d5a4477d2f..988264b0d6b 100644
--- a/modules/costs/spec/lib/api/v3/costs_api_user_permission_check_spec.rb
+++ b/modules/costs/spec/lib/api/v3/costs_api_user_permission_check_spec.rb
@@ -53,8 +53,7 @@ RSpec.describe API::V3::CostsApiUserPermissionCheck do
before do
without_partial_double_verification do
- allow(subject).to receive(:current_user).and_return(user)
- allow(subject).to receive(:represented).and_return(work_package)
+ allow(subject).to receive_messages(current_user: user, represented: work_package) # rubocop:disable RSpec/SubjectStub
end
mock_permissions_for(user) do |mock|
diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb
index 4a5387222d7..e0477e4de28 100644
--- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb
+++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe TwoFactorAuthentication::AuthenticationController, with_settings:
session[:stage_secrets] = { two_factor_authentication: "asdf" }
without_partial_double_verification do
- allow_any_instance_of(User).to receive(:any_active_memberships?).and_return(true)
+ allow_any_instance_of(User).to receive(:any_active_memberships?).and_return(true) # rubocop:disable RSpec/AnyInstance
end
end
diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb
index 44710cc06ad..e2bd9744abd 100644
--- a/spec/controllers/concerns/omniauth_login_spec.rb
+++ b/spec/controllers/concerns/omniauth_login_spec.rb
@@ -29,8 +29,8 @@
require "spec_helper"
# Concern is included into AccountController and depends on methods available there
-RSpec.describe AccountController, :skip_2fa_stage do
- let(:omniauth_strategy) { double("Google Strategy", name: "google") }
+RSpec.describe AccountController, :skip_2fa_stage do # rubocop:disable RSpec/SpecFilePathFormat
+ let(:omniauth_strategy) { double("Google Strategy", name: "google") } # rubocop:disable RSpec/VerifiedDoubles
let(:omniauth_hash) do
OmniAuth::AuthHash.new(
provider: "google",
@@ -52,9 +52,9 @@ RSpec.describe AccountController, :skip_2fa_stage do
User.current = nil
end
- context "GET #omniauth_login", with_settings: { self_registration: Setting::SelfRegistration.automatic } do
- describe "with on-the-fly registration" do
- context "providing all required fields" do
+ describe "GET #omniauth_login", with_settings: { self_registration: Setting::SelfRegistration.automatic } do
+ context "with on-the-fly registration" do
+ context "when providing all required fields" do
before do
request.env["omniauth.origin"] = "https://example.net/some_back_url"
post :omniauth_login, params: { provider: :google }
@@ -118,7 +118,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
)
end
- context "available" do
+ describe "available" do
it "merges the strategy mapping" do
allow(omniauth_strategy).to receive(:omniauth_hash_to_user_attributes) do |auth|
raw_info = auth[:extra][:raw_info]
@@ -129,18 +129,18 @@ RSpec.describe AccountController, :skip_2fa_stage do
}
end
- expect(omniauth_strategy).to receive(:omniauth_hash_to_user_attributes)
-
post :omniauth_login, params: { provider: :google }
user = User.find_by_login("[email protected]")
expect(user).to be_an_instance_of(User)
expect(user.firstname).to eql("foo")
expect(user.lastname).to eql("bar")
+
+ expect(omniauth_strategy).to have_received(:omniauth_hash_to_user_attributes)
end
end
- context "unavailable" do
+ describe "unavailable" do
it "keeps the default mapping" do
post :omniauth_login, params: { provider: :google }
@@ -152,7 +152,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
end
- context "not providing all required fields" do
+ context "when not providing all required fields" do
let(:omniauth_hash) do
OmniAuth::AuthHash.new(
provider: "google",
@@ -169,7 +169,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
it "registers user via post" do
- expect(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |user, auth_hash|
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |user, auth_hash|
new_user = User.find_by_login("[email protected]")
expect(user).to eq new_user
expect(auth_hash).to include(omniauth_hash)
@@ -177,7 +177,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
auth_source_registration = omniauth_hash.merge(
omniauth: true,
- timestamp: Time.new
+ timestamp: Time.zone.now
)
session[:auth_source_registration] = auth_source_registration
post :register,
@@ -198,11 +198,11 @@ RSpec.describe AccountController, :skip_2fa_stage do
expect(user.identity_url).to eql("google:123545")
end
- context "after a timeout expired" do
+ context "when after a timeout expired" do
before do
session[:auth_source_registration] = omniauth_hash.merge(
omniauth: true,
- timestamp: Time.new - 42.days
+ timestamp: 42.days.ago
)
end
@@ -220,21 +220,6 @@ RSpec.describe AccountController, :skip_2fa_stage do
expect(flash[:error]).to eq(I18n.t(:error_omniauth_registration_timed_out))
expect(User.find_by_login("[email protected]")).to be_nil
end
-
- it "does not register the user when providing all the missing fields" do
- post :register,
- params: {
- user: {
- firstname: "Foo",
- # lastname intentionally not provided
- }
- }
-
- expect(response).to redirect_to signin_path
- expect(flash[:error]).to eq(I18n.t(:error_omniauth_registration_timed_out))
- expect(User.find_by_login("[email protected]")).to be_nil
- end
end
end
@@ -390,8 +375,8 @@ RSpec.describe AccountController, :skip_2fa_stage do
OpenProject::OmniAuth::Authorization.callbacks.clear
end
- it "works" do
- expect(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |u, auth|
+ it "logs in the user" do
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |u, auth|
expect(u).to eq user
expect(auth).to eq omniauth_hash
end
@@ -407,22 +392,26 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
it "is rejected against google" do
- expect(OpenProject::OmniAuth::Authorization).not_to receive(:after_login!).with(user, any_args)
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!)
post :omniauth_login, params: { provider: :google }
expect(response).to redirect_to signin_path
expect(flash[:error]).to eq "I only want to see [email protected] here."
+
+ expect(OpenProject::OmniAuth::Authorization).not_to have_received(:after_login!).with(user, any_args)
end
it "is rejected against any other provider too" do
- expect(OpenProject::OmniAuth::Authorization).not_to receive(:after_login!).with(user, any_args)
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!)
omniauth_hash.provider = "any other"
post :omniauth_login, params: { provider: :google }
expect(response).to redirect_to signin_path
expect(flash[:error]).to eq "I only want to see [email protected] here."
+
+ expect(OpenProject::OmniAuth::Authorization).not_to have_received(:after_login!).with(user, any_args)
end
end
@@ -434,16 +423,18 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
it "is rejected against google" do
- expect(OpenProject::OmniAuth::Authorization).not_to receive(:after_login!).with(user, any_args)
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!)
post :omniauth_login, params: { provider: :google }
expect(response).to redirect_to signin_path
expect(flash[:error]).to eq "Go away foo!"
+
+ expect(OpenProject::OmniAuth::Authorization).not_to have_received(:after_login!).with(user, any_args)
end
it "is approved against any other provider" do
- expect(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |u|
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!) do |u|
new_user = User.find_by identity_url: "some other:123545"
expect(u).to eq new_user
@@ -461,7 +452,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
# ... and to confirm that, here's what happens when the authorization fails
it "is rejected against any other provider with the wrong email" do
- expect(OpenProject::OmniAuth::Authorization).not_to receive(:after_login!).with(user, any_args)
+ allow(OpenProject::OmniAuth::Authorization).to receive(:after_login!)
omniauth_hash.provider = "yet another"
config.global_email = "[email protected]"
@@ -470,6 +461,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
expect(response).to redirect_to signin_path
expect(flash[:error]).to eq "I only want to see [email protected] here."
+ expect(OpenProject::OmniAuth::Authorization).not_to have_received(:after_login!).with(user, any_args)
end
end
end
@@ -541,7 +533,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
it "does not sign in the user" do
- expect(controller.send(:current_user).logged?).to be_falsey
+ expect(controller.send(:current_user)).not_to be_logged
end
it "does not set registration information in the session" do
@@ -556,8 +548,10 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
it "logs a warn message" do
- expect(Rails.logger).to receive(:warn).with("invalid_credentials")
+ allow(Rails.logger).to receive(:warn)
post :omniauth_failure, params: { message: "invalid_credentials" }
+
+ expect(Rails.logger).to have_received(:warn).with("invalid_credentials")
end
end
end
diff --git a/spec/lib/acts_as_list/acts_as_list_patch_spec.rb b/spec/lib/acts_as_list/acts_as_list_patch_spec.rb
index 635ec04fccb..f7409075211 100644
--- a/spec/lib/acts_as_list/acts_as_list_patch_spec.rb
+++ b/spec/lib/acts_as_list/acts_as_list_patch_spec.rb
@@ -28,50 +28,65 @@
require "spec_helper"
-RSpec.describe "Models acting as list (acts_as_list)" do
+RSpec.describe "Models acting as list (acts_as_list)" do # rubocop:disable RSpec/DescribeClass
it "includes the patch" do
expect(ActiveRecord::Acts::List::InstanceMethods.included_modules).to include(OpenProject::Patches::ActsAsList)
end
describe "#move_to=" do
let(:includer) do
- class ActsAsListPatchIncluder
+ clazz = Class.new do
include OpenProject::Patches::ActsAsList
+
+ def move_to_top; end
+
+ def move_to_bottom; end
+
+ def move_higher; end
+
+ def move_lower; end
end
- ActsAsListPatchIncluder.new
+ clazz.new
+ end
+
+ before do
+ allow(includer).to receive(:move_to_top)
+ allow(includer).to receive(:move_to_bottom)
+ allow(includer).to receive(:move_higher)
+ allow(includer).to receive(:move_lower)
end
it "moves to top when wanting to move highest" do
+ includer.move_to = "highest"
+
without_partial_double_verification do
- expect(includer).to receive :move_to_top
+ expect(includer).to have_received :move_to_top
end
-
- includer.move_to = "highest"
end
it "moves to bottom when wanting to move lowest" do
+ includer.move_to = "lowest"
+
without_partial_double_verification do
- expect(includer).to receive :move_to_bottom
+ expect(includer).to have_received :move_to_bottom
end
-
- includer.move_to = "lowest"
end
it "moves higher when wanting to move higher" do
+ includer.move_to = "higher"
+
without_partial_double_verification do
- expect(includer).to receive :move_higher
+ expect(includer).to have_received :move_higher
end
-
- includer.move_to = "higher"
end
it "moves lower when wanting to move lower" do
+ includer.move_to = "lower"
+
without_partial_double_verification do
- expect(includer).to receive :move_lower
+ expect(includer).to have_received :move_lower
end
-
- includer.move_to = "lower"
end
end
end
diff --git a/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb b/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
index 9d95eba9080..a567fbdbcb9 100644
--- a/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
@@ -89,11 +89,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, "render
.with(:wrapped?)
.and_return(true)
allow(wp)
- .to receive(:available_custom_fields)
- .and_return(available_custom_fields)
- allow(wp)
- .to receive(:custom_field_values)
- .and_return([custom_value])
+ .to receive_messages(available_custom_fields:, custom_field_values: [custom_value])
end
end
let(:timestamp) { Timestamp.new(1.day.ago) }
@@ -109,23 +105,11 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, "render
# Mimicking the eager loading wrapper
without_partial_double_verification do
allow(model)
- .to receive(:timestamp)
- .and_return(timestamp)
- allow(model)
- .to receive(:attributes_changed_to_baseline)
- .and_return(attributes_changed_to_baseline)
- allow(model)
- .to receive(:exists_at_timestamp?)
- .and_return(exists_at_timestamp)
- allow(model)
- .to receive(:with_query?)
- .and_return(with_query)
- allow(model)
- .to receive(:matches_filters_at_timestamp?)
- .and_return(matches_filters_at_timestamp)
- allow(model)
- .to receive(:exists_at_current_timestamp?)
- .and_return(exists_at_current_timestamp)
+ .to receive_messages(timestamp:, attributes_changed_to_baseline:,
+ exists_at_timestamp?: exists_at_timestamp,
+ with_query?: with_query,
+ matches_filters_at_timestamp?: matches_filters_at_timestamp,
+ exists_at_current_timestamp?: exists_at_current_timestamp)
end
end
end
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index ec7e65cce61..38e7ae1d4fd 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -1583,20 +1583,18 @@ RSpec.describe WorkPackages::SetAttributesService,
end
before do
- allow(new_project)
- .to receive(:shared_versions)
- .and_return(new_versions)
- allow(new_project_categories)
+ without_partial_double_verification do
+ allow(new_project_categories)
.to receive(:find_by)
.with(name: category.name)
.and_return nil
- allow(new_project)
- .to receive(:types)
- .and_return(new_types)
- allow(new_types)
- .to receive(:order)
- .with(:position)
- .and_return(new_types)
+ allow(new_project)
+ .to receive_messages(shared_versions: new_versions, types: new_types)
+ allow(new_types)
+ .to receive(:order)
+ .with(:position)
+ .and_return(new_types)
+ end
end
shared_examples_for "updating the project" do
@@ -1775,7 +1773,7 @@ RSpec.describe WorkPackages::SetAttributesService,
subject { instance.call(call_attributes) }
context "for non existing fields" do
- let(:call_attributes) { { custom_field_891: "1" } } # rubocop:disable Naming/VariableNumber
+ let(:call_attributes) { { custom_field_891: "1" } }
before do
subject
diff --git a/spec/support/shared/with_direct_uploads.rb b/spec/support/shared/with_direct_uploads.rb
index 1c192159274..05d86f913d7 100644
--- a/spec/support/shared/with_direct_uploads.rb
+++ b/spec/support/shared/with_direct_uploads.rb
@@ -149,6 +149,7 @@ class WithDirectUploads
creds = config[:fog][:credentials]
without_partial_double_verification do
+ # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(FogFileUploader).to receive(:fog_credentials).and_return creds
allow_any_instance_of(FogFileUploader).to receive(:aws_access_key_id).and_return creds[:aws_access_key_id]
@@ -158,6 +159,7 @@ class WithDirectUploads
allow_any_instance_of(FogFileUploader).to receive(:directory).and_return config[:fog][:directory]
allow(OpenProject::Configuration).to receive(:direct_uploads?).and_return(true)
+ # rubocop:enable RSpec/AnyInstance
end
end
diff --git a/spec/support_spec/mocked_permission_helper_spec.rb b/spec/support_spec/mocked_permission_helper_spec.rb
index 5cf36015711..23422f86b5d 100644
--- a/spec/support_spec/mocked_permission_helper_spec.rb
+++ b/spec/support_spec/mocked_permission_helper_spec.rb
@@ -185,7 +185,7 @@ RSpec.describe MockedPermissionHelper do
end
it "allows the project permission when querying with controller and action hash" do
- expect(user).to be_allowed_in_project({ controller: "work_packages", action: "index", project_id: project.id })
+ expect(user).to be_allowed_in_project({ controller: "work_packages", action: "index", project_id: project.id }, nil)
expect(user).to be_allowed_in_any_project({ controller: "work_packages", action: "index" })
end
diff --git a/spec/views/layouts/admin.html.erb_spec.rb b/spec/views/layouts/admin.html.erb_spec.rb
index d71a6dfa0a7..cd0aec85ecf 100644
--- a/spec/views/layouts/admin.html.erb_spec.rb
+++ b/spec/views/layouts/admin.html.erb_spec.rb
@@ -36,13 +36,12 @@ RSpec.describe "layouts/admin" do
before do
without_partial_double_verification do
- allow(view).to receive(:current_menu_item).and_return("overview")
allow(view).to receive(:default_breadcrumb)
- allow(view).to receive(:current_user).and_return admin
parent_menu_item = Object.new
allow(parent_menu_item).to receive(:name).and_return :root
- allow(view).to receive(:admin_first_level_menu_entry).and_return parent_menu_item
+ allow(view).to receive_messages(current_menu_item: "overview", current_user: admin,
+ admin_first_level_menu_entry: parent_menu_item)
allow(controller).to receive(:default_search_scope)
allow(view).to receive(:render_to_string)
diff --git a/spec/views/layouts/base.html.erb_spec.rb b/spec/views/layouts/base.html.erb_spec.rb
index 3b895a88847..1031875f376 100644
--- a/spec/views/layouts/base.html.erb_spec.rb
+++ b/spec/views/layouts/base.html.erb_spec.rb
@@ -42,11 +42,10 @@ RSpec.describe "layouts/base" do
before do
without_partial_double_verification do
- allow(view).to receive(:current_menu_item).and_return("overview")
allow(view).to receive(:default_breadcrumb)
allow(controller).to receive(:default_search_scope)
allow(view).to receive(:render_to_string)
- allow(view).to receive(:current_user).and_return current_user
+ allow(view).to receive_messages(current_menu_item: "overview", current_user:)
end
allow(User).to receive(:current).and_return current_user
diff --git a/spec/views/users/index.html.erb_spec.rb b/spec/views/users/index.html.erb_spec.rb
index cbfb9d85eff..ac1dbdb7c2f 100644
--- a/spec/views/users/index.html.erb_spec.rb
+++ b/spec/views/users/index.html.erb_spec.rb
@@ -40,9 +40,7 @@ RSpec.describe "users/index" do
assign(:groups, Group.all)
without_partial_double_verification do
- allow(view).to receive(:current_user).and_return(admin)
- allow(view).to receive(:controller_name).and_return("users")
- allow(view).to receive(:action_name).and_return("index")
+ allow(view).to receive_messages(current_user: admin, controller_name: "users", action_name: "index")
end
end