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

adapt specs to altered interface

ulfertscd3ffe0cc53f
diff --git a/app/contracts/queries/base_contract.rb b/app/contracts/queries/base_contract.rb
index 23db2a6560d..68d5eab36e1 100644
--- a/app/contracts/queries/base_contract.rb
+++ b/app/contracts/queries/base_contract.rb
@@ -58,14 +58,6 @@ module Queries
Query
end
- attr_reader :user
-
- def initialize(query, user)
- super(query, user)
-
- @user = user
- end
-
def validate
validate_project
user_allowed_to_make_public
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rb
index d386bb0cc4f..0c02886c950 100644
--- a/app/contracts/users/base_contract.rb
+++ b/app/contracts/users/base_contract.rb
@@ -48,12 +48,6 @@ module Users
User
end
- def initialize(user, current_user)
- super(user, current_user)
-
- @current_user = current_user
- end
-
def validate
existing_auth_source
@@ -62,8 +56,6 @@ module Users
private
- attr_reader :current_user
-
def existing_auth_source
if auth_source_id && AuthSource.find_by_unique(auth_source_id).nil?
errors.add :auth_source, :error_not_found
diff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rb
index 7960429c5d7..6e3012c74a4 100644
--- a/app/contracts/users/create_contract.rb
+++ b/app/contracts/users/create_contract.rb
@@ -55,7 +55,7 @@ module Users
##
# Users can only be created by Admins
def user_allowed_to_add
- unless current_user.admin?
+ unless user.admin?
errors.add :base, :error_unauthorized
end
end
diff --git a/app/contracts/users/update_contract.rb b/app/contracts/users/update_contract.rb
index 4a73d0f2194..68b1acd4f51 100644
--- a/app/contracts/users/update_contract.rb
+++ b/app/contracts/users/update_contract.rb
@@ -43,7 +43,7 @@ module Users
##
# Users can only be updated by Admins
def user_allowed_to_update
- unless current_user.admin?
+ unless user.admin?
errors.add :base, :error_unauthorized
end
end
diff --git a/app/contracts/work_packages/create_note_contract.rb b/app/contracts/work_packages/create_note_contract.rb
index 6f08600c5db..92d029c47c1 100644
--- a/app/contracts/work_packages/create_note_contract.rb
+++ b/app/contracts/work_packages/create_note_contract.rb
@@ -33,22 +33,20 @@ module WorkPackages
WorkPackage
end
- attr_accessor :policy
-
attribute :journal_notes do
errors.add(:journal_notes, :error_unauthorized) unless can?(:comment)
end
- def initialize(work_package, user)
- super(work_package, user)
-
- self.policy = WorkPackagePolicy.new(user)
- end
-
private
def can?(permission)
policy.allowed?(model, permission)
end
+
+ attr_writer :policy
+
+ def policy
+ @policy ||= WorkPackagePolicy.new(user)
+ end
end
end
diff --git a/modules/grids/spec/services/grids/set_attributes_service_spec.rb b/modules/grids/spec/services/grids/set_attributes_service_spec.rb
index fac38fbd9b2..f297a619ff1 100644
--- a/modules/grids/spec/services/grids/set_attributes_service_spec.rb
+++ b/modules/grids/spec/services/grids/set_attributes_service_spec.rb
@@ -37,7 +37,7 @@ describe Grids::SetAttributesService, type: :model do
allow(contract)
.to receive(:new)
- .with(grid, user)
+ .with(grid, user, options: { changed_by_system: [] })
.and_return(contract_instance)
contract
diff --git a/spec/contracts/work_packages/create_note_contract_spec.rb b/spec/contracts/work_packages/create_note_contract_spec.rb
index 4693e995d12..02974b1ce4a 100644
--- a/spec/contracts/work_packages/create_note_contract_spec.rb
+++ b/spec/contracts/work_packages/create_note_contract_spec.rb
@@ -42,13 +42,13 @@ describe WorkPackages::CreateNoteContract do
let(:user) { FactoryBot.build_stubbed(:user) }
let(:policy_instance) { double('WorkPackagePolicyInstance') }
- subject(:contract) {
+ subject(:contract) do
contract = described_class.new(work_package, user)
- contract.policy = policy_instance
+ contract.send(:'policy=', policy_instance)
contract
- }
+ end
describe 'note' do
before do
diff --git a/spec/services/custom_actions/update_work_package_service_spec.rb b/spec/services/custom_actions/update_work_package_service_spec.rb
index 5b191e0d9e7..4a1eaba3385 100644
--- a/spec/services/custom_actions/update_work_package_service_spec.rb
+++ b/spec/services/custom_actions/update_work_package_service_spec.rb
@@ -94,7 +94,7 @@ describe CustomActions::UpdateWorkPackageService do
allow(WorkPackages::UpdateContract)
.to receive(:new)
- .with(work_package, user)
+ .with(work_package, user, options: { changed_by_system: [] })
.and_return(contract)
allow(contract)
diff --git a/spec/services/members/set_attributes_service_spec.rb b/spec/services/members/set_attributes_service_spec.rb
index 93203675886..396ecac7b26 100644
--- a/spec/services/members/set_attributes_service_spec.rb
+++ b/spec/services/members/set_attributes_service_spec.rb
@@ -37,7 +37,7 @@ describe Members::SetAttributesService, type: :model do
allow(contract)
.to receive(:new)
- .with(member, user)
+ .with(member, user, options: { changed_by_system: [] })
.and_return(contract_instance)
contract
diff --git a/spec/services/projects/schedule_deletion_service_spec.rb b/spec/services/projects/schedule_deletion_service_spec.rb
index 8009f59a922..ed11655f6b5 100644
--- a/spec/services/projects/schedule_deletion_service_spec.rb
+++ b/spec/services/projects/schedule_deletion_service_spec.rb
@@ -34,7 +34,7 @@ describe ::Projects::ScheduleDeletionService, type: :model do
allow(contract)
.to receive(:new)
- .with(project, user)
+ .with(project, user, options: { changed_by_system: [] })
.and_return(contract_instance)
contract
diff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rb
index 261e1fd8b29..9e1574c6d4f 100644
--- a/spec/services/projects/set_attributes_service_spec.rb
+++ b/spec/services/projects/set_attributes_service_spec.rb
@@ -37,8 +37,8 @@ describe Projects::SetAttributesService, type: :model do
allow(contract)
.to receive(:new)
- .with(project, user)
- .and_return(contract_instance)
+ .with(project, user, options: { changed_by_system: [] })
+ .and_return(contract_instance)
contract
end
diff --git a/spec/services/relations/create_service_spec.rb b/spec/services/relations/create_service_spec.rb
index 8616304ac9c..35e14a625e1 100644
--- a/spec/services/relations/create_service_spec.rb
+++ b/spec/services/relations/create_service_spec.rb
@@ -86,7 +86,7 @@ describe Relations::CreateService do
allow(Relations::CreateContract)
.to receive(:new)
- .with(relation, user)
+ .with(relation, user, options: { changed_by_system: [] })
.and_return(contract)
allow(contract)
.to receive(:validate)
diff --git a/spec/services/relations/update_service_spec.rb b/spec/services/relations/update_service_spec.rb
index 7c6f0428710..544288fa171 100644
--- a/spec/services/relations/update_service_spec.rb
+++ b/spec/services/relations/update_service_spec.rb
@@ -86,7 +86,7 @@ describe Relations::UpdateService do
allow(Relations::UpdateContract)
.to receive(:new)
- .with(relation, user)
+ .with(relation, user, options: { changed_by_system: [] })
.and_return(contract)
allow(contract)
.to receive(:validate)
diff --git a/spec/services/time_entries/set_attributes_service_spec.rb b/spec/services/time_entries/set_attributes_service_spec.rb
index 597bf1e8a93..2eb059de543 100644
--- a/spec/services/time_entries/set_attributes_service_spec.rb
+++ b/spec/services/time_entries/set_attributes_service_spec.rb
@@ -61,7 +61,7 @@ describe TimeEntries::SetAttributesService, type: :model do
let(:contract_class) do
allow(TimeEntries::CreateContract)
.to receive(:new)
- .with(anything, user)
+ .with(anything, user, options: { changed_by_system: [] })
.and_return(contract_instance)
TimeEntries::CreateContract