Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/60718 activity field populates automatically #17675

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions modules/costs/app/services/time_entries/set_attributes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def set_attributes(_attributes) # rubocop:disable Metrics/AbcSize
def set_default_attributes(*)
set_default_user
set_default_hours
set_default_activity if model.activity.nil?
end

def set_logged_by
Expand All @@ -73,28 +72,6 @@ def set_default_user
end
end

def set_default_activity
return unless TimeEntryActivity.default

if model.project
assign_default_project_activity
else
assign_default_activity
end
end

def assign_default_project_activity
if TimeEntryActivity.active_in_project(model.project).exists?(id: TimeEntryActivity.default.id)
assign_default_activity
end
end

def assign_default_activity
model.change_by_system do
model.activity = TimeEntryActivity.default
end
end

def set_default_hours
model.hours = nil if model.hours&.zero?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
let(:hours) { 5.0 }
let(:comments) { "some comment" }
let(:contract_instance) do
contract = double("contract_instance") # rubocop:disable RSpec/VerifiedDoubles
allow(contract)
.to receive(:validate)
.and_return(contract_valid)
allow(contract)
.to receive(:errors)
.and_return(contract_errors)
contract
double("contract_instance").tap do |contract| # rubocop:disable RSpec/VerifiedDoubles
allow(contract).to receive_messages(
validate: contract_valid,
errors: contract_errors
)
end
end

let(:contract_errors) { double("contract_errors") } # rubocop:disable RSpec/VerifiedDoubles
Expand Down Expand Up @@ -103,17 +101,6 @@
.to eql [nil, user.id]
end

it "assigns the default TimeEntryActivity" do
allow(TimeEntryActivity)
.to receive(:default)
.and_return(default_activity)

subject

expect(time_entry_instance.activity)
.to eql default_activity
end

context "with params" do
let(:params) do
{
Expand Down
24 changes: 15 additions & 9 deletions spec/models/changeset_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
Expand Down Expand Up @@ -80,7 +82,7 @@
end

describe "stripping commit" do
let(:comment) { "This is a looooooooooooooong comment" + (((" " * 80) + "\n") * 5) }
let(:comment) { "This is a looooooooooooooong comment#{"#{' ' * 80}\n" * 5}" }

with_virtual_subversion_repository do
let(:changeset) do
Expand Down Expand Up @@ -219,9 +221,11 @@
repository.project.save!
end

it "refs keywords any with timelog" do
allow(Setting).to receive(:commit_ref_keywords).and_return "*"
allow(Setting).to receive(:commit_logtime_enabled?).and_return true
it "refs keywords any with timelog" do # rubocop:disable RSpec/ExampleLength
allow(Setting).to receive_messages(
commit_ref_keywords: "*",
commit_logtime_enabled?: true
)

{
"2" => 2.0,
Expand Down Expand Up @@ -259,7 +263,7 @@
expect(time.hours).to eq expected_hours
expect(time.spent_on).to eq Date.yesterday

expect(time.activity.is_default).to be true
expect(time.activity).to be_nil
expect(time.comments).to include "r520"
end
end
Expand All @@ -268,10 +272,12 @@
let!(:work_package2) { create(:work_package, project: repository.project, status: open_status) }

it "refs keywords closing with timelog" do
allow(Setting).to receive(:commit_fix_status_id).and_return closed_status.id
allow(Setting).to receive(:commit_ref_keywords).and_return "*"
allow(Setting).to receive(:commit_fix_keywords).and_return "fixes , closes"
allow(Setting).to receive(:commit_logtime_enabled?).and_return true
allow(Setting).to receive_messages(
commit_fix_status_id: closed_status.id,
commit_ref_keywords: "*",
commit_fix_keywords: "fixes , closes",
commit_logtime_enabled?: true
)

c = build(:changeset,
repository:,
Expand Down
Loading