Skip to content

Commit

Permalink
Fixes zammad#1103 - 'time_unit' attribute is not propagated over tick…
Browse files Browse the repository at this point in the history
…et articles API.

Co-authored-by: Florian Liebe <[email protected]>
Co-authored-by: Tobias Schäfer <[email protected]>
  • Loading branch information
fliebe92 and tschaefer committed Jun 6, 2023
1 parent 1a90563 commit 99c1694
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/ticket/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def sanitizeable?(attribute, _value)
def attributes_with_association_names(empty_keys: false)
attributes = super
add_attachments_to_attributes(attributes)
add_time_unit_to_attributes(attributes)
Ticket::Article.insert_urls(attributes)
end

Expand Down Expand Up @@ -318,6 +319,11 @@ def add_attachments_to_attributes(attributes)
attributes
end

def add_time_unit_to_attributes(attributes)
attributes['time_unit'] = ticket_time_accounting&.time_unit.presence || nil
attributes
end

# strip not wanted chars
def check_subject
return true if subject.blank?
Expand Down
35 changes: 35 additions & 0 deletions spec/requests/ticket/article/time_accounting_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe 'Ticket::Article API > Time Accounting', :aggregate_failures, type: :request do
describe 'GET /api/v1/ticket_articles' do
let(:agent) { create(:agent, groups: Group.all) }
let(:ticket) { create(:ticket) }
let(:article) { create(:ticket_article, ticket: ticket) }
let(:accounted_time) { create(:ticket_time_accounting, ticket: ticket, ticket_article: article, time_unit: 42) }

before do
article && accounted_time

authenticated_as(agent)
get "/api/v1/ticket_articles/#{article.id}?expand=true"
end

context 'when no time was accounted' do
let(:accounted_time) { nil }

it 'returns nil' do
expect(response).to have_http_status(:ok)
expect(json_response['time_unit']).to be_nil
end
end

context 'when time was accounted' do
it 'returns the accounted time' do
expect(response).to have_http_status(:ok)
expect(json_response['time_unit']).to eq(accounted_time.time_unit.to_s)
end
end
end
end

0 comments on commit 99c1694

Please sign in to comment.